-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HYDRA-312 : Add Scene Index for Texture Toggling (#131)
* Add Scene Index to support texture togglging * Add unit test * style changes * renamed variable
- Loading branch information
1 parent
c0d05d8
commit 514fed5
Showing
12 changed files
with
635 additions
and
2 deletions.
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
104 changes: 104 additions & 0 deletions
104
lib/flowViewport/sceneIndex/fvpPruneTexturesSceneIndex.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,104 @@ | ||
// 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/fvpPruneTexturesSceneIndex.h" | ||
|
||
#include <pxr/base/tf/staticTokens.h> | ||
#include <pxr/imaging/hd/sceneIndexPrimView.h> | ||
#include <pxr/imaging/hd/materialSchema.h> | ||
|
||
#include <iostream> | ||
namespace FVP_NS_DEF { | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
TF_DEFINE_PRIVATE_TOKENS( | ||
_tokens, | ||
(UsdPreviewSurface) | ||
(ND_standard_surface_surfaceshader) | ||
); | ||
|
||
namespace { | ||
|
||
void | ||
_PruneTexturesFromMatNetwork( | ||
HdMaterialNetworkInterface *networkInterface) | ||
{ | ||
if (!networkInterface) { | ||
return; | ||
} | ||
const TfTokenVector nodeNames = networkInterface->GetNodeNames(); | ||
for (TfToken const &nodeName : nodeNames) { | ||
const TfToken nodeType = networkInterface->GetNodeType(nodeName); | ||
if (nodeType == _tokens->ND_standard_surface_surfaceshader || | ||
nodeType == _tokens->UsdPreviewSurface) { | ||
// Look for incoming connection(textures) to surface shader params | ||
TfTokenVector inputConnections = networkInterface->GetNodeInputConnectionNames(nodeName); | ||
for (TfToken const &connection : inputConnections) { | ||
// Trivially remove all input connections to match Maya VP2 behavior | ||
networkInterface->DeleteNodeInputConnection(nodeName, connection); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // Anonymous namespace | ||
|
||
// static | ||
PruneTexturesSceneIndexRefPtr | ||
PruneTexturesSceneIndex::New( | ||
const HdSceneIndexBaseRefPtr &inputSceneIndex) | ||
{ | ||
return TfCreateRefPtr( | ||
new PruneTexturesSceneIndex(inputSceneIndex)); | ||
} | ||
|
||
void | ||
PruneTexturesSceneIndex::MarkTexturesDirty(bool isTextured) | ||
{ | ||
_needsTexturesPruned = isTextured; | ||
const HdDataSourceLocatorSet locators( | ||
HdMaterialSchema::GetDefaultLocator() | ||
.Append(HdMaterialSchemaTokens->material)); | ||
|
||
_DirtyAllPrims(locators); | ||
} | ||
|
||
PruneTexturesSceneIndex::PruneTexturesSceneIndex( | ||
HdSceneIndexBaseRefPtr const &inputSceneIndex) | ||
: HdMaterialFilteringSceneIndexBase(inputSceneIndex) | ||
{ | ||
} | ||
|
||
PruneTexturesSceneIndex::FilteringFnc | ||
PruneTexturesSceneIndex::_GetFilteringFunction() const | ||
{ | ||
return !_needsTexturesPruned ? | ||
_PruneTexturesFromMatNetwork : | ||
[](HdMaterialNetworkInterface*){}; | ||
} | ||
|
||
void | ||
PruneTexturesSceneIndex::_DirtyAllPrims( | ||
const HdDataSourceLocatorSet locators) | ||
{ | ||
HdSceneIndexObserver::DirtiedPrimEntries entries; | ||
for (const SdfPath &path : HdSceneIndexPrimView(_GetInputSceneIndex())) { | ||
entries.push_back({path, locators}); | ||
} | ||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
} //end of namespace FVP_NS_DEF |
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,56 @@ | ||
// 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_PRUNE_TEXTURE_SCENE_INDEX_NEW_H | ||
#define FVP_PRUNE_TEXTURE_SCENE_INDEX_NEW_H | ||
|
||
#include "flowViewport/api.h" | ||
#include "flowViewport/sceneIndex/fvpSceneIndexUtils.h" | ||
|
||
#include <pxr/imaging/hdsi/api.h> | ||
#include <pxr/imaging/hd/materialFilteringSceneIndexBase.h> | ||
#include <pxr/imaging/hd/materialNetworkInterface.h> | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
class PruneTexturesSceneIndex; | ||
typedef PXR_NS::TfRefPtr<PruneTexturesSceneIndex> PruneTexturesSceneIndexRefPtr; | ||
typedef PXR_NS::TfRefPtr<const PruneTexturesSceneIndex> PruneTexturesSceneIndexConstRefPtr; | ||
|
||
class PruneTexturesSceneIndex : | ||
public PXR_NS::HdMaterialFilteringSceneIndexBase | ||
{ | ||
public: | ||
FVP_API | ||
static PruneTexturesSceneIndexRefPtr New( | ||
const PXR_NS::HdSceneIndexBaseRefPtr &inputScene); | ||
|
||
FVP_API | ||
void MarkTexturesDirty(bool isTextured); | ||
|
||
bool _needsTexturesPruned = false; | ||
|
||
void _DirtyAllPrims(const PXR_NS::HdDataSourceLocatorSet locators); | ||
|
||
protected: | ||
FilteringFnc _GetFilteringFunction() const override; | ||
|
||
private: | ||
PruneTexturesSceneIndex( | ||
PXR_NS::HdSceneIndexBaseRefPtr const &inputSceneIndex); | ||
}; | ||
|
||
} //end of namespace FVP_NS_DEF | ||
|
||
#endif //FVP_PRUNE_TEXTURE_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
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
Binary file added
BIN
+3.59 KB
test/lib/mayaUsd/render/mayaToHydra/UsdTextureToggleTest/usd_texture_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32 KB
test/lib/mayaUsd/render/mayaToHydra/UsdTextureToggleTest/usd_texture_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions
48
test/lib/mayaUsd/render/mayaToHydra/testUsdTextureToggle.py
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,48 @@ | ||
# | ||
# Copyright 2024 Autodesk, Inc. All rights reserved. | ||
# | ||
# 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. | ||
# | ||
|
||
import maya.cmds as cmds | ||
import fixturesUtils | ||
import mtohUtils | ||
import mayaUtils | ||
|
||
import platform | ||
|
||
class TestUsdTextureToggle(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUtils.MayaHydraBaseTestCase to be able to call self.assertSnapshotClose | ||
# MayaHydraBaseTestCase.setUpClass requirement. | ||
_file = __file__ | ||
|
||
IMAGE_DIFF_FAIL_THRESHOLD = 0.2 | ||
IMAGE_DIFF_FAIL_PERCENT = 0.55 | ||
|
||
def test_UsdTextureToggle(self): | ||
|
||
# open simple Maya scene | ||
testFile = mayaUtils.openTestScene( | ||
"testUsdTextureToggle", | ||
"testUsdTextureToggle.ma", useTestSettings=False) | ||
cmds.refresh() | ||
|
||
panel = mayaUtils.activeModelPanel() | ||
self.assertSnapshotClose("usd_texture_on" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
cmds.refresh() | ||
cmds.modelEditor(panel, edit=True, displayTextures=False) | ||
self.assertSnapshotClose("usd_texture_off" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT) | ||
|
||
|
||
if __name__ == '__main__': | ||
fixturesUtils.runTests(globals()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.