Commit: 39e00e5959094747618541030ef258bb1ee2600d
Author: Martin Felke
Date: Thu Jan 28 21:01:14 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB39e00e5959094747618541030ef258bb1ee2600d
fix: dynamic mode didnt work at all anymore and has still some issues like
flickering after baking and a crasher on exiting blender, also testwise enabled
autoexecute on prefracture during sim
===================================================================
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/pointcache.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
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 bbedf57..b0b3fbf 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1847,7 +1847,7 @@ void BKE_get_next_entries(FractureModifierData *fmd)
void BKE_get_prev_entries(FractureModifierData *fmd)
{
/*meshislands and shards SHOULD be synchronized !!!!*/
- if (fmd->current_mi_entry->prev != NULL) {
+ if (fmd->current_mi_entry && fmd->current_mi_entry->prev) {
fmd->current_mi_entry = fmd->current_mi_entry->prev;
fmd->current_shard_entry = fmd->current_shard_entry->prev;
@@ -1873,7 +1873,7 @@ bool BKE_lookup_mesh_state(FractureModifierData *fmd, int
frame, int do_lookup)
if (do_lookup)
{
while (fmd->current_mi_entry &&
fmd->current_mi_entry->prev &&
- frame <= fmd->current_mi_entry->prev->frame)
+ frame < fmd->current_mi_entry->prev->frame)
{
printf("Jumping backward because %d is smaller
than %d\n", frame, fmd->current_mi_entry->prev->frame);
changed = true;
@@ -2586,7 +2586,7 @@ void BKE_fracture_free_mesh_island(FractureModifierData
*rmd, MeshIsland *mi, bo
}
if (mi->rigidbody) {
- if (remove_rigidbody)
+ if (remove_rigidbody && rmd->modifier.scene)
BKE_rigidbody_remove_shard(rmd->modifier.scene, mi);
MEM_freeN(mi->rigidbody);
mi->rigidbody = NULL;
diff --git a/source/blender/blenkernel/intern/pointcache.c
b/source/blender/blenkernel/intern/pointcache.c
index 1d0af16..f141d7e 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1024,12 +1024,13 @@ static int ptcache_rigidbody_write(int index, void
*rb_v, void **data, int cfra
if (rbo && rbo->type == RBO_TYPE_ACTIVE && rbo->physics_object)
{
-#ifdef WITH_BULLET
- RB_body_get_position(rbo->physics_object, rbo->pos);
- RB_body_get_orientation(rbo->physics_object, rbo->orn);
-#endif
if (!fmd || fmd->fracture_mode != MOD_FRACTURE_DYNAMIC)
{
+
+#ifdef WITH_BULLET
+ RB_body_get_position(rbo->physics_object, rbo->pos);
+ RB_body_get_orientation(rbo->physics_object, rbo->orn);
+#endif
PTCACHE_DATA_FROM(data, BPHYS_DATA_LOCATION, rbo->pos);
PTCACHE_DATA_FROM(data, BPHYS_DATA_ROTATION, rbo->orn);
}
@@ -1037,6 +1038,17 @@ static int ptcache_rigidbody_write(int index, void
*rb_v, void **data, int cfra
{
MeshIsland *mi = BLI_findlink(&fmd->meshIslands,
rbo->meshisland_index);
int frame = (int)floor(cfra);
+
+ if (!mi)
+ return 0;
+
+ rbo = mi->rigidbody;
+
+#ifdef WITH_BULLET
+ RB_body_get_position(rbo->physics_object, rbo->pos);
+ RB_body_get_orientation(rbo->physics_object, rbo->orn);
+#endif
+
frame = frame - mi->start_frame;
//printf("Writing frame %d %d %d %d\n", (int)cfra,
mi->start_frame, frame, fmd->last_frame);
@@ -1053,6 +1065,7 @@ static int ptcache_rigidbody_write(int index, void
*rb_v, void **data, int cfra
//dummy data
PTCACHE_DATA_FROM(data, BPHYS_DATA_LOCATION, rbo->pos);
PTCACHE_DATA_FROM(data, BPHYS_DATA_ROTATION, rbo->orn);
+
}
}
@@ -1100,10 +1113,16 @@ static void ptcache_rigidbody_read(int index, void
*rb_v, void **data, float cfr
int frame = (int)floor(cfra);
mi = BLI_findlink(&fmd->meshIslands,
rbo->meshisland_index);
+
+ if (!mi)
+ return;
+
frame = frame - mi->start_frame;
if (frame < 0)
+ {
frame = 0; //grrr, why does this happen ?!
+ }
//printf("Reading frame %d %d %d %d\n", (int)cfra,
mi->start_frame, frame, fmd->last_frame);
diff --git a/source/blender/blenkernel/intern/rigidbody.c
b/source/blender/blenkernel/intern/rigidbody.c
index 48dd9e3..9f1bce2 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -73,6 +73,9 @@
#include "BKE_scene.h"
#include "PIL_time.h"
+#include "WM_types.h"
+#include "WM_api.h"
+
#ifdef WITH_BULLET
static void resetDynamic(RigidBodyWorld *rbw);
@@ -2636,6 +2639,7 @@ void BKE_rigidbody_remove_shard(Scene *scene, MeshIsland
*mi)
if (mi->rigidbody != NULL && rbw != NULL) {
RigidBodyShardCon *con;
+
for (i = 0; i < mi->participating_constraint_count; i++) {
con = mi->participating_constraints[i];
BKE_rigidbody_remove_shard_con(scene, con);
@@ -2653,15 +2657,18 @@ void BKE_rigidbody_remove_shard(Scene *scene,
MeshIsland *mi)
RB_shape_delete(mi->rigidbody->physics_shape);
mi->rigidbody->physics_shape = NULL;
}
-
- /* this SHOULD be the correct global index */
+
+ /* this SHOULD be the correct global index, mark with NULL as
'dirty' BEFORE deleting */
/* need to check whether we didnt create the rigidbody world
manually already, prior to fracture, in this
* case cache_index_map might be not initialized ! checking
numbodies here, they should be 0 in a fresh
* rigidbody world */
- if ((rbw->cache_index_map != NULL) && (rbw->numbodies > 0))
+
+ if ((rbw->cache_index_map != NULL) && (rbw->numbodies > 0) &&
mi->linear_index < rbw->numbodies) {
+ //mi->rigidbody = NULL;
rbw->cache_index_map[mi->linear_index] = NULL;
+ }
- BKE_rigidbody_update_ob_array(rbw);
+ //BKE_rigidbody_update_ob_array(rbw);
}
}
@@ -2814,7 +2821,7 @@ static int rigidbody_group_count_items(const ListBase
*group, int *r_num_objects
for (md = gob->ob->modifiers.first; md; md = md->next) {
if (md->type == eModifierType_Fracture) {
rmd = (FractureModifierData *)md;
- if (isModifierActive(rmd))
+ if (isModifierActive(rmd) &&
rmd->meshIslands.first != NULL)
{
found_modifiers = true;
*r_num_shards +=
BLI_listbase_count(&rmd->meshIslands);
@@ -2879,7 +2886,8 @@ void BKE_rigidbody_update_ob_array(RigidBodyWorld *rbw)
rbw->cache_index_map[counter] =
mi->rigidbody; /* map all shards of an object to this object index*/
rbw->cache_offset_map[counter]
= i;
mi->linear_index = counter;
- mi->rigidbody->meshisland_index
= j;
+ if (mi->rigidbody)
+
mi->rigidbody->meshisland_index = j;
counter++;
j++;
}
@@ -3436,10 +3444,10 @@ static bool do_update_modifier(Scene* scene, Object*
ob, RigidBodyWorld *rbw, bo
//print_m4("Obmat: \n", ob->obmat);
//print_m4("Passivemat: \n", fmd->passive_parent_mat);
-
- BKE_object_where_is_calc(scene, ob);
}
+ BKE_object_where_is_calc(scene, ob);
+
for (mi = fmd->meshIslands.first; mi; mi = mi->next) {
if (mi->rigidbody == NULL) {
continue;
@@ -4098,13 +4106,28 @@ static void resetDynamic(RigidBodyWorld *rbw)
FractureModifierData *fmd =
(FractureModifierData*)modifiers_findByType(go->ob, eModifierType_Fracture);
if (fmd && fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
{
+ //const ModifierTypeInfo *mti =
modifierType_getInfo(fmd->modifier.type);
Scene *scene = fmd->modifier.scene;
- fmd->last_frame = INT_MAX;
- fmd->refresh = true;
- //need really to trigger modifier stack evaluation here
at once, next depgraph tag is too late
- //apparently
- makeDerivedMesh(scene, go->ob, NULL,
scene->customdata_mask | CD_MASK_BAREMESH, 0);
+ //free modifier data "by hand", right now
+ if (BLI_listbase_count(&fmd->meshIslands) > 1)
+ {
+ 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);
+ }
+
+ fmd->refresh = true;
+ fmd->reset_shards = true;
+
+ DAG_id_tag_update(go->ob, OB_RECALC_ALL);
+ WM_main_add_notifier(NC_OBJECT | ND_MODIFIER,
go->ob);
+ WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM,
go->ob);
+ }
}
}
}
@@ -4114,8 +4137,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);
}
}
@@ -4180,8 +4203,12 @@ void BKE_rigidbody_do_simulation(Scene *scene, float
ctime)
{
rbw->flag &= ~RBW_FLAG_OBJECT_CHANGED;
if (!(cache->flag & PTCACHE_BAKED))
+ {
/* dont mess with baked data */
+ //if (ctime <= startframe)
+ // BKE_rigidbody_cache_reset(rbw);
rigidbody_update_simulation(scene, rbw, true);
+ }
rbw->flag &= ~RBW_FLAG_REFRESH_MODIFIERS;
}
diff --git a/source/blender/blenloader/intern/readfile.c
b/source/blender/blenloader/intern/readfile.c
index 1154eb7..9286abb 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5122,9 +5122,12 @@ static int initialize_meshisland(FractureModifierData*
fmd, MeshIsland** mii, MV
static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd,
Object* ob)
{
FracMesh* fm;
+ bool autoexec = false;
fm = fmd->frac_mesh = newdataadr(fd, fmd->frac_mesh);
+ autoexec = fmd->auto_execute;
+ fmd->auto_execute = false;
fmd->refresh = false; /* do not execute modifier here yet*/
fmd->refresh_constraints = false;
fmd->nor_tree = NULL;
@@ -5248,7 +5251,7 @@ static void load_fracture_modifier(FileData* fd,
FractureModifierData *fmd, Obje
}
}
}
- else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
+ else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC &&
!fd->memfile)
{
ShardSequence *ssq = NULL;
MeshIslandSequence *msq = NULL;
@@ -5325,6 +5328,7 @@ static void load_fracture_modifier(FileData* fd,
FractureModifierData *fmd, Obje
}
fmd->refresh_images = true;
+ fmd->auto_execute = autoexec;
}
}
diff --git a/source/blender/blenloader/intern/writefile.c
b/source/blender/blenloader/intern/writefile.c
index 10afc3a..5175b0d 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1759,7 +1759,7 @@ static void write_modifiers(WriteData *wd, ListBase
*modbase)
}
}
}
- else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
+ else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC &&
!wd->current)
{
ShardSequence *ssq;
MeshIslandSequence *msq;
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/bl
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs