Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2020-09-08 12:33:35 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-09-08 12:33:35 +0300
commit63dc72c35215d38c437a5d20a8dc8f6e25e1fc8c (patch)
tree228683e5201e83ad39913f3d277a49a634d6b360 /source/blender/io
parentb8d4a2aff8069dd7d6fb91ad0d9427eed489b68f (diff)
Cleanup: USD export, refactor mesh instancing
Extract the mesh instancing code from the mesh writing function into a generic 'mark as instance' function on the abstract USD writer. This will help in supporting non-mesh instances. No functional changes.
Diffstat (limited to 'source/blender/io')
-rw-r--r--source/blender/io/usd/intern/usd_writer_abstract.cc27
-rw-r--r--source/blender/io/usd/intern/usd_writer_abstract.h4
-rw-r--r--source/blender/io/usd/intern/usd_writer_mesh.cc23
3 files changed, 37 insertions, 17 deletions
diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc
index 4910b7f11dd..082a60d102e 100644
--- a/source/blender/io/usd/intern/usd_writer_abstract.cc
+++ b/source/blender/io/usd/intern/usd_writer_abstract.cc
@@ -21,6 +21,8 @@
#include <pxr/base/tf/stringUtils.h>
+#include "BLI_assert.h"
+
/* TfToken objects are not cheap to construct, so we do it once. */
namespace usdtokens {
// Materials
@@ -128,6 +130,31 @@ void USDAbstractWriter::write_visibility(const HierarchyContext &context,
usd_value_writer_.SetAttribute(attr_visibility, pxr::VtValue(visibility), timecode);
}
+/* Reference the original data instead of writing a copy. */
+bool USDAbstractWriter::mark_as_instance(HierarchyContext &context, const pxr::UsdPrim &prim)
+{
+ BLI_assert(context.is_instance());
+
+ if (context.export_path == context.original_export_path) {
+ printf("USD ref error: export path is reference path: %s\n", context.export_path.c_str());
+ BLI_assert(!"USD reference error");
+ return false;
+ }
+
+ pxr::SdfPath ref_path(context.original_export_path);
+ if (!prim.GetReferences().AddInternalReference(ref_path)) {
+ /* See this URL for a description fo why referencing may fail"
+ * https://graphics.pixar.com/usd/docs/api/class_usd_references.html#Usd_Failing_References
+ */
+ printf("USD Export warning: unable to add reference from %s to %s, not instancing object\n",
+ context.export_path.c_str(),
+ context.original_export_path.c_str());
+ return false;
+ }
+
+ return true;
+}
+
} // namespace usd
} // namespace io
} // namespace blender
diff --git a/source/blender/io/usd/intern/usd_writer_abstract.h b/source/blender/io/usd/intern/usd_writer_abstract.h
index 248bdd22a3b..f702768f734 100644
--- a/source/blender/io/usd/intern/usd_writer_abstract.h
+++ b/source/blender/io/usd/intern/usd_writer_abstract.h
@@ -76,6 +76,10 @@ class USDAbstractWriter : public AbstractHierarchyWriter {
void write_visibility(const HierarchyContext &context,
const pxr::UsdTimeCode timecode,
pxr::UsdGeomImageable &usd_geometry);
+
+ /* Turn `prim` into an instance referencing `context.original_export_path`.
+ * Return true when the instancing was succesful, false otherwise. */
+ virtual bool mark_as_instance(HierarchyContext &context, const pxr::UsdPrim &prim);
};
} // namespace usd
diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc
index 7d3ea911a65..2073d4cbe87 100644
--- a/source/blender/io/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/io/usd/intern/usd_writer_mesh.cc
@@ -160,29 +160,18 @@ void USDGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh)
get_geometry_data(mesh, usd_mesh_data);
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());
- BLI_assert(!"USD reference error");
- return;
- }
- pxr::SdfPath ref_path(context.original_export_path);
- if (!usd_mesh.GetPrim().GetReferences().AddInternalReference(ref_path)) {
- /* See this URL for a description fo why referencing may fail"
- * https://graphics.pixar.com/usd/docs/api/class_usd_references.html#Usd_Failing_References
- */
- printf("USD Export warning: unable to add reference from %s to %s, not instancing object\n",
- context.export_path.c_str(),
- context.original_export_path.c_str());
+ if (!mark_as_instance(context, usd_mesh.GetPrim())) {
return;
}
+
/* The material path will be of the form </_materials/{material name}>, which is outside the
- sub-tree pointed to by ref_path. As a result, the referenced data is not allowed to point out
- of its own sub-tree. It does work when we override the material with exactly the same path,
- though.*/
+ * sub-tree pointed to by ref_path. As a result, the referenced data is not allowed to point
+ * out of its own sub-tree. It does work when we override the material with exactly the same
+ * path, though.*/
if (usd_export_context_.export_params.export_materials) {
assign_materials(context, usd_mesh, usd_mesh_data.face_groups);
}
+
return;
}