Blender V5.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
8
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
24namespace blender {
25
26static void deform_verts(ModifierData * /*md*/,
27 const ModifierEvalContext *ctx,
28 Mesh * /*mesh*/,
29 MutableSpan<float3> positions)
30{
31 Key *key = BKE_key_from_object(ctx->object);
32
33 if (key && key->block.first_) {
34 int deformedVerts_tot;
36 &deformedVerts_tot,
37 reinterpret_cast<float *>(positions.data()),
38 sizeof(float3) * positions.size(),
39 std::nullopt,
40 nullptr);
41 }
42}
43
45 const ModifierEvalContext *ctx,
46 Mesh *mesh,
47 MutableSpan<float3> positions,
48 MutableSpan<float3x3> matrices)
49{
50 Key *key = BKE_key_from_object(ctx->object);
52
53 if (kb && kb->totelem == positions.size() && kb != key->refkey) {
54 float scale[3][3];
55 int a;
56
57 if (ctx->object->shapeflag & OB_SHAPE_LOCK) {
59 }
60 else {
62 }
63
64 for (a = 0; a < positions.size(); a++) {
65 copy_m3_m3(matrices[a].ptr(), scale);
66 }
67 }
68
69 deform_verts(md, ctx, mesh, positions);
70}
71
73 const ModifierEvalContext *ctx,
74 Mesh *mesh,
75 MutableSpan<float3> positions)
76{
77 Key *key = BKE_key_from_object(ctx->object);
78
79 if (key && key->type == KEY_RELATIVE) {
80 deform_verts(md, ctx, mesh, positions);
81 }
82}
83
84static void deform_matrices_EM(ModifierData * /*md*/,
85 const ModifierEvalContext *ctx,
86 Mesh * /*mesh*/,
87 MutableSpan<float3> /*positions*/,
88 MutableSpan<float3x3> matrices)
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];
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 /*foreach_working_space_color*/ nullptr,
138};
139
140} // namespace blender
Object is a sort of wrapper for general info.
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr T * data() const
Definition BLI_span.hh:545
float3x3 scale(float3x3 mat, float2 scale)
BMesh Iterators.
void copy_m3_m3(float m1[3][3], const float m2[3][3])
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1407
float * BKE_key_evaluate_object_ex(Object *ob, int *r_totelem, float *arr, size_t arr_size, std::optional< Span< bool > > keys_to_process, ID *obdata)
Definition key.cc:1009
static void deform_verts_EM(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions)
static void deform_matrices(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions, MutableSpan< float3x3 > matrices)
@ eModifierTypeFlag_AcceptsCVs
@ eModifierTypeFlag_SupportsEditmode
@ eModifierTypeFlag_AcceptsVertexCosOnly
void scale_m3_fl(float R[3][3], float scale)
static void deform_matrices_EM(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions, MutableSpan< float3x3 > matrices)
ModifierTypeInfo modifierType_ShapeKey
static void deform_verts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions)
VecBase< float, 3 > float3
Key * BKE_key_from_object(Object *ob)
Definition key.cc:1311
KeyBlock * refkey
ListBaseT< KeyBlock > block
ShapekeyContainerType type
eObject_ShapeFlag shapeflag
#define N_(msgid)