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