[Bf-blender-cvs] [fa5306c9b16] usd-importer-T81257: USD importer: new USDPrimReader base class.

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


Commit: fa5306c9b16d6ff2c0c452f7331067c93612b53a
Author: Michael A. Kowalski
Date:   Tue Nov 3 21:32:00 2020 -0500
Branches: usd-importer-T81257
https://developer.blender.org/rBfa5306c9b16d6ff2c0c452f7331067c93612b53a

USD importer: new USDPrimReader base class.

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

M	source/blender/io/usd/CMakeLists.txt
M	source/blender/io/usd/import/usd_reader_object.cc
M	source/blender/io/usd/import/usd_reader_object.h
A	source/blender/io/usd/import/usd_reader_prim.cc
A	source/blender/io/usd/import/usd_reader_prim.h
M	source/blender/io/usd/intern/usd_capi.cc

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

diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt
index 1a0f85fcef8..973072e5c1c 100644
--- a/source/blender/io/usd/CMakeLists.txt
+++ b/source/blender/io/usd/CMakeLists.txt
@@ -57,6 +57,7 @@ set(SRC
   import/usd_import_util.cc
   import/usd_prim_iterator.cc
   import/usd_reader_mesh.cc
+  import/usd_reader_prim.cc
   import/usd_reader_object.cc
   import/usd_reader_transform.cc
   intern/usd_capi.cc
@@ -74,6 +75,7 @@ set(SRC
   import/usd_import_util.h
   import/usd_prim_iterator.h
   import/usd_reader_mesh.h
+  import/usd_reader_prim.h
   import/usd_reader_object.h
   import/usd_reader_transform.h
   intern/usd_exporter_context.h
diff --git a/source/blender/io/usd/import/usd_reader_object.cc b/source/blender/io/usd/import/usd_reader_object.cc
index 733f1971994..fa2db829b14 100644
--- a/source/blender/io/usd/import/usd_reader_object.cc
+++ b/source/blender/io/usd/import/usd_reader_object.cc
@@ -20,15 +20,9 @@
 #include "usd_reader_object.h"
 #include "usd_import_util.h"
 
-#include "DNA_cachefile_types.h"
-#include "DNA_constraint_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_space_types.h" /* for FILE_MAX */
-
-#include "BKE_constraint.h"
 #include "BKE_lib_id.h"
-#include "BKE_modifier.h"
 #include "BKE_object.h"
+#include "DNA_object_types.h"
 
 #include "BLI_listbase.h"
 #include "BLI_math_geom.h"
@@ -43,19 +37,13 @@
 namespace blender::io::usd {
 
 USDObjectReader::USDObjectReader(const pxr::UsdPrim &prim, const USDImporterContext &context)
-    : prim_path_(""),
+    : USDPrimReader(prim, context),
       prim_parent_name_(""),
       prim_name_(""),
       object_(nullptr),
-      prim_(prim),
-      context_(context),
-      min_time_(std::numeric_limits<double>::max()),
-      max_time_(std::numeric_limits<double>::min()),
-      refcount_(0),
       parent_(nullptr),
       merged_with_parent_(false)
 {
-  prim_path_ = prim.GetPath().GetString();
   prim_name_ = prim.GetName().GetString();
 
   pxr::UsdPrim parent = prim.GetParent();
@@ -66,11 +54,6 @@ USDObjectReader::~USDObjectReader()
 {
 }
 
-const pxr::UsdPrim &USDObjectReader::prim() const
-{
-  return prim_;
-}
-
 Object *USDObjectReader::object() const
 {
   return object_;
@@ -164,30 +147,4 @@ void USDObjectReader::read_matrix(float r_mat[4][4] /* local matrix */,
   }
 }
 
-double USDObjectReader::minTime() const
-{
-  return min_time_;
-}
-
-double USDObjectReader::maxTime() const
-{
-  return max_time_;
-}
-
-int USDObjectReader::refcount() const
-{
-  return refcount_;
-}
-
-void USDObjectReader::incref()
-{
-  refcount_++;
-}
-
-void USDObjectReader::decref()
-{
-  refcount_--;
-  BLI_assert(refcount_ >= 0);
-}
-
 } /* namespace blender::io::usd */
diff --git a/source/blender/io/usd/import/usd_reader_object.h b/source/blender/io/usd/import/usd_reader_object.h
index 9c6ec1cce2c..3e796900276 100644
--- a/source/blender/io/usd/import/usd_reader_object.h
+++ b/source/blender/io/usd/import/usd_reader_object.h
@@ -20,8 +20,7 @@
 
 #include "usd.h"
 #include "usd_importer_context.h"
-
-#include <pxr/usd/usd/prim.h>
+#include "usd_reader_prim.h"
 
 #include <string>
 #include <vector>
@@ -32,14 +31,11 @@ struct Object;
 
 namespace blender::io::usd {
 
-class USDObjectReader {
+class USDObjectReader : public USDPrimReader {
  public:
   typedef std::vector<USDObjectReader *> ptr_vector;
 
  protected:
-  /* The USD prim path. */
-  std::string prim_path_;
-
   /* The USD prim parent name. */
   std::string prim_parent_name_;
 
@@ -47,17 +43,6 @@ class USDObjectReader {
   std::string prim_name_;
 
   Object *object_;
-  pxr::UsdPrim prim_;
-
-  USDImporterContext context_;
-
-  /* Not setting min/max time yet. */
-  double min_time_;
-  double max_time_;
-
-  /* Use reference counting since the same reader may be used by multiple
-   * modifiers and/or constraints. */
-  int refcount_;
 
   USDObjectReader *parent_;
 
@@ -68,8 +53,6 @@ class USDObjectReader {
 
   virtual ~USDObjectReader();
 
-  const pxr::UsdPrim &prim() const;
-
   Object *object() const;
 
   void setObject(Object *ob);
@@ -94,10 +77,6 @@ class USDObjectReader {
     return merged_with_parent_;
   }
 
-  const std::string &prim_path() const
-  {
-    return prim_path_;
-  }
   const std::string &prim_parent_name() const
   {
     return prim_parent_name_;
@@ -118,13 +97,6 @@ class USDObjectReader {
   /* Reads the object matrix and sets up an object transform if animated. */
   void setupObjectTransform(const double time);
 
-  double minTime() const;
-  double maxTime() const;
-
-  int refcount() const;
-  void incref();
-  void decref();
-
   void read_matrix(float r_mat[4][4], const double time, const float scale, bool &is_constant);
 };
 
diff --git a/source/blender/io/usd/import/usd_reader_prim.cc b/source/blender/io/usd/import/usd_reader_prim.cc
new file mode 100644
index 00000000000..d51fe39bb7e
--- /dev/null
+++ b/source/blender/io/usd/import/usd_reader_prim.cc
@@ -0,0 +1,73 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+#include "usd_reader_prim.h"
+#include "BLI_assert.h"
+
+namespace blender::io::usd {
+
+USDPrimReader::USDPrimReader(const pxr::UsdPrim &prim, const USDImporterContext &context)
+  : prim_(prim),
+    prim_path_(""),
+    context_(context),
+    min_time_(std::numeric_limits<double>::max()),
+    max_time_(std::numeric_limits<double>::min()),
+    refcount_(0)
+{
+  if (prim) {
+    prim_path_ = prim.GetPath().GetString();
+  }
+}
+
+USDPrimReader::~USDPrimReader()
+{
+}
+
+const pxr::UsdPrim &USDPrimReader::prim() const
+{
+  return prim_;
+}
+
+double USDPrimReader::min_time() const
+{
+  return min_time_;
+}
+
+double USDPrimReader::max_time() const
+{
+  return max_time_;
+}
+
+int USDPrimReader::refcount() const
+{
+  return refcount_;
+}
+
+void USDPrimReader::incref()
+{
+  refcount_++;
+}
+
+void USDPrimReader::decref()
+{
+  refcount_--;
+  BLI_assert(refcount_ >= 0);
+}
+
+} /* namespace blender::io::usd */
diff --git a/source/blender/io/usd/import/usd_reader_prim.h b/source/blender/io/usd/import/usd_reader_prim.h
new file mode 100644
index 00000000000..9c5b1f9de28
--- /dev/null
+++ b/source/blender/io/usd/import/usd_reader_prim.h
@@ -0,0 +1,68 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd.h"
+#include "usd_importer_context.h"
+
+#include <pxr/usd/usd/prim.h>
+
+namespace blender::io::usd {
+
+class USDPrimReader {
+
+protected:
+  pxr::UsdPrim prim_;
+
+  /* The USD prim path. */
+  std::string prim_path_;
+
+  USDImporterContext context_;
+
+  /* Not setting min/max time yet. */
+  double min_time_;
+  double max_time_;
+
+  /* Use reference counting since the same reader may be used by multiple
+  * modifiers and/or constraints. */
+  int refcount_;
+
+public:
+  explicit USDPrimReader(const pxr::UsdPrim &prim, const USDImporterContext &context);
+
+  virtual ~USDPrimReader();
+
+  const pxr::UsdPrim &prim() const;
+
+  const std::string &prim_path() const
+  {
+    return prim_path_;
+  }
+
+  virtual bool valid() const = 0;
+
+  double min_time() const;
+  double max_time() const;
+
+  int refcount() const;
+  void incref();
+  void decref();
+};
+
+} /* namespace blender::io::usd */
diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc
index 2e2377375ca..446701fdbaa 100644
--- a/source/blender/io/usd/intern/usd_capi.cc
+++ b/source/blender/io/usd/intern/usd_capi.cc
@@ -282,9 +282,6 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
   const float size = static_cast<float>(data->readers.size());
   size_t i = 0;
 
-  double min_time = std::numeric_limits<double>::max();
-  double max_time = std::numeric_limits<double>::min();
-
   double time = CFRA;
 
   std::vector<USDObjectReader *>::iterator iter;
@@ -293,9 +290,6 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
 
     if (reader->valid()) {
       reader->readObjectData(data->bmain, time);
-
-      min_time = std::min(min_time, reader->minTime());
-      max_time = std::max(max_time, reader->maxTime());
     }
     else {
       std::cerr << "Object " << reader->prim_path() << " in USD file " << data->filename



More information about the Bf-blender-cvs mailing list