Blender  V2.93
MOD_shapekey.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 by the Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BLI_utildefines.h"
25 
26 #include "BLI_math.h"
27 
28 #include "DNA_key_types.h"
29 #include "DNA_mesh_types.h"
30 #include "DNA_object_types.h"
31 
32 #include "BKE_key.h"
33 #include "BKE_particle.h"
34 
35 #include "RNA_access.h"
36 
37 #include "MOD_modifiertypes.h"
38 
39 #include "UI_resources.h"
40 
41 static void deformVerts(ModifierData *UNUSED(md),
42  const ModifierEvalContext *ctx,
43  Mesh *UNUSED(mesh),
44  float (*vertexCos)[3],
45  int numVerts)
46 {
47  Key *key = BKE_key_from_object(ctx->object);
48 
49  if (key && key->block.first) {
50  int deformedVerts_tot;
52  ctx->object, &deformedVerts_tot, (float *)vertexCos, sizeof(*vertexCos) * numVerts);
53  }
54 }
55 
56 static void deformMatrices(ModifierData *md,
57  const ModifierEvalContext *ctx,
58  Mesh *mesh,
59  float (*vertexCos)[3],
60  float (*defMats)[3][3],
61  int numVerts)
62 {
63  Key *key = BKE_key_from_object(ctx->object);
65  float scale[3][3];
66 
67  (void)vertexCos; /* unused */
68 
69  if (kb && kb->totelem == numVerts && kb != key->refkey) {
70  int a;
71 
72  if (ctx->object->shapeflag & OB_SHAPE_LOCK) {
73  scale_m3_fl(scale, 1);
74  }
75  else {
76  scale_m3_fl(scale, kb->curval);
77  }
78 
79  for (a = 0; a < numVerts; a++) {
80  copy_m3_m3(defMats[a], scale);
81  }
82  }
83 
84  deformVerts(md, ctx, mesh, vertexCos, numVerts);
85 }
86 
87 static void deformVertsEM(ModifierData *md,
88  const ModifierEvalContext *ctx,
89  struct BMEditMesh *UNUSED(editData),
90  Mesh *mesh,
91  float (*vertexCos)[3],
92  int numVerts)
93 {
94  Key *key = BKE_key_from_object(ctx->object);
95 
96  if (key && key->type == KEY_RELATIVE) {
97  deformVerts(md, ctx, mesh, vertexCos, numVerts);
98  }
99 }
100 
102  const ModifierEvalContext *ctx,
103  struct BMEditMesh *UNUSED(editData),
104  Mesh *UNUSED(mesh),
105  float (*vertexCos)[3],
106  float (*defMats)[3][3],
107  int numVerts)
108 {
109  Key *key = BKE_key_from_object(ctx->object);
111  float scale[3][3];
112 
113  (void)vertexCos; /* unused */
114 
115  if (kb && kb->totelem == numVerts && kb != key->refkey) {
116  int a;
117  scale_m3_fl(scale, kb->curval);
118 
119  for (a = 0; a < numVerts; a++) {
120  copy_m3_m3(defMats[a], scale);
121  }
122  }
123 }
124 
126  /* name */ "ShapeKey",
127  /* structName */ "ShapeKeyModifierData",
128  /* structSize */ sizeof(ShapeKeyModifierData),
129  /* srna */ &RNA_Modifier,
130  /* type */ eModifierTypeType_OnlyDeform,
133  /* icon */ ICON_DOT,
134 
135  /* copyData */ NULL,
136 
137  /* deformVerts */ deformVerts,
138  /* deformMatrices */ deformMatrices,
139  /* deformVertsEM */ deformVertsEM,
140  /* deformMatricesEM */ deformMatricesEM,
141  /* modifyMesh */ NULL,
142  /* modifyHair */ NULL,
143  /* modifyGeometrySet */ NULL,
144  /* modifyVolume */ NULL,
145 
146  /* initData */ NULL,
147  /* requiredDataMask */ NULL,
148  /* freeData */ NULL,
149  /* isDisabled */ NULL,
150  /* updateDepsgraph */ NULL,
151  /* dependsOnTime */ NULL,
152  /* dependsOnNormals */ NULL,
153  /* foreachIDLink */ NULL,
154  /* foreachTexLink */ NULL,
155  /* freeRuntimeData */ NULL,
156  /* panelRegister */ NULL,
157  /* blendWrite */ NULL,
158  /* blendRead */ NULL,
159 };
float * BKE_key_evaluate_object_ex(struct Object *ob, int *r_totelem, float *arr, size_t arr_size)
Definition: key.c:1520
struct Key * BKE_key_from_object(const struct Object *ob)
struct KeyBlock * BKE_keyblock_from_object(struct Object *ob)
Definition: key.c:1902
@ eModifierTypeFlag_AcceptsCVs
Definition: BKE_modifier.h:81
@ eModifierTypeFlag_SupportsEditmode
Definition: BKE_modifier.h:83
@ eModifierTypeFlag_AcceptsVertexCosOnly
Definition: BKE_modifier.h:114
@ eModifierTypeType_OnlyDeform
Definition: BKE_modifier.h:58
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:89
void scale_m3_fl(float R[3][3], float scale)
Definition: math_matrix.c:2301
#define UNUSED(x)
@ KEY_RELATIVE
struct ShapeKeyModifierData ShapeKeyModifierData
Object is a sort of wrapper for general info.
@ OB_SHAPE_LOCK
ModifierTypeInfo modifierType_ShapeKey
Definition: MOD_shapekey.c:125
static void deformMatrices(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, float(*vertexCos)[3], float(*defMats)[3][3], int numVerts)
Definition: MOD_shapekey.c:56
static void deformVerts(ModifierData *UNUSED(md), const ModifierEvalContext *ctx, Mesh *UNUSED(mesh), float(*vertexCos)[3], int numVerts)
Definition: MOD_shapekey.c:41
static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *UNUSED(editData), Mesh *mesh, float(*vertexCos)[3], int numVerts)
Definition: MOD_shapekey.c:87
static void deformMatricesEM(ModifierData *UNUSED(md), const ModifierEvalContext *ctx, struct BMEditMesh *UNUSED(editData), Mesh *UNUSED(mesh), float(*vertexCos)[3], float(*defMats)[3][3], int numVerts)
Definition: MOD_shapekey.c:101
StructRNA RNA_Modifier
static unsigned a[3]
Definition: RandGen.cpp:92
float curval
Definition: DNA_key_types.h:50
char type
ListBase block
KeyBlock * refkey
Definition: DNA_key_types.h:88
void * first
Definition: DNA_listBase.h:47
struct Object * object
Definition: BKE_modifier.h:154
char shapeflag