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-927 - Expose complexity settings in globalRenderSettings #106

Merged
merged 7 commits into from
Mar 26, 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
2 changes: 2 additions & 0 deletions lib/flowViewport/sceneIndex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ target_sources(${TARGET_NAME}
fvpSceneIndexUtils.cpp
fvpSelectionSceneIndex.cpp
fvpWireframeSelectionHighlightSceneIndex.cpp
fvpDisplayStyleOverrideSceneIndex.cpp
fvpBBoxSceneIndex.cpp
)

Expand All @@ -22,6 +23,7 @@ set(HEADERS
fvpSceneIndexUtils.h
fvpSelectionSceneIndex.h
fvpWireframeSelectionHighlightSceneIndex.h
fvpDisplayStyleOverrideSceneIndex.h
fvpBBoxSceneIndex.h
)

Expand Down
230 changes: 230 additions & 0 deletions lib/flowViewport/sceneIndex/fvpDisplayStyleOverrideSceneIndex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
// 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/sceneIndex/fvpDisplayStyleOverrideSceneIndex.h"

#include "pxr/imaging/hd/tokens.h"
#include "pxr/imaging/hd/legacyDisplayStyleSchema.h"
#include "pxr/imaging/hd/overlayContainerDataSource.h"
#include "pxr/imaging/hd/sceneIndexPrimView.h"
#include "pxr/imaging/hd/retainedDataSource.h"

namespace FVP_NS_DEF {

PXR_NAMESPACE_USING_DIRECTIVE

namespace DisplayStyleSceneIndex_Impl
{

using OptionalInt = DisplayStyleOverrideSceneIndex::OptionalInt;

struct _StyleInfo
{
OptionalInt refineLevel;
/// Retained data source storing refineLevel (or null ptr if empty optional
/// value) to avoid allocating a data source for every prim.
HdDataSourceBaseHandle refineLevelDs;
};

/// Data source for locator displayStyle.
class _DisplayStyleDataSource : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(_DisplayStyleDataSource);

HdDataSourceBaseHandle Get(const TfToken &name) override
{
if (name == HdLegacyDisplayStyleSchemaTokens->refineLevel) {
return _styleInfo->refineLevelDs;
}
return nullptr;
}

TfTokenVector GetNames() override
{
static const TfTokenVector names = {
HdLegacyDisplayStyleSchemaTokens->refineLevel
};

return names;
}

private:
_DisplayStyleDataSource(_StyleInfoSharedPtr const &styleInfo)
: _styleInfo(styleInfo)
{
}

_StyleInfoSharedPtr _styleInfo;
};

} // namespace DisplayStyleSceneIndex_Impl

using namespace DisplayStyleSceneIndex_Impl;

DisplayStyleOverrideSceneIndexRefPtr
DisplayStyleOverrideSceneIndex::New(
const HdSceneIndexBaseRefPtr &inputSceneIndex)
{
return TfCreateRefPtr(
new DisplayStyleOverrideSceneIndex(
inputSceneIndex));
}

DisplayStyleOverrideSceneIndex::
DisplayStyleOverrideSceneIndex(
const HdSceneIndexBaseRefPtr &inputSceneIndex)
: HdSingleInputFilteringSceneIndexBase(inputSceneIndex)
, _styleInfo(std::make_shared<_StyleInfo>())
, _overlayDs(
HdRetainedContainerDataSource::New(
HdLegacyDisplayStyleSchemaTokens->displayStyle,
_DisplayStyleDataSource::New(_styleInfo)))
{
}

HdSceneIndexPrim
DisplayStyleOverrideSceneIndex::GetPrim(
const SdfPath &primPath) const
{
HdSceneIndexPrim prim = _GetInputSceneIndex()->GetPrim(primPath);
if (prim.dataSource) {
if (!isExcluded(primPath) && prim.primType == HdPrimTypeTokens->mesh) {
prim.dataSource =
HdOverlayContainerDataSource::New(
_overlayDs, prim.dataSource);
}
}
return prim;
}

SdfPathVector
DisplayStyleOverrideSceneIndex::GetChildPrimPaths(
const SdfPath &primPath) const
{
return _GetInputSceneIndex()->GetChildPrimPaths(primPath);
}

void
DisplayStyleOverrideSceneIndex::SetRefineLevel(
const OptionalInt &refineLevel)
{
if (refineLevel == _styleInfo->refineLevel) {
return;
}

_styleInfo->refineLevel = refineLevel;
_styleInfo->refineLevelDs =
refineLevel
? HdRetainedTypedSampledDataSource<int>::New(*refineLevel)
: nullptr;

static const HdDataSourceLocatorSet locators(
HdLegacyDisplayStyleSchema::GetDefaultLocator()
.Append(HdLegacyDisplayStyleSchemaTokens->refineLevel));

_DirtyAllPrims(locators);
}

void
DisplayStyleOverrideSceneIndex::_DirtyAllPrims(
const HdDataSourceLocatorSet &locators)
{
if (!_IsObserved()) {
return;
}

HdSceneIndexObserver::DirtiedPrimEntries entries;
for (const SdfPath &path : HdSceneIndexPrimView(_GetInputSceneIndex())) {
entries.push_back({path, locators});
}

_SendPrimsDirtied(entries);
}

void
DisplayStyleOverrideSceneIndex::_PrimsAdded(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::AddedPrimEntries &entries)
{
if (!_IsObserved()) {
return;
}

_SendPrimsAdded(entries);
}

void
DisplayStyleOverrideSceneIndex::_PrimsRemoved(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::RemovedPrimEntries &entries)
{
if (!_IsObserved()) {
return;
}

_SendPrimsRemoved(entries);
}

void
DisplayStyleOverrideSceneIndex::_PrimsDirtied(
const HdSceneIndexBase &sender,
const HdSceneIndexObserver::DirtiedPrimEntries &entries)
{
if (!_IsObserved()) {
return;
}

_SendPrimsDirtied(entries);
}

void DisplayStyleOverrideSceneIndex::addExcludedSceneRoot(
const PXR_NS::SdfPath& sceneRoot
)
{
_excludedSceneRoots.emplace(sceneRoot);
}

bool DisplayStyleOverrideSceneIndex::isExcluded(
const PXR_NS::SdfPath& sceneRoot
) const
{
for (const auto& excluded : _excludedSceneRoots) {
if (sceneRoot.HasPrefix(excluded)) {
return true;
}
}
return false;
}

bool operator==(
const DisplayStyleOverrideSceneIndex::OptionalInt &a,
const DisplayStyleOverrideSceneIndex::OptionalInt &b)
{
if (a.hasValue == false && b.hasValue == false) {
return true;
}

return a.hasValue == b.hasValue && a.value == b.value;
}

bool operator!=(
const DisplayStyleOverrideSceneIndex::OptionalInt &a,
const DisplayStyleOverrideSceneIndex::OptionalInt &b)
{
return !(a == b);
}

} //end of namespace FVP_NS_DEF
124 changes: 124 additions & 0 deletions lib/flowViewport/sceneIndex/fvpDisplayStyleOverrideSceneIndex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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_DISPLAY_STYLE_OVERRIDE_SCENE_INDEX_H
#define FVP_DISPLAY_STYLE_OVERRIDE_SCENE_INDEX_H

#include "flowViewport/api.h"

#include "pxr/imaging/hdsi/api.h"
#include "pxr/imaging/hd/filteringSceneIndex.h"

#include <set>

namespace FVP_NS_DEF {

namespace DisplayStyleSceneIndex_Impl
{
struct _StyleInfo;
using _StyleInfoSharedPtr = std::shared_ptr<_StyleInfo>;
}

class DisplayStyleOverrideSceneIndex;
typedef PXR_NS::TfRefPtr<DisplayStyleOverrideSceneIndex> DisplayStyleOverrideSceneIndexRefPtr;
typedef PXR_NS::TfRefPtr<const DisplayStyleOverrideSceneIndex> DisplayStyleOverrideSceneIndexConstRefPtr;

///
/// \class DisplayStyleOverrideSceneIndex
///
/// A scene index overriding the display style for each prim.
///
class DisplayStyleOverrideSceneIndex :
public PXR_NS::HdSingleInputFilteringSceneIndexBase
{
public:
FVP_API
static DisplayStyleOverrideSceneIndexRefPtr
New(const PXR_NS::HdSceneIndexBaseRefPtr &inputSceneIndex);

FVP_API
PXR_NS::HdSceneIndexPrim GetPrim(const PXR_NS::SdfPath &primPath) const override;

FVP_API
PXR_NS::SdfPathVector GetChildPrimPaths(const PXR_NS::SdfPath &primPath) const override;

/// A replacement for std::optional<int> that is not available until C++17.
struct OptionalInt
{
bool hasValue = false;
int value = 0;

operator bool() const { return hasValue; }
int operator*() const { return value; }
};

/// Sets the refine level (at data source locator displayStyle:refineLevel)
/// for every prim in the input scene inedx.
///
/// If an empty optional value is provided, a null data source will be
/// returned for the data source locator.
///
FVP_API
void SetRefineLevel(const OptionalInt &refineLevel);

FVP_API
void addExcludedSceneRoot(const PXR_NS::SdfPath& sceneRoot);

protected:
FVP_API
DisplayStyleOverrideSceneIndex(
const PXR_NS::HdSceneIndexBaseRefPtr &inputSceneIndex);

FVP_API
void _PrimsAdded(
const PXR_NS::HdSceneIndexBase &sender,
const PXR_NS::HdSceneIndexObserver::AddedPrimEntries &entries) override;

FVP_API
void _PrimsRemoved(
const PXR_NS::HdSceneIndexBase &sender,
const PXR_NS::HdSceneIndexObserver::RemovedPrimEntries &entries) override;

FVP_API
void _PrimsDirtied(
const PXR_NS::HdSceneIndexBase &sender,
const PXR_NS::HdSceneIndexObserver::DirtiedPrimEntries &entries) override;

private:
void _DirtyAllPrims(const PXR_NS::HdDataSourceLocatorSet &locators);

bool isExcluded(const PXR_NS::SdfPath& sceneRoot) const;

std::set<PXR_NS::SdfPath> _excludedSceneRoots;

DisplayStyleSceneIndex_Impl::
_StyleInfoSharedPtr const _styleInfo;

/// Prim overlay data source.
PXR_NS::HdContainerDataSourceHandle const _overlayDs;
};

HDSI_API
bool operator==(
const DisplayStyleOverrideSceneIndex::OptionalInt &a,
const DisplayStyleOverrideSceneIndex::OptionalInt &b);

HDSI_API
bool operator!=(
const DisplayStyleOverrideSceneIndex::OptionalInt &a,
const DisplayStyleOverrideSceneIndex::OptionalInt &b);

} //end of namespace FVP_NS_DEF

#endif //FVP_DISPLAY_STYLE_OVERRIDE_SCENE_INDEX_H
1 change: 1 addition & 0 deletions lib/mayaHydra/hydraExtensions/mayaHydraParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct MayaHydraParams
float motionSampleStart = 0;
float motionSampleEnd = 0;
bool displaySmoothMeshes = true;
int refineLevel = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about the refineLevel which is adapters, MayaHydraAdapter::GetDisplayStyle().refineLevel > 0)
Is what you do replaces this ? Or is this something else ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume the added one is the global refine level, while the one in DisplayStyle is per-primitive, but it's not enabled yet due to MRenderItem was already refined. HdsiLegacyDisplayStyleOverrideSceneIndex can be used to override the per-primitive one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As far as I understand MayaHydraAdapter is used only for Maya native prims. The new scene index is supposed to be used only for USD prims. I will add "addExcludedSceneRoot" to it in my next commit to exclude Maya prims


bool motionSamplesEnabled() const { return motionSampleStart != 0 || motionSampleEnd != 0; }
};
Expand Down
Loading