[Bf-blender-cvs] [cd60367] fracture_modifier: dynamic fracture: re-added modified version of speed transfer, it depends now on linear / angular deactivation threshold whether speed is transferred or not (to reduce "jumping" of shards on the ground)
Martin Felke
noreply at git.blender.org
Fri Jun 5 09:21:56 CEST 2015
Commit: cd603674c9b15f6e3871e985bc9f2d4114622465
Author: Martin Felke
Date: Thu Jun 4 14:20:13 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rBcd603674c9b15f6e3871e985bc9f2d4114622465
dynamic fracture: re-added modified version of speed transfer, it depends now on linear / angular deactivation threshold whether speed is transferred or not (to reduce "jumping" of shards on the ground)
===================================================================
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/makesdna/DNA_rigidbody_types.h
M source/blender/modifiers/intern/MOD_fracture.c
===================================================================
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 163f065..3dcd7ec 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1698,8 +1698,8 @@ bool BKE_lookup_mesh_state(FractureModifierData *fmd, int frame, int do_lookup)
{
if (forward || backward)
{
- fmd->modifier.scene->rigidbody_world->refresh_modifiers = true;
- fmd->modifier.scene->rigidbody_world->object_changed = true;
+ fmd->modifier.scene->rigidbody_world->flag |= RBW_FLAG_REFRESH_MODIFIERS;
+ fmd->modifier.scene->rigidbody_world->flag |= RBW_FLAG_OBJECT_CHANGED;
}
return forward || backward;
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 2757a06..fb2a670 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1209,13 +1209,23 @@ void BKE_rigidbody_validate_sim_shard(RigidBodyWorld *rbw, MeshIsland *mi, Objec
RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
RB_body_set_kinematic_state(rbo->physics_object, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
+
+ if ((len_squared_v3(rbo->lin_vel) > (rbo->lin_sleep_thresh * rbo->lin_sleep_thresh)))
+ {
+ //printf("Setting linear velocity (%f, %f, %f)\n", rbo->lin_vel[0], rbo->lin_vel[1], rbo->lin_vel[2]);
+ RB_body_set_linear_velocity(rbo->physics_object, rbo->lin_vel);
+ }
+
+ if ((len_squared_v3(rbo->ang_vel) > (rbo->ang_sleep_thresh * rbo->ang_sleep_thresh)))
+ {
+ //printf("Setting angular velocity (%f, %f, %f)\n", rbo->ang_vel[0], rbo->ang_vel[1], rbo->ang_vel[2]);
+ RB_body_set_angular_velocity(rbo->physics_object, rbo->ang_vel);
+ }
}
if (rbw && rbw->physics_world && rbo->physics_object)
{
RB_dworld_add_body(rbw->physics_world, rbo->physics_object, rbo->col_groups, mi, ob, mi->linear_index);
-
- //apply_movement_update(rbo, mi);
}
rbo->flag &= ~RBO_FLAG_NEEDS_VALIDATE;
@@ -2010,8 +2020,8 @@ RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene)
rbw->pointcache = BKE_ptcache_add(&(rbw->ptcaches));
rbw->pointcache->step = 1;
- rbw->object_changed = false;
- rbw->refresh_modifiers = false;
+ rbw->flag &=~ RBW_FLAG_OBJECT_CHANGED;
+ rbw->flag &=~ RBW_FLAG_REFRESH_MODIFIERS;
rbw->objects = MEM_mallocN(sizeof(Object *), "objects");
rbw->cache_index_map = MEM_mallocN(sizeof(RigidBodyOb *), "cache_index_map");
@@ -2171,6 +2181,9 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
rbo->meshisland_index = -1;
+ zero_v3(rbo->lin_vel);
+ zero_v3(rbo->ang_vel);
+
fmd = (FractureModifierData*)modifiers_findByType(ob, eModifierType_Fracture);
if (fmd && fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
{ //keep cache here
@@ -2620,7 +2633,7 @@ static void rigidbody_update_sim_world(Scene *scene, RigidBodyWorld *rbw)
RB_dworld_set_gravity(rbw->physics_world, adj_gravity);
/* update object array in case there are changes */
- if (!rbw->refresh_modifiers)
+ if (!(rbw->flag & RBW_FLAG_REFRESH_MODIFIERS))
rigidbody_update_ob_array(rbw);
}
@@ -3009,7 +3022,7 @@ static bool do_update_modifier(Scene* scene, Object* ob, RigidBodyWorld *rbw, bo
BKE_rigidbody_validate_sim_shard_constraint(rbw, rbsc, false);
}
- if (rbsc->physics_constraint && rbw && rbw->rebuild_comp_con) {
+ if (rbsc->physics_constraint && rbw && (rbw->flag & RBW_FLAG_REBUILD_CONSTRAINTS)) {
RB_constraint_set_enabled(rbsc->physics_constraint, true);
}
@@ -3088,7 +3101,7 @@ static void rigidbody_update_simulation(Scene *scene, RigidBodyWorld *rbw, bool
rigidbody_update_sim_ob(scene, rbw, ob, rbo, centroid);
}
- rbw->refresh_modifiers = false;
+ rbw->flag &= ~RBW_FLAG_REFRESH_MODIFIERS;
}
/* update constraints */
@@ -3155,6 +3168,10 @@ static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw)
if (rbo->type == RBO_TYPE_PASSIVE)
RB_body_deactivate(rbo->physics_object);
}
+
+ /* update stored velocities, can be set again after sim rebuild */
+ RB_body_get_linear_velocity(rbo->physics_object, rbo->lin_vel);
+ RB_body_get_angular_velocity(rbo->physics_object, rbo->ang_vel);
}
modFound = true;
break;
@@ -3208,7 +3225,7 @@ static bool do_sync_modifier(ModifierData *md, Object *ob, RigidBodyWorld *rbw,
if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ && rbw) {
RigidBodyShardCon *con;
- rbw->object_changed = true;
+ rbw->flag |= RBW_FLAG_OBJECT_CHANGED;
BKE_rigidbody_cache_reset(rbw);
/* re-enable all constraints as well */
for (con = fmd->meshConstraints.first; con; con = con->next) {
@@ -3218,7 +3235,7 @@ static bool do_sync_modifier(ModifierData *md, Object *ob, RigidBodyWorld *rbw,
}
}
- if (!is_zero_m4(fmd->origmat) && rbw && !rbw->object_changed) {
+ if (!is_zero_m4(fmd->origmat) && rbw && !(rbw->flag & RBW_FLAG_OBJECT_CHANGED)) {
copy_m4_m4(ob->obmat, fmd->origmat);
}
@@ -3316,7 +3333,7 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime)
/* otherwise set rigid body transform to current obmat */
else {
if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ)
- rbw->object_changed = true;
+ rbw->flag |= RBW_FLAG_OBJECT_CHANGED;
mat4_to_loc_quat(rbo->pos, rbo->orn, ob->obmat);
}
@@ -3473,22 +3490,22 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
cache = rbw->pointcache;
/*trigger dynamic update*/
- if ((rbw->object_changed))
+ if ((rbw->flag & RBW_FLAG_OBJECT_CHANGED))
{
- rbw->object_changed = false;
+ rbw->flag &= ~RBW_FLAG_OBJECT_CHANGED;
rigidbody_update_simulation(scene, rbw, true);
- rbw->refresh_modifiers = false;
+ rbw->flag &= ~RBW_FLAG_REFRESH_MODIFIERS;
}
if (ctime <= startframe) {
/* rebuild constraints */
- rbw->rebuild_comp_con = true;
+ rbw->flag |= RBW_FLAG_REBUILD_CONSTRAINTS;
rbw->ltime = startframe;
- if (rbw->object_changed)
+ if (rbw->flag & RBW_FLAG_OBJECT_CHANGED)
{ /* flag modifier refresh at their next execution XXX TODO -> still used ? */
- rbw->refresh_modifiers = true;
- rbw->object_changed = false;
+ rbw->flag |= RBW_FLAG_REFRESH_MODIFIERS;
+ rbw->flag &= ~RBW_FLAG_OBJECT_CHANGED;
rigidbody_update_simulation(scene, rbw, true);
}
return;
@@ -3527,7 +3544,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
}
if (rbw->ltime > startframe) {
- rbw->rebuild_comp_con = false;
+ rbw->flag &= ~RBW_FLAG_REBUILD_CONSTRAINTS;
}
/* update and validate simulation */
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index a7f0c90..ab17416 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -74,13 +74,8 @@ typedef struct RigidBodyWorld {
/* References to Physics Sim objects. Exist at runtime only ---------------------- */
void *physics_world; /* Physics sim world (i.e. btDiscreteDynamicsWorld) */
RigidBodyOb **cache_index_map; /* Maps the linear RigidbodyOb index to the nested Object(Modifier) Index, at runtime*/
- void *last_contact_point;
int *cache_offset_map; /* Maps the linear RigidbodyOb index to the nested Object(Modifier) cell offset, at runtime, so it does not need to be calced in cache*/
- int *local_index_map;
- int refresh_modifiers; /* If we have rigidbody modifiers, time to refresh them if flag is set*/
- int object_changed; /* Flag changes to objects (especially those with modifiers)*/
- int rebuild_comp_con;
- char pad2[4];
+ //char pad2[4];
} RigidBodyWorld;
/* Flags for RigidBodyWorld */
@@ -89,8 +84,14 @@ typedef enum eRigidBodyWorld_Flag {
RBW_FLAG_MUTED = (1 << 0),
/* sim data needs to be rebuilt */
RBW_FLAG_NEEDS_REBUILD = (1 << 1),
- /* usse split impulse when stepping the simulation */
- RBW_FLAG_USE_SPLIT_IMPULSE = (1 << 2)
+ /* use split impulse when stepping the simulation */
+ RBW_FLAG_USE_SPLIT_IMPULSE = (1 << 2),
+ /* Flag changes to objects (especially those with modifiers)*/
+ RBW_FLAG_OBJECT_CHANGED = (1 << 3),
+ /* If we have rigidbody modifiers, time to refresh them if flag is set*/
+ RBW_FLAG_REFRESH_MODIFIERS = (1 << 4),
+ /* Flag rebuild of constraints in fracture modifier objects */
+ RBW_FLAG_REBUILD_CONSTRAINTS = (1 << 5),
} eRigidBodyWorld_Flag;
/* ******************************** */
@@ -134,6 +135,8 @@ typedef struct RigidBodyOb {
float orn[4]; /* rigid body orientation */
float pos[3]; /* rigid body position */
+ float lin_vel[3]; /* rigid body linear velocity, important for dynamic fracture*/
+ float ang_vel[3]; /* rigid body angular velocity, important for dynamic fracture*/
float pad1;
} RigidBodyOb;
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 2634d68..94a6793 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -207,7 +207,7 @@ static void initData(ModifierData *md)
fmd->last_frame = FLT_MIN;
fmd->dynamic_force = 10.0f;
fmd->update_dynamic = false;
- fmd->limit_impact = true;
+ fmd->limit_impact = false;
}
static void freeMeshIsland(FractureModifierData *rmd, MeshIsland *mi, bool remove_rigidbody)
@@ -2773,7 +2773,7 @@ static void do_handle_parent_mi(FractureModifierData *fmd, MeshIsland *mi, MeshI
BKE_match_vertex_coords(mi, par, ob, frame, is_parent);
BKE_rigidbody_remove_shard(fmd->modifier.scene, par);
- fmd->modifier.scene->rigidbody_world->object_changed = true;
+ fmd->modifier.scene->rigidbody_world->flag |= RBW_FLAG_OBJECT_CHANGED;
par->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
}
@@ -2838,6 +2838,8 @@ static void do_island_from_shard(FractureModifierData *fmd, Object *ob, Shard* s
int i, int thresh_defgrp_index, int ground_defgrp_index, int vertstart)
{
MeshIsland *mi;
+ MeshIsland *par = NULL;
+ bool is_parent = false;
short rb_type = RBO_TYPE_ACTIVE;
float dummyloc[3], rot[4];
//float linvel[3], angvel[3];
@@ -2935,20 +2937,21 @@ static void do_island_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list