[Bf-blender-cvs] [9644035] alembic_basic_io: Initial support for streaming meshes with a varying number of vertices.

Kévin Dietrich noreply at git.blender.org
Tue May 31 17:54:08 CEST 2016


Commit: 9644035713578ddf0a1357c802397bd44c3e393c
Author: Kévin Dietrich
Date:   Tue May 31 02:28:12 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB9644035713578ddf0a1357c802397bd44c3e393c

Initial support for streaming meshes with a varying number of
vertices.

This is achieved by making use of a new modifier since the mesh cache
modifier cannot modifiy the number of vertices in a mesh. This modifier
also brings support to read file sequences.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/abc_hair.cc
M	source/blender/alembic/intern/abc_mesh.cc
M	source/blender/alembic/intern/abc_mesh.h
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/MOD_modifiertypes.h
A	source/blender/modifiers/intern/MOD_meshsequencecache.c
M	source/blender/modifiers/intern/MOD_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 7e1965d..870658a 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -222,6 +222,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         row = split.row()
         row.prop(md, "flip_axis")
 
+    def MESH_SEQUENCE_CACHE(self, layout, ob, md):
+        layout.prop(md, "filepath")
+        layout.prop(md, "abc_object_path")
+
     def CAST(self, layout, ob, md):
         split = layout.split(percentage=0.25)
 
diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h
index daef9e2..31065c0 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -28,6 +28,7 @@ extern "C" {
 #endif
 
 struct bContext;
+struct DerivedMesh;
 struct Object;
 struct Scene;
 
@@ -62,6 +63,8 @@ int ABC_check_subobject_valid(const char *filepath, const char *object_path);
 
 void ABC_get_transform(struct Object *ob, const char *filepath, const char *object_path, float r_mat[4][4], float time);
 
+struct DerivedMesh *ABC_read_mesh(const char *filepath, const char *object_path, const float path);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc
index dd62c1f..565a6aa 100644
--- a/source/blender/alembic/intern/abc_hair.cc
+++ b/source/blender/alembic/intern/abc_hair.cc
@@ -35,11 +35,13 @@ extern "C" {
 
 #include "BLI_listbase.h"
 #include "BLI_math_geom.h"
+#include "BLI_string.h"
 
 #include "BKE_curve.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
+#include "BKE_modifier.h"
 
 #include "ED_curve.h"
 }
@@ -307,9 +309,10 @@ bool AbcHairReader::valid() const
 	return m_curves_schema.valid();
 }
 
+
 void AbcHairReader::readObjectData(Main *bmain, Scene *scene, float time)
 {
-	Curve *cu = BKE_curve_add(bmain, "abc_hair", OB_CURVE);
+	Curve *cu = BKE_curve_add(bmain, m_data_name.c_str(), OB_CURVE);
 	cu->flag |= CU_DEFORM_FILL | CU_PATH | CU_3D;
 
 	const ISampleSelector sample_sel(time);
@@ -359,4 +362,18 @@ void AbcHairReader::readObjectData(Main *bmain, Scene *scene, float time)
 
 	cu->actnu = hvertices->size() - 1;
 	cu->actvert = CU_ACT_NONE;
+
+	if (true) {
+		ModifierData *md = modifier_new(eModifierType_MeshSequenceCache);
+		BLI_addtail(&m_object->modifiers, md);
+
+		MeshSeqCacheModifierData *mcmd = reinterpret_cast<MeshSeqCacheModifierData *>(md);
+//		mcmd->type = MOD_MESHCACHE_TYPE_ABC;
+//		mcmd->time_mode = MOD_MESHCACHE_TIME_SECONDS;
+//		mcmd->forward_axis = OB_POSZ;
+//		mcmd->up_axis = OB_NEGY;
+
+		BLI_strncpy(mcmd->filepath, m_iobject.getArchive().getName().c_str(), 1024);
+		BLI_strncpy(mcmd->abc_object_path, m_iobject.getFullName().c_str(), 1024);
+	}
 }
diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index b4b7b85..0ee40a5 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -1131,7 +1131,7 @@ void AbcMeshReader::readObjectData(Main *bmain, Scene *scene, float time)
 		const ISubDSchema::Sample sample = m_subd_schema.getValue(sample_sel);
 
 		readVertexDataSample(mesh, sample.getPositions());
-		readPolyDataSample(mesh, sample.getFaceIndices(), sample.getFaceCounts(), poly_start);
+		readPolyDataSample(mesh, sample.getFaceIndices(), sample.getFaceCounts());
 	}
 	else {
 		is_constant = m_schema.isConstant();
@@ -1139,7 +1139,7 @@ void AbcMeshReader::readObjectData(Main *bmain, Scene *scene, float time)
 		const IPolyMeshSchema::Sample sample = m_schema.getValue(sample_sel);
 
 		readVertexDataSample(mesh, sample.getPositions());
-		readPolyDataSample(mesh, sample.getFaceIndices(), sample.getFaceCounts(), poly_start);
+		readPolyDataSample(mesh, sample.getFaceIndices(), sample.getFaceCounts());
 	}
 
 	BKE_mesh_validate(mesh, false, false);
@@ -1156,48 +1156,33 @@ void AbcMeshReader::readObjectData(Main *bmain, Scene *scene, float time)
 
 	/* Add a default mesh cache modifier */
 
-	if (!is_constant) {
-		ModifierData *md = modifier_new(eModifierType_MeshCache);
+	if (true || !is_constant) {
+		ModifierData *md = modifier_new(eModifierType_MeshSequenceCache);
 		BLI_addtail(&m_object->modifiers, md);
 
-		MeshCacheModifierData *mcmd = reinterpret_cast<MeshCacheModifierData *>(md);
-		mcmd->type = MOD_MESHCACHE_TYPE_ABC;
-		mcmd->time_mode = MOD_MESHCACHE_TIME_SECONDS;
-		mcmd->forward_axis = OB_POSZ;
-		mcmd->up_axis = OB_NEGY;
+		MeshSeqCacheModifierData *mcmd = reinterpret_cast<MeshSeqCacheModifierData *>(md);
+//		mcmd->type = MOD_MESHCACHE_TYPE_ABC;
+//		mcmd->time_mode = MOD_MESHCACHE_TIME_SECONDS;
+//		mcmd->forward_axis = OB_POSZ;
+//		mcmd->up_axis = OB_NEGY;
 
 		BLI_strncpy(mcmd->filepath, m_iobject.getArchive().getName().c_str(), 1024);
-		BLI_strncpy(mcmd->sub_object, m_iobject.getFullName().c_str(), 1024);
+		BLI_strncpy(mcmd->abc_object_path, m_iobject.getFullName().c_str(), 1024);
 	}
 }
 
 void AbcMeshReader::readVertexDataSample(Mesh *mesh, const P3fArraySamplePtr &positions)
 {
-	const size_t vertex_count = positions->size();
-	const size_t vertex_start = mesh->totvert;
-
-	utils::mesh_add_verts(mesh, vertex_count);
-
-	for (int i = 0, j = vertex_start; i < vertex_count; ++i, ++j) {
-		MVert &mvert = mesh->mvert[j];
-		Imath::V3f pos_in = (*positions)[i];
-
-		/* Convert Y-up to Z-up. */
-		mvert.co[0] = pos_in[0];
-		mvert.co[1] = -pos_in[2];
-		mvert.co[2] = pos_in[1];
-		mvert.bweight = 0;
-	}
+	utils::mesh_add_verts(mesh, positions->size());
+	read_mverts(mesh->mvert, positions);
 }
 
 void AbcMeshReader::readPolyDataSample(Mesh *mesh,
                                        const Int32ArraySamplePtr &face_indices,
-                                       const Int32ArraySamplePtr &face_counts,
-                                       const size_t poly_start)
+                                       const Int32ArraySamplePtr &face_counts)
 {
 	const size_t num_poly = face_counts->size();
 	const size_t num_loops = face_indices->size();
-	const size_t loop_pos = mesh->totloop;
 
 	utils::mesh_add_mpolygons(mesh, num_poly);
 	utils::mesh_add_mloops(mesh, num_loops);
@@ -1211,29 +1196,8 @@ void AbcMeshReader::readPolyDataSample(Mesh *mesh,
 		uvsamp_vals = uvsamp.getVals();
 	}
 
-	int j = poly_start;
-	int loopcount = loop_pos;
-	for (int i = 0; i < num_poly; ++i, ++j) {
-		int face_size = (*face_counts)[i];
-		MPoly &poly = mesh->mpoly[j];
-
-		poly.loopstart = loopcount;
-		poly.totloop = face_size;
-
-		/* TODO: reverse */
-		int rev_loop = loopcount;
-		for (int f = face_size; f-- ;) {
-			MLoop &loop 	= mesh->mloop[rev_loop + f];
-			MLoopUV &loopuv = mesh->mloopuv[rev_loop + f];
-
-			if (uvsamp_vals) {
-				loopuv.uv[0] = (*uvsamp_vals)[loopcount][0];
-				loopuv.uv[1] = (*uvsamp_vals)[loopcount][1];
-			}
-
-			loop.v = (*face_indices)[loopcount++];
-		}
-	}
+	read_mpolys(mesh->mpoly, mesh->mloop, mesh->mloopuv,
+	            face_indices, face_counts, uvsamp_vals);
 }
 
 void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start,
@@ -1292,6 +1256,51 @@ void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_star
 	utils::assign_materials(bmain, m_object, mat_map);
 }
 
+/* ********************************************************** */
+
+void read_mverts(MVert *mverts, const Alembic::AbcGeom::P3fArraySamplePtr &positions)
+{
+	for (int i = 0; i < positions->size(); ++i) {
+		MVert &mvert = mverts[i];
+		Imath::V3f pos_in = (*positions)[i];
+
+		/* Convert Y-up to Z-up. */
+		mvert.co[0] = pos_in[0];
+		mvert.co[1] = -pos_in[2];
+		mvert.co[2] = pos_in[1];
+		mvert.bweight = 0;
+	}
+}
+
+void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs,
+                 const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
+                 const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
+                 const Alembic::AbcGeom::V2fArraySamplePtr &uvs)
+{
+	int loopcount = 0;
+	for (int i = 0; i < face_counts->size(); ++i) {
+		int face_size = (*face_counts)[i];
+		MPoly &poly = mpolys[i];
+
+		poly.loopstart = loopcount;
+		poly.totloop = face_size;
+
+		/* TODO: reverse */
+		int rev_loop = loopcount;
+		for (int f = face_size; f-- ;) {
+			MLoop &loop 	= mloops[rev_loop + f];
+
+			if (mloopuvs && uvs) {
+				MLoopUV &loopuv = mloopuvs[rev_loop + f];
+				loopuv.uv[0] = (*uvs)[loopcount][0];
+				loopuv.uv[1] = (*uvs)[loopcount][1];
+			}
+
+			loop.v = (*face_indices)[loopcount++];
+		}
+	}
+}
+
 /* ***************************** AbcEmptyReader ***************************** */
 
 AbcEmptyReader::AbcEmptyReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
diff --git a/source/blender/alembic/intern/abc_mesh.h b/source/blender/alembic/intern/abc_mesh.h
index ef72ee1..0d51fe5 100644
--- a/source/blender/alembic/intern/abc_mesh.h
+++ b/source/blender/alembic/intern/abc_mesh.h
@@ -121,13 +121,27 @@ private:
 
 	void readPolyDataSample(Mesh *mesh,
 	                        const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
-                            const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
-                            const size_t poly_start);
+                            const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts);
 
 	void readVertexDataSample(Mesh *mesh,
 	                          const Alembic::AbcGeom::P3fArraySamplePtr &positions);
 };
 
+/* *********************************** */
+
+struct MLoop;
+struct MLoopUV;
+struct MPoly;
+struct MVert;
+
+void read_mverts(MVert *mverts, const Alembic::AbcGeom::P3fArraySamplePtr &positions);
+void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs,
+                 const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
+                 const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
+                 const Alembic::AbcGeom::V2fArraySamplePtr &uvs = Alembic::AbcGeom::V2fArraySamplePtr());
+
+/* *********************************** */
+
 class AbcEmptyReader : public AbcObjectReader {
 	Alembic::AbcGeom::IXformSchema m_schem

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list