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

Tremblp/hydra 929/custom data producer picking #140

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void DataProducerSceneIndexInterfaceImp::_AddDataProducerSceneIndexToThisViewpor
//Add it to the merging scene index if the render inex proxy is present, it may happen that it will be set later
auto renderIndexProxy = viewportInformationAndSceneIndicesPerViewportData->GetRenderIndexProxy();
if (renderIndexProxy && dataProducerSceneIndexData && dataProducerSceneIndexData->GetDataProducerLastSceneIndexChain()){
renderIndexProxy->InsertSceneIndex(dataProducerSceneIndexData->GetDataProducerLastSceneIndexChain(), SdfPath::AbsoluteRootPath());
renderIndexProxy->InsertSceneIndex(dataProducerSceneIndexData->GetDataProducerLastSceneIndexChain(), dataProducerSceneIndexData->GetPrefix());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ bool FilteringSceneIndexInterfaceImp::_CreateSceneFilteringSceneIndicesData(cons

auto findResult = std::find_if(sceneFilteringSceneIndicesData().cbegin(), sceneFilteringSceneIndicesData().cend(),
[&client](const PXR_NS::FVP_NS_DEF::FilteringSceneIndexDataBaseRefPtr& filteringSIData) { return filteringSIData->getClient() == client;});
if (findResult != sceneFilteringSceneIndicesData().cend()){
if (!TF_VERIFY(findResult == sceneFilteringSceneIndicesData().cend(),
"Filtering scene index client already found in FilteringSceneIndexInterfaceImp::_CreateSceneFilteringSceneIndicesData()")){
return false;
}

Expand Down
169 changes: 92 additions & 77 deletions lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.cpp

Large diffs are not rendered by default.

35 changes: 19 additions & 16 deletions lib/flowViewport/API/samples/fvpDataProducerSceneIndexExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
#include <pxr/base/tf/refPtr.h>
#include <pxr/base/gf/matrix4d.h>
#include <pxr/base/vt/array.h>
#include <pxr/usd/sdf/path.h>
#include <pxr/imaging/hd/retainedSceneIndex.h>
#include <pxr/imaging/hd/dataSource.h>
#include <pxr/imaging/hd/retainedDataSource.h>

#include <set>
#include <map>

namespace FVP_NS_DEF {

/** This class is an example on how to add Hydra primitives into a Hydra viewport.
Expand Down Expand Up @@ -67,17 +71,7 @@ class FVP_API DataProducerSceneIndexExample
struct CubeGridCreationParams
{
/// Constructor
CubeGridCreationParams(){
_numLevelsX = 10;//Default values
_numLevelsY = 10;
_numLevelsZ = 1;
_halfSize = 2.0;
_color = {0.f, 1.0f, 0.0f};
_opacity = 0.8;
_deltaTrans = {5.0f, 5.0f, 5.0f};
_initalTransform.SetIdentity();
_useInstancing = false;
}
CubeGridCreationParams() = default;

//Comparison operator
bool operator == (const CubeGridCreationParams& other)const{
Expand All @@ -87,9 +81,11 @@ class FVP_API DataProducerSceneIndexExample
(_halfSize == other._halfSize) &&
(_color == other._color) &&
(_opacity == other._opacity) &&
(_initalTransform == other._initalTransform)&&
(_initialTransform == other._initialTransform)&&
(_deltaTrans == other._deltaTrans) &&
(_useInstancing == other._useInstancing);
(_useInstancing == other._useInstancing) &&
(_hidden == other._hidden) &&
(_transformed == other._transformed);
}

/// Number of X levels for the 3D grid of cube primitives
Expand All @@ -105,21 +101,28 @@ class FVP_API DataProducerSceneIndexExample
/// Opacity of each cube in the 3D grid.
double _opacity{0.8};
/// Initial transform of each cube in the 3D grid.
PXR_NS::GfMatrix4d _initalTransform;
PXR_NS::GfMatrix4d _initialTransform{1.0};
/** _deltaTrans.x is the space between 2 cubes on the X axis of the 3D grid.
* _deltaTrans.y is the space between 2 cubes on the Y axis of the 3D grid.
* _deltaTrans.z is the space between 2 cubes on the Z axis of the 3D grid.
* */
PXR_NS::GfVec3f _deltaTrans{5.0f, 5.0f, 5.0f};
/// if _useInstancing is true, then we are using Hydra instancing to create the cube primitives, if it is false then we are not using Hydra instancing.
bool _useInstancing{false};

// Hidden cubes, indexed by name, when not using instancing.
std::set<std::string> _hidden{};

// Transformed cubes, indexed by name, when not using instancing.
// At time of writing (31-May-2024) only translation is supported.
std::map<std::string, PXR_NS::GfVec3d> _transformed{};
};

///Set the CubeGridCreationParams
void setCubeGridParams(const CubeGridCreationParams& params);

///Call FlowViewport::DataProducerSceneIndexInterface::_AddDataProducerSceneIndex to add our data producer scene index to create the 3D grid of cubes
void addDataProducerSceneIndex();
void addDataProducerSceneIndex(const PXR_NS::SdfPath& prefix = PXR_NS::SdfPath::AbsoluteRootPath());

///Call the FlowViewport::DataProducerSceneIndexInterface::RemoveViewportDataProducerSceneIndex to remove our data producer scene index from the Hydra viewport
void removeDataProducerSceneIndex();
Expand Down Expand Up @@ -190,4 +193,4 @@ class FVP_API DataProducerSceneIndexExample

} //end of namespace FVP_NS_DEF {

#endif //FLOW_VIEWPORT_EXAMPLES_DATA_PRODUCER_SCENE_INDEX_EXAMPLE_H
#endif //FLOW_VIEWPORT_EXAMPLES_DATA_PRODUCER_SCENE_INDEX_EXAMPLE_H
9 changes: 9 additions & 0 deletions lib/flowViewport/fvpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include "fvpUtils.h"

#include <pxr/imaging/hd/selectionSchema.h>

namespace FVP_NS_DEF {

#ifdef CODE_COVERAGE_WORKAROUND
Expand All @@ -30,4 +32,11 @@ void leakSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& si) {
}
#endif

PXR_NS::HdDataSourceBaseHandle createFullySelectedDataSource()
{
PXR_NS::HdSelectionSchema::Builder selectionBuilder;
selectionBuilder.SetFullySelected(PXR_NS::HdRetainedTypedSampledDataSource<bool>::New(true));
return PXR_NS::HdDataSourceBase::Cast(selectionBuilder.Build());
}

} // namespace FVP_NS_DEF
2 changes: 2 additions & 0 deletions lib/flowViewport/fvpUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class PrimvarDataSource final : public PXR_NS::HdContainerDataSource
PXR_NS::TfToken _role;
};

PXR_NS::HdDataSourceBaseHandle FVP_API createFullySelectedDataSource();

} // namespace FVP_NS_DEF

#endif // FVP_UTILS_H
20 changes: 19 additions & 1 deletion lib/flowViewport/sceneIndex/fvpSelectionSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "flowViewport/sceneIndex/fvpSelectionSceneIndex.h"
#include "flowViewport/sceneIndex/fvpPathInterface.h"
#include "flowViewport/selection/fvpSelection.h"
#include <flowViewport/selection/fvpPathMapper.h>
#include <flowViewport/selection/fvpPathMapperRegistry.h>

#include "flowViewport/debugCodes.h"

Expand Down Expand Up @@ -265,7 +267,23 @@ PrimSelections SelectionSceneIndex::UfePathToPrimSelections(const Ufe::Path& app
auto primSelections = _inputSceneIndexPathInterface->UfePathToPrimSelections(appPath);

if (primSelections.empty()) {
TF_WARN("SelectionSceneIndex::UfePathToPrimSelections(%s) returned no path, Hydra selection will be incorrect", Ufe::PathString::string(appPath).c_str());
// Path interface of input scene index didn't provide information.
// Try path mapper registry.
auto mapper = Fvp::PathMapperRegistry::Instance().GetMapper(appPath);

auto warnEmptyPath = [](const Ufe::Path& appPath) {
TF_WARN("SelectionSceneIndex::UfePathToPrimSelections(%s) returned no path, Hydra selection will be incorrect", Ufe::PathString::string(appPath).c_str());
};

if (!mapper) {
warnEmptyPath(appPath);
}
else {
primSelections = mapper->UfePathToPrimSelections(appPath);
if (primSelections.empty()) {
warnEmptyPath(appPath);
}
}
}

return primSelections;
Expand Down
8 changes: 8 additions & 0 deletions lib/flowViewport/selection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ target_sources(${TARGET_NAME}
fvpSelectionFwd.cpp
fvpSelectionTask.cpp
fvpSelectionTracker.cpp
fvpPathMapper.cpp
fvpPathMapperFwd.cpp
fvpPathMapperRegistry.cpp
fvpPrefixPathMapper.cpp
)

set(HEADERS
fvpSelection.h
fvpSelectionFwd.h
fvpSelectionTask.h
fvpSelectionTracker.h
fvpPathMapper.h
fvpPathMapperFwd.h
fvpPathMapperRegistry.h
fvpPrefixPathMapper.h
)

# -----------------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions lib/flowViewport/selection/fvpPathMapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include <flowViewport/selection/fvpPathMapper.h>
51 changes: 51 additions & 0 deletions lib/flowViewport/selection/fvpPathMapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef FVP_PATH_MAPPER_H
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we said the define should contain a part of the path like FVP_SELECTION_PATH_MAPPER_H

#define FVP_PATH_MAPPER_H

#include <flowViewport/api.h>
#include <flowViewport/selection/fvpPathMapperFwd.h>
#include <flowViewport/sceneIndex/fvpPathInterface.h>

#include <pxr/usd/sdf/path.h>

#include <ufe/ufe.h>

UFE_NS_DEF {
class Path;
}

namespace FVP_NS_DEF {

/// \class PathMapper
///
/// The path handler performs application path to scene index path mapping.
///
/// This is useful for selection highlighting, where an application selection
/// path is converted to a path to a Hydra scene index prim that must be
/// highlighted.

class PathMapper : public PathInterface
{
protected:

FVP_API
PathMapper() = default;
};

}

#endif
17 changes: 17 additions & 0 deletions lib/flowViewport/selection/fvpPathMapperFwd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include <flowViewport/selection/fvpPathMapperFwd.h>
32 changes: 32 additions & 0 deletions lib/flowViewport/selection/fvpPathMapperFwd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef FVP_SELECTION_PATH_MAPPER_FWD_H
#define FVP_SELECTION_PATH_MAPPER_FWD_H

#include <flowViewport/api.h>

#include <memory>

namespace FVP_NS_DEF {

class PathMapper;

using PathMapperPtr = std::shared_ptr<PathMapper>;
using PathMapperConstPtr = std::shared_ptr<const PathMapper>;

}

#endif
Loading
Loading