diff --git a/lib/flowViewport/API/interfacesImp/fvpDataProducerSceneIndexInterfaceImp.cpp b/lib/flowViewport/API/interfacesImp/fvpDataProducerSceneIndexInterfaceImp.cpp index f45c6c5d6d..f1453a1861 100644 --- a/lib/flowViewport/API/interfacesImp/fvpDataProducerSceneIndexInterfaceImp.cpp +++ b/lib/flowViewport/API/interfacesImp/fvpDataProducerSceneIndexInterfaceImp.cpp @@ -58,12 +58,12 @@ bool DataProducerSceneIndexInterfaceImp::addDataProducerSceneIndex(const PXR_NS: const std::string& rendererNames /*= allRenderers*/, const PXR_NS::SdfPath& customDataProducerSceneIndexRootPathForInsertion /*= PXR_NS::SdfPath::AbsoluteRootPath()*/) { - //hydraViewportId can DataProducerSceneIndexInterface::allViewports, meaning the user wants customDataProducerSceneIndex to be applied in all viewports. PXR_NS::FVP_NS_DEF::DataProducerSceneIndexDataBaseRefPtr dataProducerSceneIndexData = _CreateDataProducerSceneIndexData(customDataProducerSceneIndex, rendererNames, customDataProducerSceneIndexRootPathForInsertion, dccNode); if (nullptr == dataProducerSceneIndexData){ return false; } + //PXR_NS::FvpViewportAPITokens->allViewports == hydraViewportId means the user wants customDataProducerSceneIndex to be applied in all viewports. if (PXR_NS::FvpViewportAPITokens->allViewports == hydraViewportId){ //Apply this data producer scene index to all viewports return _AddDataProducerSceneIndexToAllViewports(dataProducerSceneIndexData); diff --git a/lib/flowViewport/API/perViewportSceneIndicesData/fvpDataProducerSceneIndexDataBase.cpp b/lib/flowViewport/API/perViewportSceneIndicesData/fvpDataProducerSceneIndexDataBase.cpp index fcc8f85d3b..213267280c 100644 --- a/lib/flowViewport/API/perViewportSceneIndicesData/fvpDataProducerSceneIndexDataBase.cpp +++ b/lib/flowViewport/API/perViewportSceneIndicesData/fvpDataProducerSceneIndexDataBase.cpp @@ -164,10 +164,8 @@ void DataProducerSceneIndexDataBase::_CreateSceneIndexChainForDataProducerSceneI AddParentPrimToSceneIndex(); //Create a filtering scene index to update the information (transform, visibility,...) from the parent prim. - _parentDataModifierSceneIndex = ParentDataModifierSceneIndex::New(_retainedSceneIndex); - _parentDataModifierSceneIndex->SetParentPath(_parentPath);//Set the parent path inside - _parentDataModifierSceneIndex->SetParentTransformMatrix(_parentMatrix); - + _parentDataModifierSceneIndex = ParentDataModifierSceneIndex::New(_retainedSceneIndex, _parentPath, _parentMatrix, true); + //Add a prefixing scene index to _dataProducerSceneIndex to set the parent which we added to the retainedsceneindex HdPrefixingSceneIndexRefPtr prefixingSceneIndex = HdPrefixingSceneIndex::New(_dataProducerSceneIndex, _parentPath); diff --git a/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp b/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp index ea9d8c7f05..00f139ab55 100644 --- a/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp +++ b/lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp @@ -120,8 +120,8 @@ namespace PrototypeInstancing namespace FVP_NS_DEF { DataProducerSceneIndexExample::DataProducerSceneIndexExample() : - _cubeRootPath(SdfPath(TfStringPrintf("/DataProducerSceneIndexExample/cube_%p", this))),//Is the root path for the cubes - _instancerPath(SdfPath(TfStringPrintf("/DataProducerSceneIndexExample/instancer_%p", this)))//Is the instancer path when using instancing + _cubeRootPath(SdfPath(TfStringPrintf("/cube_%p", this))),//Is the root path for the cubes + _instancerPath(SdfPath(TfStringPrintf("/instancer_%p", this)))//Is the instancer path when using instancing { //Create the HdRetainedSceneIndex to be able to easily add primitives _retainedSceneIndex = HdRetainedSceneIndex::New(); diff --git a/lib/flowViewport/sceneIndex/fvpParentDataModifierSceneIndex.h b/lib/flowViewport/sceneIndex/fvpParentDataModifierSceneIndex.h index f0bbab3b2d..f38ea99a58 100644 --- a/lib/flowViewport/sceneIndex/fvpParentDataModifierSceneIndex.h +++ b/lib/flowViewport/sceneIndex/fvpParentDataModifierSceneIndex.h @@ -40,11 +40,10 @@ class ParentDataModifierSceneIndex : public HdSingleInputFilteringSceneIndexBase public: using ParentClass = HdSingleInputFilteringSceneIndexBase; - static ParentDataModifierSceneIndexRefPtr New(const HdSceneIndexBaseRefPtr& _inputSceneIndex){ - return TfCreateRefPtr(new ParentDataModifierSceneIndex(_inputSceneIndex)); + static ParentDataModifierSceneIndexRefPtr New(const HdSceneIndexBaseRefPtr& inputSceneIndex, const SdfPath& parentPath, const GfMatrix4d& transformMatrix, bool visible){ + return TfCreateRefPtr(new ParentDataModifierSceneIndex(inputSceneIndex, parentPath, transformMatrix, visible)); } - void SetParentPath (const SdfPath& parentPath) {_parentPath = parentPath;} void SetParentTransformMatrix (const GfMatrix4d& transformMatrix) {_transformMatrix = transformMatrix;} void SetParentVisibility (bool visible) {_visible = visible;} @@ -86,7 +85,8 @@ class ParentDataModifierSceneIndex : public HdSingleInputFilteringSceneIndexBase GfMatrix4d _transformMatrix; bool _visible = true; private: - ParentDataModifierSceneIndex(const HdSceneIndexBaseRefPtr& _inputSceneIndex) : ParentClass(_inputSceneIndex){} + ParentDataModifierSceneIndex(const HdSceneIndexBaseRefPtr& _inputSceneIndex, const SdfPath& parentPath, const GfMatrix4d& transformMatrix, bool visible) : + ParentClass(_inputSceneIndex), _parentPath(parentPath), _transformMatrix(transformMatrix), _visible(visible) {} }; } //End of namespace FVP_NS_DEF diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraMayaDataProducerSceneIndexData.cpp b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraMayaDataProducerSceneIndexData.cpp index 44d84fadf0..33c40440b2 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraMayaDataProducerSceneIndexData.cpp +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraMayaDataProducerSceneIndexData.cpp @@ -89,6 +89,10 @@ MayaDataProducerSceneIndexData::MayaDataProducerSceneIndexData(const FVP_NS_DEF: MObject* mObj = reinterpret_cast(_dccNode); _mObjHandle = MObjectHandle(*mObj); + _mayaNodeDagPath = MDagPath::getAPathTo(*mObj); + + _CopyMayaNodeTransform();//Copy it so that the classes created in _CreateSceneIndexChainForDataProducerSceneIndex have the up to date matrix + //The user provided a DCC node, it's a maya MObject in maya hydra _CreateSceneIndexChainForDataProducerSceneIndex(); @@ -97,8 +101,6 @@ MayaDataProducerSceneIndexData::MayaDataProducerSceneIndexData(const FVP_NS_DEF: _nodeMessageCallbackIds.append(cbId); } - _mayaNodeDagPath = MDagPath::getAPathTo(*mObj); - //Also monitor parent DAG node to be able to update the scene index if the parent transform is modified or the visibility changed MDagPath parentDagPath = _mayaNodeDagPath; parentDagPath.pop(); @@ -136,6 +138,12 @@ MayaDataProducerSceneIndexData::~MayaDataProducerSceneIndexData() } void MayaDataProducerSceneIndexData::UpdateTransformFromMayaNode() +{ + _CopyMayaNodeTransform(); + UpdateHydraTransformFromParentPath(); +} + +void MayaDataProducerSceneIndexData::_CopyMayaNodeTransform() { if (_mayaNodeDagPath.isValid()){ //Get Maya transform value @@ -144,9 +152,6 @@ void MayaDataProducerSceneIndexData::UpdateTransformFromMayaNode() //Copy Maya matrix into _parentMatrix member of this struct memcpy(_parentMatrix.GetArray(), mayaMat[0], sizeof(double) * 16); - - //Update transform in Hydra - UpdateHydraTransformFromParentPath(); } } diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraMayaDataProducerSceneIndexData.h b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraMayaDataProducerSceneIndexData.h index 801ec927ed..e023a8829b 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraMayaDataProducerSceneIndexData.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraMayaDataProducerSceneIndexData.h @@ -57,6 +57,8 @@ TF_DECLARE_WEAK_AND_REF_PTRS(MayaDataProducerSceneIndexData);//Be able to use Re private: MayaDataProducerSceneIndexData(const FVP_NS_DEF::DataProducerSceneIndexDataBase::CreationParameters& params); + void _CopyMayaNodeTransform(); + //The following members are optional and used only when a dccNode was passed in the constructor of DataProducerSceneIndexDataBase /// Is the MObjectHandle of the maya node shape, it may be invalid if no maya node MObject pointer was passed. diff --git a/test/lib/mayaUsd/render/mayaToHydra/cpp/testFlowViewportAPIAddPrims.cpp b/test/lib/mayaUsd/render/mayaToHydra/cpp/testFlowViewportAPIAddPrims.cpp index 7dd9536dc7..8b1cc5a39f 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/cpp/testFlowViewportAPIAddPrims.cpp +++ b/test/lib/mayaUsd/render/mayaToHydra/cpp/testFlowViewportAPIAddPrims.cpp @@ -60,7 +60,7 @@ TEST(FlowViewportAPI, addPrimitives) //hydraViewportDataProducerSceneIndexExample is what will inject the 3D grid of Hydra cube mesh primitives into the viewport Fvp::DataProducerSceneIndexExample hydraViewportDataProducerSceneIndexExample; - const std::string firstCubePath (TfStringPrintf("/DataProducerSceneIndexExample/cube_%p0_0_0", &hydraViewportDataProducerSceneIndexExample)); + const std::string firstCubePath (TfStringPrintf("/cube_%p0_0_0", &hydraViewportDataProducerSceneIndexExample)); //Setup cube grid parameters hydraViewportDataProducerSceneIndexExample.setCubeGridParams(cubeGridParams);