diff options
author | Daniel Dunbar <daniel@zuster.org> | 2005-08-11 02:05:52 +0400 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2005-08-11 02:05:52 +0400 |
commit | 9030e5f686e81ab1137e0b845962298f01f6739c (patch) | |
tree | cf962f103b674b6aa4802bc0833225319adce578 /source/blender/blenkernel | |
parent | eb64e304b4f7882e6922cbf1fe3e33e07664135a (diff) |
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_deform.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_modifier.h | 25 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 14 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 147 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/depsgraph.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 229 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 63 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/softbody.c | 1 |
8 files changed, 266 insertions, 225 deletions
diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index d3baa8e7bf3..a06940e883c 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -47,8 +47,6 @@ struct bDeformGroup* copy_defgroup (struct bDeformGroup *ingroup); struct bDeformGroup *get_named_vertexgroup (Object *ob, char *name); int get_defgroup_num (struct Object *ob, struct bDeformGroup *dg); -void hook_object_deform(struct Object *ob, int index, float *vec); - int curve_modifier(struct Object *ob, char mode); void mesh_modifier(struct Object *ob, float (**vertexCos_r)[3]); int lattice_modifier(struct Object *ob, char mode); diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 19fc11424ce..e2838622494 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -38,7 +38,6 @@ struct ModifierData; struct DagForest; struct DagNode; struct Object; -struct ListBase; typedef enum { /* Should not be used, only for None modifier type */ @@ -60,14 +59,19 @@ typedef enum { eModifierTypeFlag_AcceptsCVs = (1<<1), eModifierTypeFlag_SupportsMapping = (1<<2), eModifierTypeFlag_SupportsEditmode = (1<<3), - + /* For modifiers that support editmode this determines if the * modifier should be enabled by default in editmode. This should * only be used by modifiers that are relatively speedy and * also generally used in editmode, otherwise let the user enable - * it. + * it by hand. */ eModifierTypeFlag_EnableInEditmode = (1<<4), + + /* For modifiers that require original data and so cannot + * be placed after any non-deformative modifier. + */ + eModifierTypeFlag_RequiresOriginalData = (1<<5), } ModifierTypeFlag; typedef struct ModifierTypeInfo { @@ -126,6 +130,14 @@ typedef struct ModifierTypeInfo { */ int (*dependsOnTime)(struct ModifierData *md); + /* Should call the given _walk_ function on with a pointer to each Object pointer + * that the modifier data stores. This is used for linking on file load and for + * unlinking objects or forwarding object references. + * + * This function is optional. + */ + void (*foreachObjectLink)(struct ModifierData *md, struct Object *ob, void (*walk)(void *userData, Object *ob, Object **obpoin), void *userData); + /* Only for deform types, should apply the deformation * to the given vertex array. If the deformer requires information from * the object it can obtain it from the _derivedData_ argument if non-NULL, @@ -183,9 +195,10 @@ int modifier_supportsMapping(struct ModifierData *md); int modifier_couldBeCage (struct ModifierData *md); void modifier_setError (struct ModifierData *md, char *format, ...); -struct ModifierData* modifiers_findByType (struct ListBase *lb, ModifierType type); -void modifiers_clearErrors (struct ListBase *lb); -int modifiers_getCageIndex (struct ListBase *lb, int *lastPossibleCageIndex_r); +void modifiers_foreachObjectLink (struct Object *ob, void (*walk)(void *userData, struct Object *ob, struct Object **obpoin), void *userData); +struct ModifierData* modifiers_findByType (struct Object *ob, ModifierType type); +void modifiers_clearErrors (struct Object *ob); +int modifiers_getCageIndex (struct Object *ob, int *lastPossibleCageIndex_r); #endif diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 4c5fe962c72..574ff1fd31a 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1393,7 +1393,7 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedM DerivedMesh *dm; int numVerts = me->totvert; - modifiers_clearErrors(&ob->modifiers); + modifiers_clearErrors(ob); if (deform_r) *deform_r = NULL; *final_r = NULL; @@ -1434,6 +1434,10 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedM if (!(md->mode&(1<<useRenderParams))) continue; if (mti->type==eModifierTypeType_OnlyDeform && !useDeform) continue; + if ((mti->flags&eModifierTypeFlag_RequiresOriginalData) && dm) { + modifier_setError(md, "Internal error, modifier requires original data (bad stack position)."); + continue; + } if (mti->isDisabled && mti->isDisabled(md)) continue; /* How to apply modifier depends on (a) what we already have as @@ -1521,9 +1525,9 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r, DerivedMesh **final_r) ModifierData *md; float (*deformedVerts)[3] = NULL; DerivedMesh *dm; - int i, numVerts, cageIndex = modifiers_getCageIndex(&ob->modifiers, NULL); + int i, numVerts, cageIndex = modifiers_getCageIndex(ob, NULL); - modifiers_clearErrors(&ob->modifiers); + modifiers_clearErrors(ob); if (cage_r && cageIndex==-1) { *cage_r = getEditMeshDerivedMesh(em, NULL); @@ -1535,6 +1539,10 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r, DerivedMesh **final_r) if (!(md->mode&eModifierMode_Realtime)) continue; if (!(md->mode&eModifierMode_Editmode)) continue; + if ((mti->flags&eModifierTypeFlag_RequiresOriginalData) && dm) { + modifier_setError(md, "Internal error, modifier requires original data (bad stack position)."); + continue; + } if (mti->isDisabled && mti->isDisabled(md)) continue; if (!(mti->flags&eModifierTypeFlag_SupportsEditmode)) continue; diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 8e33303d137..a1f04eaa048 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -156,98 +156,13 @@ int get_defgroup_num (Object *ob, bDeformGroup *dg) /* *************** HOOK ****************** */ -/* vec==NULL: init - vec is supposed to be local coord, deform happens in local space -*/ - -void hook_object_deform(Object *ob, int index, float *vec) -{ - float totforce; - ObHook *hook; - float vect[3], vectot[3]; - - if(ob->hooks.first==NULL) return; - - /* reinitialize if... */ - if(vec==NULL) { - totforce= 0.0; - for(hook= ob->hooks.first; hook; hook= hook->next) { - if(hook->parent) { - hook->curindex= 0; - Mat4Invert(ob->imat, ob->obmat); - /* apparently this call goes from right to left... */ - Mat4MulSerie(hook->mat, ob->imat, hook->parent->obmat, hook->parentinv, NULL, - NULL, NULL, NULL, NULL); - } - } - return; - } - - totforce= 0.0; - vectot[0]= vectot[1]= vectot[2]= 0.0; - - for(hook= ob->hooks.first; hook; hook= hook->next) { - if(hook->parent) { - - /* is 'index' in hook array? */ - while(hook->curindex < hook->totindex-1) { - if( hook->indexar[hook->curindex] < index ) hook->curindex++; - else break; - } - - if( hook->indexar[hook->curindex]==index ) { - float fac= hook->force, len; - - VecMat4MulVecfl(vect, hook->mat, vec); - - if(hook->falloff!=0.0) { - /* hook->cent is in local coords */ - len= VecLenf(vec, hook->cent); - if(len > hook->falloff) fac= 0.0; - else if(len>0.0) fac*= sqrt(1.0 - len/hook->falloff); - } - if(fac!=0.0) { - totforce+= fac; - vectot[0]+= fac*vect[0]; - vectot[1]+= fac*vect[1]; - vectot[2]+= fac*vect[2]; - } - } - } - } - - /* if totforce < 1.0, we take old position also into account */ - if(totforce<1.0) { - vectot[0]+= (1.0-totforce)*vec[0]; - vectot[1]+= (1.0-totforce)*vec[1]; - vectot[2]+= (1.0-totforce)*vec[2]; - } - else VecMulf(vectot, 1.0/totforce); - - VECCOPY(vec, vectot); -} - - void mesh_modifier(Object *ob, float (**vertexCos_r)[3]) { Mesh *me= ob->data; float (*vertexCos)[3] = NULL; - int a; do_mesh_key(me); - /* hooks */ - if(ob->hooks.first) { - if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL); - - /* NULL signals initialize */ - hook_object_deform(ob, 0, NULL); - - for(a=0; a<me->totvert; a++) { - hook_object_deform(ob, a, vertexCos[a]); - } - } - if((ob->softflag & OB_SB_ENABLE) && !(ob->softflag & OB_SB_POSTDEF)) { if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL); sbObjectStep(ob, (float)G.scene->r.cfra, vertexCos); @@ -281,15 +196,12 @@ int curve_modifier(Object *ob, char mode) static ListBase nurb={NULL, NULL}; Curve *cu= ob->data; Nurb *nu, *newnu; - BezTriple *bezt; - BPoint *bp; - int a, index, done= 0; + int done= 0; do_curve_key(cu); /* conditions if it's needed */ - if(ob->hooks.first); - else if(ob->parent && ob->partype==PARSKEL); + if(ob->parent && ob->partype==PARSKEL); else if(ob->parent && ob->parent->type==OB_LATTICE); else return 0; @@ -302,39 +214,6 @@ int curve_modifier(Object *ob, char mode) BLI_addtail(&nurb, newnu); nu= nu->next; } - - /* hooks */ - if(ob->hooks.first) { - done= 1; - - /* NULL signals initialize */ - hook_object_deform(ob, 0, NULL); - index= 0; - - nu= cu->nurb.first; - while(nu) { - if((nu->type & 7)==CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; - while(a--) { - hook_object_deform(ob, index++, bezt->vec[0]); - hook_object_deform(ob, index++, bezt->vec[1]); - hook_object_deform(ob, index++, bezt->vec[2]); - bezt++; - } - } - else { - bp= nu->bp; - a= nu->pntsu*nu->pntsv; - while(a--) { - hook_object_deform(ob, index++, bp->vec); - bp++; - } - } - - nu= nu->next; - } - } } else if(mode=='e') { /* paste */ @@ -352,14 +231,12 @@ int lattice_modifier(Object *ob, char mode) { static BPoint *bpoint; Lattice *lt= ob->data; - BPoint *bp; - int a, index, done= 0; + int done= 0; do_latt_key(lt); /* conditions if it's needed */ - if(ob->hooks.first); - else if(ob->parent && ob->partype==PARSKEL); + if(ob->parent && ob->partype==PARSKEL); else if((ob->softflag & OB_SB_ENABLE)); else return 0; @@ -367,25 +244,9 @@ int lattice_modifier(Object *ob, char mode) /* copy */ bpoint= MEM_dupallocN(lt->def); - /* hooks */ - if(ob->hooks.first) { - done= 1; - - /* NULL signals initialize */ - hook_object_deform(ob, 0, NULL); - index= 0; - bp= lt->def; - a= lt->pntsu*lt->pntsv*lt->pntsw; - while(a--) { - hook_object_deform(ob, index++, bp->vec); - bp++; - } - } - if((ob->softflag & OB_SB_ENABLE)) { sbObjectStep(ob, (float)G.scene->r.cfra, NULL); } - } else { // end MEM_freeN(lt->def); diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index c3428d865fe..323c6793c7d 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -352,16 +352,6 @@ struct DagForest *build_dag(struct Scene *sce, short mask) } } } - if (ob->hooks.first) { - ObHook *hook; - - for(hook= ob->hooks.first; hook; hook= hook->next) { - if(hook->parent) { - node3 = dag_get_node(dag,hook->parent); - dag_add_relation(dag,node3,node,DAG_RL_OB_DATA); - } - } - } if (ob->modifiers.first) { ModifierData *md; diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 6f9e2f861b2..d6c4a6838ae 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -4,6 +4,7 @@ #include "BLI_blenlib.h" #include "BLI_rand.h" +#include "BLI_arithb.h" #include "MEM_guardedalloc.h" @@ -56,6 +57,13 @@ static int curveModifier_isDisabled(ModifierData *md) return !cmd->object; } +static void curveModifier_foreachObjectLink(ModifierData *md, Object *ob, void (*walk)(void *userData, Object *ob, Object **obpoin), void *userData) +{ + CurveModifierData *cmd = (CurveModifierData*) md; + + walk(userData, ob, &cmd->object); +} + static void curveModifier_updateDepgraph(ModifierData *md, DagForest *forest, Object *ob, DagNode *obNode) { CurveModifierData *cmd = (CurveModifierData*) md; @@ -98,6 +106,13 @@ static int latticeModifier_isDisabled(ModifierData *md) return !lmd->object; } +static void latticeModifier_foreachObjectLink(ModifierData *md, Object *ob, void (*walk)(void *userData, Object *ob, Object **obpoin), void *userData) +{ + LatticeModifierData *lmd = (LatticeModifierData*) md; + + walk(userData, ob, &lmd->object); +} + static void latticeModifier_updateDepgraph(ModifierData *md, DagForest *forest, Object *ob, DagNode *obNode) { LatticeModifierData *lmd = (LatticeModifierData*) md; @@ -1007,6 +1022,158 @@ static void waveModifier_deformVertsEM(ModifierData *md, Object *ob, void *editD waveModifier_deformVerts(md, ob, NULL, vertexCos, numVerts); } +/* Armature */ + +static void armatureModifier_copyData(ModifierData *md, ModifierData *target) +{ + ArmatureModifierData *amd = (ArmatureModifierData*) md; + ArmatureModifierData *tamd = (ArmatureModifierData*) target; + + tamd->object = amd->object; +} + +static int armatureModifier_isDisabled(ModifierData *md) +{ + ArmatureModifierData *amd = (ArmatureModifierData*) md; + + return !amd->object; +} + +static void armatureModifier_foreachObjectLink(ModifierData *md, Object *ob, void (*walk)(void *userData, Object *ob, Object **obpoin), void *userData) +{ + ArmatureModifierData *amd = (ArmatureModifierData*) md; + + walk(userData, ob, &amd->object); +} + +static void armatureModifier_updateDepgraph(ModifierData *md, DagForest *forest, Object *ob, DagNode *obNode) +{ + ArmatureModifierData *amd = (ArmatureModifierData*) md; + + if (amd->object) { + DagNode *curNode = dag_get_node(forest, amd->object); + + dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA); + } +} + +static void armatureModifier_deformVerts(ModifierData *md, Object *ob, void *derivedData, float (*vertexCos)[3], int numVerts) +{ + ArmatureModifierData *amd = (ArmatureModifierData*) md; + + armature_deform_verts(amd->object, ob, vertexCos, numVerts); +} + +static void armatureModifier_deformVertsEM(ModifierData *md, Object *ob, void *editData, void *derivedData, float (*vertexCos)[3], int numVerts) +{ + ArmatureModifierData *amd = (ArmatureModifierData*) md; + + armature_deform_verts(amd->object, ob, vertexCos, numVerts); +} + +/* Hook */ + +static void hookModifier_initData(ModifierData *md) +{ + HookModifierData *hmd = (HookModifierData*) md; + + hmd->force= 1.0; +} + +static void hookModifier_copyData(ModifierData *md, ModifierData *target) +{ + HookModifierData *hmd = (HookModifierData*) md; + HookModifierData *thmd = (HookModifierData*) target; + + VECCOPY(thmd->cent, hmd->cent); + thmd->falloff = hmd->falloff; + thmd->force = hmd->force; + thmd->object = hmd->object; + thmd->totindex = hmd->totindex; + thmd->indexar = MEM_dupallocN(hmd->indexar); + memcpy(thmd->parentinv, hmd->parentinv, sizeof(hmd->parentinv)); +} + +static void hookModifier_freeData(ModifierData *md) +{ + HookModifierData *hmd = (HookModifierData*) md; + + if (hmd->indexar) MEM_freeN(hmd->indexar); +} + +static int hookModifier_isDisabled(ModifierData *md) +{ + HookModifierData *hmd = (HookModifierData*) md; + + return !hmd->object; +} + +static void hookModifier_foreachObjectLink(ModifierData *md, Object *ob, void (*walk)(void *userData, Object *ob, Object **obpoin), void *userData) +{ + HookModifierData *hmd = (HookModifierData*) md; + + walk(userData, ob, &hmd->object); +} + +static void hookModifier_updateDepgraph(ModifierData *md, DagForest *forest, Object *ob, DagNode *obNode) +{ + HookModifierData *hmd = (HookModifierData*) md; + + if (hmd->object) { + DagNode *curNode = dag_get_node(forest, hmd->object); + + dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA); + } +} + +static void hookModifier_deformVerts(ModifierData *md, Object *ob, void *derivedData, float (*vertexCos)[3], int numVerts) +{ + HookModifierData *hmd = (HookModifierData*) md; + float vec[3], mat[4][4]; + int i; + + Mat4Invert(ob->imat, ob->obmat); + Mat4MulSerie(mat, ob->imat, hmd->object->obmat, hmd->parentinv, NULL, NULL, NULL, NULL, NULL); + + for (i=0; i<hmd->totindex; i++) { + float *co = vertexCos[hmd->indexar[i]]; + float fac = hmd->force; + + if(hmd->falloff!=0.0) { + float len= VecLenf(co, hmd->cent); + if(len > hmd->falloff) fac = 0.0; + else if(len>0.0) fac *= sqrt(1.0 - len/hmd->falloff); + } + + if(fac!=0.0) { + VecMat4MulVecfl(vec, mat, co); + VecLerpf(co, co, vec, fac); + } + } +} + +static void hookModifier_deformVertsEM(ModifierData *md, Object *ob, void *editData, void *derivedData, float (*vertexCos)[3], int numVerts) +{ + HookModifierData *hmd = (HookModifierData*) md; + + hookModifier_deformVerts(md, ob, derivedData, vertexCos, numVerts); +} + +/* Softbody */ + +static void softbodyModifier_deformVerts(ModifierData *md, Object *ob, void *derivedData, float (*vertexCos)[3], int numVerts) +{ + SoftbodyModifierData *hmd = (SoftbodyModifierData*) md; + +// sbObjectStep(ob, (float)G.scene->r.cfra, vertexCos); +} + +static void softbodyModifier_deformVertsEM(ModifierData *md, Object *ob, void *editData, void *derivedData, float (*vertexCos)[3], int numVerts) +{ + SoftbodyModifierData *hmd = (SoftbodyModifierData*) md; + +// sbObjectStep(ob, (float)G.scene->r.cfra, vertexCos); +} /***/ @@ -1044,6 +1211,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode; mti->copyData = curveModifier_copyData; mti->isDisabled = curveModifier_isDisabled; + mti->foreachObjectLink = curveModifier_foreachObjectLink; mti->updateDepgraph = curveModifier_updateDepgraph; mti->deformVerts = curveModifier_deformVerts; mti->deformVertsEM = curveModifier_deformVertsEM; @@ -1053,6 +1221,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode; mti->copyData = latticeModifier_copyData; mti->isDisabled = latticeModifier_isDisabled; + mti->foreachObjectLink = latticeModifier_foreachObjectLink; mti->updateDepgraph = latticeModifier_updateDepgraph; mti->deformVerts = latticeModifier_deformVerts; mti->deformVertsEM = latticeModifier_deformVertsEM; @@ -1097,6 +1266,34 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti->deformVerts = waveModifier_deformVerts; mti->deformVertsEM = waveModifier_deformVertsEM; + mti = INIT_TYPE(Armature); + mti->type = eModifierTypeType_OnlyDeform; + mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode; + mti->copyData = armatureModifier_copyData; + mti->isDisabled = armatureModifier_isDisabled; + mti->foreachObjectLink = armatureModifier_foreachObjectLink; + mti->updateDepgraph = armatureModifier_updateDepgraph; + mti->deformVerts = armatureModifier_deformVerts; + mti->deformVertsEM = armatureModifier_deformVertsEM; + + mti = INIT_TYPE(Hook); + mti->type = eModifierTypeType_OnlyDeform; + mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_RequiresOriginalData; + mti->initData = hookModifier_initData; + mti->copyData = hookModifier_copyData; + mti->freeData = hookModifier_freeData; + mti->isDisabled = hookModifier_isDisabled; + mti->foreachObjectLink = hookModifier_foreachObjectLink; + mti->updateDepgraph = hookModifier_updateDepgraph; + mti->deformVerts = hookModifier_deformVerts; + mti->deformVertsEM = hookModifier_deformVertsEM; + + mti = INIT_TYPE(Softbody); + mti->type = eModifierTypeType_OnlyDeform; + mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode; + mti->deformVerts = softbodyModifier_deformVerts; + mti->deformVertsEM = softbodyModifier_deformVertsEM; + typeArrInit = 0; #undef INIT_TYPE } @@ -1108,11 +1305,15 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) } } +/***/ + ModifierData *modifier_new(int type) { ModifierTypeInfo *mti = modifierType_getInfo(type); ModifierData *md = MEM_callocN(mti->structSize, mti->structName); + strcpy(md->name, mti->name); + md->type = type; md->mode = eModifierMode_Realtime|eModifierMode_Render|eModifierMode_Expanded; @@ -1150,9 +1351,9 @@ int modifier_supportsMapping(ModifierData *md) (mti->flags&eModifierTypeFlag_SupportsMapping))) ); } -ModifierData *modifiers_findByType(struct ListBase *lb, ModifierType type) +ModifierData *modifiers_findByType(Object *ob, ModifierType type) { - ModifierData *md = lb->first; + ModifierData *md = ob->modifiers.first; for (; md; md=md->next) if (md->type==type) @@ -1161,18 +1362,32 @@ ModifierData *modifiers_findByType(struct ListBase *lb, ModifierType type) return md; } -void modifiers_clearErrors(struct ListBase *lb) +void modifiers_clearErrors(Object *ob) { - ModifierData *md = lb->first; + ModifierData *md = ob->modifiers.first; + int qRedraw = 0; for (; md; md=md->next) { if (md->error) { MEM_freeN(md->error); md->error = NULL; - allqueue(REDRAWBUTSEDIT, 0); + qRedraw = 1; } } + + if (qRedraw) allqueue(REDRAWBUTSEDIT, 0); +} + +void modifiers_foreachObjectLink(Object *ob, void (*walk)(void *userData, Object *ob, Object **obpoin), void *userData) +{ + ModifierData *md = ob->modifiers.first; + + for (; md; md=md->next) { + ModifierTypeInfo *mti = modifierType_getInfo(md->type); + + if (mti->foreachObjectLink) mti->foreachObjectLink(md, ob, walk, userData); + } } void modifier_copyData(ModifierData *md, ModifierData *target) @@ -1212,9 +1427,9 @@ void modifier_setError(ModifierData *md, char *format, ...) allqueue(REDRAWBUTSEDIT, 0); } -int modifiers_getCageIndex(ListBase *lb, int *lastPossibleCageIndex_r) +int modifiers_getCageIndex(Object *ob, int *lastPossibleCageIndex_r) { - ModifierData *md = lb->first; + ModifierData *md = ob->modifiers.first; int i, cageIndex = -1; /* Find the last modifier acting on the cage. */ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index c8feb7f89ce..ab0ee151209 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -149,29 +149,6 @@ void update_base_layer(Object *ob) } } -static void free_hooks(ListBase *lb) -{ - while(lb->first) { - ObHook *hook= lb->first; - if(hook->indexar) MEM_freeN(hook->indexar); - BLI_remlink(lb, hook); - MEM_freeN(hook); - } -} - -static void copy_hooks(ListBase *new, ListBase *old) -{ - ObHook *hook, *hookn; - new->first= new->last= NULL; - - for(hook= old->first; hook; hook= hook->next) { - hookn= MEM_dupallocN(hook); - hookn->indexar= MEM_dupallocN(hookn->indexar); - BLI_addtail(new, hookn); - } - -} - void object_free_modifiers(Object *ob) { while (ob->modifiers.first) { @@ -233,8 +210,6 @@ void free_object(Object *ob) free_constraint_channels(&ob->constraintChannels); free_nlastrips(&ob->nlastrips); - free_hooks(&ob->hooks); - freedisplist(&ob->disp); BPY_free_scriptlink(&ob->scriptlink); @@ -243,6 +218,15 @@ void free_object(Object *ob) if(ob->soft) sbFree(ob->soft); } +static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin) +{ + Object *unlinkOb = userData; + + if (*obpoin==unlinkOb) { + *obpoin = NULL; + ob->recalc |= OB_RECALC; + } +} void unlink_object(Object *ob) { Object *obt; @@ -252,10 +236,8 @@ void unlink_object(Object *ob) Scene *sce; Curve *cu; Tex *tex; - ObHook *hook; Group *group; bConstraint *con; - ModifierData *md; int a; char *str; @@ -277,30 +259,7 @@ void unlink_object(Object *ob) obt->recalc |= OB_RECALC_OB; } - for(hook=obt->hooks.first; hook; hook= hook->next) { - if(hook->parent==ob) { - hook->parent= NULL; - obt->recalc |= OB_RECALC; - } - } - - for (md=obt->modifiers.first; md; md=md->next) { - if (md->type==eModifierType_Curve) { - CurveModifierData *cmd = (CurveModifierData*) md; - - if (cmd->object==ob) { - cmd->object = NULL; - obt->recalc |= OB_RECALC; - } - } else if (md->type==eModifierType_Lattice) { - LatticeModifierData *lmd = (LatticeModifierData*) md; - - if (lmd->object==ob) { - lmd->object = NULL; - obt->recalc |= OB_RECALC; - } - } - } + modifiers_foreachObjectLink(obt, unlink_object__unlinkModifierLinks, ob); if ELEM(obt->type, OB_CURVE, OB_FONT) { cu= obt->data; @@ -860,8 +819,6 @@ Object *copy_object(Object *ob) copy_nlastrips(&obn->nlastrips, &ob->nlastrips); copy_constraints (&obn->constraints, &ob->constraints); - copy_hooks( &obn->hooks, &ob->hooks); - actcon = clone_constraint_channels (&obn->constraintChannels, &ob->constraintChannels, ob->activecon); /* If the active constraint channel was in this list, update it */ if (actcon) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index d010d16c786..b4da0f1097c 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -745,7 +745,6 @@ static int object_has_edges(Object *ob) /* helper call */ static void set_body_point(Object *ob, BodyPoint *bp, float *vec) { - VECCOPY(bp->pos, vec); Mat4MulVecfl(ob->obmat, bp->pos); // yep, sofbody is global coords VECCOPY(bp->origS, bp->pos); |