5 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version. The Blender
11 * Foundation also sells licenses for use in proprietary software under
12 * the Blender License. See http://www.blender.org/BL/ for information
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
25 * All rights reserved.
27 * The Original Code is: all of this file.
29 * Contributor(s): none yet.
31 * ***** END GPL/BL DUAL LICENSE BLOCK *****
33 #ifndef BKE_MODIFIER_H
34 #define BKE_MODIFIER_H
36 #include "DNA_modifier_types.h" /* needed for all enum typdefs */
37 #include "BKE_customdata.h"
50 /* Should not be used, only for None modifier type */
51 eModifierTypeType_None,
53 /* Modifier only does deformation, implies that modifier
54 * type should have a valid deformVerts function. OnlyDeform
55 * style modifiers implicitly accept either mesh or CV
56 * input but should still declare flags appropriately.
58 eModifierTypeType_OnlyDeform,
60 eModifierTypeType_Constructive,
61 eModifierTypeType_Nonconstructive,
63 /* both deformVerts & applyModifier are valid calls
64 * used for particles modifier that doesn't actually modify the object
65 * unless it's a mesh and can be exploded -> curve can also emit particles
67 eModifierTypeType_DeformOrConstruct
71 eModifierTypeFlag_AcceptsMesh = (1<<0),
72 eModifierTypeFlag_AcceptsCVs = (1<<1),
73 eModifierTypeFlag_SupportsMapping = (1<<2),
74 eModifierTypeFlag_SupportsEditmode = (1<<3),
76 /* For modifiers that support editmode this determines if the
77 * modifier should be enabled by default in editmode. This should
78 * only be used by modifiers that are relatively speedy and
79 * also generally used in editmode, otherwise let the user enable
82 eModifierTypeFlag_EnableInEditmode = (1<<4),
84 /* For modifiers that require original data and so cannot
85 * be placed after any non-deformative modifier.
87 eModifierTypeFlag_RequiresOriginalData = (1<<5),
90 typedef void (*ObjectWalkFunc)(void *userData, struct Object *ob, struct Object **obpoin);
91 typedef void (*IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin);
93 typedef struct ModifierTypeInfo {
94 /* The user visible name for this modifier */
97 /* The DNA struct name for the modifier data type, used to
98 * write the DNA data out.
102 /* The size of the modifier data type, used by allocation. */
105 ModifierTypeType type;
106 ModifierTypeFlag flags;
109 /********************* Non-optional functions *********************/
111 /* Copy instance data for this modifier type. Should copy all user
112 * level settings to the target modifier.
114 void (*copyData)(struct ModifierData *md, struct ModifierData *target);
116 /********************* Deform modifier functions *********************/
118 /* Only for deform types, should apply the deformation
119 * to the given vertex array. If the deformer requires information from
120 * the object it can obtain it from the derivedData argument if non-NULL,
121 * and otherwise the ob argument.
123 void (*deformVerts)(struct ModifierData *md, struct Object *ob,
124 struct DerivedMesh *derivedData,
125 float (*vertexCos)[3], int numVerts);
127 /* Like deformVerts but called during editmode (for supporting modifiers)
129 void (*deformVertsEM)(
130 struct ModifierData *md, struct Object *ob,
131 struct EditMesh *editData, struct DerivedMesh *derivedData,
132 float (*vertexCos)[3], int numVerts);
134 /* Set deform matrix per vertex for crazyspace correction */
135 void (*deformMatricesEM)(
136 struct ModifierData *md, struct Object *ob,
137 struct EditMesh *editData, struct DerivedMesh *derivedData,
138 float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
140 /********************* Non-deform modifier functions *********************/
142 /* For non-deform types: apply the modifier and return a derived
143 * data object (type is dependent on object type).
145 * The derivedData argument should always be non-NULL; the modifier
146 * should read the object data from the derived object instead of the
147 * actual object data.
149 * The useRenderParams argument indicates if the modifier is being
150 * applied in the service of the renderer which may alter quality
153 * The isFinalCalc parameter indicates if the modifier is being
154 * calculated for a final result or for something temporary
155 * (like orcos). This is a hack at the moment, it is meant so subsurf
156 * can know if it is safe to reuse its internal cache.
158 * The modifier may reuse the derivedData argument (i.e. return it in
159 * modified form), but must not release it.
161 struct DerivedMesh *(*applyModifier)(
162 struct ModifierData *md, struct Object *ob,
163 struct DerivedMesh *derivedData,
164 int useRenderParams, int isFinalCalc);
166 /* Like applyModifier but called during editmode (for supporting
169 * The derived object that is returned must support the operations that
170 * are expected from editmode objects. The same qualifications regarding
171 * derivedData apply as for applyModifier.
173 struct DerivedMesh *(*applyModifierEM)(
174 struct ModifierData *md, struct Object *ob,
175 struct EditMesh *editData,
176 struct DerivedMesh *derivedData);
179 /********************* Optional functions *********************/
181 /* Initialize new instance data for this modifier type, this function
182 * should set modifier variables to their default values.
184 * This function is optional.
186 void (*initData)(struct ModifierData *md);
188 /* Should return a CustomDataMask indicating what data this
189 * modifier needs. If (mask & (1 << (layer type))) != 0, this modifier
190 * needs that custom data layer. This function's return value can change
191 * depending on the modifier's settings.
193 * Note that this means extra data (e.g. vertex groups) - it is assumed
194 * that all modifiers need mesh data and deform modifiers need vertex
197 * Note that this limits the number of custom data layer types to 32.
199 * If this function is not present or it returns 0, it is assumed that
200 * no extra data is needed.
202 * This function is optional.
204 CustomDataMask (*requiredDataMask)(struct ModifierData *md);
206 /* Free internal modifier data variables, this function should
207 * not free the md variable itself.
209 * This function is optional.
211 void (*freeData)(struct ModifierData *md);
213 /* Return a boolean value indicating if this modifier is able to be
214 * calculated based on the modifier data. This is *not* regarding the
215 * md->flag, that is tested by the system, this is just if the data
216 * validates (for example, a lattice will return false if the lattice
217 * object is not defined).
219 * This function is optional (assumes never disabled if not present).
221 int (*isDisabled)(struct ModifierData *md);
223 /* Add the appropriate relations to the DEP graph depending on the
226 * This function is optional.
228 void (*updateDepgraph)(struct ModifierData *md, struct DagForest *forest,
229 struct Object *ob, struct DagNode *obNode);
231 /* Should return true if the modifier needs to be recalculated on time
234 * This function is optional (assumes false if not present).
236 int (*dependsOnTime)(struct ModifierData *md);
238 /* Should call the given walk function on with a pointer to each Object
239 * pointer that the modifier data stores. This is used for linking on file
240 * load and for unlinking objects or forwarding object references.
242 * This function is optional.
244 void (*foreachObjectLink)(struct ModifierData *md, struct Object *ob,
245 ObjectWalkFunc walk, void *userData);
247 /* Should call the given walk function with a pointer to each ID
248 * pointer (i.e. each datablock pointer) that the modifier data
249 * stores. This is used for linking on file load and for
250 * unlinking datablocks or forwarding datablock references.
252 * This function is optional. If it is not present, foreachObjectLink
255 void (*foreachIDLink)(struct ModifierData *md, struct Object *ob,
256 IDWalkFunc walk, void *userData);
259 ModifierTypeInfo *modifierType_getInfo (ModifierType type);
261 /* Modifier utility calls, do call through type pointer and return
262 * default values if pointer is optional.
264 struct ModifierData *modifier_new(int type);
265 void modifier_free(struct ModifierData *md);
267 void modifier_copyData(struct ModifierData *md, struct ModifierData *target);
268 int modifier_dependsOnTime(struct ModifierData *md);
269 int modifier_supportsMapping(struct ModifierData *md);
270 int modifier_couldBeCage(struct ModifierData *md);
271 int modifier_isDeformer(struct ModifierData *md);
272 void modifier_setError(struct ModifierData *md, char *format, ...);
274 void modifiers_foreachObjectLink(struct Object *ob,
277 void modifiers_foreachIDLink(struct Object *ob,
280 struct ModifierData *modifiers_findByType(struct Object *ob, ModifierType type);
281 void modifiers_clearErrors(struct Object *ob);
282 int modifiers_getCageIndex(struct Object *ob,
283 int *lastPossibleCageIndex_r);
285 int modifiers_isSoftbodyEnabled(struct Object *ob);
286 int modifiers_isParticleEnabled(struct Object *ob);
287 struct Object *modifiers_isDeformedByArmature(struct Object *ob);
288 struct Object *modifiers_isDeformedByLattice(struct Object *ob);
289 int modifiers_usesArmature(struct Object *ob, struct bArmature *arm);
290 int modifiers_isDeformed(struct Object *ob);
292 int modifiers_indexInObject(struct Object *ob, struct ModifierData *md);
294 /* Calculates and returns a linked list of CustomDataMasks indicating the
295 * data required by each modifier in the stack pointed to by md for correct
296 * evaluation, assuming the data indicated by dataMask is required at the
299 struct LinkNode *modifiers_calcDataMasks(struct ModifierData *md,
300 CustomDataMask dataMask);
301 struct ModifierData *modifiers_getVirtualModifierList(struct Object *ob);