[Bf-blender-cvs] [a7306bd50f6] temp-fracture-modifier-2.8: attempt to fix pack group and export to objects

Martin Felke noreply at git.blender.org
Fri Nov 30 16:07:08 CET 2018


Commit: a7306bd50f60ef85a7a055fb9fb821a655a5dfd5
Author: Martin Felke
Date:   Fri Nov 30 16:06:45 2018 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rBa7306bd50f60ef85a7a055fb9fb821a655a5dfd5

attempt to fix pack group and export to objects

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

M	source/blender/blenkernel/BKE_fracture.h
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/fracture_external.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/makesrna/intern/rna_fracture.c
M	source/blender/makesrna/intern/rna_fracture_api.c

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

diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index eaa52b25ce8..35d2d3fb7f4 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -114,7 +114,7 @@ void BKE_fracture_constraints_refresh(struct FractureModifierData *fmd, struct O
 
 /* external mode */
 struct Shard* BKE_fracture_mesh_island_add(struct Main* bmain, struct FractureModifierData *fmd, struct Object* own,
-                                                struct Object *target, struct Scene *scene);
+                                                struct Object *target, struct Scene *scene, int id);
 
 void BKE_fracture_mesh_island_remove(struct FractureModifierData *fmd, struct Shard *mi, struct Scene* scene);
 void BKE_fracture_mesh_island_remove_all(struct FractureModifierData *fmd, struct Scene* scene);
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 218e410e457..71746f61b17 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -2677,7 +2677,7 @@ void BKE_fracture_do(FractureModifierData *fmd, Shard *mi, Object *obj, Depsgrap
 					result->id = mi->id + j;
 					result->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
 					result->rigidbody->flag |= RBO_FLAG_NEEDS_RESHAPE;
-					//BKE_rigidbody_validate_sim_shard(scene->rigidbody_world, result, obj, fmd, true, true, size);
+					BKE_rigidbody_validate_sim_shard(scene->rigidbody_world, result, obj, fmd, true, true, size);
 
 					j++;
 				}
@@ -3373,16 +3373,17 @@ void BKE_fracture_external_constraints_setup(FractureModifierData *fmd, Scene *s
 
 void BKE_fracture_meshislands_pack(FractureModifierData *fmd, Object* obj, Main* bmain, Scene* scene)
 {
+	int i = 0;
 	if (fmd->pack_group)
 	{
 		BKE_fracture_mesh_island_remove_all(fmd, scene);
 
 		FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(fmd->pack_group, ob)
 		{
-			BKE_fracture_mesh_island_add(bmain, fmd, obj, ob, scene);
+			BKE_fracture_mesh_island_add(bmain, fmd, obj, ob, scene, i);
+			i++;
 		}
 		FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
-		fmd->shared->flag |= MOD_FRACTURE_REFRESH;
 	}
 }
 
diff --git a/source/blender/blenkernel/intern/fracture_external.c b/source/blender/blenkernel/intern/fracture_external.c
index d57ea2857eb..b83ea922ffe 100644
--- a/source/blender/blenkernel/intern/fracture_external.c
+++ b/source/blender/blenkernel/intern/fracture_external.c
@@ -114,7 +114,7 @@ short BKE_fracture_collect_materials(Main* bmain, Object* o, Object* ob, int mat
 	return (*totcolp);
 }
 
-Shard* BKE_fracture_mesh_island_add(Main* bmain, FractureModifierData *fmd, Object* own, Object *target, Scene *scene)
+Shard* BKE_fracture_mesh_island_add(Main* bmain, FractureModifierData *fmd, Object* own, Object *target, Scene *scene, int id)
 {
 	Shard *mi;
 	short totcol = 0, totdef = 0;
@@ -133,9 +133,14 @@ Shard* BKE_fracture_mesh_island_add(Main* bmain, FractureModifierData *fmd, Obje
 
 	mi = fracture_object_to_island(fmd, own, target, scene);
 	mi->endframe = endframe;
+	mi->id = id;
+
+	if (mi->id == -1) {
+		mi->id = BLI_listbase_count(&fmd->shared->shards) - 1;
+	}
 
-	copy_v3_v3(mi->loc, loc);
 	copy_qt_qt(mi->rot, quat);
+	copy_qt_qt(mi->rigidbody->orn, mi->rot);
 
 	//mi->rigidbody = BKE_rigidbody_create_shard(bmain, scene, own, target, mi);
 	BLI_strncpy(mi->name, target->id.name + 2, MAX_ID_NAME - 2);
@@ -336,6 +341,7 @@ static Shard* fracture_object_to_island(FractureModifierData* fmd, Object *own,
 	}
 
 	BLI_space_transform_apply(&trans, mi->loc);
+	copy_v3_v3(mi->rigidbody->pos, mi->loc);
 
 	return mi;
 }
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index f3b8a0b0f78..45e0ea62258 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2470,13 +2470,16 @@ static int fracture_refresh_exec(bContext *C, wmOperator *op)
 	rmd->shared->flag |= MOD_FRACTURE_REFRESH;
 	rmd->last_frame = 0;
 
-	DEG_id_tag_update(&obact->id, OB_RECALC_DATA | DEG_TAG_COPY_ON_WRITE);
-	DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
+	DEG_id_tag_update(&obact->id, OB_RECALC_DATA | OB_RECALC_OB | OB_RECALC_TIME |
+									DEG_TAG_COPY_ON_WRITE | DEG_TAG_BASE_FLAGS_UPDATE);
+	DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE | DEG_TAG_BASE_FLAGS_UPDATE);
+
+	//DEG_id_tag_update(&obact->id, OB_RECALC_DATA | DEG_TAG_COPY_ON_WRITE);
+	//DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
+	DEG_relations_tag_update(bmain);
 
 	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obact);
 	WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
-
-	DEG_relations_tag_update(bmain);
 	WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
 	WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
 	WM_event_add_notifier(C, NC_SCENE | ND_FRAME, NULL);
@@ -2619,13 +2622,15 @@ void OBJECT_OT_fracture_refresh(wmOperatorType *ot)
 					"Reset all shards in next refracture, instead of keeping similar ones");
 }
 
-static void do_add_group_unchecked(Collection* group, Object *ob)
+static void do_add_group_unchecked(Main *bmain, Collection* group, Object *ob)
 {
 	CollectionObject *go;
 
 	go = MEM_callocN(sizeof(CollectionObject), "groupobject");
 	BLI_addtail(&group->gobject, go);
 	go->ob = ob;
+
+	//BKE_collection_object_add(bmain, group, ob);
 }
 
 static bool do_unchecked_constraint_add(Main *bmain, Scene *scene, Object *ob, RigidBodyShardCon *con, ReportList *reports)
@@ -2646,7 +2651,7 @@ static bool do_unchecked_constraint_add(Main *bmain, Scene *scene, Object *ob, R
 	ob->rigidbody_constraint->flag |= RBC_FLAG_NEEDS_VALIDATE;
 
 	/* add constraint to rigid body constraint group */
-	do_add_group_unchecked(rbw->constraints, ob);
+	do_add_group_unchecked(bmain, rbw->constraints, ob);
 
 	DEG_id_tag_update(&ob->id, OB_RECALC_OB);
 	return true;
@@ -2663,9 +2668,10 @@ static Object* do_convert_meshisland_to_object(Main* bmain, Shard *mi, Scene* sc
 	MVert* mv = NULL;
 	int v = 0;
 
-	char *name = mi->name ? BLI_strdupn(mi->name, MAX_ID_NAME) : BLI_strdupcat(ob->id.name + 2, "_shard");
+	char *name = mi->name[0] != '\0' ? BLI_strdupn(mi->name, MAX_ID_NAME) : BLI_strdupcat(ob->id.name + 2, "_shard");
 
 	ob_new = BKE_object_add(bmain, scene, layer, OB_MESH, name);
+	//BKE_collection_object_remove(bmain, layer->active_collection->collection, ob_new, false);
 
 	{	//TODO, this still necessary ?
 		copy_m4_m4(ob_new->obmat, ob->obmat);
@@ -2686,12 +2692,12 @@ static Object* do_convert_meshisland_to_object(Main* bmain, Shard *mi, Scene* sc
 		ob_new->rigidbody_object->flag |= RBO_FLAG_NEEDS_VALIDATE;
 
 		/* add object to rigid body group */
-		do_add_group_unchecked(rbw->group, ob_new);
+		do_add_group_unchecked(bmain, rbw->group, ob_new);
 
 		DEG_id_tag_update(&ob_new->id, OB_RECALC_ALL);
 	}
 
-	do_add_group_unchecked(g, ob_new);
+	do_add_group_unchecked(bmain, g, ob_new);
 
 	/* throw away all modifiers before fracture, result is stored inside it */
 	while (ob_new->modifiers.first != NULL) {
@@ -2713,7 +2719,7 @@ static Object* do_convert_meshisland_to_object(Main* bmain, Shard *mi, Scene* sc
 
 	assign_matarar(bmain, ob_new, give_matarar(ob), *give_totcolp(ob));
 
-	ob_new->data = BKE_fracture_mesh_copy(mi->mesh, ob);
+	ob_new->data = BKE_mesh_copy(bmain, mi->mesh);//BKE_fracture_mesh_copy(mi->mesh, ob);
 	me = (Mesh*)ob_new->data;
 	me->edit_btmesh = NULL;
 
@@ -2850,7 +2856,7 @@ static void convert_modifier_to_objects(Main* bmain, ReportList *reports, Scene*
 	int i = 0;
 	RigidBodyWorld *rbw = scene->rigidbody_world;
 	const char *name = BLI_strdupcat(ob->id.name, "_conv");
-	Collection *g = BKE_collection_add(bmain, NULL, name);
+	Collection *g = BKE_collection_add(bmain, scene->master_collection, name);
 
 	int count = BLI_listbase_count(&rmd->shared->shards);
 	KDTree* objtree = BLI_kdtree_new(count);
@@ -3094,6 +3100,7 @@ static Object* do_convert_meshIsland(Main* bmain, Depsgraph *depsgraph, Shard *m
 	char *name = BLI_strdupcat(ob->id.name + 2, "_key");
 
 	ob_new = BKE_object_add(bmain, scene, layer, OB_MESH, name);
+	//BKE_collection_object_remove(bmain, layer->active_collection->collection, ob_new, false);
 
 	//this and keyframing quats hopefully solves the sudden rotation / gimbal lock (?) issue
 	ob_new->rotmode = ROT_MODE_QUAT;
@@ -3102,7 +3109,7 @@ static Object* do_convert_meshIsland(Main* bmain, Depsgraph *depsgraph, Shard *m
 
 	assign_matarar(bmain, ob_new, give_matarar(ob), *give_totcolp(ob));
 
-	do_add_group_unchecked(gr, ob_new);
+	do_add_group_unchecked(bmain, gr, ob_new);
 
 	ob_new->data = BKE_fracture_mesh_copy(mi->mesh, ob);
 	me = (Mesh*)ob_new->data;
diff --git a/source/blender/makesrna/intern/rna_fracture.c b/source/blender/makesrna/intern/rna_fracture.c
index 39e08f7669d..b6ccc922d1a 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -553,18 +553,18 @@ static void rna_FractureModifier_dupli_ob_set(PointerRNA* ptr, PointerRNA value)
 	rmd->shared->flag |= MOD_FRACTURE_REFRESH;
 }
 
+static void rna_FractureModifier_use_dupli_set(PointerRNA* ptr, int value)
+{
+	FractureModifierData *rmd = (FractureModifierData *)ptr->data;
+	FM_FLAG_SET(rmd->flag, value, MOD_FRACTURE_USE_DUPLI);
+	FM_FLAG_SET(rmd->shared->flag, true, MOD_FRACTURE_REFRESH);
+}
+
 
 static void rna_Modifier_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
 {
-	FractureModifierData *fmd = (FractureModifierData*)ptr->data;
-	bool dupli = (fmd->flag & MOD_FRACTURE_USE_DUPLI) && fmd->dupli_ob;
-
 	BKE_rigidbody_cache_reset(scene);
 
-	if (dupli) {
-		fmd->shared->flag |= MOD_FRACTURE_REFRESH;
-	}
-
 	DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA | OB_RECALC_OB | OB_RECALC_TIME |
 									DEG_TAG_COPY_ON_WRITE | DEG_TAG_BASE_FLAGS_UPDATE);
 	DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE | DEG_TAG_BASE_FLAGS_UPDATE);
@@ -1302,6 +1302,7 @@ void RNA_def_fracture(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "use_dupli", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_FRACTURE_USE_DUPLI);
+	RNA_def_property_boolean_funcs(prop, NULL, "rna_FractureModif

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list