[Bf-blender-cvs] [e4758d3] alembic: Use quaternions instead of 3x3 matrices to store rotation of strand roots in Alembic caches.
Lukas Tönne
noreply at git.blender.org
Tue Apr 28 11:36:25 CEST 2015
Commit: e4758d3dfb6f311c7700a7efd9a25a3b3224456a
Author: Lukas Tönne
Date: Tue Apr 28 11:34:02 2015 +0200
Branches: alembic
https://developer.blender.org/rBe4758d3dfb6f311c7700a7efd9a25a3b3224456a
Use quaternions instead of 3x3 matrices to store rotation of strand
roots in Alembic caches.
This kind of data is a big chunk of massive hair systems. Test files
could be reduced this way by almost 30%.
===================================================================
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 34b0728..6ebaa36 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -43,7 +43,7 @@ using namespace AbcGeom;
struct StrandsChildrenSample {
std::vector<int32_t> numverts;
- std::vector<M33f> root_matrix;
+ std::vector<Quatf> root_rotations;
std::vector<V3f> root_positions;
std::vector<V3f> positions;
@@ -56,7 +56,7 @@ struct StrandsChildrenSample {
struct StrandsSample {
std::vector<int32_t> numverts;
- std::vector<M33f> root_matrix;
+ std::vector<Quatf> root_rotations;
std::vector<V3f> positions;
std::vector<float32_t> times;
@@ -88,7 +88,7 @@ void AbcHairChildrenWriter::init_abc(OObject parent)
OCompoundProperty geom_props = schema.getArbGeomParams();
OCompoundProperty user_props = schema.getUserProperties();
- m_prop_root_matrix = OM33fArrayProperty(user_props, "root_matrix", abc_archive()->frame_sampling());
+ m_prop_root_rot = OQuatfArrayProperty(user_props, "root_rotations", abc_archive()->frame_sampling());
m_prop_root_positions = OV3fArrayProperty(user_props, "root_positions", abc_archive()->frame_sampling());
m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, 0);
m_prop_parents = OInt32ArrayProperty(user_props, "parents", abc_archive()->frame_sampling());
@@ -317,7 +317,7 @@ static void hair_children_create_sample(Object *ob, ParticleSystem *psys, Partic
sample.times.reserve(totkeys);
}
- sample.root_matrix.reserve(totpart);
+ sample.root_rotations.reserve(totpart);
sample.root_positions.reserve(totpart);
for (p = 0; p < totpart; ++p) {
@@ -370,9 +370,9 @@ static void hair_children_create_sample(Object *ob, ParticleSystem *psys, Partic
}
}
- float mat3[3][3];
- copy_m3_m4(mat3, hairmat);
- sample.root_matrix.push_back(M33f(mat3));
+ float qt[4];
+ mat4_to_quat(qt, hairmat);
+ sample.root_rotations.push_back(Quatf(qt[0], qt[1], qt[2], qt[3]));
float *co = hairmat[3];
sample.root_positions.push_back(V3f(co[0], co[1], co[2]));
}
@@ -418,7 +418,7 @@ void AbcHairChildrenWriter::write_sample()
hair_children_create_sample(m_ob, m_psys, m_psmd, m_psys->childcache, m_psys->totchild, totkeys, maxkeys, child_sample, false);
}
- m_prop_root_matrix.set(M33fArraySample(child_sample.root_matrix));
+ m_prop_root_rot.set(QuatfArraySample(child_sample.root_rotations));
m_prop_root_positions.set(V3fArraySample(child_sample.root_positions));
}
@@ -449,7 +449,7 @@ void AbcHairWriter::init_abc(OObject parent)
OCurvesSchema &schema = m_curves.getSchema();
OCompoundProperty geom_props = schema.getArbGeomParams();
- m_param_root_matrix = OM33fGeomParam(geom_props, "root_matrix", false, kUniformScope, 1, 0);
+ m_param_root_rot = OQuatfGeomParam(geom_props, "root_rotations", false, kUniformScope, 1, 0);
m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, 0);
m_param_weights = OFloatGeomParam(geom_props, "weights", false, kVertexScope, 1, 0);
@@ -481,7 +481,7 @@ static void hair_create_sample(Object *ob, DerivedMesh *dm, ParticleSystem *psys
if (do_numverts)
sample.numverts.reserve(totpart);
- sample.root_matrix.reserve(totpart);
+ sample.root_rotations.reserve(totpart);
sample.positions.reserve(totverts);
sample.times.reserve(totverts);
sample.weights.reserve(totverts);
@@ -489,14 +489,15 @@ static void hair_create_sample(Object *ob, DerivedMesh *dm, ParticleSystem *psys
for (p = 0; p < totpart; ++p) {
ParticleData *pa = &psys->particles[p];
int numverts = pa->totkey;
- float hairmat[4][4], root_matrix[3][3];
+ float hairmat[4][4];
if (do_numverts)
sample.numverts.push_back(numverts);
psys_mat_hair_to_object(ob, dm, psys->part->from, pa, hairmat);
- copy_m3_m4(root_matrix, hairmat);
- sample.root_matrix.push_back(M33f(root_matrix));
+ float root_qt[4];
+ mat4_to_quat(root_qt, hairmat);
+ sample.root_rotations.push_back(Quatf(root_qt[0], root_qt[1], root_qt[2], root_qt[3]));
for (k = 0; k < numverts; ++k) {
HairKey *key = &pa->hair[k];
@@ -540,7 +541,7 @@ void AbcHairWriter::write_sample()
}
schema.set(sample);
- m_param_root_matrix.set(OM33fGeomParam::Sample(M33fArraySample(hair_sample.root_matrix), kUniformScope));
+ m_param_root_rot.set(OQuatfGeomParam::Sample(QuatfArraySample(hair_sample.root_rotations), kUniformScope));
m_param_times.set(OFloatGeomParam::Sample(FloatArraySample(hair_sample.times), kVertexScope));
m_param_weights.set(OFloatGeomParam::Sample(FloatArraySample(hair_sample.weights), kVertexScope));
@@ -571,7 +572,7 @@ void AbcStrandsChildrenWriter::init_abc(OObject parent)
OCompoundProperty geom_props = schema.getArbGeomParams();
OCompoundProperty user_props = schema.getUserProperties();
- m_prop_root_matrix = OM33fArrayProperty(user_props, "root_matrix", abc_archive()->frame_sampling());
+ m_prop_root_rot = OQuatfArrayProperty(user_props, "root_rotations", abc_archive()->frame_sampling());
m_prop_root_positions = OV3fArrayProperty(user_props, "root_positions", abc_archive()->frame_sampling());
m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, abc_archive()->frame_sampling());
m_prop_parents = OInt32ArrayProperty(user_props, "parents", abc_archive()->frame_sampling());
@@ -618,7 +619,7 @@ static void strands_children_create_sample(StrandsChildren *strands, StrandsChil
sample.times.reserve(totverts);
}
- sample.root_matrix.reserve(totcurves);
+ sample.root_rotations.reserve(totcurves);
sample.root_positions.reserve(totcurves);
StrandChildIterator it_strand;
@@ -645,9 +646,9 @@ static void strands_children_create_sample(StrandsChildren *strands, StrandsChil
}
}
- float mat3[3][3];
- copy_m3_m4(mat3, it_strand.curve->root_matrix);
- sample.root_matrix.push_back(M33f(mat3));
+ float qt[4];
+ mat4_to_quat(qt, it_strand.curve->root_matrix);
+ sample.root_rotations.push_back(Quatf(qt[0], qt[1], qt[2], qt[3]));
float *co = it_strand.curve->root_matrix[3];
sample.root_positions.push_back(V3f(co[0], co[1], co[2]));
}
@@ -688,7 +689,7 @@ void AbcStrandsChildrenWriter::write_sample()
strands_children_create_sample(strands, strands_sample, false);
}
- m_prop_root_matrix.set(M33fArraySample(strands_sample.root_matrix));
+ m_prop_root_rot.set(QuatfArraySample(strands_sample.root_rotations));
m_prop_root_positions.set(V3fArraySample(strands_sample.root_positions));
}
@@ -720,7 +721,7 @@ void AbcStrandsWriter::init_abc(OObject parent)
OCurvesSchema &schema = m_curves.getSchema();
OCompoundProperty geom_props = schema.getArbGeomParams();
- m_param_root_matrix = OM33fGeomParam(geom_props, "root_matrix", false, kUniformScope, 1, abc_archive()->frame_sampling());
+ m_param_root_rot = OQuatfGeomParam(geom_props, "root_rotations", false, kUniformScope, 1, abc_archive()->frame_sampling());
m_param_times = OFloatGeomParam(geom_props, "times", false, kVertexScope, 1, abc_archive()->frame_sampling());
m_param_weights = OFloatGeomParam(geom_props, "weights", false, kVertexScope, 1, abc_archive()->frame_sampling());
@@ -744,7 +745,7 @@ static void strands_create_sample(Strands *strands, StrandsSample &sample, bool
if (do_numverts)
sample.numverts.reserve(totcurves);
- sample.root_matrix.reserve(totcurves);
+ sample.root_rotations.reserve(totcurves);
sample.positions.reserve(totverts);
sample.times.reserve(totverts);
@@ -760,7 +761,9 @@ static void strands_create_sample(Strands *strands, StrandsSample &sample, bool
if (do_numverts)
sample.numverts.push_back(numverts);
- sample.root_matrix.push_back(M33f(it_strand.curve->root_matrix));
+ float qt[4];
+ mat3_to_quat(qt, it_strand.curve->root_matrix);
+ sample.root_rotations.push_back(Quatf(qt[0], qt[1], qt[2], qt[3]));
StrandVertexIterator it_vert;
for (BKE_strand_vertex_iter_init(&it_vert, &it_strand); BKE_strand_vertex_iter_valid(&it_vert); BKE_strand_vertex_iter_next(&it_vert)) {
@@ -802,7 +805,7 @@ void AbcStrandsWriter::write_sample()
}
schema.set(sample);
- m_param_root_matrix.set(OM33fGeomParam::Sample(M33fArraySample(strands_sample.root_matrix), kUniformScope));
+ m_param_root_rot.set(OQuatfGeomParam::Sample(QuatfArraySample(strands_sample.root_rotations), kUniformScope));
m_param_times.set(OFloatGeomParam::Sample(FloatArraySample(strands_sample.times), kVertexScope));
m_param_weights.set(OFloatGeomParam::Sample(FloatArraySample(strands_sample.weights), kVertexScope));
@@ -842,7 +845,7 @@ void AbcStrandsChildrenReader::init_abc(IObject object)
ICompoundProperty geom_props = schema.getArbGeomParams();
ICompoundProperty user_props = schema.getUserProperties();
- m_prop_root_matrix = IM33fArrayProperty(user_props, "root_matrix");
+ m_prop_root_rot = IQuatfArrayProperty(user_props, "root_rotations");
m_prop_root_positions = IV3fArrayProperty(user_props, "root_positions");
m_param_times = IFloatGeomParam(geom_props, "times");
m_prop_parents = IInt32ArrayProperty(user_props, "parents", 0);
@@ -869,7 +872,7 @@ PTCReadSampleResult AbcStrandsChildrenReader::read_sample_abc(float frame)
P3fArraySamplePtr sample_co = sample.getPositions();
Int32ArraySamplePtr sample_numvert = sample.getCurvesNumVertices();
- M33fArraySamplePtr sample_root_matrix = m_prop_root_matrix.getValue(ss);
+ QuatfArraySamplePtr sample_root_rotations = m_prop_root_rot.getValue(ss);
V3fArraySamplePtr sample_root_positions = m_prop_root_positions.getValue(ss);
IFloatGeomParam::Sample sample_time = m_param_times.getExpandedValue(ss);
Int32ArraySamplePtr sample_parents = m_prop_parents.getValue(ss);
@@ -888,7 +891,7 @@ PTCReadSampleResult AbcStrandsChildrenReader::read_sample_abc(float frame)
return PTC_READ_SAMPLE_INVALID;
}
- if (sample_root_matrix->size() != totcurves ||
+ if (sample_root_rotations->size() != totcurves ||
sample_root_positions->size() != totcurves ||
sample_parents->size() != 4 * totcurves ||
sample_parent_weights->size() != 4 * totcurves)
@@ -900,7 +903,7 @@ PTCReadSampleResult AbcStrandsChildrenReader::read_sample_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list