[Bf-blender-cvs] [871a29e] alembic: Writer for child strand data.

Lukas Tönne noreply at git.blender.org
Thu Apr 9 14:46:49 CEST 2015


Commit: 871a29eeac6cda03c3c012350fe0c39cdd63ffb9
Author: Lukas Tönne
Date:   Thu Apr 9 14:45:16 2015 +0200
Branches: alembic
https://developer.blender.org/rB871a29eeac6cda03c3c012350fe0c39cdd63ffb9

Writer for child strand data.

Cache chains now support child strands too, instead of dropping
child data when writing out from strand data.

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

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 b9b89f6..167635a 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -129,16 +129,25 @@ PTCReadSampleResult AbcParticlesReader::read_sample(float frame)
 }
 
 
-struct HairChildrenSample {
-	std::vector<int32_t> numkeys;
+struct StrandsChildrenSample {
+	std::vector<int32_t> numverts;
 	
 	std::vector<V3f> positions;
-	std::vector<V3f> velocities;
-	std::vector<Quatf> rotations;
-	std::vector<C3f> colors;
 	std::vector<float32_t> times;
 };
 
+struct StrandsSample {
+	std::vector<int32_t> numverts;
+	std::vector<M33f> root_matrix;
+	
+	std::vector<V3f> positions;
+	std::vector<float32_t> times;
+	std::vector<float32_t> weights;
+	
+	std::vector<V3f> motion_co;
+	std::vector<V3f> motion_vel;
+};
+
 AbcHairChildrenWriter::AbcHairChildrenWriter(const std::string &name, Object *ob, ParticleSystem *psys) :
     ParticlesWriter(ob, psys, name)
 {
@@ -159,9 +168,6 @@ void AbcHairChildrenWriter::init_abc(OObject parent)
 	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);
 }
 
@@ -178,7 +184,7 @@ static int hair_children_count_totkeys(ParticleCacheKey **pathcache, int totpart
 	return totkeys;
 }
 
-static void hair_children_create_sample(ParticleCacheKey **pathcache, int totpart, int totkeys, float imat[4][4], HairChildrenSample &sample, bool do_numkeys)
+static void hair_children_create_sample(ParticleCacheKey **pathcache, int totpart, int totkeys, float imat[4][4], StrandsChildrenSample &sample, bool do_numkeys)
 {
 	float iqt[4];
 	mat4_to_quat(iqt, imat);
@@ -186,11 +192,8 @@ static void hair_children_create_sample(ParticleCacheKey **pathcache, int totpar
 	int p, k;
 	
 	if (do_numkeys)
-		sample.numkeys.reserve(totpart);
+		sample.numverts.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) {
@@ -198,7 +201,7 @@ static void hair_children_create_sample(ParticleCacheKey **pathcache, int totpar
 		int numkeys = keys->segments + 1;
 		
 		if (do_numkeys)
-			sample.numkeys.push_back(numkeys);
+			sample.numverts.push_back(numkeys);
 		
 		for (k = 0; k < numkeys; ++k) {
 			ParticleCacheKey *key = &keys[k];
@@ -210,9 +213,6 @@ static void hair_children_create_sample(ParticleCacheKey **pathcache, int totpar
 			mul_qt_qtqt(rot, iqt, key->rot);
 			
 			sample.positions.push_back(V3f(co[0], co[1], co[2]));
-			sample.velocities.push_back(V3f(vel[0], vel[1], vel[2]));
-			sample.rotations.push_back(Quatf(rot[0], rot[1], rot[2], rot[3]));
-			sample.colors.push_back(C3f(key->col[0], key->col[1], key->col[2]));
 			sample.times.push_back(key->time);
 		}
 	}
@@ -234,12 +234,12 @@ void AbcHairChildrenWriter::write_sample()
 	
 	OCurvesSchema &schema = m_curves.getSchema();
 	
-	HairChildrenSample child_sample;
+	StrandsChildrenSample 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, imat, child_sample, true);
-		sample = OCurvesSchema::Sample(child_sample.positions, child_sample.numkeys);
+		sample = OCurvesSchema::Sample(child_sample.positions, child_sample.numverts);
 	}
 	else {
 		hair_children_create_sample(m_psys->childcache, m_psys->totchild, totkeys, imat, child_sample, false);
@@ -247,22 +247,10 @@ void AbcHairChildrenWriter::write_sample()
 	}
 	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;
-	
-	std::vector<V3f> positions;
-	std::vector<float32_t> times;
-	std::vector<float32_t> weights;
-};
-
 AbcHairWriter::AbcHairWriter(const std::string &name, Object *ob, ParticleSystem *psys) :
     ParticlesWriter(ob, psys, name),
     m_child_writer("children", ob, psys)
@@ -310,7 +298,7 @@ static int hair_count_totverts(ParticleSystem *psys)
 	return totverts;
 }
 
-static void hair_create_sample(Object *ob, DerivedMesh *dm, ParticleSystem *psys, ParticleHairSample &sample, bool do_numverts)
+static void hair_create_sample(Object *ob, DerivedMesh *dm, ParticleSystem *psys, StrandsSample &sample, bool do_numverts)
 {
 	int totpart = psys->totpart;
 	int totverts = hair_count_totverts(psys);
@@ -366,7 +354,7 @@ void AbcHairWriter::write_sample()
 	
 	OCurvesSchema &schema = m_curves.getSchema();
 	
-	ParticleHairSample hair_sample;
+	StrandsSample hair_sample;
 	OCurvesSchema::Sample sample;
 	if (schema.getNumSamples() == 0) {
 		/* write curve sizes only first time, assuming they are constant! */
@@ -388,21 +376,91 @@ void AbcHairWriter::write_sample()
 }
 
 
-struct StrandsSample {
-	std::vector<int32_t> numverts;
-	std::vector<M33f> root_matrix;
+AbcStrandsChildrenWriter::AbcStrandsChildrenWriter(const std::string &name, const std::string &abc_name, DupliObjectData *dobdata) :
+    m_name(name),
+    m_abc_name(abc_name),
+    m_dobdata(dobdata)
+{
+}
+
+StrandsChildren *AbcStrandsChildrenWriter::get_strands() const
+{
+	return BKE_dupli_object_data_find_strands_children(m_dobdata, m_name.c_str());
+}
+
+void AbcStrandsChildrenWriter::init_abc(OObject parent)
+{
+	if (m_curves)
+		return;
+	m_curves = OCurves(parent, m_abc_name, abc_archive()->frame_sampling_index());
 	
-	std::vector<V3f> positions;
-	std::vector<float32_t> times;
-	std::vector<float32_t> weights;
+	OCurvesSchema &schema = m_curves.getSchema();
+	OCompoundProperty geom_props = schema.getArbGeomParams();
 	
-	std::vector<V3f> motion_co;
-	std::vector<V3f> motion_vel;
-};
+	m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, abc_archive()->frame_sampling());
+}
+
+static void strands_children_create_sample(StrandsChildren *strands, StrandsChildrenSample &sample, bool do_numverts)
+{
+	int totcurves = strands->totcurves;
+	int totverts = strands->totverts;
+	
+	if (totverts == 0)
+		return;
+	
+	if (do_numverts)
+		sample.numverts.reserve(totcurves);
+	
+	sample.positions.reserve(totverts);
+	sample.times.reserve(totverts);
+	
+	StrandChildIterator it_strand;
+	for (BKE_strand_child_iter_init(&it_strand, strands); BKE_strand_child_iter_valid(&it_strand); BKE_strand_child_iter_next(&it_strand)) {
+		int numverts = it_strand.curve->numverts;
+		
+		if (do_numverts)
+			sample.numverts.push_back(numverts);
+		
+		StrandChildVertexIterator it_vert;
+		for (BKE_strand_child_vertex_iter_init(&it_vert, &it_strand); BKE_strand_child_vertex_iter_valid(&it_vert); BKE_strand_child_vertex_iter_next(&it_vert)) {
+			const float *co = it_vert.vertex->co;
+			sample.positions.push_back(V3f(co[0], co[1], co[2]));
+			sample.times.push_back(it_vert.vertex->time);
+		}
+	}
+}
+
+void AbcStrandsChildrenWriter::write_sample()
+{
+	if (!m_curves)
+		return;
+	StrandsChildren *strands = get_strands();
+	if (!strands)
+		return;
+	
+	OCurvesSchema &schema = m_curves.getSchema();
+	
+	StrandsChildrenSample strands_sample;
+	OCurvesSchema::Sample sample;
+	if (schema.getNumSamples() == 0) {
+		/* write curve sizes only first time, assuming they are constant! */
+		strands_children_create_sample(strands, strands_sample, true);
+		sample = OCurvesSchema::Sample(strands_sample.positions, strands_sample.numverts);
+	}
+	else {
+		strands_children_create_sample(strands, strands_sample, false);
+		sample = OCurvesSchema::Sample(strands_sample.positions);
+	}
+	schema.set(sample);
+	
+	m_param_times.set(OFloatGeomParam::Sample(FloatArraySample(strands_sample.times), kVertexScope));
+}
+
 
 AbcStrandsWriter::AbcStrandsWriter(const std::string &name, DupliObjectData *dobdata) :
     m_name(name),
-    m_dobdata(dobdata)
+    m_dobdata(dobdata),
+    m_child_writer(name, "children", dobdata)
 {
 }
 
@@ -411,6 +469,12 @@ Strands *AbcStrandsWriter::get_strands() const
 	return BKE_dupli_object_data_find_strands(m_dobdata, m_name.c_str());
 }
 
+void AbcStrandsWriter::init(WriterArchive *archive)
+{
+	AbcWriter::init(archive);
+	m_child_writer.init(archive);
+}
+
 void AbcStrandsWriter::init_abc(OObject parent)
 {
 	if (m_curves)
@@ -428,6 +492,8 @@ void AbcStrandsWriter::init_abc(OObject parent)
 	m_param_motion_state = OCompoundProperty(geom_props, "motion_state", abc_archive()->frame_sampling());
 	m_param_motion_co = OP3fGeomParam(m_param_motion_state, "position", false, kVertexScope, 1, abc_archive()->frame_sampling());
 	m_param_motion_vel = OV3fGeomParam(m_param_motion_state, "velocity", false, kVertexScope, 1, abc_archive()->frame_sampling());
+	
+	m_child_writer.init_abc(m_curves);
 }
 
 static void strands_create_sample(Strands *strands, StrandsSample &sample, bool do_numverts)
@@ -509,6 +575,8 @@ void AbcStrandsWriter::write_sample()
 		m_param_motion_co.set(OP3fGeomParam::Sample(P3fArraySample(strands_sample.motion_co), kVertexScope));
 		m_param_motion_vel.set(OV3fGeomParam::Sample(V3fArraySample(strands_sample.motion_vel), 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 45ab5b4..198b3bd 100644
--- a/source/blender/pointcache/alembic/abc_particles.h
+++ b/source/blender/pointcache/alembic/abc_particles.h
@@ -83,10 +83,6 @@ public:


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list