[Bf-blender-cvs] [360c01c] fracture_modifier: dynamic fracture: attempts with loading and saving, and proper caching, still highly unstable
Martin Felke
noreply at git.blender.org
Mon Jun 1 21:29:18 CEST 2015
Commit: 360c01cb867968d4d316e78105050c71bc531ce3
Author: Martin Felke
Date: Mon May 18 16:29:39 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rB360c01cb867968d4d316e78105050c71bc531ce3
dynamic fracture: attempts with loading and saving, and proper caching, still highly unstable
===================================================================
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/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index da7242a..56cde57 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1032,11 +1032,7 @@ static int ptcache_rigidbody_write(int index, void *rb_v, void **data, int cfra
else if (fmd && fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
{
MeshIsland *mi = BLI_findlink(&fmd->meshIslands, rbo->meshisland_index);
- int frame = (int)cfra;
-
- /* if (mi == NULL) {
- return 0;
- }*/
+ int frame = (int)cfra - mi->start_frame;
mi->locs[3*frame] = rbo->pos[0];
mi->locs[3*frame+1] = rbo->pos[1];
@@ -1090,12 +1086,7 @@ static void ptcache_rigidbody_read(int index, void *rb_v, void **data, float cfr
//modifier should have "switched" this to current set of meshislands already.... so access it
MeshIsland *mi = BLI_findlink(&fmd->meshIslands, rbo->meshisland_index);
- int frame = (int)cfra;
-
- /*if (mi == NULL)
- {
- return;
- }*/
+ int frame = (int)cfra - mi->start_frame;
rbo->pos[0] = mi->locs[3*frame];
rbo->pos[1] = mi->locs[3*frame+1];
@@ -1114,23 +1105,50 @@ static void ptcache_rigidbody_interpolate(int index, void *rb_v, void **data, fl
RigidBodyOb *rbo = NULL;
ParticleKey keys[4];
float dfra;
+ Object* ob;
+ FractureModifierData *fmd;
rbo = rbw->cache_index_map[index];
if (rbo == NULL) {
return;
}
+ ob = rbw->objects[rbw->cache_offset_map[index]];
+ fmd = modifiers_findByType(ob, eModifierType_Fracture);
+
if (rbo->type == RBO_TYPE_ACTIVE) {
copy_v3_v3(keys[1].co, rbo->pos);
copy_qt_qt(keys[1].rot, rbo->orn);
- if (old_data) {
- memcpy(keys[2].co, data, 3 * sizeof(float));
- memcpy(keys[2].rot, data + 3, 4 * sizeof(float));
+ if (!fmd || fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
+ {
+ if (old_data) {
+ memcpy(keys[2].co, data, 3 * sizeof(float));
+ memcpy(keys[2].rot, data + 3, 4 * sizeof(float));
+ }
+ else {
+ BKE_ptcache_make_particle_key(keys+2, 0, data, cfra2);
+ }
}
- else {
- BKE_ptcache_make_particle_key(keys+2, 0, data, cfra2);
+ else if (fmd && fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
+ {
+ float loc[3], rot[4];
+
+ MeshIsland *mi = BLI_findlink(&fmd->meshIslands, rbo->meshisland_index);
+ int frame = (int)cfra2 - mi->start_frame;
+
+ loc[0] = mi->locs[3*frame];
+ loc[1] = mi->locs[3*frame+1];
+ loc[2] = mi->locs[3*frame+2];
+
+ rot[0] = mi->rots[4*frame];
+ rot[1] = mi->rots[4*frame+1];
+ rot[2] = mi->rots[4*frame+2];
+ rot[3] = mi->rots[4*frame+3];
+
+ copy_v3_v3(keys[2].co, loc);
+ copy_qt_qt(keys[2].rot, rot);
}
dfra = cfra2 - cfra1;
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 0b8105c..dfea905 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1843,11 +1843,18 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
ob1 = rbw->objects[ob_index1];
fmd1 = (FractureModifierData*)modifiers_findByType(ob1, eModifierType_Fracture);
- if ((fmd1 && fmd1->fracture_mode == MOD_FRACTURE_DYNAMIC) && (force > fmd1->dynamic_force)) {
- FractureID* fid1 = MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid1");
- fid1->shardID = rbw->cache_index_map[linear_index1]->meshisland_index;
- BLI_addtail(&fmd1->fracture_ids, fid1);
- fmd1->refresh = true;
+ if (fmd1 && fmd1->fracture_mode == MOD_FRACTURE_DYNAMIC) {
+ if (force > fmd1->dynamic_force) {
+ if (fmd1->current_shard_entry && fmd1->current_shard_entry->is_new)
+ {
+ /*only fracture on new entries, this is necessary because after loading a file
+ *the pointcache thinks it is empty and a fracture is attempted ! */
+ FractureID* fid1 = MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid1");
+ fid1->shardID = rbw->cache_index_map[linear_index1]->meshisland_index;
+ BLI_addtail(&fmd1->fracture_ids, fid1);
+ //fmd1->refresh = true;
+ }
+ }
}
}
@@ -1857,11 +1864,16 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
ob2 = rbw->objects[ob_index2];
fmd2 = (FractureModifierData*)modifiers_findByType(ob2, eModifierType_Fracture);
- if ((fmd2 && fmd2->fracture_mode == MOD_FRACTURE_DYNAMIC) && (force > fmd2->dynamic_force)) {
- FractureID* fid2 = MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid2");
- fid2->shardID = rbw->cache_index_map[linear_index2]->meshisland_index;
- BLI_addtail(&fmd2->fracture_ids, fid2);
- fmd2->refresh = true;
+ if (fmd2 && fmd2->fracture_mode == MOD_FRACTURE_DYNAMIC) {
+ if (force > fmd2->dynamic_force){
+ if (fmd2->current_shard_entry && fmd2->current_shard_entry->is_new)
+ {
+ FractureID* fid2 = MEM_mallocN(sizeof(FractureID), "contact_callback_fractureid2");
+ fid2->shardID = rbw->cache_index_map[linear_index2]->meshisland_index;
+ BLI_addtail(&fmd2->fracture_ids, fid2);
+ //fmd2->refresh = true;
+ }
+ }
}
}
@@ -3409,7 +3421,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
else if (rbw->ltime == startframe)
{
restoreKinematic(rbw);
- rigidbody_update_simulation(scene, rbw, true);
+ //rigidbody_update_simulation(scene, rbw, true);
}
/* advance simulation, we can only step one frame forward */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 098b817..65f273c 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -228,7 +228,7 @@ typedef struct OldNewMap {
/* local prototypes */
static void *read_struct(FileData *fd, BHead *bh, const char *blockname);
-static void direct_link_modifiers(FileData *fd, ListBase *lb);
+static void direct_link_modifiers(FileData *fd, ListBase *lb, Object* ob);
static void convert_tface_mt(FileData *fd, Main *main);
/* this function ensures that reports are printed,
@@ -4759,8 +4759,106 @@ static void read_meshIsland(FileData *fd, MeshIsland **address)
mi->participating_constraints = NULL;
}
+/*inlined from MOD_fracture.c*/
+static void do_match_vertex_coords(MeshIsland* mi, MeshIsland *par, Object *ob, int frame)
+{
+ float loc[3] = {0.0f, 0.0f, 0.0f};
+ float rot[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ int j = 0;
+ float irot[4];
+ invert_m4_m4(ob->imat, ob->obmat);
+
+ loc[0] = par->locs[3*frame];
+ loc[1] = par->locs[3*frame+1];
+ loc[2] = par->locs[3*frame+2];
+
+ rot[0] = par->rots[4*frame];
+ rot[1] = par->rots[4*frame+1];
+ rot[2] = par->rots[4*frame+2];
+ rot[3] = par->rots[4*frame+3];
+
+ mul_m4_v3(ob->imat, loc);
+ mat4_to_quat(irot, ob->imat);
+ mul_qt_qtqt(rot, rot, irot);
+
+ //match vertices and vertco, perhaps vertno too, yuck...
+ for (j = 0; j < mi->vertex_count; j++)
+ {
+ float co[3];
+
+ mul_qt_v3(rot, mi->vertices_cached[j]->co);
+ add_v3_v3(mi->vertices_cached[j]->co, loc);
+
+ co[0] = mi->vertco[3*j];
+ co[1] = mi->vertco[3*j+1];
+ co[2] = mi->vertco[3*j+2];
+
+ mul_qt_v3(rot, co);
+ add_v3_v3(co, loc);
+
+ mi->vertco[3*j] = co[0];
+ mi->vertco[3*j+1] = co[1];
+ mi->vertco[3*j+2] = co[2];
+ }
+}
+
+static int initialize_meshisland(FractureModifierData* fmd, MeshIsland** mii, MVert* mverts, int vertstart, Object *ob, ShardID parent_id)
+{
+ MVert *mv;
+ int k = 0;
+ MeshIsland* mi = *mii;
+
+ mi->vertices_cached = MEM_mallocN(sizeof(MVert*) * mi->vertex_count, "mi->vertices_cached readfile");
+ mv = mi->physics_mesh->getVertArray(mi->physics_mesh);
+
+ for (k = 0; k < mi->vertex_count; k++) {
+ MVert* v = mverts + vertstart + k ;
+ MVert* v2 = mv + k;
+ mi->vertices_cached[k] = v;
+ if (mi->vertex_indices) {
+ mi->vertex_indices[k] = vertstart + k;
+ }
+ mi->vertco[k*3] = v->co[0];
+ mi->vertco[k*3+1] = v->co[1];
+ mi->vertco[k*3+2] = v->co[2];
+
+ if (mi->vertno != NULL && fmd->fix_normals) {
+ short sno[3];
+ sno[0] = mi->vertno[k*3];
+ sno[1] = mi->vertno[k*3+1];
+ sno[2] = mi->vertno[k*3+2];
+ copy_v3_v3_short(v->no, sno);
+ copy_v3_v3_short(v2->no, sno);
+ }
+ }
+
+ if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
+ {
+ MeshIslandSequence *prev = NULL;
+
+ if (fmd->current_mi_entry) {
+ prev = fmd->current_mi_entry->prev;
+ }
+
+ if (prev)
+ {
+ MeshIsland *par = NULL;
+ int frame = prev->frame;
+ par = BLI_findlink(&prev->meshIslands, parent_id);
+ frame -= par->start_frame;
+
+ if (par)
+ {
+ do_match_vertex_coords(mi, par, ob, frame);
+ }
+ }
+ }
+
+ return mi->vertex_count;
+}
+
/*refactor this loading routine out, for better readability*/
-static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd)
+static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd, Object* ob)
{
FracMesh* fm;
@@ -4797,78 +4895,124 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd)
Shard *s;
int count = 0;
- link_list(fd, &fmd->frac_mesh->shard_map);
- for (s = fmd->frac_mesh->shard_map.first; s; s = s->next) {
- read_shard(fd, &s);
- }
+ if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
+ {
+ link_list(fd, &fmd->frac_mesh->shard_map);
+ for (s = fmd->frac_mesh->shard_map.first; s; s = s->next) {
+ read_shard(fd, &s);
+ }
- fmd->dm = NULL;
- fmd->visible_mesh = NULL;
+ fmd->dm = NULL;
+ fmd->visible_mesh = NULL;
- link_list(fd, &fmd->islandShards);
- for (s = fmd->islandShards.first; s; s = s->next) {
- read_shard(fd, &s);
- }
+ link_list(fd, &fmd->islandShards);
+ for (s = fmd->islandShards.first; s; s = s->next) {
+ read_shard(fd, &s);
+ }
- link_list(fd, &fmd->meshIslands);
- count = BLI_listbase_count(&fmd->islandShards);
+ link_list(fd, &fmd->meshIslands);
+ count = BLI_listbase_count(&fmd->islandShards);
- if ((fmd->islandShards.first == NULL || count == 0) && fm->shard_count > 0) {
- /* oops, a refresh was missing, so disable this flag here better, otherwise
- * we attempt to load non existing data */
- fmd->shards_to_islands = false;
- }
- else if (fm->shard_count == 0) {
- fmd->shards_to_islands = true;
- }
+ if ((fmd->islandShards.first == NULL || count == 0) &&
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list