From 774bd258d861a40bacea4a7103dd33dfc1af449c Mon Sep 17 00:00:00 2001 From: Keli Li Date: Tue, 16 Jan 2024 14:05:41 -0500 Subject: [PATCH] fix the double transform issue on instanced prims --- .../fvpDataProducerSceneIndexExample.cpp | 22 ++++--------------- .../fvpDataProducerSceneIndexExample.h | 7 +----- .../flowViewportAPIMayaLocator.cpp | 18 --------------- 3 files changed, 5 insertions(+), 42 deletions(-) diff --git a/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp b/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp index 00f139ab55..15122fc76b 100644 --- a/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp +++ b/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp @@ -126,9 +126,6 @@ DataProducerSceneIndexExample::DataProducerSceneIndexExample() : //Create the HdRetainedSceneIndex to be able to easily add primitives _retainedSceneIndex = HdRetainedSceneIndex::New(); - //set the container node inverse transform being identity - _containerNodeInvTransform.SetIdentity(); - //Add all primitives _AddAllPrims(); } @@ -218,13 +215,10 @@ void DataProducerSceneIndexExample::_AddAllPrimsWithInstancing() { static const bool instancing = true; - //We need to apply the inverse of the container node transform for instances so that it is not applied twice, once on the original cube and once on the instancer node. - GfMatrix4d transform = _currentCubeGridParams._initalTransform * _containerNodeInvTransform; - //Copy the main cube primitive in the array, we will update only the SdfPath and the transform, all others attributes are identical HdRetainedSceneIndex::AddedPrimEntry cubePrimEntry = _CreateCubePrim(_cubeRootPath, _currentCubeGridParams._halfSize, _currentCubeGridParams._color, _currentCubeGridParams._opacity, - transform, instancing); + _currentCubeGridParams._initalTransform, instancing); //Add the cube to the retained scene index _retainedSceneIndex->AddPrims({cubePrimEntry}); @@ -499,7 +493,9 @@ HdRetainedSceneIndex::AddedPrimEntry DataProducerSceneIndexExample::_CreateCubeP HdXformSchemaTokens->xform, HdXformSchema::Builder() .SetMatrix(HdRetainedTypedSampledDataSource::New( - transform)).Build(), + transform)) + .SetResetXformStack(HdRetainedTypedSampledDataSource::New(true)) //Mark the transform of prototype not inherit from parent + .Build(), //create a mesh HdMeshSchemaTokens->mesh, @@ -550,14 +546,4 @@ void DataProducerSceneIndexExample::removeDataProducerSceneIndex() } } -void DataProducerSceneIndexExample::setContainerNodeInverseTransform(const PXR_NS::GfMatrix4d& InvTransform) -{ - _containerNodeInvTransform = InvTransform; - if (_currentCubeGridParams._useInstancing){ - //Update with the current transform - _RemoveAllPrims(); - _AddAllPrims(); - } -} - } //End of namespace FVP_NS_DEF diff --git a/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.h b/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.h index b19706b247..e30c45feb1 100644 --- a/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.h +++ b/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.h @@ -42,8 +42,7 @@ namespace FVP_NS_DEF { * Fvp::DataProducerSceneIndexInterface& dataProducerSceneIndexInterface = Fvp::DataProducerSceneIndexInterface::get() * 2. Optionally, set the DCC container node (for example : a MObject* for maya) by calling the setContainerNode function. * 3. Optionally, if you want to change the grid of cubes primitives, call setCubeGridParams -* 4. Optionally, if you are using instancing on the cube primitives, call setContainerNodeInverseTransform with the suitable transform from your DCC node. -* 5. Call addDataProducerSceneIndex() which will add the data producer scene index to all viewports +* 4. Call addDataProducerSceneIndex() which will add the data producer scene index to all viewports * * The call to removeDataProducerSceneIndex() which will remove the primitives from the viewport is done in the destructor of this class. */ @@ -60,7 +59,6 @@ class FVP_API DataProducerSceneIndexExample * Is also our triggering function to add the data producer scene index as we want to wait to have the DCC node pointer value initialized before dataProducer the scene index. */ void setContainerNode(void* node){_containerNode = node;} - void setContainerNodeInverseTransform(const PXR_NS::GfMatrix4d& InvTransform); /// Compute the resulting axis aligned bounding box of the 3D grid of cube primitives, is used by the DCC node to give its bounding box void getPrimsBoundingBox(float& corner1X, float& corner1Y, float& corner1Z, float& corner2X, float& corner2Y, float& corner2Z)const; @@ -152,9 +150,6 @@ class FVP_API DataProducerSceneIndexExample /// Container node from a DCC (maya for example) void* _containerNode {nullptr};//Is a MObject* for Maya - ///Is the container node inverse transform matrix to remove transform matrix being applied twice for instances - PXR_NS::GfMatrix4d _containerNodeInvTransform; - /// Did we already add this data producer scene index to some render index ? bool _dataProducerSceneIndexAdded {false}; diff --git a/lib/mayaHydra/flowViewportAPIExamples/flowViewportAPIMayaLocator/flowViewportAPIMayaLocator.cpp b/lib/mayaHydra/flowViewportAPIExamples/flowViewportAPIMayaLocator/flowViewportAPIMayaLocator.cpp index 7fda154274..d5cf868ab9 100644 --- a/lib/mayaHydra/flowViewportAPIExamples/flowViewportAPIMayaLocator/flowViewportAPIMayaLocator.cpp +++ b/lib/mayaHydra/flowViewportAPIExamples/flowViewportAPIMayaLocator/flowViewportAPIMayaLocator.cpp @@ -156,23 +156,6 @@ namespace //Callback when an attribute of this Maya node changes void transformAttributeChangedCallback(MNodeMessage::AttributeMessage msg, MPlug& plug, MPlug & otherPlug, void* dataProducerSceneIndexData) { - //Dealing with the transform only - MFnAttribute attr (plug.attribute()); - if (MayaHydra::IsAMayaTransformAttributeName(attr.name())){ - - if (! dataProducerSceneIndexData){ - return; - } - FlowViewportAPIMayaLocator* flowViewportAPIMayaLocator = reinterpret_cast(dataProducerSceneIndexData); - - GfMatrix4d nodeInvTransform; - MObject mObj = flowViewportAPIMayaLocator->thisMObject(); - MStatus stat = GetNodeInverseTransform(mObj, nodeInvTransform); - CHECK_MSTATUS(stat); - if (MStatus::kSuccess == stat){ - flowViewportAPIMayaLocator->_hydraViewportDataProducerSceneIndexExample.setContainerNodeInverseTransform(nodeInvTransform); - } - } } //Callback when an attribute of this Maya node changes @@ -438,7 +421,6 @@ void FlowViewportAPIMayaLocator::SetupFlowViewportInterfaces() GfMatrix4d nodeInvTransform; GetNodeInverseTransform(_thisMObject, nodeInvTransform); _hydraViewportDataProducerSceneIndexExample.setContainerNode(&_thisMObject); - _hydraViewportDataProducerSceneIndexExample.setContainerNodeInverseTransform(nodeInvTransform); _hydraViewportDataProducerSceneIndexExample.addDataProducerSceneIndex(); //Register a filtering scene index client