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:
@@ -216,7 +216,7 @@ void clmdSetInterruptCallBack ( int ( *f ) ( void ) );
|
||||
void cloth_free_modifier_extern ( struct ClothModifierData *clmd );
|
||||
void cloth_free_modifier ( 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 );
|
||||
int cloth_uses_vgroup(struct ClothModifierData *clmd);
|
||||
|
||||
@@ -90,7 +90,7 @@ static CM_SOLVER_DEF solvers [] =
|
||||
/* ********** cloth engine ******* */
|
||||
/* 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 int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float framenr, int first);
|
||||
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
|
||||
************************************************/
|
||||
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;
|
||||
PTCacheID pid;
|
||||
float timescale;
|
||||
@@ -441,20 +440,14 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
|
||||
clmd->scene= scene; /* nice to pass on later :) */
|
||||
framenr= (int)scene->r.cfra;
|
||||
cache= clmd->point_cache;
|
||||
result = CDDM_copy(dm);
|
||||
|
||||
BKE_ptcache_id_from_cloth(&pid, ob, clmd);
|
||||
BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, ×cale);
|
||||
clmd->sim_parms->timescale= timescale;
|
||||
|
||||
if(!result) {
|
||||
BKE_ptcache_invalidate(cache);
|
||||
return dm;
|
||||
}
|
||||
|
||||
if(clmd->sim_parms->reset
|
||||
|| (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;
|
||||
cache->flag |= PTCACHE_OUTDATED;
|
||||
@@ -462,7 +455,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
|
||||
BKE_ptcache_validate(cache, 0);
|
||||
cache->last_exact= 0;
|
||||
cache->flag &= ~PTCACHE_REDO_NEEDED;
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
|
||||
// unused in the moment, calculated separately in implicit.c
|
||||
@@ -474,20 +467,20 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
|
||||
|
||||
/* do simulation */
|
||||
if(!do_init_cloth(ob, clmd, dm, framenr))
|
||||
return result;
|
||||
return;
|
||||
|
||||
do_step_cloth(ob, clmd, dm, framenr);
|
||||
cloth_to_object(ob, clmd, result);
|
||||
cloth_to_object(ob, clmd, vertexCos);
|
||||
|
||||
clmd->clothObject->last_frame= framenr;
|
||||
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
|
||||
/* simulation is only active during a specific period */
|
||||
if(framenr < startframe) {
|
||||
BKE_ptcache_invalidate(cache);
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
else if(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 */
|
||||
if(!do_init_cloth(ob, clmd, dm, framenr))
|
||||
return result;
|
||||
return;
|
||||
|
||||
if((framenr == startframe) && (clmd->sim_parms->preroll == 0)) {
|
||||
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);
|
||||
cache->flag &= ~PTCACHE_REDO_NEEDED;
|
||||
clmd->clothObject->last_frame= framenr;
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
implicit_set_positions(clmd);
|
||||
cloth_to_object (ob, clmd, result);
|
||||
cloth_to_object (ob, clmd, vertexCos);
|
||||
|
||||
BKE_ptcache_validate(cache, framenr);
|
||||
|
||||
@@ -520,7 +513,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
|
||||
|
||||
clmd->clothObject->last_frame= framenr;
|
||||
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
else if(cache_result==PTCACHE_READ_OLD) {
|
||||
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 */
|
||||
/* if baked and nothing in cache, do nothing */
|
||||
BKE_ptcache_invalidate(cache);
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
|
||||
if(framenr!=clmd->clothObject->last_frame+1)
|
||||
return result;
|
||||
return;
|
||||
|
||||
/* if on second frame, write cache for first frame */
|
||||
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
|
||||
BKE_ptcache_write(&pid, framenr);
|
||||
|
||||
cloth_to_object (ob, clmd, result);
|
||||
cloth_to_object (ob, clmd, vertexCos);
|
||||
clmd->clothObject->last_frame= framenr;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* frees all */
|
||||
@@ -707,24 +698,19 @@ void cloth_free_modifier_extern ( ClothModifierData *clmd )
|
||||
* 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;
|
||||
MVert *mvert = NULL;
|
||||
unsigned int numverts;
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
|
||||
if (clmd->clothObject) {
|
||||
/* inverse matrix is not uptodate... */
|
||||
invert_m4_m4(ob->imat, ob->obmat);
|
||||
|
||||
mvert = CDDM_get_verts(dm);
|
||||
numverts = dm->getNumVerts(dm);
|
||||
|
||||
for (i = 0; i < numverts; i++)
|
||||
for (i = 0; i < cloth->numverts; i++)
|
||||
{
|
||||
copy_v3_v3 (mvert[i].co, cloth->verts[i].x);
|
||||
mul_m4_v3(ob->imat, mvert[i].co); /* cloth is in global coords */
|
||||
copy_v3_v3 (vertexCos[i], cloth->verts[i].x);
|
||||
mul_m4_v3(ob->imat, vertexCos[i]); /* cloth is in global coords */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3480,6 +3480,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
|
||||
int totedge;
|
||||
int k;
|
||||
float hairmat[4][4];
|
||||
float (*deformedVerts)[3];
|
||||
|
||||
if(!psys->clmd) {
|
||||
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->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;
|
||||
}
|
||||
|
||||
@@ -67,11 +67,10 @@ static void initData(ModifierData *md)
|
||||
cloth_init (clmd);
|
||||
}
|
||||
|
||||
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
||||
DerivedMesh *dm,
|
||||
int UNUSED(useRenderParams),
|
||||
int UNUSED(isFinalCalc))
|
||||
static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3],
|
||||
int UNUSED(numVerts), int UNUSED(useRenderParams), int UNUSED(isFinalCalc))
|
||||
{
|
||||
DerivedMesh *dm;
|
||||
ClothModifierData *clmd = (ClothModifierData*) md;
|
||||
DerivedMesh *result=NULL;
|
||||
|
||||
@@ -79,19 +78,22 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
||||
if(!clmd->sim_parms || !clmd->coll_parms)
|
||||
{
|
||||
initData(md);
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
CDDM_calc_normals(result);
|
||||
return result;
|
||||
clothModifier_do(clmd, md->scene, ob, dm, vertexCos);
|
||||
|
||||
if(result) {
|
||||
result->getVertCos(result, vertexCos);
|
||||
result->release(result);
|
||||
}
|
||||
return dm;
|
||||
|
||||
if(dm != derivedData)
|
||||
dm->release(dm);
|
||||
}
|
||||
|
||||
static void updateDepgraph(
|
||||
@@ -206,17 +208,17 @@ ModifierTypeInfo modifierType_Cloth = {
|
||||
/* name */ "Cloth",
|
||||
/* structName */ "ClothModifierData",
|
||||
/* structSize */ sizeof(ClothModifierData),
|
||||
/* type */ eModifierTypeType_Nonconstructive,
|
||||
/* type */ eModifierTypeType_OnlyDeform,
|
||||
/* flags */ eModifierTypeFlag_AcceptsMesh
|
||||
| eModifierTypeFlag_UsesPointCache
|
||||
| eModifierTypeFlag_Single,
|
||||
|
||||
/* copyData */ copyData,
|
||||
/* deformVerts */ NULL,
|
||||
/* deformVerts */ deformVerts,
|
||||
/* deformMatrices */ NULL,
|
||||
/* deformVertsEM */ NULL,
|
||||
/* deformMatricesEM */ NULL,
|
||||
/* applyModifier */ applyModifier,
|
||||
/* applyModifier */ NULL,
|
||||
/* applyModifierEM */ NULL,
|
||||
/* initData */ initData,
|
||||
/* requiredDataMask */ requiredDataMask,
|
||||
|
||||
Reference in New Issue
Block a user