Durian request: Cloth

* structural can be set to 0

* pre-roll now available through GUI and works like following:
a) Pre rolled frames are NOT cached
b) reset cache + cloth on pre roll setting change
This commit is contained in:
Daniel Genrich 2009-11-18 13:33:52 +00:00
parent a62b3a534b
commit 6a357cabbf
6 changed files with 45 additions and 16 deletions

@ -83,8 +83,9 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel):
col = split.column()
col.itemL(text="Presets:")
col.itemL(text="TODO!")
col.itemL(text="Presets: TODO")
# col.itemL(text="TODO!")
col.itemR(cloth, "pre_roll")
col.itemL(text="Damping:")
sub = col.column(align=True)

@ -131,6 +131,7 @@ void cloth_init ( ClothModifierData *clmd )
clmd->sim_parms->avg_spring_len = 0.0;
clmd->sim_parms->presets = 2; /* cotton as start setting */
clmd->sim_parms->timescale = 1.0f; /* speed factor, describes how fast cloth moves */
clmd->sim_parms->reset = 0;
clmd->coll_parms->self_friction = 5.0;
clmd->coll_parms->friction = 5.0;
@ -450,6 +451,18 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
cache->last_exact= 0;
return dm;
}
if(clmd->sim_parms->reset || (framenr == (startframe - clmd->sim_parms->preroll)))
{
clmd->sim_parms->reset = 0;
cache->flag |= PTCACHE_REDO_NEEDED;
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
cache->simframe= 0;
cache->last_exact= 0;
cache->flag |= PTCACHE_SIMULATION_VALID;
cache->flag &= ~PTCACHE_REDO_NEEDED;
return result;
}
/* verify we still have the same number of vertices, if not do nothing.
* note that this should only happen if the number of vertices changes
@ -468,7 +481,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
clmd->sim_parms->dt = clmd->sim_parms->timescale / clmd->sim_parms->stepsPerFrame;
/* handle continuous simulation with the play button */
if(BKE_ptcache_get_continue_physics()) {
if(BKE_ptcache_get_continue_physics() || ((clmd->sim_parms->preroll > 0) && (framenr > startframe - clmd->sim_parms->preroll) && (framenr < startframe))) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
cache->last_exact= 0;
@ -503,7 +516,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
if(!do_init_cloth(ob, clmd, result, framenr))
return result;
if(framenr == startframe) {
if((framenr == startframe) && (clmd->sim_parms->preroll == 0)) {
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
do_init_cloth(ob, clmd, result, framenr);
cache->simframe= framenr;

@ -6008,7 +6008,7 @@ static void collisionModifier_initData(ModifierData *md)
collmd->current_x = NULL;
collmd->current_xnew = NULL;
collmd->current_v = NULL;
collmd->time = -1;
collmd->time = -1000;
collmd->numverts = 0;
collmd->bvhtree = NULL;
}
@ -6039,7 +6039,7 @@ static void collisionModifier_freeData(ModifierData *md)
collmd->current_x = NULL;
collmd->current_xnew = NULL;
collmd->current_v = NULL;
collmd->time = -1;
collmd->time = -1000;
collmd->numverts = 0;
collmd->bvhtree = NULL;
collmd->mfaces = NULL;
@ -6089,7 +6089,7 @@ static void collisionModifier_deformVerts(
if(collmd->x && (numverts != collmd->numverts))
collisionModifier_freeData((ModifierData *)collmd);
if(collmd->time == -1) // first time
if(collmd->time == -1000) // first time
{
collmd->x = dm->dupVertArray(dm); // frame start position

@ -3781,6 +3781,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
if(clmd->sim_parms) {
if(clmd->sim_parms->presets > 10)
clmd->sim_parms->presets = 0;
clmd->sim_parms->reset = 0;
}
if(clmd->sim_parms->effector_weights)
@ -3863,7 +3865,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
collmd->current_x = NULL;
collmd->current_xnew = NULL;
collmd->current_v = NULL;
collmd->time = -1;
collmd->time = -1000;
collmd->numverts = 0;
collmd->bvhtree = NULL;
collmd->mfaces = NULL;

@ -78,7 +78,7 @@ typedef struct ClothSimSettings
short vgroup_mass; /* optional vertexgroup name for assigning weight.*/
short vgroup_struct; /* vertex group for scaling structural stiffness */
short presets; /* used for presets on GUI */
short pad;
short reset;
struct EffectorWeights *effector_weights;
} ClothSimSettings;

@ -53,6 +53,18 @@ static void rna_cloth_update(bContext *C, PointerRNA *ptr)
WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
}
static void rna_cloth_reset(bContext *C, PointerRNA *ptr)
{
Object *ob= (Object*)ptr->id.data;
ClothSimSettings *settings = (ClothSimSettings*)ptr->data;
settings->reset = 1;
DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
}
static void rna_ClothSettings_max_bend_set(struct PointerRNA *ptr, float value)
{
ClothSimSettings *settings = (ClothSimSettings*)ptr->data;
@ -272,7 +284,7 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
prop= RNA_def_property(srna, "structural_stiffness", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "structural");
RNA_def_property_range(prop, 1.0f, 10000.0f);
RNA_def_property_range(prop, 0.0f, 10000.0f);
RNA_def_property_ui_text(prop, "Structural Stiffness", "Overall stiffness of structure.");
RNA_def_property_update(prop, 0, "rna_cloth_update");
@ -311,6 +323,13 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Effector Weights", "");
prop= RNA_def_property(srna, "pre_roll", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "preroll");
RNA_def_property_range(prop, 0, 200);
RNA_def_property_ui_text(prop, "Pre Roll", "Simulation starts on this frame.");
RNA_def_property_update(prop, 0, "rna_cloth_reset");
/* unused */
/* unused still
@ -337,12 +356,6 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, 100.0f);
RNA_def_property_ui_text(prop, "Effector Wind Scale", ""); */
/* unused still
prop= RNA_def_property(srna, "pre_roll", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "preroll");
RNA_def_property_range(prop, 10, 80;
RNA_def_property_ui_text(prop, "Pre Roll", "Simulation starts on this frame."); */
/* unused still
prop= RNA_def_property(srna, "tearing", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_SIMSETTINGS_FLAG_TEARING);