From f30689e12c67edec3d89caadc8f0c92a09db3bcd Mon Sep 17 00:00:00 2001 From: Michael Kowalski Date: Mon, 12 Aug 2024 16:35:51 +0200 Subject: [PATCH] Fix: USD instancing export errors Fixed two errors when exporting to USD with Instancing enabled: Ensuring the mesh prototype prim exists before referencing it to avoid the "Unresolved reference prim path" error messages in the console. Adding the Root Prim path prefix to the prototype reference path. Pull Request: https://projects.blender.org/blender/blender/pulls/126210 --- source/blender/io/usd/intern/usd_writer_abstract.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc index 4a443bbac64..5d1939c861f 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.cc +++ b/source/blender/io/usd/intern/usd_writer_abstract.cc @@ -261,7 +261,17 @@ bool USDAbstractWriter::mark_as_instance(const HierarchyContext &context, const return false; } - pxr::SdfPath ref_path(context.original_export_path); + BLI_assert(!context.original_export_path.empty()); + BLI_assert(context.original_export_path.front() == '/'); + + std::string ref_path_str(usd_export_context_.export_params.root_prim_path); + ref_path_str += context.original_export_path; + + pxr::SdfPath ref_path(ref_path_str); + + /* To avoid USD errors, make sure the referenced path exists. */ + usd_export_context_.stage->DefinePrim(ref_path); + if (!prim.GetReferences().AddInternalReference(ref_path)) { /* See this URL for a description for why referencing may fail" * https://graphics.pixar.com/usd/docs/api/class_usd_references.html#Usd_Failing_References