[Bf-blender-cvs] [4251590] alembic_basic_io: De-duplicate matrix reading code.
Kévin Dietrich
noreply at git.blender.org
Mon May 30 10:52:57 CEST 2016
Commit: 4251590929598c2acfd58e25703e40ec3a1e1b44
Author: Kévin Dietrich
Date: Mon May 30 10:17:22 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB4251590929598c2acfd58e25703e40ec3a1e1b44
De-duplicate matrix reading code.
===================================================================
M source/blender/alembic/intern/abc_object.cc
M source/blender/alembic/intern/abc_util.cc
M source/blender/alembic/intern/abc_util.h
M source/blender/alembic/intern/alembic_capi.cc
===================================================================
diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc
index 30439d8..848dc71 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -352,34 +352,11 @@ void AbcObjectReader::readObjectMatrix(const float time)
return;
}
- Alembic::AbcGeom::ISampleSelector xform_sample(time);
+ Alembic::AbcGeom::ISampleSelector sample_sel(time);
Alembic::AbcGeom::XformSample xs;
- schema.get(xs, xform_sample);
+ schema.get(xs, sample_sel);
- Alembic::Abc::M44d xfrom = xs.getMatrix();
-
- for (int i = 0; i < 4; ++i) {
- for (int j = 0; j < 4; j++) {
- m_object->obmat[i][j] = xfrom[i][j];
- }
- }
-
- if (m_object->type == OB_CAMERA) {
- float cam_to_yup[4][4];
- unit_m4(cam_to_yup);
- rotate_m4(cam_to_yup, 'X', M_PI_2);
- mul_m4_m4m4(m_object->obmat, m_object->obmat, cam_to_yup);
- }
-
- create_transform_matrix(m_object->obmat);
-
- /* TODO: apply global scale */
-#if 0
- float global_scale[4][4];
- scale_m4_fl(global_scale, m_settings->scale);
- mul_m4_m4m4(m_object->obmat, m_object->obmat, global_scale);
- mul_v3_fl(m_object->obmat[3], m_settings->scale);
-#endif
+ create_input_transform(sample_sel, x, m_object, m_object->obmat);
invert_m4_m4(m_object->imat, m_object->obmat);
diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc
index 53734e7..c64ff93 100644
--- a/source/blender/alembic/intern/abc_util.cc
+++ b/source/blender/alembic/intern/abc_util.cc
@@ -204,6 +204,66 @@ void create_transform_matrix(float r_mat[4][4])
copy_m4_m4(r_mat, transform_mat);
}
+static void get_matrix(const Alembic::AbcGeom::ISampleSelector &sample_sel,
+ const Alembic::AbcGeom::IXform &leaf, Imath::M44d &m)
+{
+ Alembic::AbcGeom::IXformSchema xform_schema = leaf.getSchema();
+ Alembic::AbcGeom::XformSample xs;
+ xform_schema.get(xs, sample_sel);
+ m = xs.getMatrix();
+
+ if (!xs.getInheritsXforms()) {
+ return;
+ }
+
+ Alembic::AbcGeom::IObject obj = leaf.getParent();
+
+ if (Alembic::AbcGeom::IXform::matches(obj.getHeader())) {
+ Alembic::AbcGeom::IXform parent = Alembic::AbcGeom::IXform(obj, Alembic::AbcGeom::kWrapExisting);
+ xform_schema = parent.getSchema();
+ xform_schema.get(xs, sample_sel);
+
+ m = m * xs.getMatrix();
+ }
+}
+
+void create_input_transform(const Alembic::AbcGeom::ISampleSelector &sample_sel,
+ const Alembic::AbcGeom::IXform &ixform, Object *ob,
+ float r_mat[4][4])
+{
+ Imath::M44d xform;
+ xform.makeIdentity();
+
+ get_matrix(sample_sel, ixform, xform);
+
+ for (int i = 0; i < 4; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ r_mat[i][j] = xform[i][j];
+ }
+ }
+
+ if (ob->type == OB_CAMERA) {
+ float cam_to_yup[4][4];
+ unit_m4(cam_to_yup);
+ rotate_m4(cam_to_yup, 'X', M_PI_2);
+ mul_m4_m4m4(r_mat, r_mat, cam_to_yup);
+ }
+
+ create_transform_matrix(r_mat);
+
+ /* TODO: apply global scale */
+#if 0
+ float global_scale[4][4];
+ scale_m4_fl(global_scale, m_settings->scale);
+ mul_m4_m4m4(m_object->obmat, m_object->obmat, global_scale);
+ mul_v3_fl(m_object->obmat[3], m_settings->scale);
+#endif
+
+ if (ob->parent) {
+ mul_m4_m4m4(r_mat, ob->parent->obmat, r_mat);
+ }
+}
+
/* recompute transform matrix of object in new coordinate system (from Z-Up to Y-Up) */
void create_transform_matrix(Object *obj, float transform_mat[4][4])
{
diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h
index d2b0b79..32de50d 100644
--- a/source/blender/alembic/intern/abc_util.h
+++ b/source/blender/alembic/intern/abc_util.h
@@ -24,6 +24,7 @@
#define __ABC_UTIL_H__
#include <Alembic/Abc/All.h>
+#include <Alembic/AbcGeom/All.h>
struct ID;
struct Object;
@@ -48,4 +49,8 @@ bool begins_with(const TContainer &input, const TContainer &match)
&& std::equal(match.begin(), match.end(), input.begin());
}
+void create_input_transform(const Alembic::AbcGeom::ISampleSelector &sample_sel,
+ const Alembic::AbcGeom::IXform &ixform, Object *ob,
+ float r_mat[4][4]);
+
#endif /* __ABC_UTIL_H__ */
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 36cd63c..6a1d13b 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -605,28 +605,6 @@ static IXform get_xform(const IObject &object, const std::string &name, bool &fo
return IXform(tmp.getParent(), kWrapExisting);
}
-void get_matrix(const ISampleSelector &sample_sel, const IXform &leaf, Imath::M44d &m)
-{
- IXformSchema xform_schema = leaf.getSchema();
- XformSample xs;
- xform_schema.get(xs, sample_sel);
- m = xs.getMatrix();
-
- if (!xs.getInheritsXforms()) {
- return;
- }
-
- IObject obj = leaf.getParent();
-
- if (IXform::matches(obj.getHeader())) {
- IXform parent = IXform(obj, kWrapExisting);
- xform_schema = parent.getSchema();
- xform_schema.get(xs, sample_sel);
-
- m = m * xs.getMatrix();
- }
-}
-
void ABC_get_transform(Object *ob, const char *filename, const char *object_path, float r_mat[4][4], float time)
{
IArchive archive = open_archive(filename);
@@ -646,27 +624,5 @@ void ABC_get_transform(Object *ob, const char *filename, const char *object_path
ISampleSelector sample_sel(time);
- Imath::M44d xform;
- xform.makeIdentity();
-
- get_matrix(sample_sel, ixform, xform);
-
- for (int i = 0; i < 4; ++i) {
- for (int j = 0; j < 4; ++j) {
- r_mat[i][j] = xform[i][j];
- }
- }
-
- if (ob->type == OB_CAMERA) {
- float cam_to_yup[4][4];
- unit_m4(cam_to_yup);
- rotate_m4(cam_to_yup, 'X', M_PI_2);
- mul_m4_m4m4(r_mat, r_mat, cam_to_yup);
- }
-
- create_transform_matrix(r_mat);
-
- if (ob->parent) {
- mul_m4_m4m4(r_mat, ob->parent->obmat, r_mat);
- }
+ create_input_transform(sample_sel, ixform, ob, r_mat);
}
More information about the Bf-blender-cvs
mailing list