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-310 : Support wireframe and wire on shaded and support selection highlight with the right colors #118

Merged
merged 12 commits into from
May 6, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,17 @@ void DataProducerSceneIndexInterfaceImp::_AddDataProducerSceneIndexToThisViewpor
}
}

void DataProducerSceneIndexInterfaceImp::hydraViewportSceneIndexAdded(const InformationInterface::ViewportInformation& viewportInfo)
bool DataProducerSceneIndexInterfaceImp::hydraViewportSceneIndexAdded(const InformationInterface::ViewportInformation& viewportInfo)
{
bool dataProducerSceneIndicesAdded = false;
//Add the data producer scene indices that apply to all viewports to this newly created hydra viewport
std::lock_guard<std::mutex> lockDataProducerSceneIndicesDataPerViewport(dataProducerSceneIndicesThatApplyToAllViewports_mutex);
for (const PXR_NS::FVP_NS_DEF::DataProducerSceneIndexDataBaseRefPtr& dataProducerSceneIndexData : dataProducerSceneIndicesThatApplyToAllViewports){
_AddDataProducerSceneIndexToThisViewport(viewportInfo, dataProducerSceneIndexData);
dataProducerSceneIndicesAdded = true;
}

return dataProducerSceneIndicesAdded;
}

void DataProducerSceneIndexInterfaceImp::setSceneIndexDataFactory(DataProducerSceneIndexDataAbstractFactory& factory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class DataProducerSceneIndexInterfaceImp : public DataProducerSceneIndexInterfac

//Called by flow viewport
///hydraViewportSceneIndexAdded is called when a new hydra viewport is created by the ViewportInformationAndSceneIndicesPerViewportDataManager, it's not a callback.
void hydraViewportSceneIndexAdded(const InformationInterface::ViewportInformation& viewportInfo);
//returns true if some data producer scene indices were added
bool hydraViewportSceneIndexAdded(const InformationInterface::ViewportInformation& viewportInfo);
void removeAllViewportDataProducerSceneIndices(ViewportInformationAndSceneIndicesPerViewportData& viewportInformationAndSceneIndicesPerViewportData);

///Since Flow viewport is DCC agnostic, the DCC will implement a concrete factory and call setSceneIndexDataFactory to register it in this class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ViewportInformationAndSceneIndicesPerViewportDataManager& ViewportInformationAnd
}

//A new Hydra viewport was created
void ViewportInformationAndSceneIndicesPerViewportDataManager::AddViewportInformation(const InformationInterface::ViewportInformation& viewportInfo, const Fvp::RenderIndexProxyPtr& renderIndexProxy,
bool ViewportInformationAndSceneIndicesPerViewportDataManager::AddViewportInformation(const InformationInterface::ViewportInformation& viewportInfo, const Fvp::RenderIndexProxyPtr& renderIndexProxy,
const HdSceneIndexBaseRefPtr& inputSceneIndexForCustomFiltering)
{
TF_AXIOM(renderIndexProxy && inputSceneIndexForCustomFiltering);
Expand All @@ -73,15 +73,15 @@ void ViewportInformationAndSceneIndicesPerViewportDataManager::AddViewportInform
auto findResult = std::find_if(_viewportsInformationAndSceneIndicesPerViewportData.begin(), _viewportsInformationAndSceneIndicesPerViewportData.end(),
[&viewportId](const ViewportInformationAndSceneIndicesPerViewportData& other) { return other.GetViewportInformation()._viewportId == viewportId;});
if (findResult != _viewportsInformationAndSceneIndicesPerViewportData.end()){
return;//It is already inside our array
return false;//It is already inside our array
}

ViewportInformationAndSceneIndicesPerViewportData temp(viewportInfo, renderIndexProxy);
newElement = &(_viewportsInformationAndSceneIndicesPerViewportData.emplace_back(temp));
}

//Call this to let the data producer scene indices that apply to all viewports to be added to this new viewport as well
DataProducerSceneIndexInterfaceImp::get().hydraViewportSceneIndexAdded(viewportInfo);
const bool dataProducerSceneIndicesAdded = DataProducerSceneIndexInterfaceImp::get().hydraViewportSceneIndexAdded(viewportInfo);

//Let the registered clients know a new viewport has been added
InformationInterfaceImp::Get().SceneIndexAdded(viewportInfo);
Expand All @@ -90,11 +90,12 @@ void ViewportInformationAndSceneIndicesPerViewportDataManager::AddViewportInform
TF_AXIOM(newElement);
const HdSceneIndexBaseRefPtr lastFilteringSceneIndex = FilteringSceneIndicesChainManager::get().createFilteringSceneIndicesChain(*newElement,
inputSceneIndexForCustomFiltering);

//Insert the last filtering scene index into the render index
auto renderIndex = renderIndexProxy->GetRenderIndex();
TF_AXIOM(renderIndex);
renderIndex->InsertSceneIndex(lastFilteringSceneIndex, SdfPath::AbsoluteRootPath());

return dataProducerSceneIndicesAdded;
}

void ViewportInformationAndSceneIndicesPerViewportDataManager::RemoveViewportInformation(const std::string& modelPanel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class FVP_API ViewportInformationAndSceneIndicesPerViewportDataManager
static ViewportInformationAndSceneIndicesPerViewportDataManager& Get();

//A new Hydra viewport was created, we need inputSceneIndexForCustomFiltering to be used as an input scene index for custom filtering scene indices
void AddViewportInformation(const InformationInterface::ViewportInformation& viewportInfo, const Fvp::RenderIndexProxyPtr& renderIndexProxy,
//return true if some data producer scene indices were added
bool AddViewportInformation(const InformationInterface::ViewportInformation& viewportInfo, const Fvp::RenderIndexProxyPtr& renderIndexProxy,
const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndexForCustomFiltering);

//A Hydra viewport was deleted
Expand Down
1 change: 1 addition & 0 deletions lib/flowViewport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(HEADERS
fvpUtils.h
global.h
tokens.h
fvpWireframeColorInterface.h
)

# -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ PXR_NAMESPACE_OPEN_SCOPE
(wireframeSelectionSecondary) \
(vertexSelection) \
(edgeSelection) \
(faceSelection)
(faceSelection) \
(polymeshDormant)
// clang-format on

TF_DECLARE_PUBLIC_TOKENS(FvpColorPreferencesTokens, FVP_API, FVP_COLOR_PREFERENCES_TOKENS);
Expand Down
54 changes: 54 additions & 0 deletions lib/flowViewport/fvpUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <pxr/imaging/hd/sceneIndex.h>
#endif

#include <pxr/imaging/hd/tokens.h>
#include <pxr/imaging/hd/retainedDataSource.h>
#include <pxr/imaging/hd/primvarsSchema.h>

namespace FVP_NS_DEF {

// At time of writing, the last reference removal causing destruction of a
Expand All @@ -35,6 +39,56 @@ namespace FVP_NS_DEF {
void FVP_API leakSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& si);
#endif

/// A convenience data source implementing the primvar schema from
/// a triple of primvar value, interpolation and role. The latter two
/// are given as tokens. The value can be given either as data source
/// or as thunk returning a data source which is evaluated on each
/// Get.
class PrimvarDataSource final : public PXR_NS::HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(PrimvarDataSource);

PXR_NS::TfTokenVector GetNames() override {
return {PXR_NS::HdPrimvarSchemaTokens->primvarValue,
PXR_NS::HdPrimvarSchemaTokens->interpolation,
PXR_NS::HdPrimvarSchemaTokens->role};
}

PXR_NS::HdDataSourceBaseHandle Get(const PXR_NS::TfToken &name) override {
if (name == PXR_NS::HdPrimvarSchemaTokens->primvarValue) {
return _primvarValueSrc;
}
if (name == PXR_NS::HdPrimvarSchemaTokens->interpolation) {
return
PXR_NS::HdPrimvarSchema::BuildInterpolationDataSource(
_interpolation);
}
if (name == PXR_NS::HdPrimvarSchemaTokens->role) {
return
PXR_NS::HdPrimvarSchema::BuildRoleDataSource(
_role);
}

return nullptr;
}

private:
PrimvarDataSource(
const PXR_NS::HdDataSourceBaseHandle &primvarValueSrc,
const PXR_NS::TfToken &interpolation,
const PXR_NS::TfToken &role)
: _primvarValueSrc(primvarValueSrc)
, _interpolation(interpolation)
, _role(role)
{
}

PXR_NS::HdDataSourceBaseHandle _primvarValueSrc;
PXR_NS::TfToken _interpolation;
PXR_NS::TfToken _role;
};

} // namespace FVP_NS_DEF

#endif // FVP_UTILS_H
40 changes: 40 additions & 0 deletions lib/flowViewport/fvpWireframeColorInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// 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 FLOW_VIEWPORT_WIREFRAME_COLOR_INTERFACE_H
#define FLOW_VIEWPORT_WIREFRAME_COLOR_INTERFACE_H

//Local headers
#include "flowViewport/api.h"

//Hydra headers
#include <pxr/usd/sdf/path.h>
#include <pxr/base/gf/vec4f.h>

namespace FVP_NS_DEF {


/// \class WireframeColorInterface
/// An interface to get the wireframe color from a prim
class WireframeColorInterface
{
public:
//Get the wireframe color of a primitive for selection highlighting
virtual PXR_NS::GfVec4f getWireframeColor(const PXR_NS::SdfPath& primPath) const = 0;
};

}//end of namespace FVP_NS_DEF

#endif //FLOW_VIEWPORT_WIREFRAME_COLOR_INTERFACE_H
4 changes: 4 additions & 0 deletions lib/flowViewport/sceneIndex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ target_sources(${TARGET_NAME}
fvpWireframeSelectionHighlightSceneIndex.cpp
fvpDisplayStyleOverrideSceneIndex.cpp
fvpBBoxSceneIndex.cpp
fvpReprSelectorSceneIndex.cpp
fvpBlockPrimRemovalPropagationSceneIndex.cpp
)

set(HEADERS
Expand All @@ -25,6 +27,8 @@ set(HEADERS
fvpWireframeSelectionHighlightSceneIndex.h
fvpDisplayStyleOverrideSceneIndex.h
fvpBBoxSceneIndex.h
fvpReprSelectorSceneIndex.h
fvpBlockPrimRemovalPropagationSceneIndex.h
)

# -----------------------------------------------------------------------------
Expand Down
Loading
Loading