New: load cached data on file load; Fixed: Don't destroy cache on fileload, calculate normals correctly, don't reset all data when pressing partial free, making also cache free buttons available when cache is protected, duplicating cloth with shift-d should work properly now

This commit is contained in:
Daniel Genrich
2008-01-25 08:55:27 +00:00
parent 7054664d2a
commit e7f5d07781
6 changed files with 64 additions and 46 deletions

View File

@@ -128,17 +128,19 @@ ClothSpring;
/* These are the bits used in SimSettings.flags. */
typedef enum
{
CLOTH_SIMSETTINGS_FLAG_RESET = ( 1 << 1 ), // The CM object requires a reinitializaiton.
CLOTH_SIMSETTINGS_FLAG_COLLOBJ = ( 1 << 2 ), // object is only collision object, no cloth simulation is done
CLOTH_SIMSETTINGS_FLAG_GOAL = ( 1 << 3 ), // we have goals enabled
CLOTH_SIMSETTINGS_FLAG_TEARING = ( 1 << 4 ), // true if tearing is enabled
CLOTH_SIMSETTINGS_FLAG_RESET = ( 1 << 1 ), // The CM object requires a reinitializaiton.
CLOTH_SIMSETTINGS_FLAG_COLLOBJ = ( 1 << 2 ),// object is only collision object, no cloth simulation is done
CLOTH_SIMSETTINGS_FLAG_GOAL = ( 1 << 3 ), // we have goals enabled
CLOTH_SIMSETTINGS_FLAG_TEARING = ( 1 << 4 ),// true if tearing is enabled
CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT = ( 1 << 5 ), // true if tearing is enabled
CLOTH_SIMSETTINGS_FLAG_NEW = ( 1 << 6 ), // unsued, true if cloth was just enabled
} CLOTH_SIMSETTINGS_FLAGS;
/* SPRING FLAGS */
/* COLLISION FLAGS */
typedef enum
{
CLOTH_COLLISIONSETTINGS_FLAG_ENABLED = ( 1 << 1 ),
CLOTH_COLLSETTINGS_FLAG_ENABLED = ( 1 << 1 ), /* enables cloth - object collisions */
CLOTH_COLLSETTINGS_FLAG_SELF = ( 1 << 2 ), /* unused */
} CLOTH_COLLISIONSETTINGS_FLAGS;
/* Spring types as defined in the paper.*/
@@ -205,6 +207,9 @@ void bvh_update_from_cloth(ClothModifierData *clmd, int moving);
// needed for editmesh.c
void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr);
// needed for button_object.c
void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr);
////////////////////////////////////////////////

View File

@@ -153,7 +153,7 @@ void cloth_init ( ClothModifierData *clmd )
clmd->sim_parms->mass = 1.0f;
clmd->sim_parms->stepsPerFrame = 5;
clmd->sim_parms->sim_time = 1.0;
clmd->sim_parms->flags = CLOTH_SIMSETTINGS_FLAG_RESET;
clmd->sim_parms->flags = CLOTH_SIMSETTINGS_FLAG_NEW;
clmd->sim_parms->solver_type = 0;
clmd->sim_parms->preroll = 0;
clmd->sim_parms->maxspringlen = 10;
@@ -166,7 +166,7 @@ void cloth_init ( ClothModifierData *clmd )
clmd->coll_parms->friction = 10.0;
clmd->coll_parms->loop_count = 1;
clmd->coll_parms->epsilon = 0.01f;
clmd->coll_parms->flags = CLOTH_COLLISIONSETTINGS_FLAG_ENABLED;
clmd->coll_parms->flags = CLOTH_COLLSETTINGS_FLAG_ENABLED;
/* These defaults are copied from softbody.c's
* softbody_calc_forces() function.
@@ -533,7 +533,8 @@ void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
{
int stack_index = -1;
if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT))
/* clear cache if specific frame cleaning requested or cache is not protected */
if((!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT)) || (framenr > 1.0))
{
stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
@@ -635,8 +636,6 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
return result;
}
// printf("ct: %f, st: %f, r.cfra: %f, dt: %f\n", current_time, clmd->sim_parms->sim_time, ( float ) G.scene->r.cfra, deltaTime);
// unused in the moment, calculated seperately in implicit.c
clmd->sim_parms->dt = 1.0f / clmd->sim_parms->stepsPerFrame;
@@ -659,6 +658,8 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
{
cloth_clear_cache(ob, clmd, 0);
// printf("v1: %d, v2: %d\n", numverts, clmd->clothObject->numverts);
if ( !cloth_from_object ( ob, clmd, result, framenr ) )
return result;
@@ -718,6 +719,9 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
else
{
cloth_clear_cache(ob, clmd, 0);
if ( !cloth_from_object ( ob, clmd, result, framenr ) )
return result;
}
}
@@ -743,9 +747,9 @@ void cloth_free_modifier ( Object *ob, ClothModifierData *clmd )
cloth_clear_cache ( ob, clmd, 0 );
// If our solver provides a free function, call it
if ( cloth->old_solver_type < 255 && solvers [cloth->old_solver_type].free )
if ( solvers [clmd->sim_parms->solver_type].free )
{
solvers [cloth->old_solver_type].free ( clmd );
solvers [clmd->sim_parms->solver_type].free ( clmd );
}
// Free the verts.
@@ -805,9 +809,9 @@ void cloth_free_modifier_extern ( ClothModifierData *clmd )
if ( cloth )
{
// If our solver provides a free function, call it
if ( cloth->old_solver_type < 255 && solvers [cloth->old_solver_type].free )
if ( solvers [clmd->sim_parms->solver_type].free )
{
solvers [cloth->old_solver_type].free ( clmd );
solvers [clmd->sim_parms->solver_type].free ( clmd );
}
// Free the verts.
@@ -972,7 +976,9 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
// If we have a clothObject, free it.
if ( clmd->clothObject != NULL )
{
cloth_free_modifier ( ob, clmd );
}
// Allocate a new cloth object.
clmd->clothObject = MEM_callocN ( sizeof ( Cloth ), "cloth" );
@@ -1041,8 +1047,9 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
solvers [clmd->sim_parms->solver_type].init ( ob, clmd );
clmd->clothObject->tree = bvh_build_from_cloth ( clmd, clmd->coll_parms->epsilon );
cloth_write_cache(ob, clmd, framenr-1);
if(!cloth_read_cache(ob, clmd, framenr))
cloth_write_cache(ob, clmd, framenr);
return 1;
}

View File

@@ -1389,7 +1389,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
add_lfvector_lfvectorS(id->Xnew, id->X, id->Vnew, dt, numverts);
if(clmd->coll_parms->flags & CLOTH_COLLISIONSETTINGS_FLAG_ENABLED)
if(clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)
{
// collisions
// itstart();

View File

@@ -4972,6 +4972,7 @@ static DerivedMesh *clothModifier_applyModifier(ModifierData *md, Object *ob,
if(result)
{
CDDM_calc_normals(result);
return result;
}
return derivedData;
@@ -5020,6 +5021,22 @@ CustomDataMask clothModifier_requiredDataMask(ModifierData *md)
return dataMask;
}
static void clothModifier_copyData(ModifierData *md, ModifierData *target)
{
ClothModifierData *clmd = (ClothModifierData*) md;
ClothModifierData *tclmd = (ClothModifierData*) target;
if(tclmd->sim_parms)
MEM_freeN(tclmd->sim_parms);
if(tclmd->coll_parms)
MEM_freeN(tclmd->coll_parms);
tclmd->sim_parms = MEM_dupallocN(clmd->sim_parms);
tclmd->coll_parms = MEM_dupallocN(clmd->coll_parms);
tclmd->sim_parms->lastcachedframe = 0;
}
static int clothModifier_dependsOnTime(ModifierData *md)
{
@@ -5035,8 +5052,10 @@ static void clothModifier_freeData(ModifierData *md)
cloth_free_modifier_extern (clmd);
MEM_freeN(clmd->sim_parms);
MEM_freeN(clmd->coll_parms);
if(clmd->sim_parms)
MEM_freeN(clmd->sim_parms);
if(clmd->coll_parms)
MEM_freeN(clmd->coll_parms);
}
}
@@ -7033,8 +7052,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
mti->dependsOnTime = clothModifier_dependsOnTime;
mti->freeData = clothModifier_freeData;
mti->requiredDataMask = clothModifier_requiredDataMask;
// mti->copyData = clothModifier_copyData;
// mti->deformVerts = clothModifier_deformVerts;
mti->copyData = clothModifier_copyData;
mti->applyModifier = clothModifier_applyModifier;
mti->updateDepgraph = clothModifier_updateDepgraph;

View File

@@ -69,7 +69,7 @@ typedef struct SimulationSettings
float eff_force_scale;/* Scaling of effector forces (see softbody_calc_forces).*/
float eff_wind_scale; /* Scaling of effector wind (see softbody_calc_forces). */
float sim_time_old;
struct LinkNode *cache;
struct LinkNode *cache; /* UNUSED atm */
float defgoal;
int goalfrict;
float goalspring;
@@ -113,7 +113,7 @@ typedef struct Cloth
unsigned int numverts; /* The number of verts == m * n. */
unsigned int numsprings; /* The count of springs. */
unsigned int numfaces;
unsigned char old_solver_type;
unsigned char old_solver_type; /* unused, only 1 solver here */
unsigned char pad2;
short pad3;
struct BVH *tree; /* collision tree for this cloth object */

View File

@@ -2320,7 +2320,8 @@ void do_object_panels(unsigned short event)
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
if(clmd)
{
cloth_clear_cache(ob, clmd, MAX2(1.0,G.scene->r.cfra + 1.0));
cloth_clear_cache(ob, clmd, MAX2(1.0,G.scene->r.cfra));
// MAX2(1.0,G.scene->r.cfra + 1.0)
allqueue(REDRAWBUTSOBJECT, 0);
}
}
@@ -5071,18 +5072,12 @@ static void object_panel_cloth(Object *ob)
uiBlockBeginAlign(block);
uiDefButF(block, NUM, B_CLOTH_RENEW, "StructStiff:", 10,170,150,20, &clmd->sim_parms->structural, 1.0, 10000.0, 100, 0, "Overall stiffness of structure");
uiDefButF(block, NUM, B_CLOTH_RENEW, "BendStiff:", 160,170,150,20, &clmd->sim_parms->bending, 0.0, 10000.0, 1000, 0, "Wrinkle coefficient (higher = less smaller but more big wrinkles)");
uiDefButI(block, NUM, B_CLOTH_RENEW, "Quality:", 10,150,150,20, &clmd->sim_parms->stepsPerFrame, 1.0, 100.0, 5, 0, "Quality of the simulation (higher=better=slower)");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButI(block, NUM, B_CLOTH_RENEW, "Quality:", 10,150,150,20, &clmd->sim_parms->stepsPerFrame, 4.0, 100.0, 5, 0, "Quality of the simulation (higher=better=slower)");
uiDefButF(block, NUM, B_CLOTH_RENEW, "Spring Damp:", 160,150,150,20, &clmd->sim_parms->Cdis, 0.0, 10.0, 10, 0, "Spring damping");
uiDefButF(block, NUM, B_DIFF, "Air Damp:", 10,130,150,20, &clmd->sim_parms->Cvi, 0.0, 10.0, 10, 0, "Air has normaly some thickness which slows falling things down");
uiBlockEndAlign(block);
uiClearButLock();
uiBlockBeginAlign(block);
uiDefBut(block, LABEL, 0, "Gravity:", 10,100,60,20, NULL, 0.0, 0, 0, 0, "");
// uiClearButLock();
uiDefButF(block, NUM, B_CLOTH_RENEW, "X:", 70,100,80,20, &clmd->sim_parms->gravity[0], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
uiDefButF(block, NUM, B_CLOTH_RENEW, "Y:", 150,100,80,20, &clmd->sim_parms->gravity[1], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
@@ -5202,17 +5197,10 @@ static void object_panel_cloth_II(Object *ob)
{
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT, REDRAWVIEW3D, "Protect Cache & Enable Cache Editing", 10,120,300,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Protect cache from automatic freeing when scene changed. This also enabled the cache beeing edited in editmode.");
if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT))
{
uiDefBut(block, LABEL, 0, "Clear cache:", 10,100,90,20, NULL, 0.0, 0, 0, 0, "");
uiDefBut(block, BUT, B_CLOTH_CLEARCACHEALL, "All", 100, 100,100,20, NULL, 0.0, 0.0, 10, 0, "Free ALL cloth cache without preroll");
uiDefBut(block, BUT, B_CLOTH_CLEARCACHEFRAME, "From next frame", 200, 100,110,20, NULL, 0.0, 0.0, 10, 0, "Free cloth cache starting from next frame");
uiDefBut(block, LABEL, 0, " ", 10,80,300,20, NULL, 0.0, 0, 0, 0, "");
}
else
{
uiDefBut(block, LABEL, 0, " ", 10,100,300,40, NULL, 0.0, 0, 0, 0, "");
}
uiDefBut(block, LABEL, 0, "Clear cache:", 10,100,90,20, NULL, 0.0, 0, 0, 0, "");
uiDefBut(block, BUT, B_CLOTH_CLEARCACHEALL, "All", 100, 100,100,20, NULL, 0.0, 0.0, 10, 0, "Free ALL cloth cache without preroll");
uiDefBut(block, BUT, B_CLOTH_CLEARCACHEFRAME, "From next frame", 200, 100,110,20, NULL, 0.0, 0.0, 10, 0, "Free cloth cache starting from next frame");
uiDefBut(block, LABEL, 0, " ", 10,80,300,20, NULL, 0.0, 0, 0, 0, "");
}
/*
@@ -5222,8 +5210,8 @@ static void object_panel_cloth_II(Object *ob)
uiDefBut(block, LABEL, 0, " ", 10,80,145,20, NULL, 0.0, 0, 0, 0, "");
*/
uiDefButBitI(block, TOG, CLOTH_COLLISIONSETTINGS_FLAG_ENABLED, REDRAWVIEW3D, "Enable collisions", 10,60,150,20, &clmd->coll_parms->flags, 0, 0, 0, 0, "Enable collisions with this object");
if (clmd->coll_parms->flags & CLOTH_COLLISIONSETTINGS_FLAG_ENABLED)
uiDefButBitI(block, TOG, CLOTH_COLLSETTINGS_FLAG_ENABLED, REDRAWVIEW3D, "Enable collisions", 10,60,150,20, &clmd->coll_parms->flags, 0, 0, 0, 0, "Enable collisions with this object");
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)
{
uiDefButF(block, NUM, B_CLOTH_RENEW, "Min Distance:", 160,60,150,20, &clmd->coll_parms->epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in");
}