Skip to content

EMSUSD-1910 - Make USD camera invisible when the parents turn invisible #4110

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

Merged
merged 1 commit into from
Mar 19, 2025
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
9 changes: 9 additions & 0 deletions cmake/modules/FindUFE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,13 @@ if(UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/cameraHandler.h")
set(UFE_CAMERAHANDLER_HAS_FINDALL TRUE CACHE INTERNAL "ufeCameraHandlerHasFindAll")
message(STATUS "Maya has UFE CameraHandler's findAll interface")
endif()
endif()

set(UFE_CAMERA_HAS_COMPUTEDVISIBILITY FALSE CACHE INTERNAL "ufeCameraHasComputedVisiblity")
if(UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/camera.h")
file(STRINGS ${UFE_INCLUDE_DIR}/ufe/camera.h UFE_HAS_API REGEX "computedVisibility")
if(UFE_HAS_API)
set(UFE_CAMERA_HAS_COMPUTEDVISIBILITY TRUE CACHE INTERNAL "ufeCameraHasComputedVisiblity")
message(STATUS "Maya has UFE Camera's computed visibility interface")
endif()
endif()
7 changes: 7 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ if(UFE_CAMERAHANDLER_HAS_FINDALL)
ProxyShapeCameraHandler.h
)
endif()

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

if(CMAKE_UFE_V4_FEATURES_AVAILABLE)
list(APPEND HEADERS
Expand Down
32 changes: 32 additions & 0 deletions lib/mayaUsd/ufe/MayaUsdObject3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <mayaUsd/ufe/Utils.h>
#include <mayaUsd/utils/util.h>

#include <pxr/usd/usdGeom/camera.h>

namespace MAYAUSD_NS_DEF {
namespace ufe {

Expand Down Expand Up @@ -52,5 +54,35 @@ MayaUsdObject3d::adjustAlignedBBox(const Ufe::BBox3d& bbox, const PXR_NS::UsdTim
return UsdUfe::combineUfeBBox(bbox, pulledBBox);
}

// This visibility method is for older maya versions that do not have computedVisibility() for
// cameras
#ifndef UFE_CAMERA_HAS_COMPUTEDVISIBILITY
bool MayaUsdObject3d::visibility() const
{
PXR_NS::TfToken visibilityToken;
auto visAttr = PXR_NS::UsdGeomImageable(prim()).GetVisibilityAttr();
visAttr.Get(&visibilityToken);

// Check if the prim is a camera
// if its a camera, then we need to check if the camera's parents are visible
if (prim().IsA<PXR_NS::UsdGeomCamera>()
&& (visibilityToken == PXR_NS::UsdGeomTokens->inherited)) {
// get the parent of the camera
Ufe::Path parentPath = sceneItem()->path().pop();
while (!parentPath.empty()) {
// check if the parent is visible
auto parentItem = Ufe::Hierarchy::createItem(parentPath);
auto parentObject3d = Ufe::Object3d::object3d(parentItem);
if (!parentObject3d->visibility()) {
return false;
}
parentPath = parentPath.pop();
}
}

return visibilityToken != PXR_NS::UsdGeomTokens->invisible;
}
#endif // UFE_CAMERA_HAS_COMPUTEDVISIBILITY

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
3 changes: 3 additions & 0 deletions lib/mayaUsd/ufe/MayaUsdObject3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class MAYAUSD_CORE_PUBLIC MayaUsdObject3d : public UsdUfe::UsdObject3d
void adjustBBoxExtents(PXR_NS::GfBBox3d& bbox, const PXR_NS::UsdTimeCode time) const override;
Ufe::BBox3d
adjustAlignedBBox(const Ufe::BBox3d& bbox, const PXR_NS::UsdTimeCode time) const override;
#ifndef UFE_CAMERA_HAS_COMPUTEDVISIBILITY
bool visibility() const override;
#endif // UFE_CAMERA_HAS_COMPUTEDVISIBILITY

}; // MayaUsdObject3d

Expand Down
7 changes: 7 additions & 0 deletions lib/usdUfe/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ if (UFE_CAMERA_HAS_RENDERABLE)
)
endif()

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

if (UFE_CLIPBOARD_SUPPORT)
target_sources(${PROJECT_NAME}
PRIVATE
Expand Down
30 changes: 30 additions & 0 deletions lib/usdUfe/ufe/UsdCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <pxr/usd/usdGeom/camera.h>
#include <pxr/usd/usdGeom/metrics.h>

#include <ufe/object3d.h>

namespace USDUFE_NS_DEF {

USDUFE_VERIFY_CLASS_SETUP(Ufe::Camera, UsdCamera);
Expand Down Expand Up @@ -478,4 +480,32 @@ bool UsdCamera::renderable() const
return purpose == UsdGeomTokens->render || purpose == UsdGeomTokens->default_;
}
#endif

#ifdef UFE_CAMERA_HAS_COMPUTEDVISIBILITY
bool UsdCamera::computedVisibility() const
{
PXR_NS::TfToken visibilityToken;
auto visAttr = PXR_NS::UsdGeomImageable(prim()).GetVisibilityAttr();
visAttr.Get(&visibilityToken);

// Check if the prim is a camera
// if its a camera, then we need to check if the camera's parents are visible
if (visibilityToken == PXR_NS::UsdGeomTokens->inherited) {
// get the parent of the camera
Ufe::Path parentPath = sceneItem()->path().pop();
while (!parentPath.empty()) {
// check if the parent is visible
auto parentItem = Ufe::Hierarchy::createItem(parentPath);
auto parentObject3d = Ufe::Object3d::object3d(parentItem);
if (!parentObject3d->visibility()) {
return false;
}
parentPath = parentPath.pop();
}
}

return visibilityToken != PXR_NS::UsdGeomTokens->invisible;
}
#endif

} // namespace USDUFE_NS_DEF
5 changes: 5 additions & 0 deletions lib/usdUfe/ufe/UsdCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class USDUFE_PUBLIC UsdCamera : public Ufe::Camera
#ifdef UFE_CAMERA_HAS_RENDERABLE
bool renderable() const override;
#endif // UFE_CAMERA_HAS_RENDERABLE

#ifdef UFE_CAMERA_HAS_COMPUTEDVISIBILITY
bool computedVisibility() const override;
#endif // UFE_CAMERA_HAS_COMPUTEDVISIBILITY

private:
UsdSceneItem::Ptr _item;

Expand Down
Loading