[Bf-blender-cvs] [35c37d352ff] usd-importer-T81257: Renamed USDObjectReader to USDXformableReader.

Michael A. Kowalski noreply at git.blender.org
Wed Nov 4 21:11:47 CET 2020


Commit: 35c37d352ff0a7a898c872caf2b6b2e762c33a88
Author: Michael A. Kowalski
Date:   Wed Nov 4 15:01:19 2020 -0500
Branches: usd-importer-T81257
https://developer.blender.org/rB35c37d352ff0a7a898c872caf2b6b2e762c33a88

Renamed USDObjectReader to USDXformableReader.

Miscellaneous additional cleanup, including function
naming convention.

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

M	source/blender/io/usd/import/usd_prim_iterator.cc
M	source/blender/io/usd/import/usd_prim_iterator.h
M	source/blender/io/usd/import/usd_reader_mesh.cc
M	source/blender/io/usd/import/usd_reader_mesh.h
M	source/blender/io/usd/import/usd_reader_object.cc
M	source/blender/io/usd/import/usd_reader_object.h
M	source/blender/io/usd/import/usd_reader_prim.cc
M	source/blender/io/usd/import/usd_reader_prim.h
M	source/blender/io/usd/import/usd_reader_transform.cc
M	source/blender/io/usd/import/usd_reader_transform.h
M	source/blender/io/usd/intern/usd_capi.cc

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

diff --git a/source/blender/io/usd/import/usd_prim_iterator.cc b/source/blender/io/usd/import/usd_prim_iterator.cc
index 45ebd58dac6..4c114621e78 100644
--- a/source/blender/io/usd/import/usd_prim_iterator.cc
+++ b/source/blender/io/usd/import/usd_prim_iterator.cc
@@ -38,10 +38,10 @@
 
 namespace blender::io::usd {
 
-USDObjectReader *USDPrimIterator::get_reader(const pxr::UsdPrim &prim,
-                                             const USDImporterContext &context)
+USDXformableReader *USDPrimIterator::get_reader(const pxr::UsdPrim &prim,
+                                                const USDImporterContext &context)
 {
-  USDObjectReader *result = nullptr;
+  USDXformableReader *result = nullptr;
 
   if (prim.IsA<pxr::UsdGeomMesh>()) {
     result = new USDMeshReader(prim, context);
@@ -55,14 +55,14 @@ USDObjectReader *USDPrimIterator::get_reader(const pxr::UsdPrim &prim,
 
 void USDPrimIterator::create_readers(const pxr::UsdPrim &prim,
                                      const USDImporterContext &context,
-                                     std::vector<USDObjectReader *> &r_readers,
-                                     std::vector<USDObjectReader *> &r_child_readers)
+                                     std::vector<USDXformableReader *> &r_readers,
+                                     std::vector<USDXformableReader *> &r_child_readers)
 {
   if (!prim) {
     return;
   }
 
-  std::vector<USDObjectReader *> child_readers;
+  std::vector<USDXformableReader *> child_readers;
 
   /* Recursively create readers for the child prims. */
   pxr::UsdPrimSiblingRange child_prims = prim.GetFilteredChildren(
@@ -100,10 +100,10 @@ void USDPrimIterator::create_readers(const pxr::UsdPrim &prim,
     return;
   }
 
-  USDObjectReader *reader = get_reader(prim, context);
+  USDXformableReader *reader = get_reader(prim, context);
 
   if (reader) {
-    for (USDObjectReader *child_reader : child_readers) {
+    for (USDXformableReader *child_reader : child_readers) {
       child_reader->set_parent(reader);
     }
     r_child_readers.push_back(reader);
diff --git a/source/blender/io/usd/import/usd_prim_iterator.h b/source/blender/io/usd/import/usd_prim_iterator.h
index 3cfc992f9b4..a1d9a8ad97a 100644
--- a/source/blender/io/usd/import/usd_prim_iterator.h
+++ b/source/blender/io/usd/import/usd_prim_iterator.h
@@ -25,16 +25,17 @@
 namespace blender::io::usd {
 
 struct USDImporterContext;
-class USDObjectReader;
+class USDXformableReader;
 
 class USDPrimIterator {
  public:
-  static USDObjectReader *get_reader(const pxr::UsdPrim &prim, const USDImporterContext &context);
+  static USDXformableReader *get_reader(const pxr::UsdPrim &prim,
+                                        const USDImporterContext &context);
 
   static void create_readers(const pxr::UsdPrim &root,
                              const USDImporterContext &context,
-                             std::vector<USDObjectReader *> &r_readers,
-                             std::vector<USDObjectReader *> &r_child_readers);
+                             std::vector<USDXformableReader *> &r_readers,
+                             std::vector<USDXformableReader *> &r_child_readers);
 
   static void debug_traverse_stage(const pxr::UsdStageRefPtr &usd_stage);
 };
diff --git a/source/blender/io/usd/import/usd_reader_mesh.cc b/source/blender/io/usd/import/usd_reader_mesh.cc
index 67a13a03a47..eac7ac9f88d 100644
--- a/source/blender/io/usd/import/usd_reader_mesh.cc
+++ b/source/blender/io/usd/import/usd_reader_mesh.cc
@@ -331,7 +331,7 @@ void build_mtl_map(const Main *bmain, std::map<std::string, Material *> &mat_map
 }  // anonymous namespace
 
 USDMeshReader::USDMeshReader(const pxr::UsdPrim &prim, const USDImporterContext &context)
-    : USDObjectReader(prim, context), mesh_(prim)
+    : USDXformableReader(prim, context), mesh_(prim)
 {
 }
 
@@ -351,7 +351,14 @@ Mesh *USDMeshReader::read_mesh(Main *bmain, double time)
     return nullptr;
   }
 
-  Mesh *mesh = BKE_mesh_add(bmain, prim_name_.c_str());
+  std::string mesh_name = this->prim_name();
+
+  if (mesh_name.empty()) {
+    /* Sanity check. */
+    std::cerr << "Warning: couldn't determine mesh name for " << this->prim_path() << std::endl;
+  }
+
+  Mesh *mesh = BKE_mesh_add(bmain, mesh_name.c_str());
 
   MeshSampleData mesh_data;
 
@@ -402,7 +409,7 @@ Mesh *USDMeshReader::read_mesh(Main *bmain, double time)
   return mesh;
 }
 
-void USDMeshReader::readObjectData(Main *bmain, double time)
+void USDMeshReader::create_object(Main *bmain, double time)
 {
   if (!this->valid()) {
     return;
@@ -417,7 +424,12 @@ void USDMeshReader::readObjectData(Main *bmain, double time)
     return;
   }
 
-  std::string obj_name = merged_with_parent_ ? prim_parent_name_ : prim_name_;
+  std::string obj_name = merged_with_parent_ ? this->parent_prim_name() : this->prim_name();
+
+  if (obj_name.empty()) {
+    /* Sanity check. */
+    std::cerr << "Warning: couldn't determine object name for " << this->prim_path() << std::endl;
+  }
 
   object_ = BKE_object_add_only_object(bmain, OB_MESH, obj_name.c_str());
   Mesh *mesh = this->read_mesh(bmain, time);
diff --git a/source/blender/io/usd/import/usd_reader_mesh.h b/source/blender/io/usd/import/usd_reader_mesh.h
index 0f6bf502d4e..62a2017fd83 100644
--- a/source/blender/io/usd/import/usd_reader_mesh.h
+++ b/source/blender/io/usd/import/usd_reader_mesh.h
@@ -24,7 +24,7 @@
 
 namespace blender::io::usd {
 
-class USDMeshReader : public USDObjectReader {
+class USDMeshReader : public USDXformableReader {
  protected:
   pxr::UsdGeomMesh mesh_;
 
@@ -35,7 +35,7 @@ class USDMeshReader : public USDObjectReader {
 
   bool valid() const override;
 
-  void readObjectData(Main *bmain, double time) override;
+  void create_object(Main *bmain, double time) override;
 
   struct Mesh *read_mesh(Main *bmain, double time) override;
 
diff --git a/source/blender/io/usd/import/usd_reader_object.cc b/source/blender/io/usd/import/usd_reader_object.cc
index fa2db829b14..5c2fd6f4ef6 100644
--- a/source/blender/io/usd/import/usd_reader_object.cc
+++ b/source/blender/io/usd/import/usd_reader_object.cc
@@ -36,47 +36,26 @@
 
 namespace blender::io::usd {
 
-USDObjectReader::USDObjectReader(const pxr::UsdPrim &prim, const USDImporterContext &context)
-    : USDPrimReader(prim, context),
-      prim_parent_name_(""),
-      prim_name_(""),
-      object_(nullptr),
-      parent_(nullptr),
-      merged_with_parent_(false)
+USDXformableReader::USDXformableReader(const pxr::UsdPrim &prim, const USDImporterContext &context)
+    : USDPrimReader(prim, context), object_(nullptr), parent_(nullptr), merged_with_parent_(false)
 {
-  prim_name_ = prim.GetName().GetString();
-
-  pxr::UsdPrim parent = prim.GetParent();
-  prim_parent_name_ = parent ? parent.GetName().GetString() : prim_name_;
 }
 
-USDObjectReader::~USDObjectReader()
+USDXformableReader::~USDXformableReader()
 {
 }
 
-Object *USDObjectReader::object() const
+Object *USDXformableReader::object() const
 {
   return object_;
 }
 
-void USDObjectReader::setObject(Object *ob)
-{
-  object_ = ob;
-}
-
-struct Mesh *USDObjectReader::read_mesh(Main *UNUSED(bmain), double UNUSED(time))
+struct Mesh *USDXformableReader::read_mesh(Main *UNUSED(bmain), double UNUSED(time))
 {
   return nullptr;
 }
 
-bool USDObjectReader::topology_changed(Mesh * /*existing_mesh*/, double /*time*/)
-{
-  /* The default implementation of read_mesh() just returns the original mesh, so never changes the
-   * topology. */
-  return false;
-}
-
-void USDObjectReader::setupObjectTransform(const double time)
+void USDXformableReader::setup_object_transform(const double time)
 {
   if (!this->object_) {
     return;
@@ -94,10 +73,10 @@ void USDObjectReader::setupObjectTransform(const double time)
   /* TODO(makowalski):  Set up transform constraint if not constant. */
 }
 
-void USDObjectReader::read_matrix(float r_mat[4][4] /* local matrix */,
-                                  const double time,
-                                  const float scale,
-                                  bool &is_constant)
+void USDXformableReader::read_matrix(float r_mat[4][4] /* local matrix */,
+                                     const double time,
+                                     const float scale,
+                                     bool &is_constant)
 {
   pxr::UsdGeomXformable xformable(prim_);
 
diff --git a/source/blender/io/usd/import/usd_reader_object.h b/source/blender/io/usd/import/usd_reader_object.h
index 3e796900276..4e248cea4ce 100644
--- a/source/blender/io/usd/import/usd_reader_object.h
+++ b/source/blender/io/usd/import/usd_reader_object.h
@@ -31,38 +31,28 @@ struct Object;
 
 namespace blender::io::usd {
 
-class USDObjectReader : public USDPrimReader {
- public:
-  typedef std::vector<USDObjectReader *> ptr_vector;
+class USDXformableReader : public USDPrimReader {
 
  protected:
-  /* The USD prim parent name. */
-  std::string prim_parent_name_;
-
-  /* The USD prim name. */
-  std::string prim_name_;
-
   Object *object_;
 
-  USDObjectReader *parent_;
+  USDXformableReader *parent_;
 
   bool merged_with_parent_;
 
  public:
-  explicit USDObjectReader(const pxr::UsdPrim &prim, const USDImporterContext &context);
+  explicit USDXformableReader(const pxr::UsdPrim &prim, const USDImporterContext &context);
 
-  virtual ~USDObjectReader();
+  virtual ~USDXformableReader();
 
   Object *object() const;
 
-  void setObject(Object *ob);
-
-  USDObjectReader *parent() const
+  USDXformableReader *parent() const
   {
     return parent_;
   }
 
-  void set_parent(USDObjectReader *par)
+  void set_parent(USDXformableReader *par)
   {
     parent_ = par;
   }
@@ -77,25 +67,14 @@ class USDObjectReader : public USDPrimReader {
     return merged_with_parent_;
   }
 
-  const std::string &prim_parent_name() const
-  {
-    return prim_parent_name_;
-  }
-  const std::string &prim_name() const
-  {
-    return prim_name_;
-  }
-
   virtual bool valid() const = 0;
 
-  virtual void readObjectData(Main *bmain, double time) = 0;
+  virtual void create_object(Main *bmain, double time) = 0;
 
   virtual struct Mesh *read_mesh(Main *bmain, double time);
 
-  virtual bool topology_changed(Mesh *existing_mesh,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list