code cleanup: make bmesh operator names more consistant since python has access to...
[blender.git] / source / blender / modifiers / intern / MOD_lattice.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_lattice.c
32  *  \ingroup modifiers
33  */
34
35
36 #include <string.h>
37
38 #include "DNA_object_types.h"
39
40 #include "BLI_utildefines.h"
41 #include "BLI_string.h"
42
43 #include "BKE_cdderivedmesh.h"
44 #include "BKE_lattice.h"
45 #include "BKE_modifier.h"
46
47 #include "depsgraph_private.h"
48
49 #include "MOD_util.h"
50
51 static void initData(ModifierData *md)
52 {
53         LatticeModifierData *lmd = (LatticeModifierData *) md;
54         lmd->strength = 1.0f;
55 }
56
57 static void copyData(ModifierData *md, ModifierData *target)
58 {
59         LatticeModifierData *lmd = (LatticeModifierData *) md;
60         LatticeModifierData *tlmd = (LatticeModifierData *) target;
61
62         tlmd->object = lmd->object;
63         BLI_strncpy(tlmd->name, lmd->name, sizeof(tlmd->name));
64 }
65
66 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
67 {
68         LatticeModifierData *lmd = (LatticeModifierData *)md;
69         CustomDataMask dataMask = 0;
70
71         /* ask for vertexgroups if we need them */
72         if (lmd->name[0]) dataMask |= CD_MASK_MDEFORMVERT;
73
74         return dataMask;
75 }
76
77 static int isDisabled(ModifierData *md, int UNUSED(userRenderParams))
78 {
79         LatticeModifierData *lmd = (LatticeModifierData *) md;
80
81         return !lmd->object;
82 }
83
84 static void foreachObjectLink(
85         ModifierData *md, Object *ob,
86         void (*walk)(void *userData, Object *ob, Object **obpoin),
87         void *userData)
88 {
89         LatticeModifierData *lmd = (LatticeModifierData *) md;
90
91         walk(userData, ob, &lmd->object);
92 }
93
94 static void updateDepgraph(ModifierData *md, DagForest *forest,
95                            struct Scene *UNUSED(scene),
96                            Object *UNUSED(ob),
97                            DagNode *obNode)
98 {
99         LatticeModifierData *lmd = (LatticeModifierData *) md;
100
101         if (lmd->object) {
102                 DagNode *latNode = dag_get_node(forest, lmd->object);
103
104                 dag_add_relation(forest, latNode, obNode,
105                                  DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Lattice Modifier");
106         }
107 }
108
109 static void deformVerts(ModifierData *md, Object *ob,
110                         DerivedMesh *derivedData,
111                         float (*vertexCos)[3],
112                         int numVerts,
113                         ModifierApplyFlag UNUSED(flag))
114 {
115         LatticeModifierData *lmd = (LatticeModifierData *) md;
116
117
118         modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
119         
120         lattice_deform_verts(lmd->object, ob, derivedData,
121                              vertexCos, numVerts, lmd->name, lmd->strength);
122 }
123
124 static void deformVertsEM(
125         ModifierData *md, Object *ob, struct BMEditMesh *em,
126         DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
127 {
128         DerivedMesh *dm = derivedData;
129
130         if (!derivedData) dm = CDDM_from_editbmesh(em, FALSE, FALSE);
131
132         deformVerts(md, ob, dm, vertexCos, numVerts, 0);
133
134         if (!derivedData) dm->release(dm);
135 }
136
137
138 ModifierTypeInfo modifierType_Lattice = {
139         /* name */              "Lattice",
140         /* structName */        "LatticeModifierData",
141         /* structSize */        sizeof(LatticeModifierData),
142         /* type */              eModifierTypeType_OnlyDeform,
143         /* flags */             eModifierTypeFlag_AcceptsCVs |
144                                 eModifierTypeFlag_SupportsEditmode,
145         /* copyData */          copyData,
146         /* deformVerts */       deformVerts,
147         /* deformMatrices */    NULL,
148         /* deformVertsEM */     deformVertsEM,
149         /* deformMatricesEM */  NULL,
150         /* applyModifier */     NULL,
151         /* applyModifierEM */   NULL,
152         /* initData */          initData,
153         /* requiredDataMask */  requiredDataMask,
154         /* freeData */          NULL,
155         /* isDisabled */        isDisabled,
156         /* updateDepgraph */    updateDepgraph,
157         /* dependsOnTime */     NULL,
158         /* dependsOnNormals */  NULL,
159         /* foreachObjectLink */ foreachObjectLink,
160         /* foreachIDLink */     NULL,
161         /* foreachTexLink */    NULL,
162 };