diff options
-rw-r--r-- | release/scripts/startup/bl_operators/presets.py | 1 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/properties_physics_fracture.py | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_rigidbody.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fracture.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_distribute.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 99 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 1 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 6 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_fracture.c | 20 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_fracture.c | 15 |
11 files changed, 131 insertions, 27 deletions
diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py index 3eec5077eef..fe8750e6450 100644 --- a/release/scripts/startup/bl_operators/presets.py +++ b/release/scripts/startup/bl_operators/presets.py @@ -705,6 +705,7 @@ class AddPresetFracture(AddPresetBase, Operator): "fracture.grid_resolution" "fracture.min_acceleration", "fracture.max_acceleration", + "fracture.acceleration_fade" ] preset_subdir = "fracture" diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py index 95a4f88c047..e6cf1d43926 100644 --- a/release/scripts/startup/bl_ui/properties_physics_fracture.py +++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py @@ -172,6 +172,7 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel): row = box.row(align=True) row.prop(md, "min_acceleration") row.prop(md, "max_acceleration") + row.prop(md, "acceleration_fade") if (md.frac_algorithm in {'BISECT_FAST', 'BISECT_FAST_FILL'}): box.prop(md, "orthogonality_factor", text="Rectangular Alignment") diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h index 50728e8a32d..714a8bcfd0a 100644 --- a/source/blender/blenkernel/BKE_rigidbody.h +++ b/source/blender/blenkernel/BKE_rigidbody.h @@ -87,7 +87,8 @@ void BKE_rigidbody_validate_sim_shard(struct RigidBodyWorld *rbw, struct MeshIsl void BKE_rigidbody_validate_sim_shard_shape(struct MeshIsland *mi, struct Object *ob, short rebuild); /* move the islands of the visible mesh according to shard rigidbody movement */ -void BKE_rigidbody_update_cell(struct MeshIsland *mi, struct Object* ob, float loc[3], float rot[4], struct FractureModifierData *rmd, int frame); +void BKE_rigidbody_update_cell(struct MeshIsland *mi, struct Object* ob, float loc[3], float rot[4], struct FractureModifierData *rmd, + int frame, struct RigidBodyWorld *rbw); void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_center[3]); diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c index 4ac0c3ee556..85fe91270c6 100644 --- a/source/blender/blenkernel/intern/fracture.c +++ b/source/blender/blenkernel/intern/fracture.c @@ -3293,6 +3293,12 @@ void BKE_fracture_free_mesh_island(FractureModifierData *rmd, MeshIsland *mi, bo mi->locs = NULL; } + if (mi->acc_sequence) + { + MEM_freeN(mi->acc_sequence); + mi->acc_sequence = NULL; + } + mi->frame_count = 0; MEM_freeN(mi); diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c index fc2271e045e..291903b418a 100644 --- a/source/blender/blenkernel/intern/particle_distribute.c +++ b/source/blender/blenkernel/intern/particle_distribute.c @@ -1039,7 +1039,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti } } - if (totmapped == 0) { + if (totmapped < 2) { /* We are not allowed to distribute particles anywhere... */ return 0; } diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 04d2592df19..11cb0430e90 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -104,6 +104,7 @@ static bool restoreKinematic(RigidBodyWorld *rbw); static void DM_mesh_boundbox(DerivedMesh *bm, float r_loc[3], float r_size[3]); static void test_deactivate_rigidbody(RigidBodyOb *rbo); static float box_volume(float size[3]); +static void updateAccelerationMap(FractureModifierData *fmd, MeshIsland* mi, Object* ob, rbContactPoint* cp, int ctime); #endif @@ -2908,7 +2909,8 @@ static void initNormals(struct MeshIsland *mi, Object *ob, FractureModifierData } } -void BKE_rigidbody_update_cell(struct MeshIsland *mi, Object *ob, float loc[3], float rot[4], FractureModifierData *rmd, int frame) +void BKE_rigidbody_update_cell(struct MeshIsland *mi, Object *ob, float loc[3], float rot[4], FractureModifierData *rmd, int frame, + struct RigidBodyWorld *rbw) { float startco[3], centr[3], size[3]; short startno[3]; @@ -2958,9 +2960,16 @@ void BKE_rigidbody_update_cell(struct MeshIsland *mi, Object *ob, float loc[3], mi->rots[3] = rota[3]; } + if (mi->acc_sequence == NULL) + { + mi->acc_sequence = MEM_mallocN(sizeof(float), "mi->acc_sequence"); + } + if (n > mi->frame_count) { mi->locs = MEM_reallocN(mi->locs, sizeof(float) * 3 * n); mi->rots = MEM_reallocN(mi->rots, sizeof(float) * 4 * n); + mi->acc_sequence = MEM_reallocN(mi->acc_sequence, sizeof(float) * (n+1)); + mi->acc_sequence[n] = 0.0f; mi->locs[x*3] = loc[0]; mi->locs[x*3+1] = loc[1]; @@ -2972,6 +2981,8 @@ void BKE_rigidbody_update_cell(struct MeshIsland *mi, Object *ob, float loc[3], mi->rots[x*4+3] = rot[3]; mi->frame_count = n; } + + updateAccelerationMap(rmd, mi, ob, NULL, frame); } for (j = 0; j < mi->vertex_count; j++) { @@ -4317,16 +4328,16 @@ static bool check_constraints(FractureModifierData *fmd, MeshIsland *mi, RigidBo return false; } -static void updateAccelerationMap(FractureModifierData *fmd, RigidBodyOb* rbo, Object* ob, rbContactPoint* cp) +static void updateAccelerationMap(FractureModifierData *fmd, MeshIsland* mi, Object* ob, rbContactPoint* cp, int ctime) { const int acc_defgrp_index = defgroup_name_index(ob, fmd->acceleration_defgrp_name); - MeshIsland *mi = findMeshIsland(fmd, rbo->meshisland_index); DerivedMesh *dm = fmd->visible_mesh_cached; - MDeformVert *dvert = NULL, *dv; + MDeformVert *dvert = NULL, *dv = NULL; MDeformWeight *dw = NULL; - float weight = 0.0f, denom; + float weight = 0.0f, denom, force = 0.0f; int i = 0, w = 0; int totvert = dm->getNumVerts(dm); + float dampen = fmd->acceleration_fade; dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); @@ -4343,20 +4354,66 @@ static void updateAccelerationMap(FractureModifierData *fmd, RigidBodyOb* rbo, O if (denom == 0.0f) denom = 1.0f; - weight = (cp->contact_force - fmd->min_acceleration) / denom; - - for (i = 0; i < mi->vertex_count; i++) + if (cp) { - dv = dvert + mi->vertex_indices[i]; - if (dv) { - if (dv->dw == NULL) { - defvert_add_index_notest(dv, acc_defgrp_index, 0.0f); + force = cp->contact_force; + if ((force > fmd->min_acceleration && force < fmd->max_acceleration)) + { + float lastforce = 0.0f; + float lastweight = -1; + + if (ctime > mi->start_frame + 1) { + //keep value for fading it ? + lastforce = mi->acc_sequence[ctime - mi->start_frame -1]; + lastweight = (lastforce - fmd->min_acceleration) / denom; } + else { + lastweight = 0.0f; + } + + weight = (force - fmd->min_acceleration) / denom; - for (dw = dv->dw, w = 0; w < dv->totweight; dw++, w++) + //if (fabsf(lastweight - weight) < (1.0f - dampen) && (lastweight >= 0.0f)) + { + if (force > mi->acc_sequence[ctime - mi->start_frame]) + { + //printf("force :%f\n", force); + mi->acc_sequence[ctime - mi->start_frame] = force; + } + else { + mi->acc_sequence[ctime - mi->start_frame] = lastforce * dampen; + } + } + /*else { - if (dw->def_nr == acc_defgrp_index) { - dw->weight = weight; + mi->acc_sequence[ctime - mi->start_frame] = lastforce * dampen; + }*/ + } + } + else if (mi->acc_sequence) + { //read cached force, but update weights only if != 0 (maybe decrement then + force = mi->acc_sequence[ctime - mi->start_frame]; + weight = (force - fmd->min_acceleration) / denom; + + if (weight < 0.0f) + weight = 0.0f; + + if (weight > 1.0f) + weight = 1.0f; + + for (i = 0; i < mi->vertex_count; i++) + { + dv = dvert + mi->vertex_indices[i]; + if (dv) { + if (dv->dw == NULL) { + defvert_add_index_notest(dv, acc_defgrp_index, weight); + } + + for (dw = dv->dw, w = 0; w < dv->totweight; dw++, w++) + { + if (dw->def_nr == acc_defgrp_index) { + dw->weight = weight; + } } } } @@ -4403,7 +4460,10 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw, Object *obA, if (fmd1) { - updateAccelerationMap(fmd1, rbw->cache_index_map[linear_index1], ob1, cp); + RigidBodyOb *rbo = rbw->cache_index_map[linear_index1]; + int id = rbo->meshisland_index; + MeshIsland* mi = findMeshIsland(fmd1, id); + updateAccelerationMap(fmd1, mi, ob1, cp, rbw->ltime+1); } if (fmd1 && fmd1->fracture_mode == MOD_FRACTURE_DYNAMIC) @@ -4462,7 +4522,10 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw, Object *obA, if (fmd2) { - updateAccelerationMap(fmd2, rbw->cache_index_map[linear_index2], ob2, cp); + RigidBodyOb *rbo = rbw->cache_index_map[linear_index2]; + int id = rbo->meshisland_index; + MeshIsland* mi = findMeshIsland(fmd2, id); + updateAccelerationMap(fmd2, mi, ob2, cp, rbw->ltime+1); } if (fmd2 && fmd2->fracture_mode == MOD_FRACTURE_DYNAMIC) @@ -5399,7 +5462,7 @@ static bool do_sync_modifier(ModifierData *md, Object *ob, RigidBodyWorld *rbw, copy_qt_qt(quat, rbo->orn); } - BKE_rigidbody_update_cell(mi, ob, rbo->pos, quat, fmd, (int)ctime); + BKE_rigidbody_update_cell(mi, ob, rbo->pos, quat, fmd, (int)ctime, rbw); } } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 482ecec8d93..6dd67dcefb5 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5211,6 +5211,7 @@ static void read_meshIsland(FileData *fd, MeshIsland **address) mi->locs = newdataadr(fd, mi->locs); mi->rots = newdataadr(fd, mi->rots); + mi->acc_sequence = newdataadr(fd, mi->acc_sequence); /* will be refreshed on the fly if not there*/ mi->participating_constraints = newdataadr(fd, mi->participating_constraints); diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index a8cd11bb004..589f6707b8f 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1749,6 +1749,7 @@ static void write_meshIsland(WriteData* wd, MeshIsland* mi, bool write_data) if (write_data) { writedata(wd, DATA, sizeof(float) * 3 * mi->frame_count, mi->locs); writedata(wd, DATA, sizeof(float) * 4 * mi->frame_count, mi->rots); + writedata(wd, DATA, sizeof(float) * mi->frame_count, mi->acc_sequence); } else { if (mi->locs) { @@ -1761,6 +1762,11 @@ static void write_meshIsland(WriteData* wd, MeshIsland* mi, bool write_data) mi->rots = NULL; } + if (mi->acc_sequence){ + MEM_freeN(mi->acc_sequence); + mi->acc_sequence = NULL; + } + mi->frame_count = 0; } diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 498ee71e018..bc8c3b5db94 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1464,6 +1464,7 @@ typedef struct MeshIsland { struct RigidBodyShardCon **participating_constraints; float *locs; float *rots; + float *acc_sequence; char name[66]; /* MAX_ID_NAME */ char pad1[2]; @@ -1774,6 +1775,7 @@ typedef struct FractureModifierData { float orthogonality_factor; float min_acceleration; float max_acceleration; + float acceleration_fade; /* flags */ int refresh; @@ -1832,7 +1834,7 @@ typedef struct FractureModifierData { short mat_ofs_intersect; short mat_ofs_difference; - //char pad[4]; + char pad[4]; } FractureModifierData; typedef struct DataTransferModifierData { diff --git a/source/blender/makesrna/intern/rna_fracture.c b/source/blender/makesrna/intern/rna_fracture.c index 566ab9674d0..892276336e1 100644 --- a/source/blender/makesrna/intern/rna_fracture.c +++ b/source/blender/makesrna/intern/rna_fracture.c @@ -1473,18 +1473,26 @@ void RNA_def_fracture(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "min_acceleration"); RNA_def_property_range(prop, 0, FLT_MAX); RNA_def_property_float_funcs(prop, NULL, "rna_FractureModifier_min_acceleration_set", NULL); - RNA_def_property_ui_text(prop, "Min Acceleration", "The minimum against which the force will be normed against"); - RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 0.1f, 2); - RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Min", "The minimum against which the force will be normed against"); + RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 0.1f, 4); + //RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, 0, "rna_Modifier_update"); prop = RNA_def_property(srna, "max_acceleration", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "max_acceleration"); RNA_def_property_range(prop, 0, FLT_MAX); RNA_def_property_float_funcs(prop, NULL, "rna_FractureModifier_max_acceleration_set", NULL); - RNA_def_property_ui_text(prop, "Max Acceleration", "The maximum against which the force will be normed against"); - RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 0.1f, 2); - RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Max", "The maximum against which the force will be normed against"); + RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 0.1f, 4); + //RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "acceleration_fade", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "acceleration_fade"); + RNA_def_property_range(prop, 0, 1.0f); + RNA_def_property_ui_text(prop, "Fade", "Multiplier to fade out the weights with"); + RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 4); + //RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, 0, "rna_Modifier_update"); RNA_api_fracture(brna, srna); diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c index e63b2956399..30f179d3fb9 100644 --- a/source/blender/modifiers/intern/MOD_fracture.c +++ b/source/blender/modifiers/intern/MOD_fracture.c @@ -260,6 +260,7 @@ static void initData(ModifierData *md) fmd->min_acceleration = 0.0f; fmd->max_acceleration = 1.0f; + fmd->acceleration_fade = 0.85f; } //XXX TODO, freeing functionality should be in BKE too @@ -1864,6 +1865,7 @@ static void copyData(ModifierData *md, ModifierData *target) trmd->min_acceleration = rmd->min_acceleration; trmd->max_acceleration = rmd->max_acceleration; + trmd->acceleration_fade = rmd->acceleration_fade; } //XXXX TODO, is BB really useds still ? aint there exact volume calc now ? @@ -2073,6 +2075,7 @@ static float do_setup_meshisland(FractureModifierData *fmd, Object *ob, int totv { mi->locs = NULL; mi->rots = NULL; + mi->acc_sequence = NULL; mi->frame_count = 0; if (fmd->modifier.scene->rigidbody_world) @@ -3756,6 +3759,7 @@ static void do_island_from_shard(FractureModifierData *fmd, Object *ob, Shard* s { mi->locs = NULL; mi->rots = NULL; + mi->acc_sequence = NULL; mi->frame_count = 0; if (fmd->modifier.scene->rigidbody_world) @@ -3988,6 +3992,17 @@ static DerivedMesh *output_dm(FractureModifierData* fmd, DerivedMesh *dm, Object } } + //fade out acceleration map weights too + /*if (dvert) { + int i; + int defgrp = defgroup_name_index(ob, fmd->acceleration_defgrp_name); + for (i = 0; i < fmd->visible_mesh_cached->numVertData; i++) { + if (dvert[i].dw && dvert[i].dw->def_nr == defgrp && dvert[i].dw->weight >= 0.0f) { + dvert[i].dw->weight -= 0.5f; + } + } + }*/ + if (fmd->autohide_dist > 0 || fmd->automerge_dist > 0 || fmd->use_centroids || fmd->use_vertices) { //printf("Autohide \n"); |