Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'usdcat --flattenLayerStack' output #2832

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 foo.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/testFlattenLayerStack
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/testFlattenLayerStack/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