Skip to content

Commit

Permalink
Merge pull request #2832 from jackohoeg/dev_flattenlayerstack
Browse files Browse the repository at this point in the history
Fix 'usdcat --flattenLayerStack' output

(Internal change: 2307678)
  • Loading branch information
pixar-oss committed Dec 7, 2023
2 parents 4f325c1 + a2a4adf commit 7361178
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
16 changes: 16 additions & 0 deletions pxr/usd/bin/usdcat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ pxr_register_test(testUsdCatMissingOrInvalidFiles2
EXPECTED_RETURN_CODE 1
)

pxr_register_test(testUsdCatMissingOrInvalidFiles3
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/usdcat --flattenLayerStack missingFile.usda"
EXPECTED_RETURN_CODE 1
)

pxr_install_test_dir(
SRC testenv/testUsdCatMask
DEST testUsdCatMask
Expand Down Expand Up @@ -86,3 +91,14 @@ pxr_register_test(testUsdCatLayerMetadata
DIFF_COMPARE output.usda
EXPECTED_RETURN_CODE 0
)

pxr_install_test_dir(
SRC testenv/testUsdCatFlattenLayerStack
DEST testUsdCatFlattenLayerStack
)

pxr_register_test(testUsdCatFlattenLayerStack
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/usdcat --flattenLayerStack input.usda --out output.usda"
DIFF_COMPARE output.usda
EXPECTED_RETURN_CODE 0
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#usda 1.0

def Xform "Prim" (
references = @reference.usda@</Prim>
)
{
int primvars:should_be_here = 0
}

12 changes: 12 additions & 0 deletions pxr/usd/bin/usdcat/testenv/testUsdCatFlattenLayerStack/input.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#usda 1.0
(
subLayers = [
@./sublayer.usda@
]
)

over "Prim" (
references = @reference.usda@</Prim>
)
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#usda 1.0

def Xform "Prim" {
int primvars:should_be_here = 0
}
19 changes: 11 additions & 8 deletions pxr/usd/bin/usdcat/usdcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ static int UsdCat(const Args &args) {
}
} else if (args.flattenLayerStack) {
stage = UsdStage::Open(input, UsdStage::LoadNone);
layer = UsdUtilsFlattenLayerStack(stage);
if (stage) {
layer = UsdUtilsFlattenLayerStack(stage);
}
} else if (args.layerMetadata) {
auto srcLayer = SdfLayer::OpenAsAnonymous(
input, /* metadataOnly = */ true);
Expand Down Expand Up @@ -263,13 +265,13 @@ static int UsdCat(const Args &args) {

// Write to either stdout or the specified output file
if (!args.output.empty()) {
if (stage) {
if (layer) {
layer->Export(args.output, std::string(), formatArgs);
}
else {
stage->Export(
args.output, !args.skipSourceFileComment, formatArgs);
}
else if (layer) {
layer->Export(args.output, std::string(), formatArgs);
}

if (!errMark.IsClean()) {
exitCode = 1;
Expand All @@ -288,11 +290,12 @@ static int UsdCat(const Args &args) {
}
else {
std::string usdString;
if (stage) {
stage->ExportToString(&usdString);
} else {
if (layer) {
layer->ExportToString(&usdString);
}
else {
stage->ExportToString(&usdString);
}

if (errMark.IsClean()) {
std::cout << usdString;
Expand Down

0 comments on commit 7361178

Please sign in to comment.