[Bf-blender-cvs] [0c4939c] fracture_modifier: added a RNA function to read the appliedImpulse from each constraints live, during simulation (slow when done from a python frame handler over all constraints)

Martin Felke noreply at git.blender.org
Thu Jan 28 23:04:30 CET 2016


Commit: 0c4939c0132aceb7922c6fca2a5ffc65b4f7656d
Author: Martin Felke
Date:   Thu Jan 28 23:04:12 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB0c4939c0132aceb7922c6fca2a5ffc65b4f7656d

added a RNA function to read the appliedImpulse from each constraints live, during simulation (slow when done from a python frame handler over all constraints)

===================================================================

M	intern/rigidbody/RBI_api.h
M	intern/rigidbody/rb_bullet_api.cpp
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fracture.c

===================================================================

diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 69a8324..0791bda 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -306,6 +306,7 @@ void RB_constraint_delete(rbConstraint *con);
 /* Enable or disable constraint */
 void RB_constraint_set_enabled(rbConstraint *con, int enabled);
 int RB_constraint_is_enabled(rbConstraint *con);
+float RB_constraint_get_applied_impulse(rbConstraint *con);
 
 /* Limits */
 #define RB_LIMIT_LIN_X 0
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 2e9f543..c3b63d2 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -1370,6 +1370,7 @@ void RB_constraint_set_enabled(rbConstraint *con, int enabled)
 	btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint*>(con);
 	
 	constraint->setEnabled(enabled);
+	constraint->enableFeedback(enabled);
 }
 
 int RB_constraint_is_enabled(rbConstraint *con)
@@ -1379,6 +1380,12 @@ int RB_constraint_is_enabled(rbConstraint *con)
 	return constraint->isEnabled();
 }
 
+float RB_constraint_get_applied_impulse(rbConstraint *con)
+{
+	btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint*>(con);
+	return (float)constraint->getAppliedImpulse();
+}
+
 void RB_constraint_set_limits_hinge(rbConstraint *con, float lower, float upper)
 {
 	btHingeConstraint *constraint = reinterpret_cast<btHingeConstraint*>(con);
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 9f1bce2..cb6e6a5 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -4115,7 +4115,7 @@ static void resetDynamic(RigidBodyWorld *rbw)
 				MeshIsland *mi;
 				//mti->freeData((ModifierData*)fmd);
 				//BKE_object_where_is_calc(scene, go->ob);
-				//fmd->last_frame = INT_MAX;
+
 				for (mi = fmd->meshIslands.first; mi; mi = mi->next)
 				{
 					BKE_rigidbody_remove_shard(scene, mi);
@@ -4123,6 +4123,7 @@ static void resetDynamic(RigidBodyWorld *rbw)
 
 				fmd->refresh = true;
 				fmd->reset_shards = true;
+				fmd->last_frame = INT_MAX;
 
 				DAG_id_tag_update(go->ob, OB_RECALC_ALL);
 				WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, go->ob);
@@ -4137,8 +4138,8 @@ void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw)
 	if (rbw) {
 		rbw->pointcache->flag |= PTCACHE_OUTDATED;
 		//restoreKinematic(rbw);
-		if (!(rbw->pointcache->flag & PTCACHE_BAKED))
-			resetDynamic(rbw);
+		//if (!(rbw->pointcache->flag & PTCACHE_BAKED))
+		resetDynamic(rbw);
 	}
 }
 
@@ -4202,7 +4203,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 	if ((rbw->flag & RBW_FLAG_OBJECT_CHANGED))
 	{
 		rbw->flag &= ~RBW_FLAG_OBJECT_CHANGED;
-		if (!(cache->flag & PTCACHE_BAKED))
+		//if (!(cache->flag & PTCACHE_BAKED))
 		{
 			/* dont mess with baked data */
 			//if (ctime <= startframe)
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 3f9463f..8b0b322 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -1306,6 +1306,15 @@ static void rna_FractureModifier_mesh_constraint_clear(ID *id, FractureModifierD
 	}
 }
 
+static float rna_MeshCon_get_applied_impulse(RigidBodyShardCon *con)
+{
+#ifdef WITH_BULLET
+	if (con && con->physics_constraint)
+		return RB_constraint_get_applied_impulse(con->physics_constraint);
+#endif
+	return 0.0f;
+}
+
 #define RB_FLAG_SET(dest, value, flag) { \
 	if (value) \
 		dest |= flag; \
@@ -5280,8 +5289,8 @@ static void rna_def_mesh_island(BlenderRNA *brna)
 static void rna_def_mesh_constraint(BlenderRNA *brna)
 {
 	StructRNA *srna;
-	PropertyRNA *prop;
-	//FunctionRNA *func;
+	PropertyRNA *prop, *parm;
+	FunctionRNA *func;
 
 	srna = RNA_def_struct(brna, "MeshConstraint", NULL);
 	RNA_def_struct_sdna(srna, "RigidBodyShardCon");
@@ -5627,6 +5636,11 @@ static void rna_def_mesh_constraint(BlenderRNA *brna)
 	RNA_def_property_range(prop, -1.0f, DEG2RADF(360.0));
 	RNA_def_property_ui_text(prop, "Plastic Angle", "Angle Tolerance of this constraint, when exceeded enter plastic mode, -1 disables");
 	//RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	//do as function, dont need an dna value for storage, instead query from bullet directly
+	func = RNA_def_function(srna, "appliedImpulse", "rna_MeshCon_get_applied_impulse");
+	parm = RNA_def_float(func, "impulse", 0, -FLT_MAX, FLT_MAX, "Applied Impulse", "The currently applied impulse on this constraint", -FLT_MIN, FLT_MAX);
+	RNA_def_function_return(func, parm);
 }
 
 static void rna_def_fracture_meshislands(BlenderRNA *brna, PropertyRNA *cprop)
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index d5fa533..6b7d914 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -425,7 +425,7 @@ static void freeData(ModifierData *md)
 
 	/*force deletion of meshshards here, it slips through improper state detection*/
 	/*here we know the modifier is about to be deleted completely*/
-	//free_shards(fmd);
+	free_shards(fmd);
 }
 
 //XXX TODO move cluster handling to BKE too




More information about the Bf-blender-cvs mailing list