Blender V5.0
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
8
9#include "BLI_math_matrix.h"
10
11#include "BLT_translation.hh"
12
13#include "DNA_key_types.h"
14#include "DNA_object_types.h"
15
16#include "BKE_key.hh"
17
18#include "RNA_prototypes.hh"
19
20#include "MOD_modifiertypes.hh"
21
22#include "UI_resources.hh"
23
24static void deform_verts(ModifierData * /*md*/,
25 const ModifierEvalContext *ctx,
26 Mesh * /*mesh*/,
28{
29 Key *key = BKE_key_from_object(ctx->object);
30
31 if (key && key->block.first) {
32 int deformedVerts_tot;
34 &deformedVerts_tot,
35 reinterpret_cast<float *>(positions.data()),
36 sizeof(blender::float3) * positions.size(),
37 nullptr);
38 }
39}
40
42 const ModifierEvalContext *ctx,
43 Mesh *mesh,
46{
47 Key *key = BKE_key_from_object(ctx->object);
49
50 if (kb && kb->totelem == positions.size() && kb != key->refkey) {
51 float scale[3][3];
52 int a;
53
54 if (ctx->object->shapeflag & OB_SHAPE_LOCK) {
55 scale_m3_fl(scale, 1);
56 }
57 else {
58 scale_m3_fl(scale, kb->curval);
59 }
60
61 for (a = 0; a < positions.size(); a++) {
62 copy_m3_m3(matrices[a].ptr(), scale);
63 }
64 }
65
66 deform_verts(md, ctx, mesh, positions);
67}
68
70 const ModifierEvalContext *ctx,
71 const BMEditMesh * /*em*/,
72 Mesh *mesh,
74{
75 Key *key = BKE_key_from_object(ctx->object);
76
77 if (key && key->type == KEY_RELATIVE) {
78 deform_verts(md, ctx, mesh, positions);
79 }
80}
81
82static void deform_matrices_EM(ModifierData * /*md*/,
83 const ModifierEvalContext *ctx,
84 const BMEditMesh * /*em*/,
85 Mesh * /*mesh*/,
88{
89 Key *key = BKE_key_from_object(ctx->object);
91
92 if (kb && kb->totelem == matrices.size() && kb != key->refkey) {
93 float scale[3][3];
94 scale_m3_fl(scale, kb->curval);
95
96 for (int a = 0; a < matrices.size(); a++) {
97 copy_m3_m3(matrices[a].ptr(), scale);
98 }
99 }
100}
101
103 /*idname*/ "ShapeKey",
104 /*name*/ N_("ShapeKey"),
105 /*struct_name*/ "ShapeKeyModifierData",
106 /*struct_size*/ sizeof(ShapeKeyModifierData),
107 /*srna*/ &RNA_Modifier,
111 /*icon*/ ICON_DOT,
112
113 /*copy_data*/ nullptr,
114
115 /*deform_verts*/ deform_verts,
116 /*deform_matrices*/ deform_matrices,
117 /*deform_verts_EM*/ deform_verts_EM,
118 /*deform_matrices_EM*/ deform_matrices_EM,
119 /*modify_mesh*/ nullptr,
120 /*modify_geometry_set*/ nullptr,
121
122 /*init_data*/ nullptr,
123 /*required_data_mask*/ nullptr,
124 /*free_data*/ nullptr,
125 /*is_disabled*/ nullptr,
126 /*update_depsgraph*/ nullptr,
127 /*depends_on_time*/ nullptr,
128 /*depends_on_normals*/ nullptr,
129 /*foreach_ID_link*/ nullptr,
130 /*foreach_tex_link*/ nullptr,
131 /*free_runtime_data*/ nullptr,
132 /*panel_register*/ nullptr,
133 /*blend_write*/ nullptr,
134 /*blend_read*/ nullptr,
135 /*foreach_cache*/ nullptr,
136 /*foreach_working_space_color*/ nullptr,
137};
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1889
float * BKE_key_evaluate_object_ex(Object *ob, int *r_totelem, float *arr, size_t arr_size, ID *obdata)
Definition key.cc:1488
Key * BKE_key_from_object(Object *ob)
Definition key.cc:1791
@ 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
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_verts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, blender::MutableSpan< blender::float3 > positions)
static void deform_matrices_EM(ModifierData *md, const ModifierEvalContext *ctx, const BMEditMesh *em, Mesh *, blender::MutableSpan< blender::float3 > positions, blender::MutableSpan< blender::float3x3 > matrices)
static void deform_verts_EM(ModifierData *md, const ModifierEvalContext *ctx, const BMEditMesh *em, Mesh *mesh, blender::MutableSpan< blender::float3 > positions)
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:493
constexpr T * data() const
Definition BLI_span.hh:539
VecBase< float, 3 > float3
float curval
char type
ListBase block
KeyBlock * refkey
void * first
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4238