Skip to content

Commit

Permalink
HYDRA-718 : Fix added prims being at the wrong place when saving/load…
Browse files Browse the repository at this point in the history
…ing a scene.
  • Loading branch information
lanierd-adsk committed Dec 6, 2023
1 parent 5d77522 commit 1d0d5fc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, this))),//Is the root path for the cubes
_instancerPath(SdfPath(TfStringPrintf("/instancer_%p", this, this)))//Is the instancer path when using instancing
{
//Create the HdRetainedSceneIndex to be able to easily add primitives
_retainedSceneIndex = HdRetainedSceneIndex::New();
Expand Down
8 changes: 4 additions & 4 deletions lib/flowViewport/sceneIndex/fvpParentDataModifierSceneIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ MayaDataProducerSceneIndexData::MayaDataProducerSceneIndexData(const FVP_NS_DEF:
MObject* mObj = reinterpret_cast<MObject*>(_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();

Expand All @@ -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();
Expand Down Expand Up @@ -136,6 +138,12 @@ MayaDataProducerSceneIndexData::~MayaDataProducerSceneIndexData()
}

void MayaDataProducerSceneIndexData::UpdateTransformFromMayaNode()
{
_CopyMayaNodeTransform();
UpdateHydraTransformFromParentPath();
}

void MayaDataProducerSceneIndexData::_CopyMayaNodeTransform()
{
if (_mayaNodeDagPath.isValid()){
//Get Maya transform value
Expand All @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1d0d5fc

Please sign in to comment.