Alembic import: separated reading matrix and getting the appropriate Xform object
authorSybren A. Stüvel <sybren@stuvel.eu>
Thu, 23 Feb 2017 14:58:36 +0000 (15:58 +0100)
committerSybren A. Stüvel <sybren@stuvel.eu>
Thu, 6 Apr 2017 14:04:31 +0000 (16:04 +0200)
Also added a bit better error reporting, instead of silently ignoring
invalid Alembic data.

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

index 3765e13d585336930e630e5a5cbfabbe9df8e740..0b2c8cb6b8a19b80a886a1303cd6b43b91aa109c 100644 (file)
@@ -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())) {
        /* 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. */
        /* 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;
        }
 
                return;
        }
 
-       const IXformSchema &schema(ixform.getSchema());
-
+       const IXformSchema & schema(ixform.getSchema());
        if (!schema.valid()) {
        if (!schema.valid()) {
+               std::cerr << "Alembic object " << ixform.getFullName()
+                         << " has an invalid schema." << std::endl;
                return;
        }
 
        bool has_alembic_parent;
                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". */
        if (!ixform_parent.getParent()) {
                /* The archive top object certainly is not a transform itself, so handle
                 * it as "no parent". */
index 7d400f17a2a594a3c52d87b9ba7a66dae0f0345e..6d97c0359b7365231aa1d2c913c30017cf9daced 100644 (file)
@@ -158,6 +158,12 @@ public:
 
        const Alembic::Abc::IObject &iobject() const;
 
 
        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);
 
        Object *object() const;
        void object(Object *ob);