Skip to content

Commit

Permalink
Merge pull request #1241 from mattyjams/pr/ufe_point_instance_manipul…
Browse files Browse the repository at this point in the history
…ation

add support for manipulating point instances via UFE
  • Loading branch information
Krystian Ligenza authored Mar 12, 2021
2 parents 1a14155 + d504519 commit 9a96421
Show file tree
Hide file tree
Showing 15 changed files with 1,491 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ target_sources(${PROJECT_NAME}
StagesSubject.cpp
UsdHierarchy.cpp
UsdHierarchyHandler.cpp
UsdPointInstanceOrientationModifier.cpp
UsdPointInstancePositionModifier.cpp
UsdPointInstanceScaleModifier.cpp
UsdRootChildHierarchy.cpp
UsdRotatePivotTranslateUndoableCommand.cpp
UsdRotateUndoableCommand.cpp
Expand Down Expand Up @@ -48,6 +51,7 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE)
UsdTransform3dFallbackMayaXformStack.cpp
UsdTransform3dMatrixOp.cpp
UsdTransform3dMayaXformStack.cpp
UsdTransform3dPointInstance.cpp
UsdTransform3dSetObjectMatrix.cpp
UsdUIInfoHandler.cpp
UsdUndoAddNewPrimCommand.cpp
Expand All @@ -68,6 +72,10 @@ set(HEADERS
StagesSubject.h
UsdHierarchy.h
UsdHierarchyHandler.h
UsdPointInstanceModifierBase.h
UsdPointInstanceOrientationModifier.h
UsdPointInstancePositionModifier.h
UsdPointInstanceScaleModifier.h
UsdRootChildHierarchy.h
UsdRotatePivotTranslateUndoableCommand.h
UsdRotateUndoableCommand.h
Expand Down Expand Up @@ -100,11 +108,13 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE)
UsdContextOpsHandler.h
UsdObject3d.h
UsdObject3dHandler.h
UsdPointInstanceUndoableCommands.h
UsdTransform3dBase.h
UsdTransform3dCommonAPI.h
UsdTransform3dFallbackMayaXformStack.h
UsdTransform3dMatrixOp.h
UsdTransform3dMayaXformStack.h
UsdTransform3dPointInstance.h
UsdTransform3dSetObjectMatrix.h
UsdUIInfoHandler.h
UsdUndoableCommand.h
Expand Down
53 changes: 53 additions & 0 deletions lib/mayaUsd/ufe/StagesSubject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include <mayaUsd/undo/UsdUndoManager.h>
#endif

#include <pxr/pxr.h>
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usdGeom/pointInstancer.h>
#include <pxr/usd/usdGeom/tokens.h>
#include <pxr/usd/usdGeom/xformOp.h>

Expand All @@ -38,6 +41,7 @@
#include <ufe/transform3d.h>

#include <atomic>
#include <limits>
#include <vector>

#ifdef UFE_V2_FEATURES_AVAILABLE
Expand Down Expand Up @@ -305,10 +309,59 @@ void StagesSubject::stageChanged(

if (!InTransform3dChange::inTransform3dChange()) {
// Is the change a Transform3d change?
const UsdPrim prim = stage->GetPrimAtPath(changedPath.GetPrimPath());
const TfToken nameToken = changedPath.GetNameToken();
if (nameToken == UsdGeomTokens->xformOpOrder || UsdGeomXformOp::IsXformOp(nameToken)) {
Ufe::Transform3d::notify(ufePath);
UFE_V2(sendValueChangedFallback = false;)
} else if (prim && prim.IsA<UsdGeomPointInstancer>()) {
// If the prim at the changed path is a PointInstancer, check
// whether the modified path is one of the attributes authored
// by point instance manipulation.
if (nameToken == UsdGeomTokens->orientations
|| nameToken == UsdGeomTokens->positions
|| nameToken == UsdGeomTokens->scales) {
// This USD change represents a Transform3d change to a
// PointInstancer prim.
// Unfortunately though, there is no way for us to know
// which point instance indices were actually affected by
// this change. As a result, we must assume that they *all*
// may have been affected, so we construct UFE paths for
// every instance and issue a notification for each one.
const UsdGeomPointInstancer pointInstancer(prim);

#if PXR_VERSION >= 2011
const size_t numInstances
= bool(pointInstancer) ? pointInstancer.GetInstanceCount() : 0u;
#else
VtIntArray protoIndices;
if (pointInstancer) {
const UsdAttribute protoIndicesAttr = pointInstancer.GetProtoIndicesAttr();
if (protoIndicesAttr) {
protoIndicesAttr.Get(&protoIndices);
}
}
const size_t numInstances = protoIndices.size();
#endif

// The PointInstancer schema can theoretically support as
// as many instances as can be addressed by size_t, but
// Hydra currently only represents the instanceIndex of
// instances using int. We clamp the number of instance
// indices to the largest possible int to ensure that we
// don't overflow.
const int numIndices
= (numInstances <= static_cast<size_t>(std::numeric_limits<int>::max()))
? static_cast<int>(numInstances)
: std::numeric_limits<int>::max();

for (int instanceIndex = 0; instanceIndex < numIndices; ++instanceIndex) {
const Ufe::Path instanceUfePath = stagePath(sender)
+ usdPathToUfePathSegment(changedPath.GetPrimPath(), instanceIndex);
Ufe::Transform3d::notify(instanceUfePath);
}
UFE_V2(sendValueChangedFallback = false;)
}
}
}

Expand Down
Loading

0 comments on commit 9a96421

Please sign in to comment.