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-111889 point snapping to similar instances #1521

Merged
merged 16 commits into from
Jul 14, 2021
1 change: 1 addition & 0 deletions lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target_sources(${PROJECT_NAME}
draw_item.cpp
instancer.cpp
material.cpp
mayaPrimCommon.cpp
mesh.cpp
meshViewportCompute.cpp
proxyRenderDelegate.cpp
Expand Down
5 changes: 4 additions & 1 deletion lib/mayaUsd/render/vp2RenderDelegate/draw_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ HdVP2DrawItem::~HdVP2DrawItem()
}
}

void HdVP2DrawItem::AddRenderItem(MHWRender::MRenderItem* item, const HdGeomSubset* geomSubset)
HdVP2DrawItem::RenderItemData&
HdVP2DrawItem::AddRenderItem(MHWRender::MRenderItem* item, const HdGeomSubset* geomSubset)
{
_renderItems.emplace_back();
RenderItemData& renderItemData = _renderItems.back();
Expand All @@ -69,6 +70,8 @@ void HdVP2DrawItem::AddRenderItem(MHWRender::MRenderItem* item, const HdGeomSubs

renderItemData._indexBuffer.reset(
new MHWRender::MIndexBuffer(MHWRender::MGeometry::kUnsignedInt32));

return renderItemData;
}

PXR_NAMESPACE_CLOSE_SCOPE
15 changes: 12 additions & 3 deletions lib/mayaUsd/render/vp2RenderDelegate/draw_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,20 @@ class HdVP2DrawItem final : public HdDrawItem
//! Is _shader a fallback material?
bool _shaderIsFallback { true };

//! Fallback color changed
bool _fallbackColorDirty { true };

//! Whether or not the render item is enabled
bool _enabled { true };

//! Whether or not the render item is transparent
bool _transparent { false };

#ifdef MAYA_NEW_POINT_SNAPPING_SUPPORT
//! Whether or not the render item represents the shaded draw for selected instances
bool _shadedSelectedInstances { false };
#endif

//! Primitive type of the render item
MHWRender::MGeometry::Primitive _primitiveType {
MHWRender::MGeometry::kInvalidPrimitive
Expand Down Expand Up @@ -103,16 +111,17 @@ class HdVP2DrawItem final : public HdDrawItem
//! can be created for multiple usages.
enum RenderItemUsage
{
kRegular = 1 << 0, //!< Regular drawing (shaded, wireframe etc.)
kSelectionHighlight = 1 << 1 //!< Selection highlight.
kRegular = 1 << 0, //!< Regular drawing (shaded, wireframe etc.)
kSelectionHighlight = kRegular << 1 //!< Selection highlight.
};

public:
HdVP2DrawItem(HdVP2RenderDelegate* delegate, const HdRprimSharedData* sharedData);

~HdVP2DrawItem();

void AddRenderItem(MHWRender::MRenderItem* item, const HdGeomSubset* geomSubset = nullptr);
RenderItemData&
AddRenderItem(MHWRender::MRenderItem* item, const HdGeomSubset* geomSubset = nullptr);

using RenderItemDataVector = std::vector<RenderItemData>;
const RenderItemDataVector& GetRenderItems() const { return _renderItems; }
Expand Down
45 changes: 45 additions & 0 deletions lib/mayaUsd/render/vp2RenderDelegate/mayaPrimCommon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Copyright 2021 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 "mayaPrimCommon.h"

PXR_NAMESPACE_OPEN_SCOPE

#ifdef MAYA_NEW_POINT_SNAPPING_SUPPORT

namespace {

MayaUsdCustomData sMayaUsdCustomData;

} // namespace

/* static */
InstanceIdMap& MayaUsdCustomData::Get(const MHWRender::MRenderItem& renderItem)
{
return sMayaUsdCustomData._itemData[renderItem.InternalObjectId()];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This data structure always grows. Is there a point in time where the data can be cleaned-up?

}

/* static */
void MayaUsdCustomData::Remove(const MHWRender::MRenderItem& renderItem)
{
// not thread safe, so if they are destroyed in parallel this will crash.
// consider concurrent_hash_map for locking version that can erase
sMayaUsdCustomData._itemData.unsafe_erase(renderItem.InternalObjectId());
}

#endif

PXR_NAMESPACE_CLOSE_SCOPE
23 changes: 23 additions & 0 deletions lib/mayaUsd/render/vp2RenderDelegate/mayaPrimCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,31 @@
#include "pxr/imaging/hd/changeTracker.h"
#include "pxr/imaging/hd/types.h"

#include <maya/MHWGeometry.h>

#include <tbb/concurrent_unordered_map.h>

#include <vector>

PXR_NAMESPACE_OPEN_SCOPE

#ifdef MAYA_NEW_POINT_SNAPPING_SUPPORT
// Each instanced render item needs to map from a Maya instance id
// back to a usd instance id.
using InstanceIdMap = std::vector<unsigned int>;

// global singleton rather than MUserData, because consolidated world will
// not consolidate render items with different MUserData objects.
class MayaUsdCustomData
{
public:
tbb::concurrent_unordered_map<int, InstanceIdMap> _itemData;

static InstanceIdMap& Get(const MHWRender::MRenderItem& item);
static void Remove(const MHWRender::MRenderItem& item);
};
#endif

struct MayaPrimCommon
{
enum DirtyBits : HdDirtyBits
Expand Down
Loading