Skip to content

Commit

Permalink
Merge branch 'dev' into donnels/EMSUSD-751/move_attributes_to_usdufe
Browse files Browse the repository at this point in the history
  • Loading branch information
seando-adsk committed May 1, 2024
2 parents 5f0dbd3 + a2d0f30 commit 5944b1e
Show file tree
Hide file tree
Showing 133 changed files with 3,596 additions and 846 deletions.
3 changes: 3 additions & 0 deletions cmake/compiler_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ set(MSVC_FLAGS
$<$<BOOL:$<VERSION_GREATER:${USD_BOOST_VERSION},106600>>:/permissive->
# enable pdb generation.
/Zi
# to see the updated value of the __cplusplus macro
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
/Zc:__cplusplus
# standards compliant.
/Zc:rvalueCast
# The /Zc:inline option strips out the "arch_ctor_<name>" symbols used for
Expand Down
6 changes: 6 additions & 0 deletions cmake/modules/FindUFE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# UFE_LIGHTS_SUPPORT Presence of UFE lights support
# UFE_MATERIALS_SUPPORT Presence of UFE materials support
# UFE_SCENE_SEGMENT_SUPPORT Presence of UFE scene segment support
# UFE_CLIPBOARD_SUPPORT Presence of UFE clipboard support
# UFE_DEFAULT_VALUE_SUPPORT Presence of UFE default value support
# UFE_PREVIEW_FEATURES List of all features introduced gradually in the UFE preview version
#
Expand Down Expand Up @@ -245,3 +246,8 @@ if(UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/camera.h")
endif()
endif()

set(UFE_CLIPBOARD_SUPPORT FALSE CACHE INTERNAL "ufeClipboard")
if (UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/clipboardHandler.h")
set(UFE_CLIPBOARD_SUPPORT TRUE CACHE INTERNAL "ufeClipboard")
message(STATUS "Maya has UFE clipboard API")
endif()
10 changes: 10 additions & 0 deletions cmake/modules/FindUSD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ if(USD_INCLUDE_DIR)
endif()
endif()

# See if USD changetracker has instance count.
set(USD_HAS_TRACKER_INSTANCE_COUNT FALSE CACHE INTERNAL "USD.Track.InstanceCount")
if (USD_INCLUDE_DIR AND EXISTS "${USD_INCLUDE_DIR}/pxr/imaging/hd/changeTracker.h")
file(STRINGS ${USD_INCLUDE_DIR}/pxr/imaging/hd/changeTracker.h USD_HAS_API REGEX "GetInstanceIndicesChangeCount")
if(USD_HAS_API)
set(USD_HAS_TRACKER_INSTANCE_COUNT TRUE CACHE INTERNAL "USD.Track.InstanceCount")
message(STATUS "USD has tracker instance count")
endif()
endif()

# See if MaterialX shaders with color4 inputs exist natively in Sdr:
# Not yet in a tagged USD version: https://github.com/PixarAnimationStudios/USD/pull/1894
set(USD_HAS_COLOR4_SDR_SUPPORT FALSE CACHE INTERNAL "USD.Sdr.PropertyTypes.Color4")
Expand Down
2 changes: 1 addition & 1 deletion cmake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ finally:
# Necessary for tests like DiffCore to find python.
# See LD_LIBRARY_PATH for Linux above.
set_property(TEST "${test_name}" APPEND PROPERTY ENVIRONMENT
"DYLD_LIBRARY_PATH=${MAYA_LOCATION}/MacOS:$ENV{DYLD_LIBRARY_PATH}")
"DYLD_LIBRARY_PATH=${MAYA_LOCATION}/Maya.app/Contents/MacOS:$ENV{DYLD_LIBRARY_PATH}")
set_property(TEST "${test_name}" APPEND PROPERTY ENVIRONMENT
"DYLD_FRAMEWORK_PATH=${MAYA_LOCATION}/Maya.app/Contents/Frameworks")
endif()
Expand Down
16 changes: 15 additions & 1 deletion lib/mayaUsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ if (MAYA_HAS_GET_MEMBER_PATHS)
)
endif()

message(STATUS "USD_HAS_TRACKER_INSTANCE_COUNT is ${USD_HAS_TRACKER_INSTANCE_COUNT}")
if (USD_HAS_TRACKER_INSTANCE_COUNT)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
USD_HAS_TRACKER_INSTANCE_COUNT=1
)
endif()

message(STATUS "MAYA_HAS_DISPLAY_LAYER_API is ${MAYA_HAS_DISPLAY_LAYER_API}")
if (MAYA_HAS_DISPLAY_LAYER_API)
target_compile_definitions(${PROJECT_NAME}
Expand Down Expand Up @@ -174,6 +182,13 @@ if (MAYA_LIGHTAPI_VERSION GREATER_EQUAL 2)
)
endif()

if (UFE_CLIPBOARD_SUPPORT)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
UFE_CLIPBOARD_SUPPORT=1
)
endif()

# Some of the UFE classes are exporting STL classes which causes this warning.
if(MSVC)
target_compile_options(${PROJECT_NAME}
Expand Down Expand Up @@ -245,7 +260,6 @@ target_link_libraries(${PROJECT_NAME}
vt
${UFE_LIBRARY}
${MAYA_LIBRARIES}
mayaUsdUtils
usdUfe
PRIVATE
ghc_filesystem
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/commands/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ their own purposes, similar to the Alembic export chaser example.
| `-frameSample` | `-fs` | double (multi) | `0.0` | Specifies sample times used to multi-sample frames during animation export, where `0.0` refers to the current time sample. **This is an advanced option**; chances are, you probably want to set the `frameStride` parameter instead. But if you really do need fine-grained control on multi-sampling frames, see "Frame Samples" below. |
| `-frameStride` | `-fst` | double | `1.0` | Specifies the increment between frames during animation export, e.g. a stride of `0.5` will give you twice as many time samples, whereas a stride of `2.0` will only give you time samples every other frame. The frame stride is computed before the frame samples are taken into account. **Note**: Depending on the frame stride, the last frame of the frame range may be skipped. For example, if your frame range is `[1.0, 3.0]` but you specify a stride of `0.3`, then the time samples in your USD file will be `1.0, 1.3, 1.6, 1.9, 2.2, 2.5, 2.8`, skipping the last frame time (`3.0`). |
| `-ignoreWarnings` | `-ign` | bool | false | Ignore warnings, do not fail to export due to warnings |
| `-includeEmptyTransforms` | `-iet` | bool | true | Include Xform even if all they contain are other empty Xforms. |
| `-kind` | `-k` | string | none | Specifies the required USD kind for *root prims* in the scene. (Does not affect kind for non-root prims.) If this flag is non-empty, then the specified kind will be set on any root prims in the scene without a `USD_kind` attribute (see the "Maya Custom Attributes" table below). Furthermore, if there are any root prims in the scene that do have a `USD_kind` attribute, then their `USD_kind` values will be validated to ensure they are derived from the kind specified by the `-kind` flag. For example, if the `-kind` flag is set to `group` and a root prim has `USD_kind=assembly`, then this is allowed because `assembly` derives from `group`. However, if the root prim has `USD_kind=subcomponent` instead, then `MayaUSDExportCommand` would stop with an error, since `subcomponent` does not derive from `group`. The validation behavior understands custom kinds that are registered using the USD kind registry, in addition to the built-in kinds. |
| `-disableModelKindProcessor` | `-dmk` | bool | false | Disables the tagging of prim kinds based on the ModelKindProcessor. |
| `-materialCollectionsPath` | `-mcp` | string | none | Path to the prim where material collections must be exported. |
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/commands/baseExportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ MSyntax MayaUSDExportCommand::createSyntax()
kExportInstancesFlag,
UsdMayaJobExportArgsTokens->exportInstances.GetText(),
MSyntax::kBoolean);
syntax.addFlag(
kIncludeEmptyTransformsFlag,
UsdMayaJobExportArgsTokens->includeEmptyTransforms.GetText(),
MSyntax::kBoolean);
syntax.addFlag(
kExportRefsAsInstanceableFlag,
UsdMayaJobExportArgsTokens->exportRefsAsInstanceable.GetText(),
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/commands/baseExportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class MAYAUSD_CORE_PUBLIC MayaUSDExportCommand : public MPxCommand
static constexpr auto kMetersPerUnit = "mpu";
static constexpr auto kExcludeExportTypesFlag = "eet";
static constexpr auto kDefaultPrimFlag = "dp";
static constexpr auto kIncludeEmptyTransformsFlag = "iet";

// Short and Long forms of flags defined by this command itself:
static constexpr auto kAppendFlag = "a";
Expand Down
15 changes: 11 additions & 4 deletions lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#include <mayaUsd/fileio/utils/writeUtil.h>
#include <mayaUsd/utils/utilDictionary.h>
#include <mayaUsd/utils/utilFileSystem.h>
#include <mayaUsdUtils/DiffPrims.h>

#include <usdUfe/utils/diffPrims.h>

#include <pxr/base/tf/diagnostic.h>
#include <pxr/base/tf/envSetting.h>
Expand Down Expand Up @@ -519,8 +520,8 @@ bool _MergeJobContexts(bool isExport, const VtDictionary& userArgs, VtDictionary
if (element.IsHolding<std::vector<VtValue>>()) {
// vector<vector<string>> is common for chaserArgs and shadingModes
auto findElement = [&element](const VtValue& a) {
return MayaUsdUtils::compareValues(element, a)
== MayaUsdUtils::DiffResult::Same;
return UsdUfe::compareValues(element, a)
== UsdUfe::DiffResult::Same;
};
if (std::find_if(
mergedValues.begin(), mergedValues.end(), findElement)
Expand Down Expand Up @@ -624,6 +625,8 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs(
, exportComponentTags(extractBoolean(userArgs, UsdMayaJobExportArgsTokens->exportComponentTags))
, file(extractString(userArgs, UsdMayaJobExportArgsTokens->file))
, ignoreWarnings(extractBoolean(userArgs, UsdMayaJobExportArgsTokens->ignoreWarnings))
, includeEmptyTransforms(
extractBoolean(userArgs, UsdMayaJobExportArgsTokens->includeEmptyTransforms))
, materialCollectionsPath(
extractAbsolutePath(userArgs, UsdMayaJobExportArgsTokens->materialCollectionsPath))
, materialsScopeName(_GetMaterialsScopeName(
Expand Down Expand Up @@ -726,7 +729,9 @@ std::ostream& operator<<(std::ostream& out, const UsdMayaJobExportArgs& exportAr
<< "exportVisibility: " << TfStringify(exportArgs.exportVisibility) << std::endl
<< "exportComponentTags: " << TfStringify(exportArgs.exportComponentTags) << std::endl
<< "file: " << exportArgs.file << std::endl
<< "ignoreWarnings: " << TfStringify(exportArgs.ignoreWarnings) << std::endl;
<< "ignoreWarnings: " << TfStringify(exportArgs.ignoreWarnings) << std::endl
<< "includeEmptyTransforms: " << TfStringify(exportArgs.includeEmptyTransforms)
<< std::endl;
out << "includeAPINames (" << exportArgs.includeAPINames.size() << ")" << std::endl;
for (const std::string& includeAPIName : exportArgs.includeAPINames) {
out << " " << includeAPIName << std::endl;
Expand Down Expand Up @@ -1001,6 +1006,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
d[UsdMayaJobExportArgsTokens->file] = std::string();
d[UsdMayaJobExportArgsTokens->filterTypes] = std::vector<VtValue>();
d[UsdMayaJobExportArgsTokens->ignoreWarnings] = false;
d[UsdMayaJobExportArgsTokens->includeEmptyTransforms] = true;
d[UsdMayaJobExportArgsTokens->kind] = std::string();
d[UsdMayaJobExportArgsTokens->disableModelKindProcessor] = false;
d[UsdMayaJobExportArgsTokens->materialCollectionsPath] = std::string();
Expand Down Expand Up @@ -1100,6 +1106,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetGuideDictionary()
d[UsdMayaJobExportArgsTokens->file] = _string;
d[UsdMayaJobExportArgsTokens->filterTypes] = _stringVector;
d[UsdMayaJobExportArgsTokens->ignoreWarnings] = _boolean;
d[UsdMayaJobExportArgsTokens->includeEmptyTransforms] = _boolean;
d[UsdMayaJobExportArgsTokens->kind] = _string;
d[UsdMayaJobExportArgsTokens->disableModelKindProcessor] = _boolean;
d[UsdMayaJobExportArgsTokens->materialCollectionsPath] = _string;
Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ TF_DECLARE_PUBLIC_TOKENS(
(file) \
(filterTypes) \
(ignoreWarnings) \
(includeEmptyTransforms) \
(kind) \
(disableModelKindProcessor) \
(materialCollectionsPath) \
Expand Down Expand Up @@ -221,6 +222,7 @@ struct UsdMayaJobExportArgs
const bool exportComponentTags;
const std::string file;
const bool ignoreWarnings;
const bool includeEmptyTransforms;

/// If this is not empty, then a set of collections are exported on the
/// prim pointed to by the path, each representing the collection of
Expand Down
80 changes: 79 additions & 1 deletion lib/mayaUsd/fileio/jobs/writeJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ bool UsdMaya_WriteJob::_WriteFrame(double iFrame)

bool UsdMaya_WriteJob::_FinishWriting()
{
MayaUsd::ProgressBarScope progressBar(6);
MayaUsd::ProgressBarScope progressBar(7);

UsdPrimSiblingRange usdRootPrims = mJobCtx.mStage->GetPseudoRoot().GetChildren();

Expand Down Expand Up @@ -586,6 +586,9 @@ bool UsdMaya_WriteJob::_FinishWriting()
_PostCallback();
progressBar.advance();

_PruneEmpties();
progressBar.advance();

TF_STATUS("Saving stage");
if (mJobCtx.mStage->GetRootLayer()->PermissionToSave()) {
mJobCtx.mStage->GetRootLayer()->Save();
Expand Down Expand Up @@ -780,6 +783,81 @@ TfToken UsdMaya_WriteJob::_WriteVariants(const UsdPrim& usdRootPrim)
return defaultPrim;
}

namespace {
bool isEmptyPrim(const UsdPrim& prim)
{
// Note: prim might have been removed previously.
if (!prim.IsValid())
return false;

static std::set<TfToken> emptyTypes = std::set<TfToken>({ TfToken("Xform"), TfToken("Scope") });
TfToken primTypeName = prim.GetTypeName();
if (emptyTypes.count(primTypeName) == 0)
return false;

if (!prim.GetAllChildren().empty())
return false;

if (prim.HasAuthoredPayloads())
return false;

if (prim.HasAuthoredReferences())
return false;

return true;
}

bool isEmptyPrim(const UsdStageRefPtr& stage, const SdfPath& path)
{
return isEmptyPrim(stage->GetPrimAtPath(path));
}

std::vector<SdfPath>
removeEmptyPrims(const UsdStageRefPtr& stage, const std::vector<SdfPath>& toRemove)
{
// Once we start removing empties, we need to re-check their parents.
std::vector<SdfPath> toRecheck;

for (const SdfPath& path : toRemove) {
stage->RemovePrim(path);
toRecheck.emplace_back(path.GetParentPath());
}
return toRecheck;
}
} // namespace

void UsdMaya_WriteJob::_PruneEmpties()
{
if (mJobCtx.mArgs.includeEmptyTransforms)
return;

SdfPath defaultPrimPath;
if (mJobCtx.mArgs.defaultPrim.size() > 0) {
if (mJobCtx.mArgs.defaultPrim[0] != '/')
defaultPrimPath = SdfPath(std::string("/") + mJobCtx.mArgs.defaultPrim);
else
defaultPrimPath = SdfPath(mJobCtx.mArgs.defaultPrim);
}

std::vector<SdfPath> toRemove;

for (UsdPrim prim : mJobCtx.mStage->Traverse()) {
if (defaultPrimPath != prim.GetPath())
if (isEmptyPrim(prim))
toRemove.emplace_back(prim.GetPath());
}

while (toRemove.size()) {
std::vector<SdfPath> toRecheck = removeEmptyPrims(mJobCtx.mStage, toRemove);
toRemove.clear();

for (const SdfPath& path : toRecheck)
if (defaultPrimPath != path)
if (isEmptyPrim(mJobCtx.mStage, path))
toRemove.emplace_back(path);
}
}

void UsdMaya_WriteJob::_CreatePackage() const
{
// Since we're packaging a temporary stage file that has an
Expand Down
3 changes: 3 additions & 0 deletions lib/mayaUsd/fileio/jobs/writeJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class UsdMaya_WriteJob
/// Writes the root prim variants based on the Maya render layers.
TfToken _WriteVariants(const UsdPrim& usdRootPrim);

/// Remove empty xform and scope recursively if the options to include them is off.
void _PruneEmpties();

/// Creates a usdz package from the write job's current USD stage.
void _CreatePackage() const;

Expand Down
Loading

0 comments on commit 5944b1e

Please sign in to comment.