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-122146 - Selecting a camera and framing it with "f" shows the origin instead of the camera #2359

Merged
merged 2 commits into from
May 19, 2022
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
4 changes: 3 additions & 1 deletion lib/mayaUsd/nodes/proxyShapeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,9 +1241,11 @@ MBoundingBox MayaUsdProxyShapeBase::boundingBox() const
const TfToken purpose3 = drawProxyPurpose ? UsdGeomTokens->proxy : TfToken();
const TfToken purpose4 = drawGuidePurpose ? UsdGeomTokens->guide : TfToken();

const GfBBox3d allBox
GfBBox3d allBox
= imageablePrim.ComputeUntransformedBound(currTime, purpose1, purpose2, purpose3, purpose4);

UsdMayaUtil::AddMayaExtents(allBox, prim, currTime);

MBoundingBox& retval = nonConstThis->_boundingBoxCache[currTime];

const GfRange3d boxRange = allBox.ComputeAlignedBox();
Expand Down
8 changes: 4 additions & 4 deletions lib/mayaUsd/ufe/UsdLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class MAYAUSD_CORE_PUBLIC UsdLight : public Ufe::Light
float specular() const override;

protected:
std::shared_ptr<DirectionalInterface> directionalInterfaceImpl();
std::shared_ptr<SphereInterface> sphereInterfaceImpl();
std::shared_ptr<ConeInterface> coneInterfaceImpl();
std::shared_ptr<AreaInterface> areaInterfaceImpl();
std::shared_ptr<DirectionalInterface> directionalInterfaceImpl() override;
std::shared_ptr<SphereInterface> sphereInterfaceImpl() override;
std::shared_ptr<ConeInterface> coneInterfaceImpl() override;
std::shared_ptr<AreaInterface> areaInterfaceImpl() override;

private:
UsdSceneItem::Ptr fItem;
Expand Down
28 changes: 14 additions & 14 deletions lib/mayaUsd/ufe/UsdObject3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <mayaUsd/ufe/UsdUndoVisibleCommand.h>
#include <mayaUsd/ufe/Utils.h>
#include <mayaUsd/utils/util.h>

#include <pxr/usd/usd/timeCode.h>
#include <pxr/usd/usdGeom/bboxCache.h>
Expand Down Expand Up @@ -59,30 +60,29 @@ Ufe::SceneItem::Ptr UsdObject3d::sceneItem() const { return fItem; }

Ufe::BBox3d UsdObject3d::boundingBox() const
{
// Use USD to compute the bounding box. This is strictly speaking
// incorrect, as a USD node may eventually have a Maya child, given the
// full generality of UFE paths. However, as of 24-Oct-2019, this does not
// exist. To support this use case,
// Use USD to compute the bounding box in local space.
// UsdGeomBoundable::ComputeExtentFromPlugins() allows a plugin to register
// an extent computation; this should be explored.
//
// UsdGeomImageable::ComputeUntransformedBound() just calls
// UsdGeomBBoxCache, so do this here as well.
// an extent computation; this could be explored if needed in the future.
//
// Would be nice to know if the object extents are animated or not, so
// we can bypass time computation and simply use UsdTimeCode::Default()
// as the time.

auto path = sceneItem()->path();
auto purposes = getProxyShapePurposes(path);
const auto& path = sceneItem()->path();
auto purposes = getProxyShapePurposes(path);
// Add in the default purpose.
purposes.emplace_back(UsdGeomTokens->default_);

auto bbox = UsdGeomBBoxCache(getTime(path), purposes).ComputeUntransformedBound(fPrim);
// UsdGeomImageable::ComputeUntransformedBound() just calls
// UsdGeomBBoxCache, so do this here as well.
auto time = getTime(path);
auto bbox = UsdGeomBBoxCache(time, purposes).ComputeUntransformedBound(fPrim);

// Add maya-specific extents
UsdMayaUtil::AddMayaExtents(bbox, fPrim, time);

auto range = bbox.ComputeAlignedRange();
auto min = range.GetMin();
auto max = range.GetMax();
return Ufe::BBox3d(toVector3d(min), toVector3d(max));
return Ufe::BBox3d(toVector3d(range.GetMin()), toVector3d(range.GetMax()));
}

bool UsdObject3d::visibility() const
Expand Down
32 changes: 32 additions & 0 deletions lib/mayaUsd/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@
#include <pxr/base/vt/value.h>
#include <pxr/usd/sdf/path.h>
#include <pxr/usd/sdf/tokens.h>
#include <pxr/usd/usdGeom/camera.h>
#include <pxr/usd/usdGeom/mesh.h>
#include <pxr/usd/usdGeom/metrics.h>
#include <pxr/usd/usdGeom/xformCache.h>

using namespace MAYAUSD_NS_DEF;

Expand Down Expand Up @@ -118,6 +120,18 @@ bool shouldAddToSet(const MDagPath& toAdd, const UsdMayaUtil::MDagPathSet& dagPa

return true;
}

bool GetMayaExtent(const UsdPrim& prim, GfRange3d& range)
{
if (prim.IsA<UsdGeomCamera>()) {
// UsdGeomCamera, not being a UsdGeomBoundable, doesn't provide any extent information.
// So let's add Maya camera dimensions here
range = GfRange3d(GfVec3d(-0.4f, -0.3f, -2.0f), GfVec3d(0.4f, 1.0f, 2.0f));
return true;
}

return false;
}
} // namespace

double UsdMayaUtil::ConvertMDistanceUnitToUsdGeomLinearUnit(const MDistance::Unit mdistanceUnit)
Expand Down Expand Up @@ -2523,3 +2537,21 @@ UsdMayaUtil::getAllSublayers(const std::vector<std::string>& layerPaths, bool in

return layers;
}

void UsdMayaUtil::AddMayaExtents(GfBBox3d& bbox, const UsdPrim& root, const UsdTimeCode time)
{
GfRange3d localExtents;
if (GetMayaExtent(root, localExtents)) {
bbox = GfBBox3d::Combine(bbox, GfBBox3d(localExtents));
}

UsdGeomXformCache xformCache(time);
UsdPrimSubtreeRange descendants = root.GetDescendants();
for (auto it = descendants.begin(); it != descendants.end(); ++it) {
if (GetMayaExtent(*it, localExtents)) {
bool resetXformStack;
auto xform = xformCache.ComputeRelativeTransform(*it, root, &resetXformStack);
bbox = GfBBox3d::Combine(bbox, GfBBox3d(localExtents, xform));
}
}
}
8 changes: 8 additions & 0 deletions lib/mayaUsd/utils/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,14 @@ MAYAUSD_CORE_PUBLIC
std::set<std::string>
getAllSublayers(const std::vector<std::string>& parentLayerPaths, bool includeParents = false);

/// Takes the supplied bounding box and adds to it Maya-specific extents
/// that come from the nodes originating from the supplied root node
MAYAUSD_CORE_PUBLIC
void AddMayaExtents(
PXR_NS::GfBBox3d& bbox,
const PXR_NS::UsdPrim& root,
const PXR_NS::UsdTimeCode time);

} // namespace UsdMayaUtil

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down