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

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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_VISIBILITY FALSE CACHE INTERNAL "ufeCameraHasVisiblity")
if(UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/camera.h")
file(STRINGS ${UFE_INCLUDE_DIR}/ufe/camera.h UFE_HAS_API REGEX "visibility")
if(UFE_HAS_API)
set(UFE_CAMERA_HAS_VISIBILITY TRUE CACHE INTERNAL "ufeCameraHasVisiblity")
message(STATUS "Maya has UFE Camera's 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_VISIBILITY)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
UFE_CAMERA_HAS_VISIBILITY=1
)
endif()

if(CMAKE_UFE_V4_FEATURES_AVAILABLE)
list(APPEND HEADERS
Expand Down
30 changes: 30 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,33 @@ MayaUsdObject3d::adjustAlignedBBox(const Ufe::BBox3d& bbox, const PXR_NS::UsdTim
return UsdUfe::combineUfeBBox(bbox, pulledBBox);
}

#ifndef UFE_CAMERA_HAS_VISIBILITY
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a comment here stating that when the camera has the visibility method it will be used and this method is used in the older Maya case.

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>()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will not break 3dsmax, but i still find it a bit iffy that now the behavior varies per object type. Makes the API inconsistant / contract unclear

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also awkward because now setVisiblity and getVisibility will not be symmetrical, you will set the authored attr but return the resolved visibility

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deboisj Do you have another suggestion on how we can accomplish this task to hide cameras in the 3d viewport when they are hidden because their parent is hidden?

Copy link
Collaborator

@deboisj deboisj Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure - how do you handle this for lights? Isnt it the same problem? In max - we have a mechanism to get the resolved visibility and maintain / update a cache for that - but i guess in your case that would have to be done in maya which sounds impractical Could you "hide" it by giving it no gizmo / render item? Do you control anything VS how the camera gizmo is displayed? If maya thought it was visible, but in the end nothing displays, that's probably closest to how the rest of things work in maya-usd - because everything else currently reports "visible' and may actually be "invisible", i.e. in the outliner it would not be color coded insivible

Copy link
Collaborator

@deboisj deboisj Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually said something wrong above, the setter calls "make invisible/visible". So there is already a level of asymmetry with the getter

&& (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_VISIBILITY

} // 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_VISIBILITY
bool visibility() const override;
#endif // UFE_CAMERA_HAS_VISIBILITY

}; // 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_VISIBILITY)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
UFE_CAMERA_HAS_VISIBILITY=1
)
endif()

if (UFE_CLIPBOARD_SUPPORT)
target_sources(${PROJECT_NAME}
PRIVATE
Expand Down
31 changes: 31 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,33 @@ bool UsdCamera::renderable() const
return purpose == UsdGeomTokens->render || purpose == UsdGeomTokens->default_;
}
#endif

#ifdef UFE_CAMERA_HAS_VISIBILITY
bool UsdCamera::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

} // 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_VISIBILITY
bool visibility() const override;
#endif // UFE_CAMERA_HAS_VISIBILITY

private:
UsdSceneItem::Ptr _item;

Expand Down
2 changes: 2 additions & 0 deletions lib/usdUfe/ufe/UsdObject3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//
#include "UsdObject3d.h"

#include "pxr/usd/usdGeom/camera.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?


#include <usdUfe/ufe/UsdUndoVisibleCommand.h>
#include <usdUfe/ufe/Utils.h>
#include <usdUfe/utils/editRouter.h>
Expand Down