svn merge ^/trunk/blender -r43751:43819, need to look into changes made to editmesh_l...
[blender.git] / source / blender / modifiers / intern / MOD_curve.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_curve.c
32  *  \ingroup modifiers
33  */
34
35
36 #include <string.h>
37
38 #include "DNA_scene_types.h"
39 #include "DNA_object_types.h"
40
41 #include "BLI_utildefines.h"
42 #include "BLI_string.h"
43
44
45 #include "BKE_cdderivedmesh.h"
46 #include "BKE_lattice.h"
47 #include "BKE_modifier.h"
48
49 #include "depsgraph_private.h"
50
51 #include "MOD_util.h"
52
53 static void initData(ModifierData *md)
54 {
55         CurveModifierData *cmd = (CurveModifierData*) md;
56
57         cmd->defaxis = MOD_CURVE_POSX;
58 }
59
60 static void copyData(ModifierData *md, ModifierData *target)
61 {
62         CurveModifierData *cmd = (CurveModifierData*) md;
63         CurveModifierData *tcmd = (CurveModifierData*) target;
64
65         tcmd->defaxis = cmd->defaxis;
66         tcmd->object = cmd->object;
67         BLI_strncpy(tcmd->name, cmd->name, sizeof(tcmd->name));
68 }
69
70 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
71 {
72         CurveModifierData *cmd = (CurveModifierData *)md;
73         CustomDataMask dataMask = 0;
74
75         /* ask for vertexgroups if we need them */
76         if(cmd->name[0]) dataMask |= CD_MASK_MDEFORMVERT;
77
78         return dataMask;
79 }
80
81 static int isDisabled(ModifierData *md, int UNUSED(userRenderParams))
82 {
83         CurveModifierData *cmd = (CurveModifierData*) md;
84
85         return !cmd->object;
86 }
87
88 static void foreachObjectLink(
89                                                 ModifierData *md, Object *ob,
90          void (*walk)(void *userData, Object *ob, Object **obpoin),
91                 void *userData)
92 {
93         CurveModifierData *cmd = (CurveModifierData*) md;
94
95         walk(userData, ob, &cmd->object);
96 }
97
98 static void updateDepgraph(ModifierData *md, DagForest *forest,
99                                                 Scene *UNUSED(scene),
100                                                 Object *UNUSED(ob),
101                                                 DagNode *obNode)
102 {
103         CurveModifierData *cmd = (CurveModifierData*) md;
104
105         if (cmd->object) {
106                 DagNode *curNode = dag_get_node(forest, cmd->object);
107
108                 dag_add_relation(forest, curNode, obNode,
109                                  DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Modifier");
110         }
111 }
112
113 static void deformVerts(ModifierData *md, Object *ob,
114                                                 DerivedMesh *derivedData,
115                                                 float (*vertexCos)[3],
116                                                 int numVerts,
117                                                 int UNUSED(useRenderParams),
118                                                 int UNUSED(isFinalCalc))
119 {
120         CurveModifierData *cmd = (CurveModifierData*) md;
121
122         /* silly that defaxis and curve_deform_verts are off by 1
123          * but leave for now to save having to call do_versions */
124         curve_deform_verts(md->scene, cmd->object, ob, derivedData, vertexCos, numVerts,
125                            cmd->name, cmd->defaxis-1);
126 }
127
128 static void deformVertsEM(
129                                         ModifierData *md, Object *ob, struct BMEditMesh *editData,
130          DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
131 {
132         DerivedMesh *dm = derivedData;
133
134         if(!derivedData) dm = CDDM_from_BMEditMesh(editData, ob->data, FALSE, FALSE);
135
136         deformVerts(md, ob, dm, vertexCos, numVerts, 0, 0);
137
138         if(!derivedData) dm->release(dm);
139 }
140
141
142 ModifierTypeInfo modifierType_Curve = {
143         /* name */              "Curve",
144         /* structName */        "CurveModifierData",
145         /* structSize */        sizeof(CurveModifierData),
146         /* type */              eModifierTypeType_OnlyDeform,
147         /* flags */             eModifierTypeFlag_AcceptsCVs
148                                                         | eModifierTypeFlag_SupportsEditmode,
149
150         /* copyData */          copyData,
151         /* deformVerts */       deformVerts,
152         /* deformMatrices */    NULL,
153         /* deformVertsEM */     deformVertsEM,
154         /* deformMatricesEM */  NULL,
155         /* applyModifier */     NULL,
156         /* applyModifierEM */   NULL,
157         /* initData */          initData,
158         /* requiredDataMask */  requiredDataMask,
159         /* freeData */          NULL,
160         /* isDisabled */        isDisabled,
161         /* updateDepgraph */    updateDepgraph,
162         /* dependsOnTime */     NULL,
163         /* dependsOnNormals */  NULL,
164         /* foreachObjectLink */ foreachObjectLink,
165         /* foreachIDLink */     NULL,
166         /* foreachTexLink */    NULL,
167 };