[Bf-blender-cvs] [1ead69b66b6] usd-importer-T81257-merge: USD import: root object xform logic fix.

makowalski noreply at git.blender.org
Mon May 17 23:05:30 CEST 2021


Commit: 1ead69b66b6778f27574aa246042725801e3dfd4
Author: makowalski
Date:   Mon May 17 11:28:56 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rB1ead69b66b6778f27574aa246042725801e3dfd4

USD import: root object xform logic fix.

Fixed logic for determining if a USDXformReader object
is the root of a transform hierarchy.  The previous
implementation did not work for USDXformReader instances
created for transform cache contraints, since in that case
parent readers aren't set. Also, now checking if the
prim is a root xform in the USDXformReader constructor,
to avoid repeating this check every time the matrix
is computed.

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

M	source/blender/io/usd/intern/usd_reader_xform.cc
M	source/blender/io/usd/intern/usd_reader_xform.h

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

diff --git a/source/blender/io/usd/intern/usd_reader_xform.cc b/source/blender/io/usd/intern/usd_reader_xform.cc
index 46f8331c3c7..5cdf126d6eb 100644
--- a/source/blender/io/usd/intern/usd_reader_xform.cc
+++ b/source/blender/io/usd/intern/usd_reader_xform.cc
@@ -113,7 +113,7 @@ void USDXformReader::read_matrix(float r_mat[4][4] /* local matrix */,
 
   /* Apply global scaling and rotation only to root objects, parenting
    * will propagate it. */
-  if ((scale != 1.0 || settings_->do_convert_mat) && is_root_xform_object()) {
+  if ((scale != 1.0 || settings_->do_convert_mat) && is_root_xform_) {
 
     if (scale != 1.0f) {
       float scale_mat[4][4];
@@ -141,12 +141,11 @@ bool USDXformReader::prim_has_xform_ops() const
   return !xformable.GetOrderedXformOps(&reset_xform_stack).empty();
 }
 
-bool USDXformReader::is_root_xform_object() const
+bool USDXformReader::is_root_xform_prim() const
 {
-  // It's not sufficient to check for a null parent to determine
-  // if the current object is the root, because the parent could
-  // represent a scope, which is not xformable.  E.g., an Xform
-  // parented to a single Scope would be considered the root.
+  if (!prim_.IsValid()) {
+    return false;
+  }
 
   if (prim_.IsInMaster()) {
     // We don't consider prototypes to be root prims,
@@ -156,22 +155,22 @@ bool USDXformReader::is_root_xform_object() const
   }
 
   if (prim_.IsA<pxr::UsdGeomXformable>()) {
-    // If we don't have an ancestor that also wraps
-    // UsdGeomXformable, then we are the root.
-    const USDPrimReader *cur_parent = parent_reader_;
+    /* If this prim doesn't have an ancestor that's a
+     * UsdGeomXformable, then it's a root prim.  Note
+     * that it's not sufficient to only check the immediate
+     * parent prim, since the immediate parent could be a
+     * UsdGeomScope that has an xformable ancestor. */
+    pxr::UsdPrim cur_parent = prim_.GetParent();
 
     while (cur_parent) {
-      if (cur_parent->prim().IsA<pxr::UsdGeomXformable>()) {
+      if (cur_parent.IsA<pxr::UsdGeomXformable>()) {
         return false;
       }
-      cur_parent = cur_parent->parent();
+      cur_parent = cur_parent.GetParent();
     }
 
-    if (!cur_parent) {
-      // No ancestor prim was an xformable, so we
-      // are the root.
-      return true;
-    }
+    /* We didn't find an xformable ancestor. */
+    return true;
   }
 
   return false;
diff --git a/source/blender/io/usd/intern/usd_reader_xform.h b/source/blender/io/usd/intern/usd_reader_xform.h
index 4afc994157b..194eee8918b 100644
--- a/source/blender/io/usd/intern/usd_reader_xform.h
+++ b/source/blender/io/usd/intern/usd_reader_xform.h
@@ -24,11 +24,17 @@ class USDXformReader : public USDPrimReader {
  private:
   bool use_parent_xform_;
 
+  /* Indicates if the created object is the root of a
+   * transform hierarchy. */
+  bool is_root_xform_;
+
  public:
   USDXformReader(const pxr::UsdPrim &prim,
                  const USDImportParams &import_params,
                  const ImportSettings &settings)
-      : USDPrimReader(prim, import_params, settings), use_parent_xform_(false)
+      : USDPrimReader(prim, import_params, settings),
+        use_parent_xform_(false),
+        is_root_xform_(is_root_xform_prim())
   {
   }
 
@@ -48,9 +54,9 @@ class USDXformReader : public USDPrimReader {
 
   bool prim_has_xform_ops() const;
 
-  // Returns true if this reader represents an object that is the root of the
-  // transform hierarchy.
-  bool is_root_xform_object() const;
+ protected:
+  /* Returns true if the contained USD prim is the root of a transform hierarchy. */
+  bool is_root_xform_prim() const;
 };
 
 }  // namespace blender::io::usd



More information about the Bf-blender-cvs mailing list