[Bf-blender-cvs] [16f161e5f61] fracture_modifier: added acceleration maps which should be also be usable in playback
Martin Felke
noreply at git.blender.org
Mon Dec 25 23:30:58 CET 2017
Commit: 16f161e5f61993a9aa8d64ec83880dc48ca13310
Author: Martin Felke
Date: Mon Dec 25 23:30:15 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rB16f161e5f61993a9aa8d64ec83880dc48ca13310
added acceleration maps which should be also be usable in playback
===================================================================
M release/scripts/startup/bl_operators/presets.py
M release/scripts/startup/bl_ui/properties_physics_fracture.py
M source/blender/blenkernel/BKE_rigidbody.h
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/particle_distribute.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_fracture.c
M source/blender/modifiers/intern/MOD_fracture.c
===================================================================
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/blenlo
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list