[Bf-blender-cvs] [b3320a3] alembic_basic_io: Improve (fix a few bugs in) the transform hierarchy creation.

Kévin Dietrich noreply at git.blender.org
Thu Jun 2 22:37:24 CEST 2016


Commit: b3320a3596a2f8f768d2ea4bb88ead13685aeca2
Author: Kévin Dietrich
Date:   Thu Jun 2 10:44:13 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rBb3320a3596a2f8f768d2ea4bb88ead13685aeca2

Improve (fix a few bugs in) the transform hierarchy creation.

Now an empty is created for every transform node except for the cases
when the transform node only has a single child that is not a transform
itself.

There are still a few issues in complex hierarchies where multiple
objects have the same name (which is legal in Alembic since it is the
whole path to the object that counts, not just the name).

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

M	source/blender/alembic/intern/abc_object.cc
M	source/blender/alembic/intern/abc_util.cc
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 054707a..94e62a0 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -45,6 +45,8 @@ extern "C" {
 }
 
 using Alembic::AbcGeom::IObject;
+using Alembic::AbcGeom::IXform;
+using Alembic::AbcGeom::IXformSchema;
 
 using Alembic::AbcGeom::OCompoundProperty;
 using Alembic::AbcGeom::ODoubleArrayProperty;
@@ -321,13 +323,7 @@ AbcObjectReader::AbcObjectReader(const IObject &object, ImportSettings &settings
 	std::vector<std::string> parts;
 	split(m_name, '/', parts);
 
-	if (parts.size() >= 2) {
-		m_object_name = parts[parts.size() - 2];
-		m_data_name = parts[parts.size() - 1];
-	}
-	else {
-		m_object_name = m_data_name = parts[parts.size() - 1];
-	}
+	m_object_name = m_data_name = parts[parts.size() - 1];
 }
 
 AbcObjectReader::~AbcObjectReader()
@@ -345,14 +341,19 @@ Object *AbcObjectReader::object() const
 
 void AbcObjectReader::readObjectMatrix(const float time)
 {
-	const Alembic::AbcGeom::MetaData &md = m_iobject.getParent().getMetaData();
+	IXform ixform;
 
-	if (!Alembic::AbcGeom::IXformSchema::matches(md)) {
+	if (IXform::matches(m_iobject.getMetaData())) {
+		ixform = IXform(m_iobject, Alembic::AbcGeom::kWrapExisting);
+	}
+	else if (IXform::matches(m_iobject.getParent().getMetaData())) {
+		ixform = IXform(m_iobject.getParent(), Alembic::AbcGeom::kWrapExisting);
+	}
+	else {
 		return;
 	}
 
-	Alembic::AbcGeom::IXform x(m_iobject.getParent(), Alembic::AbcGeom::kWrapExisting);
-	Alembic::AbcGeom::IXformSchema &schema(x.getSchema());
+	const IXformSchema &schema(ixform.getSchema());
 
 	if (!schema.valid()) {
 		return;
@@ -362,7 +363,7 @@ void AbcObjectReader::readObjectMatrix(const float time)
 	Alembic::AbcGeom::XformSample xs;
 	schema.get(xs, sample_sel);
 
-	create_input_transform(sample_sel, x, m_object, m_object->obmat);
+	create_input_transform(sample_sel, ixform, 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 110aa05..6377a8c 100644
--- a/source/blender/alembic/intern/abc_util.cc
+++ b/source/blender/alembic/intern/abc_util.cc
@@ -218,26 +218,6 @@ static void get_matrix(const Alembic::AbcGeom::ISampleSelector &sample_sel,
     Alembic::AbcGeom::XformSample xs;
 	leaf_schema.get(xs, sample_sel);
 	m = xs.getMatrix();
-
-	if (!xs.getInheritsXforms()) {
-		return;
-	}
-
-	Alembic::AbcGeom::IObject obj = leaf.getParent();
-
-	if (!obj.valid() || !Alembic::AbcGeom::IXform::matches(obj.getHeader())) {
-		return;
-	}
-
-	if (!is_locator(leaf) || (leaf.getNumChildren() != 0)) {
-		return;
-	}
-
-	Alembic::AbcGeom::IXform parent(obj, Alembic::AbcGeom::kWrapExisting);
-	Alembic::AbcGeom::IXformSchema parent_schema = parent.getSchema();
-    Alembic::AbcGeom::XformSample parent_xs;
-	parent_schema.get(parent_xs, sample_sel);
-	m = parent_xs.getMatrix() * m;
 }
 
 void create_input_transform(const Alembic::AbcGeom::ISampleSelector &sample_sel,
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index ce55d72..447536a 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -356,7 +356,30 @@ static void visit_object(const IObject &object,
 		const MetaData &md = child.getMetaData();
 
 		if (IXform::matches(md)) {
-			if (is_locator(child) || child.getNumChildren() == 0) {
+			bool create_xform = false;
+
+			if (is_locator(child)) {
+				create_xform = true;
+			}
+			else {
+				/* Avoid creating an empty object if the child of this transform
+				 * is not a transform (that is an empty). */
+				if (child.getNumChildren() == 1) {
+					if (IXform::matches(child.getChild(0).getMetaData())) {
+						create_xform = true;
+					}
+#if 0
+					else {
+						std::cerr << "Skipping " << child.getFullName() << '\n';
+					}
+#endif
+				}
+				else {
+					create_xform = true;
+				}
+			}
+
+			if (create_xform) {
 				reader = new AbcEmptyReader(child, settings);
 			}
 		}
@@ -429,16 +452,10 @@ static void create_hierarchy(Main *bmain, Scene *scene, AbcObjectReader *root)
 	std::vector<std::string> parts;
 	split(full_name, '/', parts);
 
-	/* Either object doesn't have any parents, since its path only contain its name,
-	 * and its data name, or is an empty with no parents. */
-	if (parts.size() <= 2) {
-		return;
-	}
-
 	Object *parent = NULL;
 
 	std::vector<std::string>::reverse_iterator iter;
-	for (iter = parts.rbegin() + 2; iter != parts.rend(); ++iter) {
+	for (iter = parts.rbegin() + 1; iter != parts.rend(); ++iter) {
 		parent = find_object(scene, *iter);
 
 		if (parent != NULL && root->object() != parent) {




More information about the Bf-blender-cvs mailing list