[Bf-blender-cvs] [87f8953] fracture_modifier: some more effort to make FM simulation results looking closer to BCB simulation results
Martin Felke
noreply at git.blender.org
Sun Jan 31 01:59:45 CET 2016
Commit: 87f895311f823394eae99e0470d5ac298cca4b5d
Author: Martin Felke
Date: Sun Jan 31 01:59:35 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB87f895311f823394eae99e0470d5ac298cca4b5d
some more effort to make FM simulation results looking closer to BCB simulation results
===================================================================
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/rigidbody.c
===================================================================
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 0a975ca..6477079 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1687,11 +1687,23 @@ static DerivedMesh* do_create(FractureModifierData *fmd, int num_verts, int num_
{
MPoly *mp;
MLoop *ml;
+ MVert *mv;
int i;
memcpy(mverts + vertstart, shard->mvert, shard->totvert * sizeof(MVert));
memcpy(mpolys + polystart, shard->mpoly, shard->totpoly * sizeof(MPoly));
+#if 0
+ if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
+ {
+ for (i = 0, mv = mverts + vertstart; i < shard->totvert; i++, mv++)
+ {
+ sub_v3_v3(mv->co, shard->centroid);
+ mul_v3_v3(mv->co, shard->raw_centroid);
+ add_v3_v3(mv->co, shard->centroid);
+ }
+ }
+#endif
for (i = 0, mp = mpolys + polystart; i < shard->totpoly; ++i, ++mp) {
/* adjust loopstart index */
@@ -2200,6 +2212,9 @@ static Shard* fracture_object_to_shard( Object *own, Object* target)
unit_m4(mat);
BLI_space_transform_from_matrices(&trans, target->obmat, mat);
//BLI_SPACE_TRANSFORM_SETUP(&trans, target, own);
+ //mat4_to_size(size, target->obmat);
+
+ //ABUSE raw_centroid here for size, its not used in this mode !!!;
mvert = dm->getVertArray(dm);
mpoly = dm->getPolyArray(dm);
@@ -2211,7 +2226,17 @@ static Shard* fracture_object_to_shard( Object *own, Object* target)
// create temp shard -> that necessary at all ?
s = BKE_create_fracture_shard(mvert, mpoly, mloop, totvert, totpoly, totloop, true);
- for(v = 0, mv = s->mvert; v < s->totvert; v++, mv++)
+#if 0
+ //ABUSE raw_centroid here for size, its not used in this mode !!!;
+ //needed to compensate scaling (smaller physicsmesh, but original mesh size or vice versa, lets test)
+ inv_size[0] = 1.0f;// / size[0];
+ inv_size[1] = 1.0f;// / size[1];
+ inv_size[2] = 1.0f;// / size[2];
+
+ copy_v3_v3(s->raw_centroid, inv_size);
+#endif
+
+ for (v = 0, mv = s->mvert; v < s->totvert; v++, mv++)
{
BLI_space_transform_apply(&trans, mv->co);
}
@@ -2318,6 +2343,13 @@ static MeshIsland* fracture_shard_to_island(FractureModifierData *fmd, Shard *s,
mi->vertno[j * 3 + 1] = no[1];
mi->vertno[j * 3 + 2] = no[2];
+#if 0
+ if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
+ {
+ mul_v3_v3(mv->co, s->raw_centroid);
+ }
+#endif
+
/* then eliminate centroid in vertex coords*/
sub_v3_v3(mv->co, s->centroid);
}
@@ -2511,7 +2543,6 @@ MeshIsland* BKE_fracture_mesh_island_add(FractureModifierData *fmd, Object* own,
MeshIsland *mi;
Shard *s;
int vertstart = 0;
- float loc[3], rot[4];
short totcol = 0, totdef = 0;
if (fmd->fracture_mode != MOD_FRACTURE_EXTERNAL || own->type != OB_MESH || !own->data)
@@ -2536,8 +2567,6 @@ MeshIsland* BKE_fracture_mesh_island_add(FractureModifierData *fmd, Object* own,
//hrm need to rebuild ALL islands since vertex refs are bonkers now after mesh has changed
mi = fracture_shard_to_island(fmd, s, vertstart);
- //mat4_to_loc_quat(loc, rot, target->obmat);
-
//lets see whether we need to add loc here too XXX TODO
mi->rigidbody = BKE_rigidbody_create_shard(fmd->modifier.scene, own, target, mi);
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index a54ab0c..aea3f2d 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1158,7 +1158,7 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland *mi, Object *ob, short re
break;
case RB_SHAPE_CONVEXH:
- /* try to emged collision margin */
+ /* try to embed collision margin */
has_volume = (MIN3(size[0], size[1], size[2]) > 0.0f);
if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && has_volume)
@@ -1171,43 +1171,6 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland *mi, Object *ob, short re
{
new_shape = rigidbody_get_shape_trimesh_from_mesh_shard(mi, ob);
break;
-#if 0
- //wtf, seems a merge gone wrong....
- if (ob->type == OB_MESH) {
- DerivedMesh *dm = rigidbody_get_mesh(ob);
- MVert *mvert;
- const MLoopTri *lt = NULL;
- int totvert, tottri = 0;
- const MLoop *mloop = NULL;
-
- /* ensure mesh validity, then grab data */
- if (dm == NULL)
- return;
-
- DM_ensure_looptri(dm);
-
- mvert = dm->getVertArray(dm);
- totvert = dm->getNumVerts(dm);
- lt = dm->getLoopTriArray(dm);
- tottri = dm->getNumLoopTri(dm);
- mloop = dm->getLoopArray(dm);
-
- if (totvert > 0 && tottri > 0) {
- BKE_mesh_calc_volume(mvert, totvert, lt, tottri, mloop, &volume, NULL);
- }
-
- /* cleanup temp data */
- if (ob->rigidbody_object->mesh_source == RBO_MESH_BASE) {
- dm->release(dm);
- }
- }
- else {
- /* rough estimate from boundbox as fallback */
- /* XXX could implement other types of geometry here (curves, etc.) */
- volume = size[0] * size[1] * size[2];
- }
- break;
-#endif
}
}
/* assign new collision shape if creation was successful */
@@ -1590,7 +1553,7 @@ static void rigidbody_set_springs_active(RigidBodyShardCon *rbc, bool active)
{
if (rbc && rbc->physics_constraint && rbc->type == RBC_TYPE_6DOF_SPRING)
{
- if (active)
+ if (active) //XXX TEST purpose only
{
RB_constraint_set_spring_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->flag & RBC_FLAG_USE_SPRING_X);
RB_constraint_set_stiffness_6dof_spring(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->spring_stiffness_x);
@@ -1733,7 +1696,7 @@ static void rigidbody_create_shard_physics_constraint(FractureModifierData* fmd,
else
{
rbc->flag &= ~RBC_FLAG_PLASTIC_ACTIVE;
- //rigidbody_set_springs_active(rbc, false);
+ rigidbody_set_springs_active(rbc, false);
}
}
}
@@ -1980,6 +1943,9 @@ static int filterCallback(void* world, void* island1, void* island2, void *blend
ob_index2 = -1;
}
+ if (!ob1 || !ob2)
+ return false;
+
if ((mi1 != NULL) && (mi2 != NULL) && ob_index1 != -1 && ob_index2 != -1) {
validOb = (ob_index1 != ob_index2 && colgroup_check(ob1->rigidbody_object->col_groups, ob2->rigidbody_object->col_groups) &&
((mi1->rigidbody->flag & RBO_FLAG_KINEMATIC) || (mi2->rigidbody->flag & RBO_FLAG_KINEMATIC)) &&
@@ -2390,6 +2356,9 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type, M
rbo->ang_sleep_thresh = mi->rigidbody->ang_sleep_thresh;
rbo->force_thresh = mi->rigidbody->force_thresh;
+ rbo->lin_damping = mi->rigidbody->lin_damping;
+ rbo->ang_damping = mi->rigidbody->ang_damping;
+
rbo->col_groups = mi->rigidbody->col_groups;
rbo->shape = mi->rigidbody->shape;
@@ -3134,7 +3103,7 @@ static void validateShard(RigidBodyWorld *rbw, MeshIsland *mi, Object *ob, int r
BKE_rigidbody_validate_sim_shard(rbw, mi, ob, false, transfer_speed);
}
/* refresh shape... */
- if (mi->rigidbody->flag & RBO_FLAG_NEEDS_RESHAPE) {
+ if (mi->rigidbody->physics_object && (mi->rigidbody->flag & RBO_FLAG_NEEDS_RESHAPE)) {
/* mesh/shape data changed, so force shape refresh */
BKE_rigidbody_validate_sim_shard_shape(mi, ob, true);
/* now tell RB sim about it */
@@ -3298,10 +3267,25 @@ static void handle_breaking_distance(FractureModifierData *fmd, Object *ob, Rigi
}
}
+static void enable_plastic(RigidBodyShardCon *rbsc)
+{
+ if (!(rbsc->flag & RBC_FLAG_PLASTIC_ACTIVE) && rbsc->plastic_dist >= 0.0f && rbsc->plastic_angle >= 0.0f)
+ {
+ if (rbsc->physics_constraint)
+ {
+ /* activate only once */
+ rbsc->flag |= RBC_FLAG_PLASTIC_ACTIVE;
+ rigidbody_set_springs_active(rbsc, true);
+ RB_constraint_set_equilibrium_6dof_spring(rbsc->physics_constraint);
+ RB_constraint_set_enabled(rbsc->physics_constraint, true);
+ }
+ }
+}
+
static void handle_plastic_breaking(RigidBodyShardCon *rbsc, RigidBodyWorld* rbw, short laststeps, float lastscale)
{
float dist, angle, distdiff, anglediff;
- bool exceededAngle = false, exceededDist = false;
+ bool exceededAngle = false, exceededDist = false, regularBroken = false;
/*match breaking threshold according to timescale and steps */
if (rbsc->physics_constraint)
@@ -3324,23 +3308,41 @@ static void handle_plastic_breaking(RigidBodyShardCon *rbsc, RigidBodyWorld* rbw
exceededAngle = ((rbsc->breaking_angle >= 0.0f) && (anglediff > rbsc->breaking_angle));
exceededDist = ((rbsc->breaking_dist >= 0.0f) && (distdiff > (rbsc->breaking_dist + (anglediff / M_PI))));
+ regularBroken = (rbsc->type != RBC_TYPE_6DOF_SPRING && rbsc->physics_constraint &&
+ !(RB_constraint_is_enabled(rbsc->physics_constraint)));
- if (exceededDist || exceededAngle)
+#if 0
+ if (regularBroken)
{
- if (rbsc->type == RBC_TYPE_6DOF_SPRING)
+ //XXX hack, if a regular constraint breaks threshold based, enable associated springs asap so the support does not collapse
+ RigidBodyShardCon *con;
+ int i;
+ for (i = 0; i < rbsc->mi1->participating_constraint_count; i++)
{
- if (!(rbsc->flag & RBC_FLAG_PLASTIC_ACTIVE) && rbsc->plastic_dist >= 0.0f && rbsc->plastic_angle >= 0.0f)
+ con = rbsc->mi1->participating_constraints[i];
+ if (con->mi1 == rbsc->mi1 && con->mi2 == rbsc->mi2)
{
- if (rbsc->physics_constraint)
- {
- /* activate only once */
- rbsc->flag |= RBC_FLAG_PLASTIC_ACTIVE;
- rigidbody_set_springs_active(rbsc, true);
- RB_constraint_set_equilibrium_6dof_spring(rbsc->physics_constraint);
- RB_constraint_set_enabled(rbsc->physics_constraint, true);
- }
+ enable_plastic(con);
+ }
+ }
+
+ for (i = 0; i < rbsc->mi2->participating_constraint_count; i++)
+ {
+ con = rbsc->mi2->participating_constraints[i];
+ if (con->mi1 == rbsc->mi1 && con->mi2 == rbsc->mi2)
+ {
+ enable_plastic(con);
}
}
+ }
+#endif
+
+ if (exceededDist || exceededAngle) //|| regularBroken)
+ {
+ if (rbsc->type == RBC_TYPE_6DOF_SPRING)
+ {
+ enable_plastic(rbsc);
+ }
else if (rbsc->physics_constraint)
{
/* break regular connections */
@@ -3352,13 +3354,13 @@ static void handle_plastic_breaking(RigidBodyShardCon *rbsc, RigidBodyWorld* rbw
exceededDist = ((rbsc->plastic_dist >= 0.0f) && (distdiff > (rbsc->plastic_dist + (anglediff / M_PI))));
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list