[Bf-blender-cvs] [6bcb6b128d6] temp-fracture-modifier-2.8: can now finally save and load fracture data (and motion data)

Martin Felke noreply at git.blender.org
Tue Mar 12 00:40:16 CET 2019


Commit: 6bcb6b128d6df38342a541858b70fb88ae13bf7e
Author: Martin Felke
Date:   Tue Mar 12 00:39:42 2019 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB6bcb6b128d6df38342a541858b70fb88ae13bf7e

can now finally save and load fracture data (and motion data)

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fb6e0585b1c..45a5ee12bb2 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5797,6 +5797,95 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 				fmd->shared->last_cache_end = 250;
 				fmd->shared->flag |= MOD_FRACTURE_REFRESH;
 			}
+			else {
+
+				SharedVertGroup *vg;
+				Shard *s;
+				RigidBodyShardCon *con;
+
+				/*clear runtime stuff */
+				fmd->shared->vertex_normals_tree = NULL;
+				fmd->shared->adjacent_face_pairs = NULL;
+				fmd->shared->vertex_index_map = NULL;
+				fmd->shared->vertex_island_map = NULL;
+				fmd->shared->material_index_map = NULL;
+				fmd->shared->defgrp_index_map = NULL;
+				fmd->shared->dupli_shard_map = NULL;
+				fmd->shared->last_islands = NULL;
+				fmd->shared->last_island_tree = NULL;
+				fmd->shared->last_islands_count = 0;
+				fmd->shared->rng = NULL;
+				fmd->shared->mesh_cached = NULL;  //what was the purpose of this again ?
+
+				link_list(fd, &fmd->shared->automerge_shared_verts);
+				for (vg = fmd->shared->automerge_shared_verts.first; vg; vg = vg->next)
+				{
+					link_list(fd, &vg->verts);
+
+					if (BLI_listbase_is_empty(&fmd->shared->automerge_shared_verts))
+					{
+						fmd->distortion_cached = false;
+					}
+					else {
+						fmd->distortion_cached = true;
+					}
+				}
+
+				link_list(fd, &fmd->shared->shards);
+
+				for (s = fmd->shared->shards.first; s; s = s->next) {
+
+					//read mesh
+					s->mesh = newdataadr(fd, s->mesh);
+					direct_link_mesh(fd, s->mesh);
+
+					//neighbors
+					s->neighbors = newdataadr(fd, s->neighbors);
+
+					//rigid body
+					s->rigidbody = newdataadr(fd, s->rigidbody);
+					if (s->rigidbody)
+					{
+						/*should not happen that a mesh island has no rigidbody... */
+						/*maybe the modifier was inactive while saving ?*/
+						//RigidBodyOb_Shared seems not to be part of the DNA for some reason, so recreate here
+						s->rigidbody->shared = MEM_callocN(sizeof(RigidBodyOb_Shared), "RigidBodyOb_Shared");
+						s->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
+						s->rigidbody->flag |= RBO_FLAG_NEEDS_RESHAPE;
+					}
+
+					/* will be refreshed on the fly if not there*/
+					s->participating_constraints = newdataadr(fd, s->participating_constraints);
+					s->participating_constraint_count = 0;
+
+					//motion data
+					s->locs = newdataadr(fd, s->locs);
+					s->rots = newdataadr(fd, s->rots);
+					s->vels = newdataadr(fd, s->vels);
+					s->aves = newdataadr(fd, s->aves);
+				}
+
+				//participating constraints (pointer to pointer)
+				link_list(fd, &fmd->shared->constraints);
+
+				for (con = fmd->shared->constraints.first; con; con = con->next) {
+					con->mi1 = newdataadr(fd, con->mi1);
+					con->mi2 = newdataadr(fd, con->mi2);
+					con->physics_constraint = NULL;
+					con->flag |= RBC_FLAG_NEEDS_VALIDATE;
+					if (con->mi1->participating_constraints != NULL) {
+						con->mi1->participating_constraints[con->mi1->participating_constraint_count] = con;
+						con->mi1->participating_constraint_count++;
+					}
+
+					if (con->mi2->participating_constraints != NULL) {
+						con->mi2->participating_constraints[con->mi2->participating_constraint_count] = con;
+						con->mi2->participating_constraint_count++;
+					}
+				}
+
+				fmd->shared->anim_bind = newdataadr(fd, fmd->shared->anim_bind);
+			}
 		}
 	}
 }
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index ef2c73a675f..aa6073f5d43 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -112,6 +112,7 @@
 #include "DNA_gpencil_modifier_types.h"
 #include "DNA_shader_fx_types.h"
 #include "DNA_fileglobal_types.h"
+#include "DNA_fracture_types.h"
 #include "DNA_key_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_light_types.h"
@@ -348,6 +349,9 @@ typedef struct {
 	WriteWrap *ww;
 } WriteData;
 
+//prototype for FM shard mesh
+static void write_mesh(WriteData *wd, Mesh *mesh);
+
 static WriteData *writedata_new(WriteWrap *ww)
 {
 	WriteData *wd = MEM_callocN(sizeof(*wd), "writedata");
@@ -1811,6 +1815,59 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 				}
 			}
 		}
+		else if (md->type == eModifierType_Fracture)
+		{
+			FractureModifierData *fmd = (FractureModifierData *)md;
+			SharedVertGroup *vg;
+			RigidBodyShardCon *con;
+			Shard *s;
+
+			writestruct(wd, DATA, FractureModifierData_Shared, 1, fmd->shared);
+
+			for (vg = fmd->shared->automerge_shared_verts.first; vg; vg = vg->next)
+			{
+				SharedVert *sv;
+				writestruct(wd, DATA, SharedVertGroup, 1, vg);
+				for (sv = vg->verts.first; sv; sv = sv->next)
+				{
+					writestruct(wd, DATA, SharedVert, 1, sv);
+				}
+			}
+
+			for (s = fmd->shared->shards.first; s; s = s->next) {
+				int frame_count = s->endframe - s->startframe + 1;
+
+				writestruct(wd, DATA, Shard, 1, s);
+
+				//write mesh
+				write_mesh(wd, s->mesh);
+
+				//write neighbors
+				writedata(wd, DATA, sizeof(int) * s->neighbor_count, s->neighbors);
+
+				//rigid body
+				writestruct(wd, DATA, RigidBodyOb, 1, s->rigidbody);
+				//writestruct(wd, DATA, RigidBodyOb_Shared, 1, s->rigidbody->shared);
+
+				//motion data
+				writedata(wd, DATA, sizeof(float) * 3 * frame_count, s->locs);
+				writedata(wd, DATA, sizeof(float) * 4 * frame_count, s->rots);
+				writedata(wd, DATA, sizeof(float) * 3 * frame_count, s->vels);
+				writedata(wd, DATA, sizeof(float) * 3 * frame_count, s->aves);
+
+				//participating constraints (pointer to pointer)
+				writedata(wd, DATA,
+				          sizeof(RigidBodyShardCon*) * s->participating_constraint_count,
+				          s->participating_constraints);
+			}
+
+			for (con = fmd->shared->constraints.first; con; con = con->next)
+			{
+				writestruct(wd, DATA, RigidBodyShardCon, 1, con);
+			}
+
+			writestruct(wd, DATA, AnimBind, fmd->shared->anim_bind_len, fmd->shared->anim_bind);
+		}
 	}
 }
 
@@ -2171,7 +2228,8 @@ static void write_mesh(WriteData *wd, Mesh *mesh)
 	CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE];
 	CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
 
-	if (mesh->id.us > 0 || wd->use_memfile) {
+	/* FM shard meshs use LIB_TAG_NO_MAIN */
+	if (mesh->id.us > 0 || wd->use_memfile || (mesh->id.tag & LIB_TAG_NO_MAIN)) {
 		/* write LibData */
 		{
 			/* write a copy of the mesh, don't modify in place because it is
@@ -2198,7 +2256,15 @@ static void write_mesh(WriteData *wd, Mesh *mesh)
 			CustomData_file_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
 			CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
 
-			writestruct_at_address(wd, ID_ME, Mesh, 1, old_mesh, mesh);
+			if (mesh->id.tag & LIB_TAG_NO_MAIN)
+			{
+				writestruct_at_address(wd, DATA, Mesh, 1, old_mesh, mesh);
+			}
+			else
+			{
+				writestruct_at_address(wd, ID_ME, Mesh, 1, old_mesh, mesh);
+			}
+
 			write_iddata(wd, &mesh->id);
 
 			/* direct data */



More information about the Bf-blender-cvs mailing list