Blender  V3.3
MOD_shapekey.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "BLI_utildefines.h"
9 
10 #include "BLI_math.h"
11 
12 #include "BLT_translation.h"
13 
14 #include "DNA_key_types.h"
15 #include "DNA_mesh_types.h"
16 #include "DNA_object_types.h"
17 
18 #include "BKE_key.h"
19 #include "BKE_particle.h"
20 
21 #include "RNA_access.h"
22 #include "RNA_prototypes.h"
23 
24 #include "MOD_modifiertypes.h"
25 
26 #include "UI_resources.h"
27 
28 static void deformVerts(ModifierData *UNUSED(md),
29  const ModifierEvalContext *ctx,
30  Mesh *UNUSED(mesh),
31  float (*vertexCos)[3],
32  int verts_num)
33 {
34  Key *key = BKE_key_from_object(ctx->object);
35 
36  if (key && key->block.first) {
37  int deformedVerts_tot;
39  ctx->object, &deformedVerts_tot, (float *)vertexCos, sizeof(*vertexCos) * verts_num, NULL);
40  }
41 }
42 
43 static void deformMatrices(ModifierData *md,
44  const ModifierEvalContext *ctx,
45  Mesh *mesh,
46  float (*vertexCos)[3],
47  float (*defMats)[3][3],
48  int verts_num)
49 {
50  Key *key = BKE_key_from_object(ctx->object);
52  float scale[3][3];
53 
54  (void)vertexCos; /* unused */
55 
56  if (kb && kb->totelem == verts_num && kb != key->refkey) {
57  int a;
58 
59  if (ctx->object->shapeflag & OB_SHAPE_LOCK) {
60  scale_m3_fl(scale, 1);
61  }
62  else {
63  scale_m3_fl(scale, kb->curval);
64  }
65 
66  for (a = 0; a < verts_num; a++) {
67  copy_m3_m3(defMats[a], scale);
68  }
69  }
70 
71  deformVerts(md, ctx, mesh, vertexCos, verts_num);
72 }
73 
74 static void deformVertsEM(ModifierData *md,
75  const ModifierEvalContext *ctx,
76  struct BMEditMesh *UNUSED(editData),
77  Mesh *mesh,
78  float (*vertexCos)[3],
79  int verts_num)
80 {
81  Key *key = BKE_key_from_object(ctx->object);
82 
83  if (key && key->type == KEY_RELATIVE) {
84  deformVerts(md, ctx, mesh, vertexCos, verts_num);
85  }
86 }
87 
89  const ModifierEvalContext *ctx,
90  struct BMEditMesh *UNUSED(editData),
91  Mesh *UNUSED(mesh),
92  float (*vertexCos)[3],
93  float (*defMats)[3][3],
94  int verts_num)
95 {
96  Key *key = BKE_key_from_object(ctx->object);
98  float scale[3][3];
99 
100  (void)vertexCos; /* unused */
101 
102  if (kb && kb->totelem == verts_num && kb != key->refkey) {
103  int a;
104  scale_m3_fl(scale, kb->curval);
105 
106  for (a = 0; a < verts_num; a++) {
107  copy_m3_m3(defMats[a], scale);
108  }
109  }
110 }
111 
113  /* name */ N_("ShapeKey"),
114  /* structName */ "ShapeKeyModifierData",
115  /* structSize */ sizeof(ShapeKeyModifierData),
116  /* srna */ &RNA_Modifier,
117  /* type */ eModifierTypeType_OnlyDeform,
120  /* icon */ ICON_DOT,
121 
122  /* copyData */ NULL,
123 
124  /* deformVerts */ deformVerts,
125  /* deformMatrices */ deformMatrices,
126  /* deformVertsEM */ deformVertsEM,
127  /* deformMatricesEM */ deformMatricesEM,
128  /* modifyMesh */ NULL,
129  /* modifyGeometrySet */ NULL,
130 
131  /* initData */ NULL,
132  /* requiredDataMask */ NULL,
133  /* freeData */ NULL,
134  /* isDisabled */ NULL,
135  /* updateDepsgraph */ NULL,
136  /* dependsOnTime */ NULL,
137  /* dependsOnNormals */ NULL,
138  /* foreachIDLink */ NULL,
139  /* foreachTexLink */ NULL,
140  /* freeRuntimeData */ NULL,
141  /* panelRegister */ NULL,
142  /* blendWrite */ NULL,
143  /* blendRead */ NULL,
144 };
float * BKE_key_evaluate_object_ex(struct Object *ob, int *r_totelem, float *arr, size_t arr_size, struct ID *obdata)
Definition: key.c:1511
struct Key * BKE_key_from_object(struct Object *ob)
Definition: key.c:1803
struct KeyBlock * BKE_keyblock_from_object(struct Object *ob)
Definition: key.c:1890
@ eModifierTypeFlag_AcceptsCVs
Definition: BKE_modifier.h:67
@ eModifierTypeFlag_SupportsEditmode
Definition: BKE_modifier.h:69
@ eModifierTypeFlag_AcceptsVertexCosOnly
Definition: BKE_modifier.h:100
@ eModifierTypeType_OnlyDeform
Definition: BKE_modifier.h:44
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:71
void scale_m3_fl(float R[3][3], float scale)
Definition: math_matrix.c:2289
#define UNUSED(x)
@ KEY_RELATIVE
struct ShapeKeyModifierData ShapeKeyModifierData
Object is a sort of wrapper for general info.
@ OB_SHAPE_LOCK
static void deformVerts(ModifierData *UNUSED(md), const ModifierEvalContext *ctx, Mesh *UNUSED(mesh), float(*vertexCos)[3], int verts_num)
Definition: MOD_shapekey.c:28
ModifierTypeInfo modifierType_ShapeKey
Definition: MOD_shapekey.c:112
static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *UNUSED(editData), Mesh *mesh, float(*vertexCos)[3], int verts_num)
Definition: MOD_shapekey.c:74
static void deformMatrices(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, float(*vertexCos)[3], float(*defMats)[3][3], int verts_num)
Definition: MOD_shapekey.c:43
static void deformMatricesEM(ModifierData *UNUSED(md), const ModifierEvalContext *ctx, struct BMEditMesh *UNUSED(editData), Mesh *UNUSED(mesh), float(*vertexCos)[3], float(*defMats)[3][3], int verts_num)
Definition: MOD_shapekey.c:88
SyclQueue void void size_t num_bytes void
static unsigned a[3]
Definition: RandGen.cpp:78
float curval
Definition: DNA_key_types.h:34
char type
Definition: DNA_key_types.h:94
ListBase block
Definition: DNA_key_types.h:84
KeyBlock * refkey
Definition: DNA_key_types.h:72
void * first
Definition: DNA_listBase.h:31
struct Object * object
Definition: BKE_modifier.h:141
char shapeflag
#define N_(msgid)