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

HYDRA-765 - fix the double transform issue on instanced prims #39

Merged
merged 1 commit into from
Jan 18, 2024
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
22 changes: 4 additions & 18 deletions lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -499,7 +493,9 @@ HdRetainedSceneIndex::AddedPrimEntry DataProducerSceneIndexExample::_CreateCubeP
HdXformSchemaTokens->xform,
HdXformSchema::Builder()
.SetMatrix(HdRetainedTypedSampledDataSource<GfMatrix4d>::New(
transform)).Build(),
transform))
.SetResetXformStack(HdRetainedTypedSampledDataSource<bool>::New(true)) //Mark the transform of prototype not inherit from parent
.Build(),

//create a mesh
HdMeshSchemaTokens->mesh,
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
Expand Down Expand Up @@ -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};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlowViewportAPIMayaLocator*>(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
Expand Down Expand Up @@ -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
Expand Down