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

MAYA121636 handle scope for read-only transform #2530

Merged
2 changes: 2 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target_sources(${PROJECT_NAME}
UsdStageMap.cpp
UsdTRSUndoableCommandBase.cpp
UsdTransform3d.cpp
UsdTransform3dReadImpl.cpp
UsdTransform3dHandler.cpp
UsdTranslateUndoableCommand.cpp
UsdUndoDeleteCommand.cpp
Expand Down Expand Up @@ -191,6 +192,7 @@ set(HEADERS
UsdStageMap.h
UsdTRSUndoableCommandBase.h
UsdTransform3d.h
UsdTransform3dReadImpl.h
UsdTransform3dHandler.h
UsdTranslateUndoableCommand.h
UsdUndoDeleteCommand.h
Expand Down
33 changes: 10 additions & 23 deletions lib/mayaUsd/ufe/UsdTransform3dBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ namespace MAYAUSD_NS_DEF {
namespace ufe {

UsdTransform3dBase::UsdTransform3dBase(const UsdSceneItem::Ptr& item)
: Transform3d()
, fItem(item)
, fPrim(item->prim())
: UsdTransform3dReadImpl(item)
, Transform3d()
{
}

const Ufe::Path& UsdTransform3dBase::path() const { return fItem->path(); }
const Ufe::Path& UsdTransform3dBase::path() const { return UsdTransform3dReadImpl::path(); }

Ufe::SceneItem::Ptr UsdTransform3dBase::sceneItem() const { return fItem; }
Ufe::SceneItem::Ptr UsdTransform3dBase::sceneItem() const
{
return UsdTransform3dReadImpl::sceneItem();
}

Ufe::TranslateUndoableCommand::Ptr
UsdTransform3dBase::translateCmd(double /* x */, double /* y */, double /* z */)
Expand Down Expand Up @@ -104,32 +106,17 @@ Ufe::SetMatrix4dUndoableCommand::Ptr UsdTransform3dBase::setMatrixCmd(const Ufe:
return nullptr;
}

Ufe::Matrix4d UsdTransform3dBase::matrix() const
{
UsdGeomXformable xformable(prim());
bool unused;
auto ops = xformable.GetOrderedXformOps(&unused);

GfMatrix4d m(1);
if (!UsdGeomXformable::GetLocalTransformation(&m, ops, getTime(path()))) {
TF_FATAL_ERROR(
"Local transformation computation for prim %s failed.", prim().GetPath().GetText());
}

return toUfe(m);
}
Ufe::Matrix4d UsdTransform3dBase::matrix() const { return UsdTransform3dReadImpl::matrix(); }
#endif

Ufe::Matrix4d UsdTransform3dBase::segmentInclusiveMatrix() const
{
UsdGeomXformCache xformCache(getTime(path()));
return toUfe(xformCache.GetLocalToWorldTransform(fPrim));
return UsdTransform3dReadImpl::segmentInclusiveMatrix();
}

Ufe::Matrix4d UsdTransform3dBase::segmentExclusiveMatrix() const
{
UsdGeomXformCache xformCache(getTime(path()));
return toUfe(xformCache.GetParentToWorldTransform(fPrim));
return UsdTransform3dReadImpl::segmentExclusiveMatrix();
}

} // namespace ufe
Expand Down
13 changes: 6 additions & 7 deletions lib/mayaUsd/ufe/UsdTransform3dBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <mayaUsd/base/api.h>
#include <mayaUsd/ufe/UsdSceneItem.h>
#include <mayaUsd/ufe/UsdTransform3dReadImpl.h>

#include <pxr/usd/usd/prim.h>

Expand All @@ -34,7 +35,9 @@ namespace ufe {
// Note that all calls to specify time use the default time, but this
// could be changed to use the current time, using getTime(path()).

class MAYAUSD_CORE_PUBLIC UsdTransform3dBase : public Ufe::Transform3d
class MAYAUSD_CORE_PUBLIC UsdTransform3dBase
: public UsdTransform3dReadImpl
, public Ufe::Transform3d
{
public:
typedef std::shared_ptr<UsdTransform3dBase> Ptr;
Expand All @@ -52,8 +55,8 @@ class MAYAUSD_CORE_PUBLIC UsdTransform3dBase : public Ufe::Transform3d
const Ufe::Path& path() const override;
Ufe::SceneItem::Ptr sceneItem() const override;

inline UsdSceneItem::Ptr usdSceneItem() const { return fItem; }
inline PXR_NS::UsdPrim prim() const { return fPrim; }
inline UsdSceneItem::Ptr usdSceneItem() const { return UsdTransform3dReadImpl::usdSceneItem(); }
inline PXR_NS::UsdPrim prim() const { return UsdTransform3dReadImpl::prim(); }

Ufe::TranslateUndoableCommand::Ptr translateCmd(double x, double y, double z) override;
Ufe::RotateUndoableCommand::Ptr rotateCmd(double x, double y, double z) override;
Expand All @@ -80,10 +83,6 @@ class MAYAUSD_CORE_PUBLIC UsdTransform3dBase : public Ufe::Transform3d
Ufe::Matrix4d segmentInclusiveMatrix() const override;
Ufe::Matrix4d segmentExclusiveMatrix() const override;

private:
UsdSceneItem::Ptr fItem;
PXR_NS::UsdPrim fPrim;

}; // UsdTransform3dBase

} // namespace ufe
Expand Down
34 changes: 9 additions & 25 deletions lib/mayaUsd/ufe/UsdTransform3dRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <mayaUsd/ufe/Utils.h>

#include <pxr/usd/usdGeom/scope.h>
#include <pxr/usd/usdGeom/xformCache.h>
#include <pxr/usd/usdGeom/xformCommonAPI.h>

PXR_NAMESPACE_USING_DIRECTIVE

Expand All @@ -32,42 +30,28 @@ UsdTransform3dRead::Ptr UsdTransform3dRead::create(const UsdSceneItem::Ptr& item
}

UsdTransform3dRead::UsdTransform3dRead(const UsdSceneItem::Ptr& item)
: Transform3dRead()
, fItem(item)
, fPrim(item->prim())
: UsdTransform3dReadImpl(item)
, Transform3dRead()
{
}

const Ufe::Path& UsdTransform3dRead::path() const { return fItem->path(); }
const Ufe::Path& UsdTransform3dRead::path() const { return UsdTransform3dReadImpl::path(); }

Ufe::SceneItem::Ptr UsdTransform3dRead::sceneItem() const { return fItem; }

Ufe::Matrix4d UsdTransform3dRead::matrix() const
Ufe::SceneItem::Ptr UsdTransform3dRead::sceneItem() const
{
GfMatrix4d m(1);
UsdGeomXformable xformable(prim());
if (xformable) {
bool unused;
auto ops = xformable.GetOrderedXformOps(&unused);
if (!UsdGeomXformable::GetLocalTransformation(&m, ops, getTime(path()))) {
TF_FATAL_ERROR(
"Local transformation computation for prim %s failed.", prim().GetPath().GetText());
}
}

return toUfe(m);
return UsdTransform3dReadImpl::sceneItem();
}

Ufe::Matrix4d UsdTransform3dRead::matrix() const { return UsdTransform3dReadImpl::matrix(); }

Ufe::Matrix4d UsdTransform3dRead::segmentInclusiveMatrix() const
{
UsdGeomXformCache xformCache(getTime(path()));
return toUfe(xformCache.GetLocalToWorldTransform(fPrim));
return UsdTransform3dReadImpl::segmentInclusiveMatrix();
}

Ufe::Matrix4d UsdTransform3dRead::segmentExclusiveMatrix() const
{
UsdGeomXformCache xformCache(getTime(path()));
return toUfe(xformCache.GetParentToWorldTransform(fPrim));
return UsdTransform3dReadImpl::segmentExclusiveMatrix();
}

//------------------------------------------------------------------------------
Expand Down
14 changes: 6 additions & 8 deletions lib/mayaUsd/ufe/UsdTransform3dRead.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <mayaUsd/base/api.h>
#include <mayaUsd/ufe/UsdSceneItem.h>
#include <mayaUsd/ufe/UsdTransform3dReadImpl.h>

#include <pxr/usd/usd/prim.h>

Expand All @@ -31,7 +32,9 @@ namespace ufe {
// Note that all calls to specify time use the default time, but this
// could be changed to use the current time, using getTime(path()).

class MAYAUSD_CORE_PUBLIC UsdTransform3dRead : public Ufe::Transform3dRead
class MAYAUSD_CORE_PUBLIC UsdTransform3dRead
: public UsdTransform3dReadImpl
ppt-adsk marked this conversation as resolved.
Show resolved Hide resolved
, public Ufe::Transform3dRead
{
public:
typedef std::shared_ptr<UsdTransform3dRead> Ptr;
Expand All @@ -52,18 +55,13 @@ class MAYAUSD_CORE_PUBLIC UsdTransform3dRead : public Ufe::Transform3dRead
const Ufe::Path& path() const override;
Ufe::SceneItem::Ptr sceneItem() const override;

inline UsdSceneItem::Ptr usdSceneItem() const { return fItem; }
inline PXR_NS::UsdPrim prim() const { return fPrim; }
inline UsdSceneItem::Ptr usdSceneItem() const { return UsdTransform3dReadImpl::usdSceneItem(); }
inline PXR_NS::UsdPrim prim() const { return UsdTransform3dReadImpl::prim(); }

Ufe::Matrix4d matrix() const override;

Ufe::Matrix4d segmentInclusiveMatrix() const override;
Ufe::Matrix4d segmentExclusiveMatrix() const override;

private:
UsdSceneItem::Ptr fItem;
PXR_NS::UsdPrim fPrim;

}; // UsdTransform3dRead

//! \brief Factory to create a UsdTransform3dRead interface object.
Expand Down
62 changes: 62 additions & 0 deletions lib/mayaUsd/ufe/UsdTransform3dReadImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// 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 "UsdTransform3dReadImpl.h"

#include <mayaUsd/ufe/Utils.h>

PXR_NAMESPACE_USING_DIRECTIVE

namespace MAYAUSD_NS_DEF {
namespace ufe {

UsdTransform3dReadImpl::UsdTransform3dReadImpl(const UsdSceneItem::Ptr& item)
: fItem(item)
, fPrim(item->prim())
{
}

#ifdef UFE_V2_FEATURES_AVAILABLE
Ufe::Matrix4d UsdTransform3dReadImpl::matrix() const
{
GfMatrix4d m(1);
UsdGeomXformable xformable(prim());
if (xformable) {
bool unused;
auto ops = xformable.GetOrderedXformOps(&unused);
if (!UsdGeomXformable::GetLocalTransformation(&m, ops, getTime(path()))) {
TF_FATAL_ERROR(
"Local transformation computation for prim %s failed.", prim().GetPath().GetText());
}
}

return toUfe(m);
}
#endif

Ufe::Matrix4d UsdTransform3dReadImpl::segmentInclusiveMatrix() const
{
UsdGeomXformCache xformCache(getTime(path()));
return toUfe(xformCache.GetLocalToWorldTransform(fPrim));
}

Ufe::Matrix4d UsdTransform3dReadImpl::segmentExclusiveMatrix() const
{
UsdGeomXformCache xformCache(getTime(path()));
return toUfe(xformCache.GetParentToWorldTransform(fPrim));
}

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
67 changes: 67 additions & 0 deletions lib/mayaUsd/ufe/UsdTransform3dReadImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// 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 <mayaUsd/ufe/UsdSceneItem.h>

#include <pxr/usd/usd/prim.h>

#include <ufe/transform3d.h>
#include <ufe/transform3dHandler.h>

namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief Read-only implementation for USD object 3D transform information.
//
// Note that all calls to specify time use the default time, but this
// could be changed to use the current time, using getTime(path()).

class MAYAUSD_CORE_PUBLIC UsdTransform3dReadImpl
{
public:
UsdTransform3dReadImpl(const UsdSceneItem::Ptr& item);
~UsdTransform3dReadImpl() = default;

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

// Ufe::Transform3d overrides
const Ufe::Path& path() const { return fItem->path(); }
Ufe::SceneItem::Ptr sceneItem() const { return fItem; }

inline UsdSceneItem::Ptr usdSceneItem() const { return fItem; }
inline PXR_NS::UsdPrim prim() const { return fPrim; }

#ifdef UFE_V2_FEATURES_AVAILABLE
Ufe::Matrix4d matrix() const;
#endif

Ufe::Matrix4d segmentInclusiveMatrix() const;
Ufe::Matrix4d segmentExclusiveMatrix() const;

private:
UsdSceneItem::Ptr fItem;
ppt-adsk marked this conversation as resolved.
Show resolved Hide resolved
PXR_NS::UsdPrim fPrim;

}; // UsdTransform3dReadImpl

} // namespace ufe
} // namespace MAYAUSD_NS_DEF