Commit: 75597c03be7270c507eca3de765b4b706f8d1ff1
Author: Sybren A. Stüvel
Date:   Thu Feb 23 15:58:36 2017 +0100
Branches: temp-sybren-alembic
https://developer.blender.org/rB75597c03be7270c507eca3de765b4b706f8d1ff1

Alembic import: separated reading matrix and getting the appropriate Xform 
object

Also added a bit better error reporting, instead of silently ignoring
invalid Alembic data.

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

M       source/blender/alembic/intern/abc_object.cc
M       source/blender/alembic/intern/abc_object.h

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

diff --git a/source/blender/alembic/intern/abc_object.cc 
b/source/blender/alembic/intern/abc_object.cc
index 3a3b076dbf..7250ebb4c0 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -236,37 +236,50 @@ void AbcObjectReader::readObjectMatrix(const float time)
        }
 }
 
-void AbcObjectReader::read_matrix(float mat[4][4], const float time, const 
float scale, bool &is_constant)
-{
-       IXform ixform;
-       IObject ixform_parent;
 
+Alembic::AbcGeom::IXform AbcObjectReader::xform()
+{
        /* Check that we have an empty object (locator, bone head/tail...).  */
        if (IXform::matches(m_iobject.getMetaData())) {
-               ixform = IXform(m_iobject, Alembic::AbcGeom::kWrapExisting);
-               ixform_parent = m_iobject.getParent();
+               return IXform(m_iobject, Alembic::AbcGeom::kWrapExisting);
        }
-       /* Check that we have an object with actual data. */
-       else if (IXform::matches(m_iobject.getParent().getMetaData())) {
-               ixform = IXform(m_iobject.getParent(), 
Alembic::AbcGeom::kWrapExisting);
-               ixform_parent = m_iobject.getParent().getParent();
+
+       /* Check that we have an object with actual data, in which case the
+        * parent Alembic object should contain the transform. */
+       IObject abc_parent = m_iobject.getParent();
+
+       /* The archive's top object can be recognised by not having a parent. */
+       if (abc_parent.getParent()
+               && IXform::matches(abc_parent.getMetaData())) {
+               return IXform(abc_parent, Alembic::AbcGeom::kWrapExisting);
        }
+
        /* Should not happen. */
-       else {
-               std::cerr << "AbcObjectReader::read_matrix: "
-                         << "unable to find IXform for Alembic object '"
-                         << m_iobject.getFullName() << "'\n";
-               BLI_assert(false);
+       std::cerr << "AbcObjectReader::xform(): "
+                 << "unable to find IXform for Alembic object '"
+                 << m_iobject.getFullName() << "'\n";
+       BLI_assert(false);
+
+       return IXform();
+}
+
+
+void AbcObjectReader::read_matrix(float mat[4][4], const float time, const 
float scale, bool &is_constant)
+{
+       IXform ixform = xform();
+       if (!ixform) {
                return;
        }
 
-       const IXformSchema &schema(ixform.getSchema());
-
+       const IXformSchema & schema(ixform.getSchema());
        if (!schema.valid()) {
+               std::cerr << "Alembic object " << ixform.getFullName()
+                         << " has an invalid schema." << std::endl;
                return;
        }
 
        bool has_alembic_parent;
+       IObject ixform_parent = ixform.getParent();
        if (!ixform_parent.getParent()) {
                /* The archive top object certainly is not a transform itself, 
so handle
                 * it as "no parent". */
diff --git a/source/blender/alembic/intern/abc_object.h 
b/source/blender/alembic/intern/abc_object.h
index 7d400f17a2..6d97c0359b 100644
--- a/source/blender/alembic/intern/abc_object.h
+++ b/source/blender/alembic/intern/abc_object.h
@@ -158,6 +158,12 @@ public:
 
        const Alembic::Abc::IObject &iobject() const;
 
+       /**
+        * Returns the transform of this object. This can be the Alembic object
+        * itself (in case of an Empty) or it can be the parent Alembic object.
+        */
+       virtual Alembic::AbcGeom::IXform xform();
+
        Object *object() const;
        void object(Object *ob);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to