-
Notifications
You must be signed in to change notification settings - Fork 5
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
Lanierd/hydra 311 #149
Merged
Merged
Lanierd/hydra 311 #149
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
18879fc
HYDRA-311 support default material for all kinds of data (maya/usd/cu…
lanierd-adsk 0b71ea8
Fix default material not always translated to hydra (random bug)
lanierd-adsk 14bf139
Apply the default material to mesh prims without a material
lanierd-adsk d405039
Add unit tests for default material
lanierd-adsk 8238845
Move global maya functions to maya utils
lanierd-adsk 16e145b
Fix unit test under OSX and Linux
lanierd-adsk 530403f
Fix images details on OSX
lanierd-adsk 00013d8
Attempt in fixing test on OSX
lanierd-adsk f573e02
Attempt in fixing test on Linux
lanierd-adsk d87cfa7
Fix case sensitive path
lanierd-adsk 38b07ad
Reset usetestsettings=False
lanierd-adsk 9a227e0
Ignore 1 image compare under OSX because of differences for the flow …
lanierd-adsk 1d73fe3
Fixes from code review
lanierd-adsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
lib/flowViewport/sceneIndex/fvpDefaultMaterialSceneIndex.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// 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/fvpDefaultMaterialSceneIndex.h" | ||
|
||
#include <pxr/imaging/hd/tokens.h> | ||
#include <pxr/imaging/hd/sceneIndexPrimView.h> | ||
#include <pxr/imaging/hd/materialSchema.h> | ||
#include <pxr/imaging/hd/materialBindingSchema.h> | ||
#include <pxr/imaging/hd/materialBindingsSchema.h> | ||
#include <pxr/imaging/hd/containerDataSourceEditor.h> | ||
#include <pxr/imaging/hd/retainedDataSource.h> | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace{ | ||
static const TfToken purposes[] = { HdMaterialBindingsSchemaTokens->allPurpose }; | ||
} | ||
|
||
// static | ||
DefaultMaterialSceneIndexRefPtr | ||
DefaultMaterialSceneIndex::New( | ||
const HdSceneIndexBaseRefPtr &inputSceneIndex, | ||
const PXR_NS::SdfPath& defaultMaterialPath, | ||
const PXR_NS::SdfPathVector& defaultMaterialExclusionList) | ||
{ | ||
return TfCreateRefPtr( | ||
new DefaultMaterialSceneIndex(inputSceneIndex, defaultMaterialPath, defaultMaterialExclusionList)); | ||
} | ||
|
||
DefaultMaterialSceneIndex::DefaultMaterialSceneIndex( | ||
HdSceneIndexBaseRefPtr const &inputSceneIndex, | ||
const PXR_NS::SdfPath& defaultMaterialPath, | ||
const PXR_NS::SdfPathVector& defaultMaterialExclusionList) | ||
: HdSingleInputFilteringSceneIndexBase(inputSceneIndex), | ||
InputSceneIndexUtils(inputSceneIndex), | ||
_defaultMaterialPath(defaultMaterialPath), | ||
_defaultMaterialExclusionList(defaultMaterialExclusionList) | ||
{ | ||
} | ||
|
||
HdSceneIndexPrim DefaultMaterialSceneIndex::GetPrim(const SdfPath& primPath) const | ||
{ | ||
HdSceneIndexPrim prim = GetInputSceneIndex()->GetPrim(primPath); | ||
if (! _isEnabled){ | ||
return prim; | ||
} | ||
|
||
_SetDefaultMaterial(prim); | ||
|
||
return prim; | ||
} | ||
|
||
bool DefaultMaterialSceneIndex::_ShouldWeApplyTheDefaultMaterial(const HdSceneIndexPrim& prim)const | ||
{ | ||
// Only for meshes so far | ||
if (HdPrimTypeTokens->mesh != prim.primType) { | ||
return false; | ||
} | ||
|
||
// Check if it has a material which is not in the exclusion list | ||
HdMaterialBindingsSchema bindings = HdMaterialBindingsSchema::GetFromParent(prim.dataSource); | ||
HdMaterialBindingSchema binding = bindings.GetMaterialBinding(); | ||
HdPathDataSourceHandle bindingPathDS = binding.GetPath(); | ||
if (bindingPathDS) { // If a mesh prim has no material( bindingPathDS is empty), apply anyway the default material | ||
const SdfPath materialPath = bindingPathDS->GetTypedValue(0.0f); | ||
auto foundExcludedMaterialPath = std::find( | ||
_defaultMaterialExclusionList.cbegin(), | ||
_defaultMaterialExclusionList.cend(), | ||
materialPath); | ||
if (foundExcludedMaterialPath != _defaultMaterialExclusionList.cend()) { | ||
return false; // materialPath is in the exclusion list ! | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void DefaultMaterialSceneIndex::_SetDefaultMaterial(HdSceneIndexPrim& inoutPrim)const | ||
{ | ||
static HdDataSourceBaseHandle const materialBindingSources[] | ||
= { HdMaterialBindingSchema::Builder() | ||
.SetPath(HdRetainedTypedSampledDataSource<SdfPath>::New(_defaultMaterialPath)) | ||
.Build() }; | ||
|
||
if (_ShouldWeApplyTheDefaultMaterial(inoutPrim)) { | ||
inoutPrim.dataSource = HdContainerDataSourceEditor(inoutPrim.dataSource) | ||
.Set( | ||
HdMaterialBindingsSchema::GetDefaultLocator(), | ||
HdMaterialBindingsSchema::BuildRetained(TfArraySize(purposes), purposes, materialBindingSources) | ||
) | ||
.Finish(); | ||
} | ||
} | ||
|
||
void DefaultMaterialSceneIndex::Enable(bool enable) | ||
{ | ||
if (_isEnabled == enable){ | ||
return; | ||
} | ||
|
||
_isEnabled = enable; | ||
_MarkMaterialsDirty(); | ||
} | ||
|
||
void DefaultMaterialSceneIndex::_MarkMaterialsDirty() | ||
{ | ||
static const auto locator = HdMaterialBindingsSchema::GetDefaultLocator(); | ||
|
||
HdSceneIndexObserver::DirtiedPrimEntries entries; | ||
for (const SdfPath& primPath : HdSceneIndexPrimView(GetInputSceneIndex())) { | ||
HdSceneIndexPrim prim = GetInputSceneIndex()->GetPrim(primPath); | ||
// Dirty only prims where we should apply the default material | ||
if (_ShouldWeApplyTheDefaultMaterial(prim)) { | ||
entries.push_back({ primPath, locator }); | ||
} | ||
} | ||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
} //end of namespace FVP_NS_DEF |
98 changes: 98 additions & 0 deletions
98
lib/flowViewport/sceneIndex/fvpDefaultMaterialSceneIndex.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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_DEFAULT_MATERIAL_SCENE_INDEX_H | ||
#define FVP_DEFAULT_MATERIAL_SCENE_INDEX_H | ||
|
||
#include "flowViewport/api.h" | ||
#include "flowViewport/sceneIndex/fvpSceneIndexUtils.h" | ||
|
||
#include <pxr/imaging/hd/filteringSceneIndex.h> | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
class DefaultMaterialSceneIndex; | ||
typedef PXR_NS::TfRefPtr<DefaultMaterialSceneIndex> DefaultMaterialSceneIndexRefPtr; | ||
typedef PXR_NS::TfRefPtr<const DefaultMaterialSceneIndex> DefaultMaterialSceneIndexConstRefPtr; | ||
|
||
class DefaultMaterialSceneIndex : | ||
public PXR_NS::HdSingleInputFilteringSceneIndexBase | ||
, public Fvp::InputSceneIndexUtils<DefaultMaterialSceneIndex> | ||
{ | ||
public: | ||
using ParentClass = PXR_NS::HdSingleInputFilteringSceneIndexBase; | ||
using ParentClass::_GetInputSceneIndex; | ||
|
||
FVP_API | ||
static DefaultMaterialSceneIndexRefPtr New( | ||
const PXR_NS::HdSceneIndexBaseRefPtr &inputScene, | ||
const PXR_NS::SdfPath& defaultMaterialPath, | ||
const PXR_NS::SdfPathVector& defaultMaterialExclusionList | ||
); | ||
|
||
FVP_API | ||
void Enable(bool enable); | ||
|
||
|
||
protected: | ||
void _MarkMaterialsDirty(); | ||
|
||
// From HdSceneIndexBase | ||
PXR_NS::HdSceneIndexPrim GetPrim(const PXR_NS::SdfPath& primPath) const override; | ||
|
||
PXR_NS::SdfPathVector GetChildPrimPaths(const PXR_NS::SdfPath& primPath) const override { | ||
return GetInputSceneIndex()->GetChildPrimPaths(primPath); | ||
} | ||
|
||
// From HdSingleInputFilteringSceneIndexBase | ||
void _PrimsAdded( | ||
const PXR_NS::HdSceneIndexBase& sender, | ||
const PXR_NS::HdSceneIndexObserver::AddedPrimEntries& entries) override{ | ||
if (!_IsObserved()) | ||
return; | ||
_SendPrimsAdded(entries); | ||
} | ||
|
||
void _PrimsRemoved( | ||
const PXR_NS::HdSceneIndexBase& sender, | ||
const PXR_NS::HdSceneIndexObserver::RemovedPrimEntries& entries) override | ||
{ | ||
if (!_IsObserved()) | ||
return; | ||
_SendPrimsRemoved(entries); | ||
} | ||
void _PrimsDirtied( | ||
const PXR_NS::HdSceneIndexBase& sender, | ||
const PXR_NS::HdSceneIndexObserver::DirtiedPrimEntries& entries) override | ||
{ | ||
if (!_IsObserved()) | ||
return; | ||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
void _SetDefaultMaterial(PXR_NS::HdSceneIndexPrim& inoutPrim) const; | ||
bool _ShouldWeApplyTheDefaultMaterial(const PXR_NS::HdSceneIndexPrim& prim)const; | ||
|
||
private: | ||
bool _isEnabled = false; | ||
const PXR_NS::SdfPath _defaultMaterialPath; | ||
PXR_NS::SdfPathVector _defaultMaterialExclusionList;//These are the materials that should not be affected by the default material, they should be skipped | ||
|
||
DefaultMaterialSceneIndex( | ||
PXR_NS::HdSceneIndexBaseRefPtr const &inputSceneIndex, const PXR_NS::SdfPath& defaultMaterialPath, const PXR_NS::SdfPathVector& defaultMaterialExclusionList); | ||
}; | ||
|
||
} //end of namespace FVP_NS_DEF | ||
|
||
#endif //FVP_DEFAULT_MATERIAL_SCENE_INDEX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What size is this _defaultMaterialExclusionList expected to be? We are looping over this for each prim. If the list size is small, it's fine, but otherwise we can consider using an std::set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is only one at this time, do you think I should switch to a std::set now ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just add a comment mentioning this as a possibility if the defaultMaterialExclusionList becomes large.