Fix #29957: Texture "Generate" mapping work as global with cloth modifier

Make Cloth modifier deformation only so now it applies on orco dm properly.
This commit is contained in:
2012-01-26 17:03:30 +00:00
parent de5d5ded7b
commit 5d49eff25a
4 changed files with 47 additions and 50 deletions

View File

@@ -216,7 +216,7 @@ void clmdSetInterruptCallBack ( int ( *f ) ( void ) );
void cloth_free_modifier_extern ( struct ClothModifierData *clmd ); void cloth_free_modifier_extern ( struct ClothModifierData *clmd );
void cloth_free_modifier ( struct ClothModifierData *clmd ); void cloth_free_modifier ( struct ClothModifierData *clmd );
void cloth_init ( struct ClothModifierData *clmd ); void cloth_init ( struct ClothModifierData *clmd );
struct DerivedMesh *clothModifier_do ( struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm); void clothModifier_do ( struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]);
void cloth_update_normals ( ClothVertex *verts, int nVerts, struct MFace *face, int totface ); void cloth_update_normals ( ClothVertex *verts, int nVerts, struct MFace *face, int totface );
int cloth_uses_vgroup(struct ClothModifierData *clmd); int cloth_uses_vgroup(struct ClothModifierData *clmd);

View File

@@ -90,7 +90,7 @@ static CM_SOLVER_DEF solvers [] =
/* ********** cloth engine ******* */ /* ********** cloth engine ******* */
/* Prototypes for internal functions. /* Prototypes for internal functions.
*/ */
static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh *dm); static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertexCos)[3]);
static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm ); static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm );
static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float framenr, int first); static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float framenr, int first);
static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ); static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm );
@@ -429,9 +429,8 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
/************************************************ /************************************************
* clothModifier_do - main simulation function * clothModifier_do - main simulation function
************************************************/ ************************************************/
DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm) void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3])
{ {
DerivedMesh *result;
PointCache *cache; PointCache *cache;
PTCacheID pid; PTCacheID pid;
float timescale; float timescale;
@@ -441,20 +440,14 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
clmd->scene= scene; /* nice to pass on later :) */ clmd->scene= scene; /* nice to pass on later :) */
framenr= (int)scene->r.cfra; framenr= (int)scene->r.cfra;
cache= clmd->point_cache; cache= clmd->point_cache;
result = CDDM_copy(dm);
BKE_ptcache_id_from_cloth(&pid, ob, clmd); BKE_ptcache_id_from_cloth(&pid, ob, clmd);
BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale); BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale);
clmd->sim_parms->timescale= timescale; clmd->sim_parms->timescale= timescale;
if(!result) {
BKE_ptcache_invalidate(cache);
return dm;
}
if(clmd->sim_parms->reset if(clmd->sim_parms->reset
|| (framenr == (startframe - clmd->sim_parms->preroll) && clmd->sim_parms->preroll != 0) || (framenr == (startframe - clmd->sim_parms->preroll) && clmd->sim_parms->preroll != 0)
|| (clmd->clothObject && result->getNumVerts(result) != clmd->clothObject->numverts)) || (clmd->clothObject && dm->getNumVerts(dm) != clmd->clothObject->numverts))
{ {
clmd->sim_parms->reset = 0; clmd->sim_parms->reset = 0;
cache->flag |= PTCACHE_OUTDATED; cache->flag |= PTCACHE_OUTDATED;
@@ -462,7 +455,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
BKE_ptcache_validate(cache, 0); BKE_ptcache_validate(cache, 0);
cache->last_exact= 0; cache->last_exact= 0;
cache->flag &= ~PTCACHE_REDO_NEEDED; cache->flag &= ~PTCACHE_REDO_NEEDED;
return result; return;
} }
// unused in the moment, calculated separately in implicit.c // unused in the moment, calculated separately in implicit.c
@@ -474,20 +467,20 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
/* do simulation */ /* do simulation */
if(!do_init_cloth(ob, clmd, dm, framenr)) if(!do_init_cloth(ob, clmd, dm, framenr))
return result; return;
do_step_cloth(ob, clmd, dm, framenr); do_step_cloth(ob, clmd, dm, framenr);
cloth_to_object(ob, clmd, result); cloth_to_object(ob, clmd, vertexCos);
clmd->clothObject->last_frame= framenr; clmd->clothObject->last_frame= framenr;
return result; return;
} }
/* simulation is only active during a specific period */ /* simulation is only active during a specific period */
if(framenr < startframe) { if(framenr < startframe) {
BKE_ptcache_invalidate(cache); BKE_ptcache_invalidate(cache);
return result; return;
} }
else if(framenr > endframe) { else if(framenr > endframe) {
framenr= endframe; framenr= endframe;
@@ -495,7 +488,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
/* initialize simulation data if it didn't exist already */ /* initialize simulation data if it didn't exist already */
if(!do_init_cloth(ob, clmd, dm, framenr)) if(!do_init_cloth(ob, clmd, dm, framenr))
return result; return;
if((framenr == startframe) && (clmd->sim_parms->preroll == 0)) { if((framenr == startframe) && (clmd->sim_parms->preroll == 0)) {
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
@@ -503,7 +496,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
BKE_ptcache_validate(cache, framenr); BKE_ptcache_validate(cache, framenr);
cache->flag &= ~PTCACHE_REDO_NEEDED; cache->flag &= ~PTCACHE_REDO_NEEDED;
clmd->clothObject->last_frame= framenr; clmd->clothObject->last_frame= framenr;
return result; return;
} }
/* try to read from cache */ /* try to read from cache */
@@ -511,7 +504,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) { if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
implicit_set_positions(clmd); implicit_set_positions(clmd);
cloth_to_object (ob, clmd, result); cloth_to_object (ob, clmd, vertexCos);
BKE_ptcache_validate(cache, framenr); BKE_ptcache_validate(cache, framenr);
@@ -520,7 +513,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
clmd->clothObject->last_frame= framenr; clmd->clothObject->last_frame= framenr;
return result; return;
} }
else if(cache_result==PTCACHE_READ_OLD) { else if(cache_result==PTCACHE_READ_OLD) {
implicit_set_positions(clmd); implicit_set_positions(clmd);
@@ -528,11 +521,11 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
else if( /*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) { /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */ else if( /*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) { /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */
/* if baked and nothing in cache, do nothing */ /* if baked and nothing in cache, do nothing */
BKE_ptcache_invalidate(cache); BKE_ptcache_invalidate(cache);
return result; return;
} }
if(framenr!=clmd->clothObject->last_frame+1) if(framenr!=clmd->clothObject->last_frame+1)
return result; return;
/* if on second frame, write cache for first frame */ /* if on second frame, write cache for first frame */
if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0)) if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
@@ -549,10 +542,8 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
else else
BKE_ptcache_write(&pid, framenr); BKE_ptcache_write(&pid, framenr);
cloth_to_object (ob, clmd, result); cloth_to_object (ob, clmd, vertexCos);
clmd->clothObject->last_frame= framenr; clmd->clothObject->last_frame= framenr;
return result;
} }
/* frees all */ /* frees all */
@@ -707,24 +698,19 @@ void cloth_free_modifier_extern ( ClothModifierData *clmd )
* cloth_to_object - copies the deformed vertices to the object. * cloth_to_object - copies the deformed vertices to the object.
* *
**/ **/
static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh *dm) static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertexCos)[3])
{ {
unsigned int i = 0; unsigned int i = 0;
MVert *mvert = NULL;
unsigned int numverts;
Cloth *cloth = clmd->clothObject; Cloth *cloth = clmd->clothObject;
if (clmd->clothObject) { if (clmd->clothObject) {
/* inverse matrix is not uptodate... */ /* inverse matrix is not uptodate... */
invert_m4_m4(ob->imat, ob->obmat); invert_m4_m4(ob->imat, ob->obmat);
mvert = CDDM_get_verts(dm); for (i = 0; i < cloth->numverts; i++)
numverts = dm->getNumVerts(dm);
for (i = 0; i < numverts; i++)
{ {
copy_v3_v3 (mvert[i].co, cloth->verts[i].x); copy_v3_v3 (vertexCos[i], cloth->verts[i].x);
mul_m4_v3(ob->imat, mvert[i].co); /* cloth is in global coords */ mul_m4_v3(ob->imat, vertexCos[i]); /* cloth is in global coords */
} }
} }
} }

View File

@@ -3480,6 +3480,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
int totedge; int totedge;
int k; int k;
float hairmat[4][4]; float hairmat[4][4];
float (*deformedVerts)[3];
if(!psys->clmd) { if(!psys->clmd) {
psys->clmd = (ClothModifierData*)modifier_new(eModifierType_Cloth); psys->clmd = (ClothModifierData*)modifier_new(eModifierType_Cloth);
@@ -3573,7 +3574,15 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
psys->clmd->point_cache = psys->pointcache; psys->clmd->point_cache = psys->pointcache;
psys->clmd->sim_parms->effector_weights = psys->part->effector_weights; psys->clmd->sim_parms->effector_weights = psys->part->effector_weights;
psys->hair_out_dm = clothModifier_do(psys->clmd, sim->scene, sim->ob, dm); deformedVerts = MEM_callocN(sizeof(*deformedVerts)*dm->getNumVerts(dm), "do_hair_dynamics vertexCos");
psys->hair_out_dm = CDDM_copy(dm);
psys->hair_out_dm->getVertCos(psys->hair_out_dm, deformedVerts);
clothModifier_do(psys->clmd, sim->scene, sim->ob, dm, deformedVerts);
CDDM_apply_vert_coords(psys->hair_out_dm, deformedVerts);
MEM_freeN(deformedVerts);
psys->clmd->sim_parms->effector_weights = NULL; psys->clmd->sim_parms->effector_weights = NULL;
} }

View File

@@ -67,11 +67,10 @@ static void initData(ModifierData *md)
cloth_init (clmd); cloth_init (clmd);
} }
static DerivedMesh *applyModifier(ModifierData *md, Object *ob, static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3],
DerivedMesh *dm, int UNUSED(numVerts), int UNUSED(useRenderParams), int UNUSED(isFinalCalc))
int UNUSED(useRenderParams),
int UNUSED(isFinalCalc))
{ {
DerivedMesh *dm;
ClothModifierData *clmd = (ClothModifierData*) md; ClothModifierData *clmd = (ClothModifierData*) md;
DerivedMesh *result=NULL; DerivedMesh *result=NULL;
@@ -79,19 +78,22 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
if(!clmd->sim_parms || !clmd->coll_parms) if(!clmd->sim_parms || !clmd->coll_parms)
{ {
initData(md); initData(md);
if(!clmd->sim_parms || !clmd->coll_parms) if(!clmd->sim_parms || !clmd->coll_parms)
return dm; return;
} }
result = clothModifier_do(clmd, md->scene, ob, dm); dm = get_dm(ob, NULL, derivedData, NULL, 0);
if(result) clothModifier_do(clmd, md->scene, ob, dm, vertexCos);
{
CDDM_calc_normals(result); if(result) {
return result; result->getVertCos(result, vertexCos);
result->release(result);
} }
return dm;
if(dm != derivedData)
dm->release(dm);
} }
static void updateDepgraph( static void updateDepgraph(
@@ -206,17 +208,17 @@ ModifierTypeInfo modifierType_Cloth = {
/* name */ "Cloth", /* name */ "Cloth",
/* structName */ "ClothModifierData", /* structName */ "ClothModifierData",
/* structSize */ sizeof(ClothModifierData), /* structSize */ sizeof(ClothModifierData),
/* type */ eModifierTypeType_Nonconstructive, /* type */ eModifierTypeType_OnlyDeform,
/* flags */ eModifierTypeFlag_AcceptsMesh /* flags */ eModifierTypeFlag_AcceptsMesh
| eModifierTypeFlag_UsesPointCache | eModifierTypeFlag_UsesPointCache
| eModifierTypeFlag_Single, | eModifierTypeFlag_Single,
/* copyData */ copyData, /* copyData */ copyData,
/* deformVerts */ NULL, /* deformVerts */ deformVerts,
/* deformMatrices */ NULL, /* deformMatrices */ NULL,
/* deformVertsEM */ NULL, /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL, /* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier, /* applyModifier */ NULL,
/* applyModifierEM */ NULL, /* applyModifierEM */ NULL,
/* initData */ initData, /* initData */ initData,
/* requiredDataMask */ requiredDataMask, /* requiredDataMask */ requiredDataMask,