[Bf-blender-cvs] [cc6cf0cdce] fracture_modifier: fix, keep bake until convert to keyframe has been finished, and delete then

Martin Felke noreply at git.blender.org
Sun Feb 5 17:25:11 CET 2017


Commit: cc6cf0cdce6a2bd69983cd3984b862f2abad973a
Author: Martin Felke
Date:   Sun Feb 5 17:24:44 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rBcc6cf0cdce6a2bd69983cd3984b862f2abad973a

fix, keep bake until convert to keyframe has been finished, and delete then

Deleting the bake after changing the rigidbody count still is necessary, else the shard order and the mesh appearance of fracture modifier objects will be messed up.
Furthermore, decreased the convert to keyframe default threshold from 0.05 to 0.005, reconverting by re-using
the operator again still is somewhat broken

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

M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/editors/include/ED_physics.h
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/physics/rigidbody_object.c

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

diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index cb4db059cd..ce0f7192de 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2802,11 +2802,6 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type, M
 		return rbo;
 	}
 
-	/* free a possible bake... else you can get all kind of trouble with stale data */
-	if (rbw) {
-		rbw->pointcache->flag &= ~PTCACHE_BAKED;
-	}
-
 	/* flag cache as outdated */
 	BKE_rigidbody_cache_reset(rbw);
 
@@ -3169,11 +3164,6 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob)
 	if (!rbw && rbo)
 		BKE_rigidbody_free_object(ob);
 
-	/* free a possible bake... else you can get all kind of trouble with stale data */
-	if (rbw) {
-		rbw->pointcache->flag &= ~PTCACHE_BAKED;
-	}
-
 	/* flag cache as outdated */
 	BKE_rigidbody_cache_reset(rbw);
 }
diff --git a/source/blender/editors/include/ED_physics.h b/source/blender/editors/include/ED_physics.h
index fed842c969..af8590d3ba 100644
--- a/source/blender/editors/include/ED_physics.h
+++ b/source/blender/editors/include/ED_physics.h
@@ -45,7 +45,8 @@ int PE_hair_poll(struct bContext *C);
 int PE_poll_view3d(struct bContext *C);
 
 /* rigidbody_object.c */
-bool ED_rigidbody_object_add(struct Main *bmain, struct Scene *scene, struct Object *ob, int type, struct ReportList *reports);
+bool ED_rigidbody_object_add(struct Main *bmain, struct Scene *scene, struct Object *ob, int type, struct ReportList *reports,
+                             bool keep_bake);
 void ED_rigidbody_object_remove(struct Main *bmain, struct Scene *scene, struct Object *ob);
 
 /* rigidbody_constraint.c */
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 90ac18923e..25d38c27c0 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -3241,7 +3241,8 @@ static Object* do_convert_meshIsland(FractureModifierData* fmd, MeshIsland *mi,
 
 	DM_to_mesh(mi->physics_mesh, me, ob_new, CD_MASK_MESH, false);
 
-	ED_rigidbody_object_add(G.main, scene, ob_new, RBO_TYPE_ACTIVE, reports);
+	//last parameter here means deferring removing the bake after all has been converted.
+	ED_rigidbody_object_add(G.main, scene, ob_new, RBO_TYPE_ACTIVE, reports, true);
 	ob_new->rigidbody_object->flag |= RBO_FLAG_KINEMATIC;
 	ob_new->rigidbody_object->mass = mi->rigidbody->mass;
 
@@ -3386,7 +3387,7 @@ static bool convert_modifier_to_keyframes(FractureModifierData* fmd, Group* gr,
 		start = cache->startframe;
 		end = cache->endframe;
 		/* need to "fill" the rigidbody world by doing 1 sim step, else bake cant be read properly */
-		BKE_rigidbody_do_simulation(scene, (float)(start+1));
+		//BKE_rigidbody_do_simulation(scene, (float)(start+1));
 		BKE_ptcache_id_from_rigidbody(&pid, NULL, scene->rigidbody_world);
 		is_baked = true;
 	}
@@ -3534,6 +3535,12 @@ static int rigidbody_convert_keyframes_exec(bContext *C, wmOperator *op)
 		}
 
 		CTX_DATA_END;
+
+		//free a possible bake... because we added new rigidbodies, and this would mess up the mesh
+		if (scene->rigidbody_world && scene->rigidbody_world->pointcache) {
+			scene->rigidbody_world->pointcache->flag &= ~PTCACHE_BAKED;
+		}
+
 		DAG_relations_tag_update(G.main);
 		WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
 		WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
@@ -3571,7 +3578,7 @@ void OBJECT_OT_rigidbody_convert_to_keyframes(wmOperatorType *ot)
 	RNA_def_int(ot->srna, "start_frame", 1,  0, 100000, "Start Frame", "", 0, 100000);
 	RNA_def_int(ot->srna, "end_frame", 250, 0, 100000, "End Frame", "", 0, 100000);
 
-	RNA_def_float(ot->srna, "threshold", 0.05f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
+	RNA_def_float(ot->srna, "threshold", 0.005f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
 	RNA_def_boolean(ot->srna, "channels", false, "Channels", "");
 
 	/* flags */
diff --git a/source/blender/editors/physics/rigidbody_object.c b/source/blender/editors/physics/rigidbody_object.c
index f13a27fad7..1ea58787cd 100644
--- a/source/blender/editors/physics/rigidbody_object.c
+++ b/source/blender/editors/physics/rigidbody_object.c
@@ -52,6 +52,7 @@
 #include "BKE_DerivedMesh.h"
 #include "BKE_cdderivedmesh.h"
 #include "BKE_object.h"
+#include "BKE_pointcache.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -91,7 +92,7 @@ static int ED_operator_rigidbody_add_poll(bContext *C)
 
 /* ----------------- */
 
-bool ED_rigidbody_object_add(Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports)
+bool ED_rigidbody_object_add(Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports, bool keep_bake)
 {
 	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
 
@@ -116,6 +117,11 @@ bool ED_rigidbody_object_add(Main *bmain, Scene *scene, Object *ob, int type, Re
 
 	/* make rigidbody object settings */
 	if (ob->rigidbody_object == NULL) {
+		/* free a possible bake... else you can get all kind of trouble with stale data in FM */
+		if (rbw->pointcache && !keep_bake)
+		{
+			rbw->pointcache->flag &= ~PTCACHE_BAKED;
+		}
 		ob->rigidbody_object = BKE_rigidbody_create_object(scene, ob, type, NULL);
 	}
 	ob->rigidbody_object->type = type;
@@ -135,8 +141,13 @@ void ED_rigidbody_object_remove(Main *bmain, Scene *scene, Object *ob)
 	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
 
 	BKE_rigidbody_remove_object(scene, ob);
-	if (rbw)
+	if (rbw) {
+		if (rbw->pointcache) {
+			rbw->pointcache->flag &= ~PTCACHE_BAKED;
+		}
+
 		BKE_group_object_unlink(rbw->group, ob, scene, NULL);
+	}
 
 	DAG_relations_tag_update(bmain);
 	DAG_id_tag_update(&ob->id, OB_RECALC_OB);
@@ -156,7 +167,7 @@ static int rigidbody_object_add_exec(bContext *C, wmOperator *op)
 	bool changed;
 
 	/* apply to active object */
-	changed = ED_rigidbody_object_add(bmain, scene, ob, type, op->reports);
+	changed = ED_rigidbody_object_add(bmain, scene, ob, type, op->reports, false);
 
 	if (changed) {
 		/* send updates */
@@ -247,7 +258,7 @@ static int rigidbody_objects_add_exec(bContext *C, wmOperator *op)
 
 	/* create rigid body objects and add them to the world's group */
 	CTX_DATA_BEGIN(C, Object *, ob, selected_objects) {
-		changed |= ED_rigidbody_object_add(bmain, scene, ob, type, op->reports);
+		changed |= ED_rigidbody_object_add(bmain, scene, ob, type, op->reports, false);
 	}
 	CTX_DATA_END;
 
@@ -301,6 +312,14 @@ static int rigidbody_objects_remove_exec(bContext *C, wmOperator *UNUSED(op))
 	CTX_DATA_END;
 
 	if (changed) {
+		/* free a possible bake... when deleting rigidbodies too, else the shard order and mesh of FM rigidbodies
+		 * gets messed up */
+		RigidBodyWorld *rbw = scene->rigidbody_world;
+
+		if (rbw && rbw->pointcache) {
+			rbw->pointcache->flag &= ~PTCACHE_BAKED;
+		}
+
 		/* send updates */
 		WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
 		WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);




More information about the Bf-blender-cvs mailing list