[Bf-blender-cvs] [0f27fe17d5d] sybren-usd: USD: No longer unpack USDExporterContext struct

Sybren A. Stüvel noreply at git.blender.org
Tue Nov 12 18:11:52 CET 2019


Commit: 0f27fe17d5db920edd925e4b2af70bbd73c9b059
Author: Sybren A. Stüvel
Date:   Tue Nov 12 17:31:21 2019 +0100
Branches: sybren-usd
https://developer.blender.org/rB0f27fe17d5db920edd925e4b2af70bbd73c9b059

USD: No longer unpack USDExporterContext struct

The `USDExporterContext` struct contents were duplicated in the
`USDAbstractWriter` member properties, a decision which in retrospect I
don't agree with.

No functional changes.

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

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_hair.cc
M	source/blender/usd/intern/usd_writer_light.cc
M	source/blender/usd/intern/usd_writer_mesh.cc
M	source/blender/usd/intern/usd_writer_transform.cc

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

diff --git a/source/blender/usd/intern/usd_writer_abstract.cc b/source/blender/usd/intern/usd_writer_abstract.cc
index c7c2496ea33..9222563e889 100644
--- a/source/blender/usd/intern/usd_writer_abstract.cc
+++ b/source/blender/usd/intern/usd_writer_abstract.cc
@@ -11,13 +11,7 @@ extern "C" {
 }
 
 USDAbstractWriter::USDAbstractWriter(const USDExporterContext &usd_export_context)
-    : depsgraph(usd_export_context.depsgraph),
-      stage(usd_export_context.stage),
-      usd_path_(usd_export_context.usd_path),
-      hierarchy_iterator(usd_export_context.hierarchy_iterator),
-      export_params(usd_export_context.export_params),
-      frame_has_been_written_(false),
-      is_animated_(false)
+    : usd_export_context_(usd_export_context), frame_has_been_written_(false), is_animated_(false)
 {
 }
 
@@ -33,7 +27,7 @@ bool USDAbstractWriter::is_supported(const Object * /*object*/) const
 pxr::UsdTimeCode USDAbstractWriter::get_export_time_code() const
 {
   if (is_animated_) {
-    return hierarchy_iterator->get_export_time_code();
+    return usd_export_context_.hierarchy_iterator->get_export_time_code();
   }
   // By using the default timecode USD won't even write a single `timeSample` for non-animated
   // data. Instead, it writes it as non-timesampled.
@@ -44,10 +38,11 @@ pxr::UsdTimeCode USDAbstractWriter::get_export_time_code() const
 void USDAbstractWriter::write(HierarchyContext &context)
 {
   if (!frame_has_been_written_) {
-    is_animated_ = export_params.export_animation && check_is_animated(context);
+    is_animated_ = usd_export_context_.export_params.export_animation &&
+                   check_is_animated(context);
   }
   else if (!is_animated_) {
-    /* A frame has alrady been written, and without animation one frame is enough. */
+    /* A frame has already been written, and without animation one frame is enough. */
     return;
   }
 
@@ -87,15 +82,16 @@ bool USDAbstractWriter::check_is_animated(const HierarchyContext &context) const
 
 const pxr::SdfPath &USDAbstractWriter::usd_path() const
 {
-  return usd_path_;
+  return usd_export_context_.usd_path;
 }
 
 pxr::UsdShadeMaterial USDAbstractWriter::ensure_usd_material(Material *material)
 {
   static pxr::SdfPath material_library_path("/_materials");
+  pxr::UsdStageRefPtr stage = usd_export_context_.stage;
 
   // Construct the material.
-  pxr::TfToken material_name(hierarchy_iterator->get_id_name(&material->id));
+  pxr::TfToken material_name(usd_export_context_.hierarchy_iterator->get_id_name(&material->id));
   pxr::SdfPath usd_path = material_library_path.AppendChild(material_name);
   pxr::UsdShadeMaterial usd_material = pxr::UsdShadeMaterial::Get(stage, usd_path);
   if (usd_material) {
diff --git a/source/blender/usd/intern/usd_writer_abstract.h b/source/blender/usd/intern/usd_writer_abstract.h
index 667baf0dc43..dfb43fbcc4d 100644
--- a/source/blender/usd/intern/usd_writer_abstract.h
+++ b/source/blender/usd/intern/usd_writer_abstract.h
@@ -21,11 +21,8 @@ struct Object;
 
 class USDAbstractWriter : public AbstractHierarchyWriter {
  protected:
-  Depsgraph *depsgraph;
-  pxr::UsdStageRefPtr stage;
-  pxr::SdfPath usd_path_;
-  USDHierarchyIterator *const hierarchy_iterator;
-  const USDExportParams &export_params;
+  const USDExporterContext usd_export_context_;
+
   bool frame_has_been_written_;
   bool is_animated_;
 
diff --git a/source/blender/usd/intern/usd_writer_camera.cc b/source/blender/usd/intern/usd_writer_camera.cc
index 4fe52deb664..ad1c0ad9d4f 100644
--- a/source/blender/usd/intern/usd_writer_camera.cc
+++ b/source/blender/usd/intern/usd_writer_camera.cc
@@ -24,10 +24,11 @@ bool USDCameraWriter::is_supported(const Object *object) const
 void USDCameraWriter::do_write(HierarchyContext &context)
 {
   pxr::UsdTimeCode timecode = get_export_time_code();
-  pxr::UsdGeomCamera usd_camera = pxr::UsdGeomCamera::Define(stage, usd_path_);
+  pxr::UsdGeomCamera usd_camera = pxr::UsdGeomCamera::Define(usd_export_context_.stage,
+                                                             usd_export_context_.usd_path);
 
   Camera *camera = static_cast<Camera *>(context.object->data);
-  Scene *scene = DEG_get_evaluated_scene(depsgraph);
+  Scene *scene = DEG_get_evaluated_scene(usd_export_context_.depsgraph);
 
   usd_camera.CreateProjectionAttr().Set(pxr::UsdGeomTokens->perspective);
 
diff --git a/source/blender/usd/intern/usd_writer_hair.cc b/source/blender/usd/intern/usd_writer_hair.cc
index cd46be4af64..d27aca8a0cd 100644
--- a/source/blender/usd/intern/usd_writer_hair.cc
+++ b/source/blender/usd/intern/usd_writer_hair.cc
@@ -23,7 +23,8 @@ void USDHairWriter::do_write(HierarchyContext &context)
   }
 
   pxr::UsdTimeCode timecode = get_export_time_code();
-  pxr::UsdGeomBasisCurves curves = pxr::UsdGeomBasisCurves::Define(stage, usd_path_);
+  pxr::UsdGeomBasisCurves curves = pxr::UsdGeomBasisCurves::Define(usd_export_context_.stage,
+                                                                   usd_export_context_.usd_path);
 
   // TODO(Sybren): deal with (psys->part->flag & PART_HAIR_BSPLINE)
   curves.CreateBasisAttr(pxr::VtValue(pxr::UsdGeomTokens->bspline));
diff --git a/source/blender/usd/intern/usd_writer_light.cc b/source/blender/usd/intern/usd_writer_light.cc
index bbba8c7ab89..08d722c6c67 100644
--- a/source/blender/usd/intern/usd_writer_light.cc
+++ b/source/blender/usd/intern/usd_writer_light.cc
@@ -26,6 +26,8 @@ bool USDLightWriter::is_supported(const Object *object) const
 
 void USDLightWriter::do_write(HierarchyContext &context)
 {
+  pxr::UsdStageRefPtr stage = usd_export_context_.stage;
+  const pxr::SdfPath &usd_path = usd_export_context_.usd_path;
   pxr::UsdTimeCode timecode = get_export_time_code();
 
   Light *light = static_cast<Light *>(context.object->data);
@@ -36,20 +38,20 @@ void USDLightWriter::do_write(HierarchyContext &context)
       switch (light->area_shape) {
         case LA_AREA_DISK:
         case LA_AREA_ELLIPSE: { /* An ellipse light will deteriorate into a disk light. */
-          pxr::UsdLuxDiskLight disk_light = pxr::UsdLuxDiskLight::Define(stage, usd_path_);
+          pxr::UsdLuxDiskLight disk_light = pxr::UsdLuxDiskLight::Define(stage, usd_path);
           disk_light.CreateRadiusAttr().Set(light->area_size, timecode);
           usd_light = disk_light;
           break;
         }
         case LA_AREA_RECT: {
-          pxr::UsdLuxRectLight rect_light = pxr::UsdLuxRectLight::Define(stage, usd_path_);
+          pxr::UsdLuxRectLight rect_light = pxr::UsdLuxRectLight::Define(stage, usd_path);
           rect_light.CreateWidthAttr().Set(light->area_size, timecode);
           rect_light.CreateHeightAttr().Set(light->area_sizey, timecode);
           usd_light = rect_light;
           break;
         }
         case LA_AREA_SQUARE: {
-          pxr::UsdLuxRectLight rect_light = pxr::UsdLuxRectLight::Define(stage, usd_path_);
+          pxr::UsdLuxRectLight rect_light = pxr::UsdLuxRectLight::Define(stage, usd_path);
           rect_light.CreateWidthAttr().Set(light->area_size, timecode);
           rect_light.CreateHeightAttr().Set(light->area_size, timecode);
           usd_light = rect_light;
@@ -58,13 +60,13 @@ void USDLightWriter::do_write(HierarchyContext &context)
       }
       break;
     case LA_LOCAL: {
-      pxr::UsdLuxSphereLight sphere_light = pxr::UsdLuxSphereLight::Define(stage, usd_path_);
+      pxr::UsdLuxSphereLight sphere_light = pxr::UsdLuxSphereLight::Define(stage, usd_path);
       sphere_light.CreateRadiusAttr().Set(light->area_size, timecode);
       usd_light = sphere_light;
       break;
     }
     case LA_SUN:
-      usd_light = pxr::UsdLuxDistantLight::Define(stage, usd_path_);
+      usd_light = pxr::UsdLuxDistantLight::Define(stage, usd_path);
       break;
     default:
       BLI_assert(!"is_supported() returned true for unsupported light type");
diff --git a/source/blender/usd/intern/usd_writer_mesh.cc b/source/blender/usd/intern/usd_writer_mesh.cc
index 83de0a528e9..3c6c6e5934c 100644
--- a/source/blender/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/usd/intern/usd_writer_mesh.cc
@@ -33,8 +33,9 @@ bool USDGenericMeshWriter::is_supported(const Object *object) const
 {
   // Reject meshes that have a particle system that should have its emitter hidden.
   if (object->particlesystem.first != NULL) {
-    char check_flag = export_params.evaluation_mode == DAG_EVAL_RENDER ? OB_DUPLI_FLAG_RENDER :
-                                                                         OB_DUPLI_FLAG_VIEWPORT;
+    char check_flag = usd_export_context_.export_params.evaluation_mode == DAG_EVAL_RENDER ?
+                          OB_DUPLI_FLAG_RENDER :
+                          OB_DUPLI_FLAG_VIEWPORT;
     return object->duplicator_visibility_flag & check_flag;
   }
 
@@ -125,12 +126,14 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_
 void USDGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh)
 {
   pxr::UsdTimeCode timecode = get_export_time_code();
+  pxr::UsdStageRefPtr stage = usd_export_context_.stage;
+  const pxr::SdfPath &usd_path = usd_export_context_.usd_path;
 
-  pxr::UsdGeomMesh usd_mesh = pxr::UsdGeomMesh::Define(stage, usd_path_);
+  pxr::UsdGeomMesh usd_mesh = pxr::UsdGeomMesh::Define(stage, usd_path);
   USDMeshData usd_mesh_data;
   get_geometry_data(mesh, usd_mesh_data);
 
-  if (export_params.use_instancing && context.is_instance()) {
+  if (usd_export_context_.export_params.use_instancing && context.is_instance()) {
     // This object data is instanced, just reference the original instead of writing a copy.
     if (context.export_path == context.original_export_path) {
       printf("USD ref error: export path is reference path: %s\n", context.export_path.c_str());
@@ -151,7 +154,7 @@ void USDGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh)
     subtree pointed to by ref_path. As a result, the referenced data is not allowed to point out
     of its own subtree. It does work when we override the material with exactly the same path,
     though.*/
-    if (export_params.export_materials) {
+    if (usd_export_context_.export_params.export_materials) {
       assign_materials(context, u

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list