[Bf-blender-cvs] [38269a9] alembic: Yet another writer class for storing child strand data generated by particles.

Lukas Tönne noreply at git.blender.org
Wed Apr 8 19:22:18 CEST 2015


Commit: 38269a93c2a8b38de0d86e1a5b7f20b31408928b
Author: Lukas Tönne
Date:   Wed Apr 8 13:45:13 2015 +0200
Branches: alembic
https://developer.blender.org/rB38269a93c2a8b38de0d86e1a5b7f20b31408928b

Yet another writer class for storing child strand data generated by
particles.

This is currently the same as the ParticlePathcache writer class, but
will be modified somewhat later to store additional information such as
parent weights. The purpose of this cache object is not to populate the
particle child caches, but to store renderable data associated to dupli
cache strands.

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

M	source/blender/pointcache/alembic/abc_particles.cpp
M	source/blender/pointcache/alembic/abc_particles.h

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

diff --git a/source/blender/pointcache/alembic/abc_particles.cpp b/source/blender/pointcache/alembic/abc_particles.cpp
index 14d0690..2d4b4db 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -129,6 +129,119 @@ PTCReadSampleResult AbcParticlesReader::read_sample(float frame)
 }
 
 
+struct HairChildrenSample {
+	std::vector<int32_t> numkeys;
+	
+	std::vector<V3f> positions;
+	std::vector<V3f> velocities;
+	std::vector<Quatf> rotations;
+	std::vector<C3f> colors;
+	std::vector<float32_t> times;
+};
+
+AbcHairChildrenWriter::AbcHairChildrenWriter(const std::string &name, Object *ob, ParticleSystem *psys) :
+    ParticlesWriter(ob, psys, name)
+{
+}
+
+AbcHairChildrenWriter::~AbcHairChildrenWriter()
+{
+}
+
+void AbcHairChildrenWriter::init_abc(OObject parent)
+{
+	if (m_curves)
+		return;
+	
+	/* XXX non-escaped string construction here ... */
+	m_curves = OCurves(parent, m_name, abc_archive()->frame_sampling_index());
+	
+	OCurvesSchema &schema = m_curves.getSchema();
+	OCompoundProperty geom_props = schema.getArbGeomParams();
+	
+	m_param_velocities = OV3fGeomParam(geom_props, "velocities", false, kVertexScope, 1, 0);
+	m_param_rotations = OQuatfGeomParam(geom_props, "rotations", false, kVertexScope, 1, 0);
+	m_param_colors = OC3fGeomParam(geom_props, "colors", false, kVertexScope, 1, 0);
+	m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, 0);
+}
+
+static int hair_children_count_totkeys(ParticleCacheKey **pathcache, int totpart)
+{
+	int p;
+	int totkeys = 0;
+	
+	for (p = 0; p < totpart; ++p) {
+		ParticleCacheKey *keys = pathcache[p];
+		totkeys += keys->segments + 1;
+	}
+	
+	return totkeys;
+}
+
+static void hair_children_create_sample(ParticleCacheKey **pathcache, int totpart, int totkeys, HairChildrenSample &sample, bool do_numkeys)
+{
+	int p, k;
+	
+	if (do_numkeys)
+		sample.numkeys.reserve(totpart);
+	sample.positions.reserve(totkeys);
+	sample.velocities.reserve(totkeys);
+	sample.rotations.reserve(totkeys);
+	sample.colors.reserve(totkeys);
+	sample.times.reserve(totkeys);
+	
+	for (p = 0; p < totpart; ++p) {
+		ParticleCacheKey *keys = pathcache[p];
+		int numkeys = keys->segments + 1;
+		
+		if (do_numkeys)
+			sample.numkeys.push_back(numkeys);
+		
+		for (k = 0; k < numkeys; ++k) {
+			ParticleCacheKey *key = &keys[k];
+			
+			sample.positions.push_back(V3f(key->co[0], key->co[1], key->co[2]));
+			sample.velocities.push_back(V3f(key->vel[0], key->vel[1], key->vel[2]));
+			sample.rotations.push_back(Quatf(key->rot[0], key->rot[1], key->rot[2], key->rot[3]));
+			sample.colors.push_back(C3f(key->col[0], key->col[1], key->col[2]));
+			sample.times.push_back(key->time);
+		}
+	}
+}
+
+void AbcHairChildrenWriter::write_sample()
+{
+	if (!m_curves)
+		return;
+	if (!m_psys->childcache)
+		return;
+	
+	int totkeys = hair_children_count_totkeys(m_psys->childcache, m_psys->totchild);
+	if (totkeys == 0)
+		return;
+	
+	OCurvesSchema &schema = m_curves.getSchema();
+	
+	HairChildrenSample child_sample;
+	OCurvesSchema::Sample sample;
+	if (schema.getNumSamples() == 0) {
+		/* write curve sizes only first time, assuming they are constant! */
+		hair_children_create_sample(m_psys->childcache, m_psys->totchild, totkeys, child_sample, true);
+		sample = OCurvesSchema::Sample(child_sample.positions, child_sample.numkeys);
+	}
+	else {
+		hair_children_create_sample(m_psys->childcache, m_psys->totchild, totkeys, child_sample, false);
+		sample = OCurvesSchema::Sample(child_sample.positions);
+	}
+	schema.set(sample);
+	
+	m_param_velocities.set(OV3fGeomParam::Sample(V3fArraySample(child_sample.velocities), kVertexScope));
+	m_param_rotations.set(OQuatfGeomParam::Sample(QuatfArraySample(child_sample.rotations), kVertexScope));
+	m_param_colors.set(OC3fGeomParam::Sample(C3fArraySample(child_sample.colors), kVertexScope));
+	m_param_times.set(OFloatGeomParam::Sample(FloatArraySample(child_sample.times), kVertexScope));
+}
+
+
 struct ParticleHairSample {
 	std::vector<int32_t> numverts;
 	std::vector<M33f> root_matrix;
@@ -139,7 +252,8 @@ struct ParticleHairSample {
 };
 
 AbcHairWriter::AbcHairWriter(const std::string &name, Object *ob, ParticleSystem *psys) :
-    ParticlesWriter(ob, psys, name)
+    ParticlesWriter(ob, psys, name),
+    m_child_writer("children", ob, psys)
 {
 	m_psmd = psys_get_modifier(ob, psys);
 }
@@ -161,6 +275,9 @@ void AbcHairWriter::init_abc(OObject parent)
 	
 	m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, 0);
 	m_param_weights = OFloatGeomParam(geom_props, "weights", false, kVertexScope, 1, 0);
+	
+	m_child_writer.init(abc_archive());
+	m_child_writer.init_abc(m_curves);
 }
 
 static int hair_count_totverts(ParticleSystem *psys)
@@ -249,6 +366,8 @@ void AbcHairWriter::write_sample()
 	
 	m_param_times.set(OFloatGeomParam::Sample(FloatArraySample(hair_sample.times), kVertexScope));
 	m_param_weights.set(OFloatGeomParam::Sample(FloatArraySample(hair_sample.weights), kVertexScope));
+	
+	m_child_writer.write_sample();
 }
 
 
diff --git a/source/blender/pointcache/alembic/abc_particles.h b/source/blender/pointcache/alembic/abc_particles.h
index b51895f..f250e03 100644
--- a/source/blender/pointcache/alembic/abc_particles.h
+++ b/source/blender/pointcache/alembic/abc_particles.h
@@ -71,6 +71,25 @@ private:
 };
 
 
+class AbcHairChildrenWriter : public ParticlesWriter, public AbcWriter {
+public:
+	AbcHairChildrenWriter(const std::string &name, Object *ob, ParticleSystem *psys);
+	~AbcHairChildrenWriter();
+	
+	void init_abc(Abc::OObject parent);
+	
+	void write_sample();
+	
+private:
+	AbcGeom::OCurves m_curves;
+	
+	AbcGeom::OV3fGeomParam m_param_velocities;
+	AbcGeom::OQuatfGeomParam m_param_rotations;
+	AbcGeom::OC3fGeomParam m_param_colors;
+	AbcGeom::OFloatGeomParam m_param_times;
+};
+
+
 class AbcHairWriter : public ParticlesWriter, public AbcWriter {
 public:
 	AbcHairWriter(const std::string &name, Object *ob, ParticleSystem *psys);
@@ -87,6 +106,8 @@ private:
 	AbcGeom::OM33fGeomParam m_param_root_matrix;
 	AbcGeom::OFloatGeomParam m_param_times;
 	AbcGeom::OFloatGeomParam m_param_weights;
+	
+	AbcHairChildrenWriter m_child_writer;
 };
 
 
@@ -113,6 +134,7 @@ private:
 	AbcGeom::OV3fGeomParam m_param_motion_vel;
 };
 
+
 class AbcStrandsReader : public AbcReader {
 public:
 	AbcStrandsReader(Strands *strands);




More information about the Bf-blender-cvs mailing list