Blender V2.61 - r43446

BKE_modifier.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 #ifndef BKE_MODIFIER_H
00028 #define BKE_MODIFIER_H
00029 
00034 #include "DNA_modifier_types.h"     /* needed for all enum typdefs */
00035 #include "BKE_customdata.h"
00036 
00037 struct ID;
00038 struct EditMesh;
00039 struct DerivedMesh;
00040 struct DagForest;
00041 struct DagNode;
00042 struct Object;
00043 struct Scene;
00044 struct ListBase;
00045 struct LinkNode;
00046 struct bArmature;
00047 struct ModifierData;
00048 
00049 typedef enum {
00050     /* Should not be used, only for None modifier type */
00051     eModifierTypeType_None,
00052 
00053     /* Modifier only does deformation, implies that modifier
00054      * type should have a valid deformVerts function. OnlyDeform
00055      * style modifiers implicitly accept either mesh or CV
00056      * input but should still declare flags appropriately.
00057      */
00058     eModifierTypeType_OnlyDeform,
00059 
00060     eModifierTypeType_Constructive,
00061     eModifierTypeType_Nonconstructive,
00062 
00063     /* both deformVerts & applyModifier are valid calls
00064      * used for particles modifier that doesn't actually modify the object
00065      * unless it's a mesh and can be exploded -> curve can also emit particles
00066      */
00067     eModifierTypeType_DeformOrConstruct,
00068 
00069     /* Like eModifierTypeType_Nonconstructive, but does not affect the geometry
00070      * of the object, rather some of its CustomData layers.
00071      * E.g. UVProject and WeightVG modifiers. */
00072     eModifierTypeType_NonGeometrical,
00073 } ModifierTypeType;
00074 
00075 typedef enum {
00076     eModifierTypeFlag_AcceptsMesh          = (1<<0),
00077     eModifierTypeFlag_AcceptsCVs           = (1<<1),
00078     eModifierTypeFlag_SupportsMapping      = (1<<2),
00079     eModifierTypeFlag_SupportsEditmode     = (1<<3),
00080 
00081     /* For modifiers that support editmode this determines if the
00082      * modifier should be enabled by default in editmode. This should
00083      * only be used by modifiers that are relatively speedy and
00084      * also generally used in editmode, otherwise let the user enable
00085      * it by hand.
00086      */
00087     eModifierTypeFlag_EnableInEditmode     = (1<<4),
00088 
00089     /* For modifiers that require original data and so cannot
00090      * be placed after any non-deformative modifier.
00091      */
00092     eModifierTypeFlag_RequiresOriginalData = (1<<5),
00093 
00094     /* For modifiers that support pointcache, so we can check to see if it has files we need to deal with
00095     */
00096     eModifierTypeFlag_UsesPointCache = (1<<6),
00097 
00098     /* For physics modifiers, max one per type */
00099     eModifierTypeFlag_Single = (1<<7),
00100 
00101     /* Some modifier can't be added manually by user */
00102     eModifierTypeFlag_NoUserAdd = (1<<8)
00103 } ModifierTypeFlag;
00104 
00105 typedef void (*ObjectWalkFunc)(void *userData, struct Object *ob, struct Object **obpoin);
00106 typedef void (*IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin);
00107 typedef void (*TexWalkFunc)(void *userData, struct Object *ob, struct ModifierData *md, const char *propname);
00108 
00109 typedef struct ModifierTypeInfo {
00110     /* The user visible name for this modifier */
00111     char name[32];
00112 
00113     /* The DNA struct name for the modifier data type, used to
00114      * write the DNA data out.
00115      */
00116     char structName[32];
00117 
00118     /* The size of the modifier data type, used by allocation. */
00119     int structSize;
00120 
00121     ModifierTypeType type;
00122     ModifierTypeFlag flags;
00123 
00124 
00125     /********************* Non-optional functions *********************/
00126 
00127     /* Copy instance data for this modifier type. Should copy all user
00128      * level settings to the target modifier.
00129      */
00130     void (*copyData)(struct ModifierData *md, struct ModifierData *target);
00131 
00132     /********************* Deform modifier functions *********************/
00133 
00134     /* Only for deform types, should apply the deformation
00135      * to the given vertex array. If the deformer requires information from
00136      * the object it can obtain it from the derivedData argument if non-NULL,
00137      * and otherwise the ob argument.
00138      */
00139     void (*deformVerts)(struct ModifierData *md, struct Object *ob,
00140                         struct DerivedMesh *derivedData,
00141                         float (*vertexCos)[3], int numVerts,
00142                         int useRenderParams, int isFinalCalc);
00143 
00144     /* Like deformMatricesEM but called from object mode (for supporting modifiers in sculpt mode) */
00145     void (*deformMatrices)(
00146                 struct ModifierData *md, struct Object *ob,
00147                 struct DerivedMesh *derivedData,
00148                 float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
00149 
00150     /* Like deformVerts but called during editmode (for supporting modifiers)
00151      */
00152     void (*deformVertsEM)(
00153                 struct ModifierData *md, struct Object *ob,
00154                 struct EditMesh *editData, struct DerivedMesh *derivedData,
00155                 float (*vertexCos)[3], int numVerts);
00156 
00157     /* Set deform matrix per vertex for crazyspace correction */
00158     void (*deformMatricesEM)(
00159                 struct ModifierData *md, struct Object *ob,
00160                 struct EditMesh *editData, struct DerivedMesh *derivedData,
00161                 float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
00162 
00163     /********************* Non-deform modifier functions *********************/
00164 
00165     /* For non-deform types: apply the modifier and return a derived
00166      * data object (type is dependent on object type).
00167      *
00168      * The derivedData argument should always be non-NULL; the modifier
00169      * should read the object data from the derived object instead of the
00170      * actual object data. 
00171      *
00172      * The useRenderParams argument indicates if the modifier is being
00173      * applied in the service of the renderer which may alter quality
00174      * settings.
00175      *
00176      * The isFinalCalc parameter indicates if the modifier is being
00177      * calculated for a final result or for something temporary
00178      * (like orcos). This is a hack at the moment, it is meant so subsurf
00179      * can know if it is safe to reuse its internal cache.
00180      *
00181      * The modifier may reuse the derivedData argument (i.e. return it in
00182      * modified form), but must not release it.
00183      */
00184     struct DerivedMesh *(*applyModifier)(
00185                                 struct ModifierData *md, struct Object *ob,
00186                                 struct DerivedMesh *derivedData,
00187                                 int useRenderParams, int isFinalCalc);
00188 
00189     /* Like applyModifier but called during editmode (for supporting
00190      * modifiers).
00191      * 
00192      * The derived object that is returned must support the operations that
00193      * are expected from editmode objects. The same qualifications regarding
00194      * derivedData apply as for applyModifier.
00195      */
00196     struct DerivedMesh *(*applyModifierEM)(
00197                                 struct ModifierData *md, struct Object *ob,
00198                                 struct EditMesh *editData,
00199                                 struct DerivedMesh *derivedData);
00200 
00201 
00202     /********************* Optional functions *********************/
00203 
00204     /* Initialize new instance data for this modifier type, this function
00205      * should set modifier variables to their default values.
00206      * 
00207      * This function is optional.
00208      */
00209     void (*initData)(struct ModifierData *md);
00210 
00211     /* Should return a CustomDataMask indicating what data this
00212      * modifier needs. If (mask & (1 << (layer type))) != 0, this modifier
00213      * needs that custom data layer. This function's return value can change
00214      * depending on the modifier's settings.
00215      *
00216      * Note that this means extra data (e.g. vertex groups) - it is assumed
00217      * that all modifiers need mesh data and deform modifiers need vertex
00218      * coordinates.
00219      *
00220      * Note that this limits the number of custom data layer types to 32.
00221      *
00222      * If this function is not present or it returns 0, it is assumed that
00223      * no extra data is needed.
00224      *
00225      * This function is optional.
00226      */
00227     CustomDataMask (*requiredDataMask)(struct Object *ob, struct ModifierData *md);
00228 
00229     /* Free internal modifier data variables, this function should
00230      * not free the md variable itself.
00231      *
00232      * This function is optional.
00233      */
00234     void (*freeData)(struct ModifierData *md);
00235 
00236     /* Return a boolean value indicating if this modifier is able to be
00237      * calculated based on the modifier data. This is *not* regarding the
00238      * md->flag, that is tested by the system, this is just if the data
00239      * validates (for example, a lattice will return false if the lattice
00240      * object is not defined).
00241      *
00242      * This function is optional (assumes never disabled if not present).
00243      */
00244     int (*isDisabled)(struct ModifierData *md, int userRenderParams);
00245 
00246     /* Add the appropriate relations to the DEP graph depending on the
00247      * modifier data. 
00248      *
00249      * This function is optional.
00250      */
00251     void (*updateDepgraph)(struct ModifierData *md, struct DagForest *forest, struct Scene *scene,
00252                            struct Object *ob, struct DagNode *obNode);
00253 
00254     /* Should return true if the modifier needs to be recalculated on time
00255      * changes.
00256      *
00257      * This function is optional (assumes false if not present).
00258      */
00259     int (*dependsOnTime)(struct ModifierData *md);
00260 
00261 
00262     /* True when a deform modifier uses normals, the requiredDataMask
00263      * cant be used here because that refers to a normal layer where as
00264      * in this case we need to know if the deform modifier uses normals.
00265      * 
00266      * this is needed because applying 2 deform modifiers will give the
00267      * second modifier bogus normals.
00268      * */
00269     int (*dependsOnNormals)(struct ModifierData *md);
00270 
00271 
00272     /* Should call the given walk function on with a pointer to each Object
00273      * pointer that the modifier data stores. This is used for linking on file
00274      * load and for unlinking objects or forwarding object references.
00275      *
00276      * This function is optional.
00277      */
00278     void (*foreachObjectLink)(struct ModifierData *md, struct Object *ob,
00279                               ObjectWalkFunc walk, void *userData);
00280 
00281     /* Should call the given walk function with a pointer to each ID
00282      * pointer (i.e. each datablock pointer) that the modifier data
00283      * stores. This is used for linking on file load and for
00284      * unlinking datablocks or forwarding datablock references.
00285      *
00286      * This function is optional. If it is not present, foreachObjectLink
00287      * will be used.
00288      */
00289     void (*foreachIDLink)(struct ModifierData *md, struct Object *ob,
00290                           IDWalkFunc walk, void *userData);
00291 
00292     /* Should call the given walk function for each texture that the
00293      * modifier data stores. This is used for finding all textures in
00294      * the context for the UI.
00295      *
00296      * This function is optional. If it is not present, it will be
00297      * assumed the modifier has no textures.
00298      */
00299     void (*foreachTexLink)(struct ModifierData *md, struct Object *ob,
00300                           TexWalkFunc walk, void *userData);
00301 } ModifierTypeInfo;
00302 
00303 ModifierTypeInfo *modifierType_getInfo (ModifierType type);
00304 
00305 /* Modifier utility calls, do call through type pointer and return
00306  * default values if pointer is optional.
00307  */
00308 struct ModifierData  *modifier_new(int type);
00309 void          modifier_free(struct ModifierData *md);
00310 
00311 void          modifier_unique_name(struct ListBase *modifiers, struct ModifierData *md);
00312 
00313 void          modifier_copyData(struct ModifierData *md, struct ModifierData *target);
00314 int           modifier_dependsOnTime(struct ModifierData *md);
00315 int           modifier_supportsMapping(struct ModifierData *md);
00316 int           modifier_couldBeCage(struct Scene *scene, struct ModifierData *md);
00317 int           modifier_isCorrectableDeformed(struct ModifierData *md);
00318 int           modifier_sameTopology(ModifierData *md);
00319 int           modifier_nonGeometrical(ModifierData *md);
00320 int           modifier_isEnabled(struct Scene *scene, struct ModifierData *md, int required_mode);
00321 void          modifier_setError(struct ModifierData *md, const char *format, ...)
00322 #ifdef __GNUC__
00323 __attribute__ ((format (printf, 2, 3)))
00324 #endif
00325 ;
00326 
00327 void          modifiers_foreachObjectLink(struct Object *ob,
00328                                           ObjectWalkFunc walk,
00329                                           void *userData);
00330 void          modifiers_foreachIDLink(struct Object *ob,
00331                                       IDWalkFunc walk,
00332                                       void *userData);
00333 void          modifiers_foreachTexLink(struct Object *ob,
00334                                       TexWalkFunc walk,
00335                                       void *userData);
00336 
00337 struct ModifierData  *modifiers_findByType(struct Object *ob, ModifierType type);
00338 struct ModifierData  *modifiers_findByName(struct Object *ob, const char *name);
00339 void          modifiers_clearErrors(struct Object *ob);
00340 int           modifiers_getCageIndex(struct Scene *scene, struct Object *ob,
00341                                      int *lastPossibleCageIndex_r, int virtual_);
00342 
00343 int           modifiers_isSoftbodyEnabled(struct Object *ob);
00344 int           modifiers_isClothEnabled(struct Object *ob);
00345 int           modifiers_isParticleEnabled(struct Object *ob);
00346 
00347 struct Object *modifiers_isDeformedByArmature(struct Object *ob);
00348 struct Object *modifiers_isDeformedByLattice(struct Object *ob);
00349 int           modifiers_usesArmature(struct Object *ob, struct bArmature *arm);
00350 int           modifiers_isCorrectableDeformed(struct Object *ob);
00351 void          modifier_freeTemporaryData(struct ModifierData *md);
00352 
00353 int           modifiers_indexInObject(struct Object *ob, struct ModifierData *md);
00354 
00355 /* Calculates and returns a linked list of CustomDataMasks indicating the
00356  * data required by each modifier in the stack pointed to by md for correct
00357  * evaluation, assuming the data indicated by dataMask is required at the
00358  * end of the stack.
00359  */
00360 struct LinkNode *modifiers_calcDataMasks(struct Scene *scene, 
00361                                          struct Object *ob,
00362                                          struct ModifierData *md,
00363                                          CustomDataMask dataMask,
00364                                          int required_mode);
00365 struct ModifierData  *modifiers_getVirtualModifierList(struct Object *ob);
00366 
00367 /* ensure modifier correctness when changing ob->data */
00368 void test_object_modifiers(struct Object *ob);
00369 
00370 /* here for do_versions */
00371 void modifier_mdef_compact_influences(struct ModifierData *md);
00372 
00373 void        modifier_path_init(char *path, int path_maxlen, const char *name);
00374 const char *modifier_path_relbase(struct Object *ob);
00375 
00376 #endif
00377