Blender V4.3
MOD_shapekey.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_math_matrix.h"
10#include "BLI_utildefines.h"
11
12#include "BLT_translation.hh"
13
14#include "DNA_key_types.h"
15#include "DNA_object_types.h"
16
17#include "BKE_key.hh"
18
19#include "RNA_prototypes.hh"
20
21#include "MOD_modifiertypes.hh"
22
23#include "UI_resources.hh"
24
25static void deform_verts(ModifierData * /*md*/,
26 const ModifierEvalContext *ctx,
27 Mesh * /*mesh*/,
29{
30 Key *key = BKE_key_from_object(ctx->object);
31
32 if (key && key->block.first) {
33 int deformedVerts_tot;
35 &deformedVerts_tot,
36 reinterpret_cast<float *>(positions.data()),
37 sizeof(blender::float3) * positions.size(),
38 nullptr);
39 }
40}
41
43 const ModifierEvalContext *ctx,
44 Mesh *mesh,
47{
48 Key *key = BKE_key_from_object(ctx->object);
50
51 if (kb && kb->totelem == positions.size() && kb != key->refkey) {
52 float scale[3][3];
53 int a;
54
55 if (ctx->object->shapeflag & OB_SHAPE_LOCK) {
56 scale_m3_fl(scale, 1);
57 }
58 else {
59 scale_m3_fl(scale, kb->curval);
60 }
61
62 for (a = 0; a < positions.size(); a++) {
63 copy_m3_m3(matrices[a].ptr(), scale);
64 }
65 }
66
67 deform_verts(md, ctx, mesh, positions);
68}
69
71 const ModifierEvalContext *ctx,
72 const BMEditMesh * /*em*/,
73 Mesh *mesh,
75{
76 Key *key = BKE_key_from_object(ctx->object);
77
78 if (key && key->type == KEY_RELATIVE) {
79 deform_verts(md, ctx, mesh, positions);
80 }
81}
82
83static void deform_matrices_EM(ModifierData * /*md*/,
84 const ModifierEvalContext *ctx,
85 const BMEditMesh * /*em*/,
86 Mesh * /*mesh*/,
89{
90 Key *key = BKE_key_from_object(ctx->object);
92
93 if (kb && kb->totelem == matrices.size() && kb != key->refkey) {
94 float scale[3][3];
95 scale_m3_fl(scale, kb->curval);
96
97 for (int a = 0; a < matrices.size(); a++) {
98 copy_m3_m3(matrices[a].ptr(), scale);
99 }
100 }
101}
102
104 /*idname*/ "ShapeKey",
105 /*name*/ N_("ShapeKey"),
106 /*struct_name*/ "ShapeKeyModifierData",
107 /*struct_size*/ sizeof(ShapeKeyModifierData),
108 /*srna*/ &RNA_Modifier,
112 /*icon*/ ICON_DOT,
113
114 /*copy_data*/ nullptr,
115
116 /*deform_verts*/ deform_verts,
117 /*deform_matrices*/ deform_matrices,
118 /*deform_verts_EM*/ deform_verts_EM,
119 /*deform_matrices_EM*/ deform_matrices_EM,
120 /*modify_mesh*/ nullptr,
121 /*modify_geometry_set*/ nullptr,
122
123 /*init_data*/ nullptr,
124 /*required_data_mask*/ nullptr,
125 /*free_data*/ nullptr,
126 /*is_disabled*/ nullptr,
127 /*update_depsgraph*/ nullptr,
128 /*depends_on_time*/ nullptr,
129 /*depends_on_normals*/ nullptr,
130 /*foreach_ID_link*/ nullptr,
131 /*foreach_tex_link*/ nullptr,
132 /*free_runtime_data*/ nullptr,
133 /*panel_register*/ nullptr,
134 /*blend_write*/ nullptr,
135 /*blend_read*/ nullptr,
136 /*foreach_cache*/ nullptr,
137};
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1905
float * BKE_key_evaluate_object_ex(Object *ob, int *r_totelem, float *arr, size_t arr_size, ID *obdata)
Definition key.cc:1522
Key * BKE_key_from_object(Object *ob)
Definition key.cc:1820
@ eModifierTypeFlag_AcceptsCVs
@ eModifierTypeFlag_SupportsEditmode
@ eModifierTypeFlag_AcceptsVertexCosOnly
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void scale_m3_fl(float R[3][3], float scale)
@ KEY_RELATIVE
struct ShapeKeyModifierData ShapeKeyModifierData
Object is a sort of wrapper for general info.
@ OB_SHAPE_LOCK
static void deform_matrices(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, blender::MutableSpan< blender::float3 > positions, blender::MutableSpan< blender::float3x3 > matrices)
static void deform_matrices_EM(ModifierData *, const ModifierEvalContext *ctx, const BMEditMesh *, Mesh *, blender::MutableSpan< blender::float3 >, blender::MutableSpan< blender::float3x3 > matrices)
ModifierTypeInfo modifierType_ShapeKey
static void deform_verts(ModifierData *, const ModifierEvalContext *ctx, Mesh *, blender::MutableSpan< blender::float3 > positions)
static void deform_verts_EM(ModifierData *md, const ModifierEvalContext *ctx, const BMEditMesh *, Mesh *mesh, blender::MutableSpan< blender::float3 > positions)
constexpr int64_t size() const
Definition BLI_span.hh:494
float curval
char type
ListBase block
KeyBlock * refkey
void * first
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4126