[Bf-blender-cvs] [899c2b921c8] fracture_modifier: further optimization attempts with convert to keyframed objects
Martin Felke
noreply at git.blender.org
Wed May 31 20:44:09 CEST 2017
Commit: 899c2b921c842ec6aea57698a820ab6566195eda
Author: Martin Felke
Date: Wed May 31 20:43:47 2017 +0200
Branches: fracture_modifier
https://developer.blender.org/rB899c2b921c842ec6aea57698a820ab6566195eda
further optimization attempts with convert to keyframed objects
===================================================================
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/blenloader/intern/writefile.c
M source/blender/editors/object/object_modifier.c
M source/blender/modifiers/intern/MOD_fracture.c
===================================================================
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index b42b94efea4..b2f8a31b549 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -511,6 +511,30 @@ void BKE_rigidbody_update_cell(struct MeshIsland *mi, Object *ob, float loc[3],
n = frame - mi->start_frame + 1;
x = frame - mi->start_frame;
+ if (mi->locs == NULL || mi->rots == NULL)
+ {
+ float loca[3], rota[4], quat[4];
+ mi->locs = MEM_mallocN(sizeof(float)*3, "mi->locs");
+ mi->rots = MEM_mallocN(sizeof(float)*4, "mi->rots");
+ mi->frame_count = 0;
+
+ copy_v3_v3(loca, mi->centroid);
+ mul_m4_v3(ob->obmat, loca);
+ mat4_to_quat(quat, ob->obmat);
+
+ copy_qt_qt(rota, mi->rot);
+ mul_qt_qtqt(rota, quat, rota);
+
+ mi->locs[0] = loca[0];
+ mi->locs[1] = loca[1];
+ mi->locs[2] = loca[2];
+
+ mi->rots[0] = rota[0];
+ mi->rots[1] = rota[1];
+ mi->rots[2] = rota[2];
+ mi->rots[3] = rota[3];
+ }
+
if (n > mi->frame_count) {
mi->locs = MEM_reallocN(mi->locs, sizeof(float) * 3 * n);
mi->rots = MEM_reallocN(mi->rots, sizeof(float) * 4 * n);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index ec0f815cf5d..f01ed46423d 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1730,7 +1730,7 @@ static void write_shard(WriteData* wd, Shard* s)
}
}
-static void write_meshIsland(WriteData* wd, MeshIsland* mi)
+static void write_meshIsland(WriteData* wd, MeshIsland* mi, bool write_data)
{
writestruct(wd, DATA, MeshIsland, 1, mi);
writedata(wd, DATA, sizeof(float) * 3 * mi->vertex_count, mi->vertco);
@@ -1741,8 +1741,14 @@ static void write_meshIsland(WriteData* wd, MeshIsland* mi)
writestruct(wd, DATA, BoundBox, 1, mi->bb);
writedata(wd, DATA, sizeof(int) * mi->vertex_count, mi->vertex_indices);
- writedata(wd, DATA, sizeof(float) * 3 * mi->frame_count, mi->locs);
- writedata(wd, DATA, sizeof(float) * 4 * mi->frame_count, mi->rots);
+ if (write_data) {
+ writedata(wd, DATA, sizeof(float) * 3 * mi->frame_count, mi->locs);
+ writedata(wd, DATA, sizeof(float) * 4 * mi->frame_count, mi->rots);
+ }
+ else {
+ mi->frame_count = 0;
+ }
+
writedata(wd, DATA, sizeof(RigidBodyShardCon*) * mi->participating_constraint_count, mi->participating_constraints);
}
@@ -1908,7 +1914,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
}
for (mi = fmd->meshIslands.first; mi; mi = mi->next) {
- write_meshIsland(wd, mi);
+ write_meshIsland(wd, mi, false);
}
for (con = fmd->meshConstraints.first; con; con = con->next)
@@ -1936,7 +1942,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
{
writestruct(wd, DATA, MeshIslandSequence, 1, msq);
for (mi = msq->meshIslands.first; mi; mi = mi->next) {
- write_meshIsland(wd, mi);
+ write_meshIsland(wd, mi, true);
}
}
}
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 66624422637..9693d28dd5c 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -3316,6 +3316,21 @@ static Object* do_convert_meshIsland(FractureModifierData* fmd, MeshIsland *mi,
//insert_keyframe(NULL, (ID*)ob_new, NULL, "Scale", "scale", 2, i, BEZT_KEYTYPE_KEYFRAME, flag);
}
+ if (mi->locs)
+ {
+ MEM_freeN(mi->locs);
+ mi->locs = NULL;
+ }
+
+ if (mi->rots)
+ {
+ MEM_freeN(mi->rots);
+ mi->rots = NULL;
+ }
+
+ mi->frame_count = 0;
+ mi->start_frame = cache->startframe;
+
/*if (i + step > end || i == end)
{
ac = make_anim_context(scene, ob_new);
@@ -3362,12 +3377,12 @@ static bool convert_modifier_to_keyframes(FractureModifierData* fmd, Group* gr,
is_baked = true;
-#if 0
if (scene && scene->rigidbody_world)
{
cache = scene->rigidbody_world->pointcache;
}
+#if 0
if (cache && (!(cache->flag & PTCACHE_OUTDATED) || cache->flag & PTCACHE_BAKED))
{
//start = cache->startframe;
@@ -3423,23 +3438,44 @@ static int rigidbody_convert_keyframes_exec(bContext *C, wmOperator *op)
Group *gr = NULL;
FractureModifierData* rmd = NULL;
bool convertable = false;
+ PointCache* cache = NULL;
-#if 0
if (scene && scene->rigidbody_world)
{
- PointCache* cache = NULL;
cache = scene->rigidbody_world->pointcache;
+ /*if (cache->flag & PTCACHE_BAKED)
+ {
+ //nudge the sim once, because the internal structures may still be not initialized after loading
+
+ }*/
+#if 0
if (cache /*&& (cache->flag & PTCACHE_OUTDATED)*/ && (!(cache->flag & PTCACHE_BAKED)))
{
BKE_report(op->reports, RPT_WARNING, "No valid cache data found, please bake a simulation first");
return OPERATOR_CANCELLED;
}
- }
#endif
+ }
//if (convertable)
+ if (cache)
{
float threshold = RNA_float_get(op->ptr, "threshold");
+ int start = RNA_int_get(op->ptr, "start_frame");
+ int end = RNA_int_get(op->ptr, "end_frame");
+ int step = RNA_int_get(op->ptr, "step");
+ int frame = 0;
+
+ //fill conversion array cache
+ if (cache->startframe > start)
+ {
+ start = cache->startframe;
+ }
+
+ if (cache->endframe < end)
+ {
+ end = cache->endframe;
+ }
CTX_DATA_BEGIN(C, Object *, selob, selected_objects)
{
@@ -3448,6 +3484,16 @@ static int rigidbody_convert_keyframes_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ //force a transform sync, gah
+ if (cache->flag & PTCACHE_BAKED || !(cache->flag & PTCACHE_OUTDATED))
+ {
+ for (frame = start; frame < end; frame++)
+ {
+ BKE_rigidbody_do_simulation(scene, (float)frame);
+ BKE_object_where_is_calc_time(scene, selob, (float)frame);
+ }
+ }
+
if (rmd && (rmd->fracture_mode != MOD_FRACTURE_DYNAMIC) && rmd->meshIslands.first)
{
MeshIsland* mi = rmd->meshIslands.first;
@@ -3456,9 +3502,6 @@ static int rigidbody_convert_keyframes_exec(bContext *C, wmOperator *op)
if (rmd && convertable) {
int count = BLI_listbase_count(&rmd->meshIslands);
- int start = RNA_int_get(op->ptr, "start_frame");
- int end = RNA_int_get(op->ptr, "end_frame");
- int step = RNA_int_get(op->ptr, "step");
if (count == 0)
{
@@ -3490,7 +3533,6 @@ static int rigidbody_convert_keyframes_exec(bContext *C, wmOperator *op)
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;
}
#if 0
@@ -3500,6 +3542,8 @@ static int rigidbody_convert_keyframes_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
#endif
+
+ return OPERATOR_FINISHED;
}
static int rigidbody_convert_keyframes_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 77aad5a8b9c..84fd018ef93 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -2023,27 +2023,18 @@ static float do_setup_meshisland(FractureModifierData *fmd, Object *ob, int totv
if (fmd->fracture_mode != MOD_FRACTURE_DYNAMIC)
{
- float loc[3], rot[4], quat[4];
-
- mi->locs = MEM_mallocN(sizeof(float)*3, "mi->locs");
- mi->rots = MEM_mallocN(sizeof(float)*4, "mi->rots");
+ mi->locs = NULL;
+ mi->rots = NULL;
mi->frame_count = 0;
- copy_v3_v3(loc, centroid);
- mul_m4_v3(ob->obmat, loc);
- mat4_to_quat(quat, ob->obmat);
-
- copy_qt_qt(rot, mi->rot);
- mul_qt_qtqt(rot, quat, rot);
-
- mi->locs[0] = loc[0];
- mi->locs[1] = loc[1];
- mi->locs[2] = loc[2];
-
- mi->rots[0] = rot[0];
- mi->rots[1] = rot[1];
- mi->rots[2] = rot[2];
- mi->rots[3] = rot[3];
+ if (fmd->modifier.scene->rigidbody_world)
+ {
+ mi->start_frame = fmd->modifier.scene->rigidbody_world->pointcache->startframe;
+ }
+ else
+ {
+ mi->start_frame = 1;
+ }
}
else
{
@@ -2114,7 +2105,7 @@ static float do_setup_meshisland(FractureModifierData *fmd, Object *ob, int totv
i = BLI_listbase_count(&fmd->meshIslands);
do_rigidbody(fmd, mi, ob, orig_dm, rb_type, i);
- mi->start_frame = fmd->modifier.scene->rigidbody_world->pointcache->startframe;
+ //mi->start_frame = fmd->modifier.scene->rigidbody_world->pointcache->startframe;
BLI_addtail(&fmd->meshIslands, mi);
@@ -3445,27 +3436,10 @@ static void do_island_from_shard(FractureModifierData *fmd, Object *ob, Shard* s
if (fmd->fracture_mode != MOD_FRACTURE_DYNAMIC)
{
- float loc[3], rot[4], quat[4];
- mi->locs = MEM_mallocN(sizeof(float)*3, "mi->locs");
- mi->rots = MEM_mallocN(sizeof(float)*4, "mi->rots");
+ mi->locs = NULL;
+ mi->rots = NULL;
mi->frame_count = 0;
- copy_v3_v3(loc, s->centroid);
- mul_m4_v3(ob->obmat, loc);
- mat4_to_quat(quat, ob->obmat);
-
- copy_qt_qt(rot, mi->rot);
- mul_qt_qtqt(rot, quat, rot);
-
- mi->locs[0] = loc[0];
- mi->locs[1] = loc[1];
- mi->locs[2] = loc[2];
-
- mi->rots[0] = rot[0];
- mi->rots[1] = rot[1];
- mi->rots[2] = rot[2];
- mi->rots[3] = rot[3];
-
if (fmd->modifier.scene->rigidbody_world)
{
mi->start_frame = fmd->modifier.scene->rigidbody_world->pointcache->startframe;
More information about the Bf-blender-cvs
mailing list