Skip to content

Commit

Permalink
Merge pull request #1521 from Autodesk/krickw/MAYA-111889/point_snapp…
Browse files Browse the repository at this point in the history
…ing_to_similar_instances

MAYA-111889 point snapping to similar instances
  • Loading branch information
Krystian Ligenza authored Jul 14, 2021
2 parents 147efb6 + 44e1108 commit 0cb5ec9
Show file tree
Hide file tree
Showing 9 changed files with 528 additions and 262 deletions.
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()];
}

/* 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

0 comments on commit 0cb5ec9

Please sign in to comment.