[Bf-blender-cvs] [035cf7c208a] temp-sybren-usd-patch-02: USD: Fix exporting of meshes of dupli-objects

Sybren A. Stüvel noreply at git.blender.org
Wed Dec 11 16:37:05 CET 2019


Commit: 035cf7c208a81482145eccdb561b1e71a13668ea
Author: Sybren A. Stüvel
Date:   Wed Dec 11 14:07:31 2019 +0100
Branches: temp-sybren-usd-patch-02
https://developer.blender.org/rB035cf7c208a81482145eccdb561b1e71a13668ea

USD: Fix exporting of meshes of dupli-objects

The dupliobject's `base_flag` variable needed to be copied from its
duplicator.

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

M	source/blender/usd/intern/usd_hierarchy_iterator.cc
M	source/blender/usd/intern/usd_writer_abstract.cc
M	source/blender/usd/intern/usd_writer_abstract.h
M	source/blender/usd/intern/usd_writer_camera.cc
M	source/blender/usd/intern/usd_writer_camera.h
M	source/blender/usd/intern/usd_writer_light.cc
M	source/blender/usd/intern/usd_writer_light.h
M	source/blender/usd/intern/usd_writer_mesh.cc
M	source/blender/usd/intern/usd_writer_mesh.h

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

diff --git a/source/blender/usd/intern/usd_hierarchy_iterator.cc b/source/blender/usd/intern/usd_hierarchy_iterator.cc
index c7531b74a4f..da69aa4a506 100644
--- a/source/blender/usd/intern/usd_hierarchy_iterator.cc
+++ b/source/blender/usd/intern/usd_hierarchy_iterator.cc
@@ -123,7 +123,7 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_data_writer(const Hierarch
       return nullptr;
   }
 
-  if (!data_writer->is_supported(context->object)) {
+  if (!data_writer->is_supported(context)) {
     delete data_writer;
     return nullptr;
   }
diff --git a/source/blender/usd/intern/usd_writer_abstract.cc b/source/blender/usd/intern/usd_writer_abstract.cc
index ff8f3c83ed0..00e7ef050f1 100644
--- a/source/blender/usd/intern/usd_writer_abstract.cc
+++ b/source/blender/usd/intern/usd_writer_abstract.cc
@@ -51,7 +51,7 @@ USDAbstractWriter::~USDAbstractWriter()
 {
 }
 
-bool USDAbstractWriter::is_supported(const Object * /*object*/) const
+bool USDAbstractWriter::is_supported(const HierarchyContext * /*context*/) const
 {
   return true;
 }
diff --git a/source/blender/usd/intern/usd_writer_abstract.h b/source/blender/usd/intern/usd_writer_abstract.h
index b48a69e4942..3c022ecf4a5 100644
--- a/source/blender/usd/intern/usd_writer_abstract.h
+++ b/source/blender/usd/intern/usd_writer_abstract.h
@@ -59,7 +59,7 @@ class USDAbstractWriter : public AbstractHierarchyWriter {
    * being exported. Returning false from a data writer (object data, hair, or particles) will
    * only prevent that data from being written (and thus cause the object to be exported as an
    * Empty). */
-  virtual bool is_supported(const Object *object) const;
+  virtual bool is_supported(const HierarchyContext *context) const;
 
   const pxr::SdfPath &usd_path() const;
 
diff --git a/source/blender/usd/intern/usd_writer_camera.cc b/source/blender/usd/intern/usd_writer_camera.cc
index 2f7a3d27a54..fa1db6ad39a 100644
--- a/source/blender/usd/intern/usd_writer_camera.cc
+++ b/source/blender/usd/intern/usd_writer_camera.cc
@@ -34,9 +34,9 @@ USDCameraWriter::USDCameraWriter(const USDExporterContext &ctx) : USDAbstractWri
 {
 }
 
-bool USDCameraWriter::is_supported(const Object *object) const
+bool USDCameraWriter::is_supported(const HierarchyContext *context) const
 {
-  Camera *camera = static_cast<Camera *>(object->data);
+  Camera *camera = static_cast<Camera *>(context->object->data);
   return camera->type == CAM_PERSP;
 }
 
diff --git a/source/blender/usd/intern/usd_writer_camera.h b/source/blender/usd/intern/usd_writer_camera.h
index fc06dbb54f1..98421b14af7 100644
--- a/source/blender/usd/intern/usd_writer_camera.h
+++ b/source/blender/usd/intern/usd_writer_camera.h
@@ -27,7 +27,7 @@ class USDCameraWriter : public USDAbstractWriter {
   USDCameraWriter(const USDExporterContext &ctx);
 
  protected:
-  virtual bool is_supported(const Object *object) const override;
+  virtual bool is_supported(const HierarchyContext *context) const override;
   virtual void do_write(HierarchyContext &context) override;
 };
 
diff --git a/source/blender/usd/intern/usd_writer_light.cc b/source/blender/usd/intern/usd_writer_light.cc
index 3fe78984f69..d505b7dbb5e 100644
--- a/source/blender/usd/intern/usd_writer_light.cc
+++ b/source/blender/usd/intern/usd_writer_light.cc
@@ -36,9 +36,9 @@ USDLightWriter::USDLightWriter(const USDExporterContext &ctx) : USDAbstractWrite
 {
 }
 
-bool USDLightWriter::is_supported(const Object *object) const
+bool USDLightWriter::is_supported(const HierarchyContext *context) const
 {
-  Light *light = static_cast<Light *>(object->data);
+  Light *light = static_cast<Light *>(context->object->data);
   return ELEM(light->type, LA_AREA, LA_LOCAL, LA_SUN);
 }
 
diff --git a/source/blender/usd/intern/usd_writer_light.h b/source/blender/usd/intern/usd_writer_light.h
index 9126435bc3c..6a0710b7dff 100644
--- a/source/blender/usd/intern/usd_writer_light.h
+++ b/source/blender/usd/intern/usd_writer_light.h
@@ -26,7 +26,7 @@ class USDLightWriter : public USDAbstractWriter {
   USDLightWriter(const USDExporterContext &ctx);
 
  protected:
-  virtual bool is_supported(const Object *object) const override;
+  virtual bool is_supported(const HierarchyContext *context) const override;
   virtual void do_write(HierarchyContext &context) override;
 };
 
diff --git a/source/blender/usd/intern/usd_writer_mesh.cc b/source/blender/usd/intern/usd_writer_mesh.cc
index 8150721eba6..9ff0be0d850 100644
--- a/source/blender/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/usd/intern/usd_writer_mesh.cc
@@ -37,6 +37,7 @@ extern "C" {
 
 #include "DEG_depsgraph.h"
 
+#include "DNA_layer_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
@@ -48,10 +49,28 @@ USDGenericMeshWriter::USDGenericMeshWriter(const USDExporterContext &ctx) : USDA
 {
 }
 
-bool USDGenericMeshWriter::is_supported(const Object *object) const
+bool USDGenericMeshWriter::is_supported(const HierarchyContext *context) const
 {
+  Object *object = context->object;
+  bool is_dupli = context->duplicator != nullptr;
+  int base_flag;
+
+  if (is_dupli) {
+    /* Construct the object's base flags from its dupliparent, just like is done in
+     * deg_objects_dupli_iterator_next(). Without this, the visiblity check below will fail. Doing
+     * this here, instead of a more suitable location in AbstractHierarchyIterator, prevents
+     * copying the Object for every dupli. */
+    base_flag = object->base_flag;
+    object->base_flag = context->duplicator->base_flag | BASE_FROM_DUPLI;
+  }
+
   int visibility = BKE_object_visibility(object,
                                          usd_export_context_.export_params.evaluation_mode);
+
+  if (is_dupli) {
+    object->base_flag = base_flag;
+  }
+
   return (visibility & OB_VISIBLE_SELF) != 0;
 }
 
diff --git a/source/blender/usd/intern/usd_writer_mesh.h b/source/blender/usd/intern/usd_writer_mesh.h
index 917e5fe6eb3..e57154556f6 100644
--- a/source/blender/usd/intern/usd_writer_mesh.h
+++ b/source/blender/usd/intern/usd_writer_mesh.h
@@ -31,7 +31,7 @@ class USDGenericMeshWriter : public USDAbstractWriter {
   USDGenericMeshWriter(const USDExporterContext &ctx);
 
  protected:
-  virtual bool is_supported(const Object *object) const override;
+  virtual bool is_supported(const HierarchyContext *context) const override;
   virtual void do_write(HierarchyContext &context) override;
 
   virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) = 0;



More information about the Bf-blender-cvs mailing list