[Bf-blender-cvs] [642728b3395] master: Alembic export: fixed exporting as "flat"

Sybren A. Stüvel noreply at git.blender.org
Wed Apr 12 12:27:51 CEST 2017


Commit: 642728b3395a49895526348e7a8b294e72ef6dcf
Author: Sybren A. Stüvel
Date:   Wed Apr 12 12:15:32 2017 +0200
Branches: master
https://developer.blender.org/rB642728b3395a49895526348e7a8b294e72ef6dcf

Alembic export: fixed exporting as "flat"

This exports all objects in world coordinates without parenting.

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

M	source/blender/alembic/intern/abc_exporter.cc
M	source/blender/alembic/intern/abc_transform.cc
M	source/blender/alembic/intern/abc_transform.h
M	source/blender/alembic/intern/abc_util.cc
M	source/blender/alembic/intern/abc_util.h

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

diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc
index 76167fc435d..39896529c97 100644
--- a/source/blender/alembic/intern/abc_exporter.cc
+++ b/source/blender/alembic/intern/abc_exporter.cc
@@ -374,7 +374,9 @@ void AbcExporter::createTransformWritersFlat()
 
 		if (export_object(&m_settings, ob) && object_is_shape(ob)) {
 			std::string name = get_id_name(ob);
-			m_xforms[name] = new AbcTransformWriter(ob, m_writer->archive().getTop(), 0, m_trans_sampling_index, m_settings);
+			m_xforms[name] = new AbcTransformWriter(
+			                     ob, m_writer->archive().getTop(), NULL,
+			                     m_trans_sampling_index, m_settings);
 		}
 
 		base = base->next;
diff --git a/source/blender/alembic/intern/abc_transform.cc b/source/blender/alembic/intern/abc_transform.cc
index cad1eae4764..2e626edeb8b 100644
--- a/source/blender/alembic/intern/abc_transform.cc
+++ b/source/blender/alembic/intern/abc_transform.cc
@@ -71,6 +71,9 @@ AbcTransformWriter::AbcTransformWriter(Object *ob,
 
 	m_xform = OXform(abc_parent, get_id_name(m_object), time_sampling);
 	m_schema = m_xform.getSchema();
+
+	/* Blender objects can't have a parent without inheriting the transform. */
+	m_inherits_xform = parent != NULL;
 }
 
 void AbcTransformWriter::do_write()
@@ -86,20 +89,18 @@ void AbcTransformWriter::do_write()
 	}
 
 	float yup_mat[4][4];
-	create_transform_matrix(m_object, yup_mat);
+	create_transform_matrix(m_object, yup_mat,
+	                        m_inherits_xform ? ABC_MATRIX_LOCAL : ABC_MATRIX_WORLD);
 
 	/* Only apply rotation to root camera, parenting will propagate it. */
-	if (m_object->type == OB_CAMERA && !has_parent_camera(m_object)) {
+	if (m_object->type == OB_CAMERA && (!m_inherits_xform || !has_parent_camera(m_object))) {
 		float rot_mat[4][4];
 		axis_angle_to_mat4_single(rot_mat, 'X', -M_PI_2);
 		mul_m4_m4m4(yup_mat, yup_mat, rot_mat);
 	}
 
-	if (!m_object->parent) {
+	if (!m_object->parent || !m_inherits_xform) {
 		/* Only apply scaling to root objects, parenting will propagate it. */
-		/* TODO Sybren: when we're exporting as "flat", i.e. non-hierarchial,
-		 * we should apply the scale even when the object has a parent
-		 * Blender Object. */
 		float scale_mat[4][4];
 		scale_m4_fl(scale_mat, m_settings.global_scale);
 		scale_mat[3][3] = m_settings.global_scale;  /* also scale translation */
@@ -108,6 +109,7 @@ void AbcTransformWriter::do_write()
 
 	m_matrix = convert_matrix(yup_mat);
 	m_sample.setMatrix(m_matrix);
+	m_sample.setInheritsXforms(m_inherits_xform);
 	m_schema.set(m_sample);
 }
 
diff --git a/source/blender/alembic/intern/abc_transform.h b/source/blender/alembic/intern/abc_transform.h
index b55fa12dadf..714adc299c1 100644
--- a/source/blender/alembic/intern/abc_transform.h
+++ b/source/blender/alembic/intern/abc_transform.h
@@ -38,6 +38,7 @@ class AbcTransformWriter : public AbcObjectWriter {
 
 	bool m_is_animated;
 	bool m_visible;
+	bool m_inherits_xform;
 
 public:
 	AbcTransformWriter(Object *ob,
diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc
index 224e0eccd00..248ca4e64ae 100644
--- a/source/blender/alembic/intern/abc_util.cc
+++ b/source/blender/alembic/intern/abc_util.cc
@@ -257,15 +257,12 @@ void convert_matrix(const Imath::M44d &xform, Object *ob, float r_mat[4][4])
 
 /* Recompute transform matrix of object in new coordinate system
  * (from Z-Up to Y-Up). */
-void create_transform_matrix(Object *obj, float r_yup_mat[4][4])
+void create_transform_matrix(Object *obj, float r_yup_mat[4][4], AbcMatrixMode mode)
 {
 	float zup_mat[4][4];
 
-	/* get local matrix. */
-	/* TODO Sybren: when we're exporting as "flat", i.e. non-hierarchial,
-	 * we should export the world matrix even when the object has a parent
-	 * Blender Object. */
-	if (obj->parent) {
+	/* get local or world matrix. */
+	if (mode == ABC_MATRIX_LOCAL && obj->parent) {
 		/* Note that this produces another matrix than the local matrix, due to
 		 * constraints and modifiers as well as the obj->parentinv matrix. */
 		invert_m4_m4(obj->parent->imat, obj->parent->obmat);
diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h
index 5b53c86a859..7bde9ac6e15 100644
--- a/source/blender/alembic/intern/abc_util.h
+++ b/source/blender/alembic/intern/abc_util.h
@@ -57,7 +57,12 @@ bool object_selected(Object *ob);
 bool parent_selected(Object *ob);
 
 Imath::M44d convert_matrix(float mat[4][4]);
-void create_transform_matrix(Object *obj, float r_transform_mat[4][4]);
+
+typedef enum {
+	ABC_MATRIX_WORLD = 1,
+	ABC_MATRIX_LOCAL = 2,
+} AbcMatrixMode;
+void create_transform_matrix(Object *obj, float r_transform_mat[4][4], AbcMatrixMode mode);
 
 void split(const std::string &s, const char delim, std::vector<std::string> &tokens);




More information about the Bf-blender-cvs mailing list