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

MAYA-122104 ProxyShapeSceneSegmentHandler and UsdCameraHandler::findCameras. #2307

Merged
merged 16 commits into from
May 12, 2022
Merged
15 changes: 15 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ if(CMAKE_UFE_V4_FEATURES_AVAILABLE)
UsdUndoCreateFromNodeDefCommand.cpp
)
endif()

if (${UFE_PREVIEW_VERSION_NUM} GREATER_EQUAL 4013)
target_sources(${PROJECT_NAME}
PRIVATE
ProxyShapeCameraHandler.cpp
ProxyShapeSceneSegmentHandler.cpp
)
endif()
endif()

set(HEADERS
Expand Down Expand Up @@ -206,6 +214,13 @@ if(CMAKE_UFE_V4_FEATURES_AVAILABLE)
UsdUndoCreateFromNodeDefCommand.h
)
endif()

if (${UFE_PREVIEW_VERSION_NUM} GREATER_EQUAL 4013)
list(APPEND HEADERS
ProxyShapeCameraHandler.h
ProxyShapeSceneSegmentHandler.h
)
endif()
endif()

# -----------------------------------------------------------------------------
Expand Down
35 changes: 35 additions & 0 deletions lib/mayaUsd/ufe/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#include <mayaUsd/ufe/UsdShaderNodeDefHandler.h>
#endif
#endif
#if defined(UFE_V4_FEATURES_AVAILABLE) && (UFE_PREVIEW_VERSION_NUM >= 4013)
#include <mayaUsd/ufe/ProxyShapeCameraHandler.h>
#include <mayaUsd/ufe/ProxyShapeSceneSegmentHandler.h>
#endif
#include <mayaUsd/utils/editRouter.h>

#include <maya/MSceneMessage.h>
Expand Down Expand Up @@ -107,6 +111,16 @@ Ufe::HierarchyHandler::Ptr g_MayaHierarchyHandler;
Ufe::ContextOpsHandler::Ptr g_MayaContextOpsHandler;
#endif

#if defined(UFE_V4_FEATURES_AVAILABLE) && (UFE_PREVIEW_VERSION_NUM >= 4013)
// The normal Maya scene segment handler, which we decorate for ProxyShape support.
// Keep a reference to it to restore on finalization.
Ufe::SceneSegmentHandler::Ptr g_MayaSceneSegmentHandler;

// The normal Maya camera handler, which we decorate for ProxyShape support.
// Keep a reference to it to restore on finalization.
Ufe::CameraHandler::Ptr g_MayaCameraHandler;
#endif

#ifdef HAVE_PATH_MAPPING
Ufe::PathMappingHandler::Ptr g_MayaPathMappingHandler;

Expand Down Expand Up @@ -173,6 +187,19 @@ MStatus initialize()
#endif
#endif

#if defined(UFE_V4_FEATURES_AVAILABLE) && (UFE_PREVIEW_VERSION_NUM >= 4013)
// set up the SceneSegmentHandler
g_MayaSceneSegmentHandler = Ufe::RunTimeMgr::instance().sceneSegmentHandler(g_MayaRtid);
auto proxyShapeSceneSegmentHandler
= ProxyShapeSceneSegmentHandler::create(g_MayaSceneSegmentHandler);
Ufe::RunTimeMgr::instance().setSceneSegmentHandler(g_MayaRtid, proxyShapeSceneSegmentHandler);

// set up the ProxyShapeCameraHandler
g_MayaCameraHandler = Ufe::RunTimeMgr::instance().cameraHandler(g_MayaRtid);
auto proxyShapeCameraHandler = ProxyShapeCameraHandler::create(g_MayaCameraHandler);
Ufe::RunTimeMgr::instance().setCameraHandler(g_MayaRtid, proxyShapeCameraHandler);
#endif

// USD has a very flexible data model to support 3d transformations --- see
// https://graphics.pixar.com/usd/docs/api/class_usd_geom_xformable.html
//
Expand Down Expand Up @@ -262,6 +289,14 @@ MStatus finalize(bool exiting)
runTimeMgr.unregister(g_USDRtid);
g_MayaHierarchyHandler.reset();

#if defined(UFE_V4_FEATURES_AVAILABLE) && (UFE_PREVIEW_VERSION_NUM >= 4013)
Ufe::RunTimeMgr::instance().setSceneSegmentHandler(g_MayaRtid, g_MayaSceneSegmentHandler);
g_MayaSceneSegmentHandler.reset();

Ufe::RunTimeMgr::instance().setCameraHandler(g_MayaRtid, g_MayaCameraHandler);
g_MayaCameraHandler.reset();
#endif

#ifdef HAVE_PATH_MAPPING
// Remove the Maya path mapping handler that we added above.
runTimeMgr.setPathMappingHandler(g_MayaRtid, g_MayaPathMappingHandler);
Expand Down
71 changes: 71 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeCameraHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// Copyright 2022 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "ProxyShapeCameraHandler.h"

#include "Global.h"
#include "UsdCameraHandler.h"
#include "pxr/usd/usdGeom/camera.h"

#include <mayaUsd/ufe/UsdSceneItem.h>
#include <mayaUsd/ufe/Utils.h>

#include <pxr/usd/sdf/path.h>
#include <pxr/usd/usd/primRange.h>
#include <pxr/usd/usd/stage.h>

PXR_NAMESPACE_USING_DIRECTIVE

namespace MAYAUSD_NS_DEF {
namespace ufe {

ProxyShapeCameraHandler::ProxyShapeCameraHandler(const Ufe::CameraHandler::Ptr& mayaCameraHandler)
: Ufe::CameraHandler()
, fMayaCameraHandler(mayaCameraHandler)
{
}

ProxyShapeCameraHandler::~ProxyShapeCameraHandler() { }

/*static*/
ProxyShapeCameraHandler::Ptr
ProxyShapeCameraHandler::create(const Ufe::CameraHandler::Ptr& mayaCameraHandler)
{
return std::make_shared<ProxyShapeCameraHandler>(mayaCameraHandler);
}

//------------------------------------------------------------------------------
// Ufe::CameraHandler overrides
//------------------------------------------------------------------------------
Ufe::Camera::Ptr ProxyShapeCameraHandler::camera(const Ufe::SceneItem::Ptr& item) const
{
return fMayaCameraHandler ? fMayaCameraHandler->camera(item) : nullptr;
}

Ufe::Selection ProxyShapeCameraHandler::find_(const Ufe::Path& path) const
{
Ufe::SceneItem::Ptr item = Ufe::Hierarchy::createItem(path);
if (isAGatewayType(item->nodeType())) {
// path is a path to a proxyShape node.
// Get the UsdStage for this proxy shape node and search it for cameras
PXR_NS::UsdStageWeakPtr stage = getStage(path);
TF_VERIFY(stage);
return UsdCameraHandler::find(path, path, stage->GetPseudoRoot());
}
return fMayaCameraHandler ? fMayaCameraHandler->find(path) : Ufe::Selection();
}

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
54 changes: 54 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeCameraHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Copyright 2020 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#pragma once

#include <mayaUsd/base/api.h>

#include <ufe/cameraHandler.h>

namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief Interface to create a ProxyShapeCameraHandler interface object.
class MAYAUSD_CORE_PUBLIC ProxyShapeCameraHandler : public Ufe::CameraHandler
{
public:
typedef std::shared_ptr<ProxyShapeCameraHandler> Ptr;

ProxyShapeCameraHandler(const Ufe::CameraHandler::Ptr&);
~ProxyShapeCameraHandler();

// Delete the copy/move constructors assignment operators.
ProxyShapeCameraHandler(const ProxyShapeCameraHandler&) = delete;
ProxyShapeCameraHandler& operator=(const ProxyShapeCameraHandler&) = delete;
ProxyShapeCameraHandler(ProxyShapeCameraHandler&&) = delete;
ProxyShapeCameraHandler& operator=(ProxyShapeCameraHandler&&) = delete;

//! Create a ProxyShapeCameraHandler from a UFE camera handler.
static ProxyShapeCameraHandler::Ptr create(const Ufe::CameraHandler::Ptr&);

// Ufe::CameraHandler overrides
Ufe::Camera::Ptr camera(const Ufe::SceneItem::Ptr& item) const override;

Ufe::Selection find_(const Ufe::Path& path) const override;

private:
Ufe::CameraHandler::Ptr fMayaCameraHandler;

}; // ProxyShapeCameraHandler

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
82 changes: 82 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeSceneSegmentHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Copyright 2022 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "ProxyShapeSceneSegmentHandler.h"

#include <mayaUsd/ufe/Utils.h>

#include <ufe/hierarchy.h>
#include <ufe/runTimeMgr.h>

namespace MAYAUSD_NS_DEF {
namespace ufe {

extern Ufe::Rtid g_USDRtid;

ProxyShapeSceneSegmentHandler::ProxyShapeSceneSegmentHandler(
const Ufe::SceneSegmentHandler::Ptr& mayaSceneSegmentHandler)
: Ufe::SceneSegmentHandler()
, fMayaSceneSegmentHandler(mayaSceneSegmentHandler)
{
}

ProxyShapeSceneSegmentHandler::~ProxyShapeSceneSegmentHandler() { }

/*static*/
ProxyShapeSceneSegmentHandler::Ptr
ProxyShapeSceneSegmentHandler::create(const Ufe::SceneSegmentHandler::Ptr& mayaSceneSegmentHandler)
{
return std::make_shared<ProxyShapeSceneSegmentHandler>(mayaSceneSegmentHandler);
}

//------------------------------------------------------------------------------
// Ufe::SceneSegmentHandler overrides
//------------------------------------------------------------------------------

Ufe::Selection ProxyShapeSceneSegmentHandler::findGatewayItems_(const Ufe::Path& path) const
{
// Handle other gateway node types that MayaUSD is not aware of
Ufe::Selection result = fMayaSceneSegmentHandler
? fMayaSceneSegmentHandler->findGatewayItems_(path)
: Ufe::Selection();

// Find the MayaUSD proxyShapes
for (const auto& stage : getAllStages()) {
Ufe::Path proxyShapePath = stagePath(stage);
// recall that findGatewayItems searches for descendents of path that are
// gateway nodes. If path itself is a gateway node it should not be included
// in the results.
if (proxyShapePath.startsWith(path) && proxyShapePath != path) {
result.append(Ufe::Hierarchy::createItem(proxyShapePath));
}
}

// If there were Usd prims that are gateway items then we'd have an implementation
// of UsdSceneSegmentHandler that could find the gateway items and extra code
// here to handle the case where isAGatewayType() for path is true. But right now
// there are no gateway items in Usd, so I don't have to handle that.

return result;
}

bool ProxyShapeSceneSegmentHandler::isGateway_(const Ufe::Path& path) const
{
PXR_NS::UsdStageWeakPtr stage = getStage(path);
return stage ? true
: fMayaSceneSegmentHandler ? fMayaSceneSegmentHandler->isGateway_(path) : false;
}

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
59 changes: 59 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeSceneSegmentHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Copyright 2022 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#pragma once

#include <mayaUsd/base/api.h>

#include <ufe/sceneSegmentHandler.h>

namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief Maya run-time scene segment handler with support for USD gateway node.
/*!
This scene segment handler is NOT a USD run-time scene segment handler: it is a
Maya run-time scene segment handler. It decorates the standard Maya run-time
scene segment handler and augments it.
*/
class MAYAUSD_CORE_PUBLIC ProxyShapeSceneSegmentHandler : public Ufe::SceneSegmentHandler
{
public:
typedef std::shared_ptr<ProxyShapeSceneSegmentHandler> Ptr;

ProxyShapeSceneSegmentHandler(const Ufe::SceneSegmentHandler::Ptr& mayaSceneSegmentHandler);
~ProxyShapeSceneSegmentHandler() override;

// Delete the copy/move constructors assignment operators.
ProxyShapeSceneSegmentHandler(const ProxyShapeSceneSegmentHandler&) = delete;
ProxyShapeSceneSegmentHandler& operator=(const ProxyShapeSceneSegmentHandler&) = delete;
ProxyShapeSceneSegmentHandler(ProxyShapeSceneSegmentHandler&&) = delete;
ProxyShapeSceneSegmentHandler& operator=(ProxyShapeSceneSegmentHandler&&) = delete;

//! Create a ProxyShapeSceneSegmentHandler from a UFE scene segment handler.
static ProxyShapeSceneSegmentHandler::Ptr
create(const Ufe::SceneSegmentHandler::Ptr& mayaSceneSegmentHandler);

// Ufe::SceneSegmentHandler overrides
Ufe::Selection findGatewayItems_(const Ufe::Path& path) const override;
bool isGateway_(const Ufe::Path& path) const override;

private:
Ufe::SceneSegmentHandler::Ptr fMayaSceneSegmentHandler;

}; // ProxyShapeSceneSegmentHandler

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
Loading