[Bf-blender-cvs] [744c07b263d] temp-fracture-modifier-2.8: made FM more CoW compliant and added some sanity checks
Martin Felke
noreply at git.blender.org
Tue Aug 14 17:30:33 CEST 2018
Commit: 744c07b263dca772be88f89ab379cc6ba59eecfc
Author: Martin Felke
Date: Tue Aug 14 17:29:33 2018 +0200
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB744c07b263dca772be88f89ab379cc6ba59eecfc
made FM more CoW compliant and added some sanity checks
===================================================================
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/fracture_prefractured.c
M source/blender/blenkernel/intern/fracture_rigidbody.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M source/blender/editors/object/object_modifier.c
===================================================================
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index e6879f18d7e..d50440ee4e9 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1831,22 +1831,25 @@ Mesh* BKE_fracture_assemble_mesh_from_islands(FractureModifierData* fmd, ListBas
{
float fno[3], centr[3];
- if (fmd->fix_normals) {
- /*ignore global quaternion rotation here */
- normal_short_to_float_v3(fno, mi->mesh->mvert[v].no);
- mul_qt_v3(mi->rigidbody->orn, fno);
- mul_qt_v3(iquat, fno);
- normal_float_to_short_v3(mv->no, fno);
- }
+ if (mi->rigidbody)
+ {
+ if (fmd->fix_normals) {
+ /*ignore global quaternion rotation here */
+ normal_short_to_float_v3(fno, mi->mesh->mvert[v].no);
+ mul_qt_v3(mi->rigidbody->orn, fno);
+ mul_qt_v3(iquat, fno);
+ normal_float_to_short_v3(mv->no, fno);
+ }
- mul_v3_v3(mv->co, size);
- mul_qt_v3(mi->rigidbody->orn, mv->co);
- copy_v3_v3(centr, mi->centroid);
- mul_v3_v3(centr, size);
- mul_qt_v3(mi->rigidbody->orn, centr);
- sub_v3_v3(mv->co, centr);
- add_v3_v3(mv->co, mi->rigidbody->pos);
- mul_m4_v3(imat, mv->co);
+ mul_v3_v3(mv->co, size);
+ mul_qt_v3(mi->rigidbody->orn, mv->co);
+ copy_v3_v3(centr, mi->centroid);
+ mul_v3_v3(centr, size);
+ mul_qt_v3(mi->rigidbody->orn, centr);
+ sub_v3_v3(mv->co, centr);
+ add_v3_v3(mv->co, mi->rigidbody->pos);
+ mul_m4_v3(imat, mv->co);
+ }
BLI_ghash_insert(fmd->shared->vert_index_map, SET_INT_IN_POINTER(vertstart + v), SET_INT_IN_POINTER(mi->id));
}
diff --git a/source/blender/blenkernel/intern/fracture_prefractured.c b/source/blender/blenkernel/intern/fracture_prefractured.c
index 2f76c4c6cbe..faeefadc224 100644
--- a/source/blender/blenkernel/intern/fracture_prefractured.c
+++ b/source/blender/blenkernel/intern/fracture_prefractured.c
@@ -75,7 +75,7 @@ MeshIsland *BKE_fracture_mesh_island_create(Mesh* me, Main* bmain, Scene *scene,
Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, Depsgraph* depsgraph)
{
- Scene *scene = DEG_get_input_scene(depsgraph);
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
//Object *ob = DEG_get_evaluated_object(depsgraph, obj);
Mesh* me_assembled = NULL;
@@ -88,7 +88,7 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
Mesh *me_tmp = NULL;
// HACK
- ob = DEG_get_original_object(ob);
+ //ob = DEG_get_original_object(ob);
/*free old stuff here */
BKE_fracture_constraints_free(fmd, scene);
@@ -117,6 +117,8 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
fmd->shared->refresh_constraints = true;
fmd->shared->refresh_autohide = true;
+
+ DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
}
else if (fmd->shared->refresh_dynamic)
{
@@ -128,6 +130,7 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
if (fmd->shared->mesh_islands.first)
{
me_assembled = BKE_fracture_assemble_mesh_from_islands(fmd, &fmd->shared->mesh_islands, ob);
+ DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE);
}
else {
me_assembled = me;
@@ -141,6 +144,10 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
BKE_fracture_constraints_free(fmd, scene);
BKE_fracture_external_constraints_setup(fmd, scene, ob);
+
+ if (!fmd->shared->refresh)
+ /* update scene here in case only the constraints updated, dont update twice*/
+ DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
}
fmd->shared->refresh = false;
diff --git a/source/blender/blenkernel/intern/fracture_rigidbody.c b/source/blender/blenkernel/intern/fracture_rigidbody.c
index 27dc04f87ee..4ad50a63786 100644
--- a/source/blender/blenkernel/intern/fracture_rigidbody.c
+++ b/source/blender/blenkernel/intern/fracture_rigidbody.c
@@ -1313,7 +1313,7 @@ static void fake_dynamic_collide(Object *ob1, Object *ob2, MeshIsland *mi1, Mesh
static bool check_constraint_island(FractureModifierData* fmd, MeshIsland *mi1, MeshIsland *mi2)
{
- if (mi1 && mi2 && !fmd->use_compounds && (!fmd->use_constraint_collision || fmd->use_self_collision)) {
+ if (mi1 && mi2 && fmd && !fmd->use_compounds && (!fmd->use_constraint_collision || fmd->use_self_collision)) {
float dist_sq = len_squared_v3v3(mi1->centroid, mi2->centroid);
bool is_near = len_squared_v3v3(mi1->rigidbody->pos, mi2->rigidbody->pos) < dist_sq;
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 0ec81abc601..afbcd0ce9cc 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1519,10 +1519,13 @@ static int object_sort_eval(const void *s1, const void *s2, void* context)
{
Object **o1 = (Object**)s1;
Object **o2 = (Object**)s2;
+ FractureModifierData *fmd1, *fmd2;
- FractureModifierData *fmd1 = (FractureModifierData*)modifiers_findByType(*o1, eModifierType_Fracture);
- FractureModifierData *fmd2 = (FractureModifierData*)modifiers_findByType(*o2, eModifierType_Fracture);
+ if (!o1 || !o2 || !(*o1) || !(*o2))
+ return 0;
+ fmd1 = (FractureModifierData*)modifiers_findByType(*o1, eModifierType_Fracture);
+ fmd2 = (FractureModifierData*)modifiers_findByType(*o2, eModifierType_Fracture);
if ((fmd1 && fmd1->dm_group && fmd1->use_constraint_group) &&
(fmd2 && fmd2->dm_group && fmd2->use_constraint_group))
@@ -1587,7 +1590,7 @@ void BKE_rigidbody_update_ob_array(RigidBodyWorld *rbw, bool do_bake_correction)
l = rigidbody_group_count_items(&rbw->group->gobject, &m, &n);
rbw->shared->numbodies = m + n;
- rbw->shared->objects = MEM_mallocN(sizeof(Object *) * l, "objects");
+ rbw->shared->objects = MEM_callocN(sizeof(Object *) * l, "objects");
rbw->shared->cache_index_map = MEM_mallocN(sizeof(RigidBodyOb *) *
rbw->shared->numbodies, "cache_index_map");
rbw->shared->cache_offset_map = MEM_mallocN(sizeof(int) * rbw->shared->numbodies, "cache_offset_map");
@@ -1612,6 +1615,8 @@ void BKE_rigidbody_update_ob_array(RigidBodyWorld *rbw, bool do_bake_correction)
//correct map if baked, it might be shifted
for (i = 0; i < l; i++) {
Object *ob = rbw->shared->objects[i];
+ if (!ob) continue;
+
printf("%s\n", ob->id.name + 2);
rmd = (FractureModifierData*)modifiers_findByType(ob, eModifierType_Fracture);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 4f94066f3bb..66c56dc6b5f 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -1482,6 +1482,11 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
continue;
}
+ //sanity check
+ if (!object->rigidbody_object) {
+ continue;
+ }
+
/* hook up evaluation order...
* 1) flushing rigidbody results follows base transforms being applied
* 2) rigidbody flushing can only be performed after simulation has been run
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 5f01e5f0929..ae96bf44b49 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2503,18 +2503,20 @@ static int fracture_refresh_exec(bContext *C, wmOperator *op)
//add first rigidbody already here, seems to trigger an important depsgraph update
ED_rigidbody_object_add(bmain, scene, obact, RBO_TYPE_ACTIVE, op->reports, false);
- 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);
-
rmd->shared->refresh = true;
rmd->last_frame = INT_MAX; // delete dynamic data as well
- DEG_id_tag_update(&obact->id, OB_RECALC_DATA | OB_RECALC_OB);
+ 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);
+
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);
+
return OPERATOR_FINISHED;
}
More information about the Bf-blender-cvs
mailing list