[Bf-blender-cvs] [c118d3d] alembic_pointcache: Implemented basic OPolyMesh Alembic writing.

Lukas Tönne noreply at git.blender.org
Fri Oct 17 11:14:54 CEST 2014


Commit: c118d3d739a98b8bcab81beccb0d962e40be137a
Author: Lukas Tönne
Date:   Fri Oct 17 11:10:51 2014 +0200
Branches: alembic_pointcache
https://developer.blender.org/rBc118d3d739a98b8bcab81beccb0d962e40be137a

Implemented basic OPolyMesh Alembic writing.

Only includes vertex positions and poly loops for now. The standard
mesh schema in Alembic includes also UV layers and some other standard
data, but all the necessary Blender custom data layers can be stored in
these files as well.

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

M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/intern/mesh.cpp
M	source/blender/pointcache/intern/mesh.h

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

diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 94a09fa..9412326 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -32,6 +32,7 @@ struct PointCache;
 struct PointerRNA;
 
 struct ClothModifierData;
+struct DerivedMesh;
 struct DynamicPaintSurface;
 struct MeshCacheModifierData;
 struct Object;
diff --git a/source/blender/pointcache/intern/mesh.cpp b/source/blender/pointcache/intern/mesh.cpp
index f27e184..3ed43cf 100644
--- a/source/blender/pointcache/intern/mesh.cpp
+++ b/source/blender/pointcache/intern/mesh.cpp
@@ -40,7 +40,7 @@ MeshCacheWriter::MeshCacheWriter(Scene *scene, Object *ob, MeshCacheModifierData
 	uint32_t fs = add_frame_sampling();
 	
 	OObject root = m_archive.getTop();
-//	m_points = OPoints(root, m_psys->name, fs);
+	m_mesh = OPolyMesh(root, m_mcmd->modifier.name, fs);
 }
 
 MeshCacheWriter::~MeshCacheWriter()
@@ -49,6 +49,45 @@ MeshCacheWriter::~MeshCacheWriter()
 
 void MeshCacheWriter::write_sample()
 {
+	DerivedMesh *source_dm = m_ob->derivedFinal;
+	if (!source_dm)
+		return;
+	
+	OPolyMeshSchema &schema = m_mesh.getSchema();
+	
+	MVert *mv, *mverts = source_dm->getVertArray(source_dm);
+	MLoop *ml, *mloops = source_dm->getLoopArray(source_dm);
+	MPoly *mp, *mpolys = source_dm->getPolyArray(source_dm);
+	int totvert = source_dm->getNumVerts(source_dm);
+	int totloop = source_dm->getNumLoops(source_dm);
+	int totpoly = source_dm->getNumPolys(source_dm);
+	int i;
+	
+	std::vector<V3f> positions;
+	positions.reserve(totvert);
+	std::vector<int> indices;
+	indices.reserve(totloop);
+	std::vector<int> counts;
+	counts.reserve(totpoly);
+	
+	for (i = 0, mv = mverts; i < totvert; ++i, ++mv) {
+		float *co = mv->co;
+		positions.push_back(V3f(co[0], co[1], co[2]));
+	}
+	for (i = 0, ml = mloops; i < totloop; ++i, ++ml) {
+		indices.push_back(ml->v);
+	}
+	for (i = 0, mp = mpolys; i < totpoly; ++i, ++mp) {
+		counts.push_back(mp->totloop);
+	}
+	
+	OPolyMeshSchema::Sample sample = OPolyMeshSchema::Sample(
+	            P3fArraySample(positions),
+	            Int32ArraySample(indices),
+	            Int32ArraySample(counts)
+	            );
+
+	schema.set(sample);
 }
 
 
@@ -59,7 +98,7 @@ MeshCacheReader::MeshCacheReader(Scene *scene, Object *ob, MeshCacheModifierData
 {
 	if (m_archive.valid()) {
 		IObject root = m_archive.getTop();
-//		m_points = IPoints(root, m_psys->name);
+		m_mesh = IPolyMesh(root, m_mcmd->modifier.name);
 	}
 }
 
@@ -69,7 +108,36 @@ MeshCacheReader::~MeshCacheReader()
 
 PTCReadSampleResult MeshCacheReader::read_sample(float frame)
 {
+#if 0
+	if (!m_mesh.valid())
+		return PTC_READ_SAMPLE_INVALID;
+	
+	IPolyMeshSchema &schema = m_mesh.getSchema();
+	TimeSamplingPtr ts = schema.getTimeSampling();
+	
+	ISampleSelector ss = get_frame_sample_selector(frame);
+	chrono_t time = ss.getRequestedTime();
+	
+	std::pair<index_t, chrono_t> sres = ts->getFloorIndex(time, schema.getNumSamples());
+	chrono_t stime = sres.second;
+	float sframe = time_to_frame(stime);
+	
+	IPolyMeshSchema::Sample sample;
+	schema.get(sample, ss);
+	
+	const V3f *positions = sample.getPositions()->get();
+	int i, totvert = m_dm->getNumVerts(m_dm);
+	MVert *mverts = m_dm->getVertArray(m_dm);
+//	for (i = 0, pa = m_psys->particles; i < sample.getPositions()->size(); ++i, ++pa) {
+//		pa->state.co[0] = positions[i].x;
+//		pa->state.co[1] = positions[i].y;
+//		pa->state.co[2] = positions[i].z;
+//	}
+	
+	return PTC_READ_SAMPLE_EXACT;
+#else
 	return PTC_READ_SAMPLE_INVALID;
+#endif
 }
 
 } /* namespace PTC */
diff --git a/source/blender/pointcache/intern/mesh.h b/source/blender/pointcache/intern/mesh.h
index 775ca59..3efa5fb 100644
--- a/source/blender/pointcache/intern/mesh.h
+++ b/source/blender/pointcache/intern/mesh.h
@@ -19,8 +19,8 @@
 #ifndef PTC_MESH_H
 #define PTC_MESH_H
 
-//#include <Alembic/AbcGeom/IPoints.h>
-//#include <Alembic/AbcGeom/OPoints.h>
+#include <Alembic/AbcGeom/IPolyMesh.h>
+#include <Alembic/AbcGeom/OPolyMesh.h>
 
 #include "reader.h"
 #include "schema.h"
@@ -28,6 +28,7 @@
 
 struct Object;
 struct MeshCacheModifierData;
+struct DerivedMesh;
 
 namespace PTC {
 
@@ -42,7 +43,7 @@ private:
 	Object *m_ob;
 	MeshCacheModifierData *m_mcmd;
 	
-//	AbcGeom::OPoints m_points;
+	AbcGeom::OPolyMesh m_mesh;
 };
 
 class MeshCacheReader : public Reader {
@@ -56,7 +57,7 @@ private:
 	Object *m_ob;
 	MeshCacheModifierData *m_mcmd;
 	
-//	AbcGeom::IPoints m_points;
+	AbcGeom::IPolyMesh m_mesh;
 };
 
 } /* namespace PTC */




More information about the Bf-blender-cvs mailing list