diff --git a/lib/mayaUsd/render/vp2RenderDelegate/basisCurves.cpp b/lib/mayaUsd/render/vp2RenderDelegate/basisCurves.cpp index 5326147aaa..8eb83e5f47 100644 --- a/lib/mayaUsd/render/vp2RenderDelegate/basisCurves.cpp +++ b/lib/mayaUsd/render/vp2RenderDelegate/basisCurves.cpp @@ -1075,6 +1075,9 @@ HdVP2BasisCurves::_UpdateDrawItem( // The current instancer invalidation tracking makes it hard for // us to tell whether transforms will be dirty, so this code // pulls them every time something changes. + // If the mesh is instanced but has 0 instance transforms remember that + // so the render item can be hidden. + bool instancerWithNoInstances = false; if (!GetInstancerId().IsEmpty()) { // Retrieve instance transforms from the instancer. @@ -1083,10 +1086,14 @@ HdVP2BasisCurves::_UpdateDrawItem( ComputeInstanceTransforms(id); MMatrix instanceMatrix; + const unsigned int instanceCount = transforms.size(); - if (isDedicatedSelectionHighlightItem) { + if (0 == instanceCount) { + instancerWithNoInstances = true; + } + else if (isDedicatedSelectionHighlightItem) { if (_selectionState == kFullySelected) { - stateToCommit._instanceTransforms.setLength(transforms.size()); + stateToCommit._instanceTransforms.setLength(instanceCount); for (size_t i = 0; i < transforms.size(); ++i) { transforms[i].Get(instanceMatrix.matrix); instanceMatrix = worldMatrix * instanceMatrix; @@ -1104,7 +1111,6 @@ HdVP2BasisCurves::_UpdateDrawItem( } } else { - const unsigned int instanceCount = transforms.size(); stateToCommit._instanceTransforms.setLength(instanceCount); for (size_t i = 0; i < instanceCount; ++i) { transforms[i].Get(instanceMatrix.matrix); @@ -1193,12 +1199,13 @@ HdVP2BasisCurves::_UpdateDrawItem( } // Determine if the render item should be enabled or not. - if (itemDirtyBits & (HdChangeTracker::DirtyVisibility | + if ((itemDirtyBits & (HdChangeTracker::DirtyVisibility | HdChangeTracker::DirtyRenderTag | HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyExtent | - DirtySelectionHighlight)) { - bool enable = drawItem->GetVisible() && !_curvesSharedData._points.empty(); + DirtySelectionHighlight)) || + !GetInstancerId().IsEmpty()) { + bool enable = drawItem->GetVisible() && !_curvesSharedData._points.empty() && !instancerWithNoInstances; if (isDedicatedSelectionHighlightItem) { enable = enable && (_selectionState != kUnselected); diff --git a/lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp b/lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp index 4a7a80c04a..29fd2430ef 100644 --- a/lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp +++ b/lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp @@ -1267,6 +1267,9 @@ void HdVP2Mesh::_UpdateDrawItem( // The current instancer invalidation tracking makes it hard for // us to tell whether transforms will be dirty, so this code // pulls them every time something changes. + // If the mesh is instanced but has 0 instance transforms remember that + // so the render item can be hidden. + bool instancerWithNoInstances = false; if (!GetInstancerId().IsEmpty()) { // Retrieve instance transforms from the instancer. @@ -1275,10 +1278,14 @@ void HdVP2Mesh::_UpdateDrawItem( ComputeInstanceTransforms(id); MMatrix instanceMatrix; + const unsigned int instanceCount = transforms.size(); - if (isDedicatedSelectionHighlightItem) { + if (0 == instanceCount) { + instancerWithNoInstances = true; + } + else if (isDedicatedSelectionHighlightItem) { if (_selectionState == kFullySelected) { - stateToCommit._instanceTransforms.setLength(transforms.size()); + stateToCommit._instanceTransforms.setLength(instanceCount); for (size_t i = 0; i < transforms.size(); ++i) { transforms[i].Get(instanceMatrix.matrix); instanceMatrix = worldMatrix * instanceMatrix; @@ -1296,7 +1303,6 @@ void HdVP2Mesh::_UpdateDrawItem( } } else { - const unsigned int instanceCount = transforms.size(); stateToCommit._instanceTransforms.setLength(instanceCount); for (size_t i = 0; i < instanceCount; ++i) { transforms[i].Get(instanceMatrix.matrix); @@ -1352,12 +1358,13 @@ void HdVP2Mesh::_UpdateDrawItem( } // Determine if the render item should be enabled or not. - if (itemDirtyBits & (HdChangeTracker::DirtyVisibility | + if ((itemDirtyBits & (HdChangeTracker::DirtyVisibility | HdChangeTracker::DirtyRenderTag | HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyExtent | - DirtySelectionHighlight)) { - bool enable = drawItem->GetVisible() && !_meshSharedData._points.empty(); + DirtySelectionHighlight)) || + !GetInstancerId().IsEmpty()) { + bool enable = drawItem->GetVisible() && !_meshSharedData._points.empty() && !instancerWithNoInstances; if (isDedicatedSelectionHighlightItem) { enable = enable && (_selectionState != kUnselected);