code cleanup: make bmesh operator names more consistant since python has access to...
[blender.git] / source / blender / modifiers / intern / MOD_shapekey.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software  Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2005 by the Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Daniel Dunbar
22  *                 Ton Roosendaal,
23  *                 Ben Batt,
24  *                 Brecht Van Lommel,
25  *                 Campbell Barton
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  *
29  */
30
31 /** \file blender/modifiers/intern/MOD_shapekey.c
32  *  \ingroup modifiers
33  */
34
35
36 #include "BLI_math.h"
37
38 #include "DNA_key_types.h"
39
40 #include "BLI_utildefines.h"
41
42
43 #include "BKE_cdderivedmesh.h"
44 #include "BKE_key.h"
45 #include "BKE_particle.h"
46
47 #include "MOD_modifiertypes.h"
48
49 #include "MEM_guardedalloc.h"
50
51 static void deformVerts(ModifierData *md, Object *ob,
52                         DerivedMesh *UNUSED(derivedData),
53                         float (*vertexCos)[3],
54                         int numVerts,
55                         ModifierApplyFlag UNUSED(flag))
56 {
57         KeyBlock *kb = BKE_keyblock_from_object(ob);
58         float (*deformedVerts)[3];
59
60         if (kb && kb->totelem == numVerts) {
61                 deformedVerts = (float(*)[3])do_ob_key(md->scene, ob);
62                 if (deformedVerts) {
63                         memcpy(vertexCos, deformedVerts, sizeof(float) * 3 * numVerts);
64                         MEM_freeN(deformedVerts);
65                 }
66         }
67 }
68
69 static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
70                            float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
71 {
72         Key *key = BKE_key_from_object(ob);
73         KeyBlock *kb = BKE_keyblock_from_object(ob);
74         float scale[3][3];
75
76         (void)vertexCos; /* unused */
77
78         if (kb && kb->totelem == numVerts && kb != key->refkey) {
79                 int a;
80
81                 if (ob->shapeflag & OB_SHAPE_LOCK) scale_m3_fl(scale, 1);
82                 else scale_m3_fl(scale, kb->curval);
83
84                 for (a = 0; a < numVerts; a++)
85                         copy_m3_m3(defMats[a], scale);
86         }
87
88         deformVerts(md, ob, derivedData, vertexCos, numVerts, 0);
89 }
90
91 static void deformVertsEM(ModifierData *md, Object *ob,
92                           struct BMEditMesh *UNUSED(editData),
93                           DerivedMesh *derivedData,
94                           float (*vertexCos)[3],
95                           int numVerts)
96 {
97         Key *key = BKE_key_from_object(ob);
98
99         if (key && key->type == KEY_RELATIVE)
100                 deformVerts(md, ob, derivedData, vertexCos, numVerts, 0);
101 }
102
103 static void deformMatricesEM(ModifierData *UNUSED(md), Object *ob,
104                              struct BMEditMesh *UNUSED(editData),
105                              DerivedMesh *UNUSED(derivedData),
106                              float (*vertexCos)[3],
107                              float (*defMats)[3][3],
108                              int numVerts)
109 {
110         Key *key = BKE_key_from_object(ob);
111         KeyBlock *kb = BKE_keyblock_from_object(ob);
112         float scale[3][3];
113
114         (void)vertexCos; /* unused */
115
116         if (kb && kb->totelem == numVerts && kb != key->refkey) {
117                 int a;
118                 scale_m3_fl(scale, kb->curval);
119
120                 for (a = 0; a < numVerts; a++)
121                         copy_m3_m3(defMats[a], scale);
122         }
123 }
124
125
126 ModifierTypeInfo modifierType_ShapeKey = {
127         /* name */              "ShapeKey",
128         /* structName */        "ShapeKeyModifierData",
129         /* structSize */        sizeof(ShapeKeyModifierData),
130         /* type */              eModifierTypeType_OnlyDeform,
131         /* flags */             eModifierTypeFlag_AcceptsCVs |
132                                 eModifierTypeFlag_SupportsEditmode,
133
134         /* copyData */          NULL,
135         /* deformVerts */       deformVerts,
136         /* deformMatrices */    deformMatrices,
137         /* deformVertsEM */     deformVertsEM,
138         /* deformMatricesEM */  deformMatricesEM,
139         /* applyModifier */     NULL,
140         /* applyModifierEM */   NULL,
141         /* initData */          NULL,
142         /* requiredDataMask */  NULL,
143         /* freeData */          NULL,
144         /* isDisabled */        NULL,
145         /* updateDepgraph */    NULL,
146         /* dependsOnTime */     NULL,
147         /* dependsOnNormals */  NULL,
148         /* foreachObjectLink */ NULL,
149         /* foreachIDLink */     NULL,
150         /* foreachTexLink */    NULL,
151 };