Fix "/" is not added to replaced path prefix.

Add feature of replacing path to 'Payload' command.
This commit is contained in:
Syoyo Fujita
2025-06-15 07:50:53 +09:00
parent 79533bc317
commit efa08f0770
2 changed files with 29 additions and 3 deletions

View File

@@ -142,6 +142,9 @@ bool ReplaceRootPrimPathRec(
(void)warn;
DCOUT("srcPrefix: " << srcPrefix);
DCOUT("dstPrefix: " << dstPrefix);
if (depth > (1024 * 1024 * 128)) {
PUSH_ERROR_AND_RETURN("PrimSpec tree too deep.");
}
@@ -839,6 +842,7 @@ bool CompositeReferencesRec(uint32_t depth, AssetResolutionResolver &resolver,
bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
const std::vector<std::string> &asset_search_paths,
const Path &dst_prim_path,
const Layer &in_layer,
PrimSpec &primspec /* [inout] */, std::string *warn,
std::string *err,
@@ -849,7 +853,8 @@ bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
// Traverse children first.
for (auto &child : primspec.children()) {
if (!CompositePayloadRec(depth + 1, resolver, asset_search_paths, in_layer, child,
const Path parent_prim_path = dst_prim_path.AppendPrim(child.name());
if (!CompositePayloadRec(depth + 1, resolver, asset_search_paths, parent_prim_path, in_layer, child,
warn, err, options)) {
return false;
}
@@ -902,6 +907,11 @@ bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
continue;
}
// Replace prim path prefix
if (!ReplaceRootPrimPathRec(0, pl.prim_path, dst_prim_path, *const_cast<PrimSpec *>(src_ps), warn, err)) {
return false;
}
// `inherits` op
if (!InheritPrimSpec(primspec, *src_ps, warn, err)) {
PUSH_ERROR_AND_RETURN(
@@ -965,6 +975,11 @@ bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
continue;
}
// Replace prim path prefix
if (!ReplaceRootPrimPathRec(0, pl.prim_path, dst_prim_path, *const_cast<PrimSpec *>(src_ps), warn, err)) {
return false;
}
// `over` op
if (!OverridePrimSpec(primspec, *src_ps, warn, err)) {
PUSH_ERROR_AND_RETURN(
@@ -1100,7 +1115,7 @@ bool CompositeReferences(AssetResolutionResolver &resolver,
Layer dst = in_layer; // deep copy
for (auto &item : dst.primspecs()) {
Path primPath(item.first, "");
Path primPath("/" + item.first, "");
if (!CompositeReferencesRec(/* depth */ 0, resolver, search_paths, primPath, in_layer,
item.second, warn, err, options)) {
PUSH_ERROR_AND_RETURN("Composite `references` failed.");
@@ -1123,8 +1138,9 @@ bool CompositePayload(AssetResolutionResolver &resolver, const Layer &in_layer,
Layer dst = in_layer; // deep copy
for (auto &item : dst.primspecs()) {
Path primPath("/" + item.first, "");
if (!CompositePayloadRec(/* depth */ 0, resolver,
item.second.get_asset_search_paths(), in_layer, item.second,
item.second.get_asset_search_paths(), primPath, in_layer, item.second,
warn, err, options)) {
PUSH_ERROR_AND_RETURN("Composite `payload` failed.");
}

View File

@@ -0,0 +1,10 @@
#usda 1.0
def "root" (
)
{
def "sub" (
payload = @pbr-mtl.usda@</root_pbr>
) {
}
}