Skip to content

Commit

Permalink
Merge branch 'dev' into debloip/HYDRA-1057/geomsubset-highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
debloip-adsk committed Jul 16, 2024
2 parents d5d074f + 64339ae commit be625bc
Show file tree
Hide file tree
Showing 17 changed files with 486 additions and 21 deletions.
9 changes: 6 additions & 3 deletions lib/flowViewport/sceneIndex/fvpPruneTexturesSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <pxr/base/tf/staticTokens.h>
#include <pxr/imaging/hd/sceneIndexPrimView.h>
#include <pxr/imaging/hd/materialSchema.h>
#include <pxr/imaging/hd/primvarsSchema.h>

#include <iostream>
namespace FVP_NS_DEF {
Expand Down Expand Up @@ -69,9 +70,11 @@ void
PruneTexturesSceneIndex::MarkTexturesDirty(bool isTextured)
{
_needsTexturesPruned = isTextured;
const HdDataSourceLocatorSet locators(
HdMaterialSchema::GetDefaultLocator()
.Append(HdMaterialSchemaTokens->material));
const HdDataSourceLocatorSet locators {
HdMaterialSchema::GetDefaultLocator().Append(HdMaterialSchemaTokens->material),
// Workaround for HYDRA-1061, see https://forum.aousd.org/t/primvars-and-material-dirtying-issue-in-storm/1675
HdPrimvarsSchema::GetDefaultLocator()
};

_DirtyAllPrims(locators);
}
Expand Down
25 changes: 17 additions & 8 deletions lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,16 +687,24 @@ VtValue MayaHydraSceneIndex::CreateMayaDefaultMaterial()
VtValue MayaHydraSceneIndex::CreateMayaFacesSelectionMaterial()
{
const GfVec4f faceSelectioncolor = getPreferencesColor(FvpColorPreferencesTokens->faceSelection);

constexpr float ogsMatchParamMult = 0.3f;
HdMaterialNetworkMap networkMap;
HdMaterialNetwork network;
HdMaterialNode node;
node.identifier = UsdImagingTokens->UsdPreviewSurface;
node.path = _mayaFacesSelectionMaterialPath;

// Diffuse
node.parameters.insert(
{ _tokens->diffuseColor,
VtValue(GfVec3f(faceSelectioncolor[0], faceSelectioncolor[1], faceSelectioncolor[2])) });
node.parameters.insert({ _tokens->opacity, VtValue(float(0.3f)) });
{ _tokens->diffuseColor,
VtValue(GfVec3f(faceSelectioncolor[0], faceSelectioncolor[1], faceSelectioncolor[2])*ogsMatchParamMult) });

// Emissive (component selection highlighting material should be independent of scene lighting)
node.parameters.insert(
{ _tokens->emissiveColor,
VtValue(GfVec3f(faceSelectioncolor[0], faceSelectioncolor[1], faceSelectioncolor[2])*ogsMatchParamMult) });

node.parameters.insert({ _tokens->opacity, VtValue(ogsMatchParamMult) });
network.nodes.push_back(std::move(node));
networkMap.map.insert({ HdMaterialTerminalTokens->surface, std::move(network) });
networkMap.terminals.push_back(_mayaFacesSelectionMaterialPath);
Expand Down Expand Up @@ -1198,22 +1206,23 @@ SdfPath MayaHydraSceneIndex::GetMaterialId(const SdfPath& id)
auto result = TfMapLookupPtr(_renderItemsAdapters, id);
if (result != nullptr) {
auto& renderItemAdapter = *result;


auto& material = renderItemAdapter->GetMaterial();
auto ismayaFacesSelectionMaterial = material == _mayaFacesSelectionMaterialPath;
// Check if this render item is a wireframe primitive
if (MHWRender::MGeometry::Primitive::kLines == renderItemAdapter->GetPrimitive()
|| MHWRender::MGeometry::Primitive::kLineStrip == renderItemAdapter->GetPrimitive()) {
return _fallbackMaterial;
}
else if (_useDefaultMaterial) {
else if (_useDefaultMaterial && !ismayaFacesSelectionMaterial) {
return _mayaDefaultMaterialPath;
}
auto& material = renderItemAdapter->GetMaterial();

if (material == kInvalidMaterial) {
return _fallbackMaterial;
}

if (material == _mayaFacesSelectionMaterialPath) {
if (ismayaFacesSelectionMaterial) {
return _mayaFacesSelectionMaterialPath;
}

Expand Down
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
cpp/testNurbsSurfaces.py
cpp/testPointInstancingWireframeHighlight.py
cpp/testGeomSubsetsPicking.py
cpp/testSinglePicking.py
cpp/testGeomSubsetsWireframeHighlight.py
)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ target_sources(${TARGET_NAME}
testNurbsSurfaces.cpp
testPointInstancingWireframeHighlight.cpp
testGeomSubsetsPicking.cpp
testSinglePicking.cpp
testGeomSubsetsWireframeHighlight.cpp
)

Expand Down
70 changes: 70 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/testSinglePicking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 "testUtils.h"

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

#include <maya/M3dView.h>

#include <ufe/globalSelection.h>
#include <ufe/observableSelection.h>

#include <gtest/gtest.h>

PXR_NAMESPACE_USING_DIRECTIVE

using namespace MayaHydra;

namespace {

bool isPrimSelectedPredicate(const HdSceneIndexBasePtr& sceneIndex, const SdfPath& primPath)
{
auto selectionsSchema = HdSelectionsSchema::GetFromParent(sceneIndex->GetPrim(primPath).dataSource);
if (!selectionsSchema.IsDefined()) {
return false;
}
for (size_t iSelection = 0; iSelection < selectionsSchema.GetNumElements(); iSelection++) {
if (selectionsSchema.GetElement(iSelection).GetFullySelected()) {
return true;
}
}
return false;
}

} // namespace

TEST(TestSinglePicking, singlePick)
{
const SceneIndicesVector& sceneIndices = GetTerminalSceneIndices();
ASSERT_GT(sceneIndices.size(), 0u);
SceneIndexInspector inspector(sceneIndices.front());

// Preconditions
ASSERT_TRUE(Ufe::GlobalSelection::get()->empty());
ASSERT_TRUE(inspector.FindPrims(isPrimSelectedPredicate).empty());

// Picking
M3dView active3dView = M3dView::active3dView();
QPoint centerMouseCoords(active3dView.portWidth() / 2, active3dView.portHeight() / 2);
mouseClick(Qt::MouseButton::LeftButton, active3dView.widget(), centerMouseCoords);
active3dView.refresh();

// Postconditions
ASSERT_EQ(Ufe::GlobalSelection::get()->size(), 1u);
ASSERT_EQ(inspector.FindPrims(isPrimSelectedPredicate).size(), 1u);
}
45 changes: 45 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/testSinglePicking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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.
#
import maya.cmds as cmds
import fixturesUtils
import mayaUtils
import mtohUtils

from testUtils import PluginLoaded

class TestSinglePicking(mtohUtils.MayaHydraBaseTestCase):
# MayaHydraBaseTestCase.setUpClass requirement.
_file = __file__

def setUp(self):
super(TestSinglePicking, self).setUp()
mayaUtils.openTestScene(
"testSinglePicking",
"testSinglePicking.ma")
cmds.select(clear=True)
cmds.optionVar(
sv=('mayaHydra_GeomSubsetsPickMode', 'None'))
cmds.optionVar(
sv=('mayaUsd_PointInstancesPickMode', 'Prototypes'))
cmds.setAttr('persp.translate', 0, 0, 10, type='float3')
cmds.setAttr('persp.rotate', 0, 0, 0, type='float3')
cmds.refresh()

def test_SinglePick(self):
with PluginLoaded('mayaHydraCppTests'):
cmds.mayaHydraCppTest(f="TestSinglePicking.singlePick")

if __name__ == '__main__':
fixturesUtils.runTests(globals())
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def test_MayaFaceComponentsPicking(self):
cmds.modelEditor(panel, edit=True, smoothWireframe=True)
cmds.refresh()
self.assertSnapshotClose("smoothwireframe" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

#Add lights
cmds.directionalLight(rotation=(45, 30, 15))
cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")
cmds.modelEditor(panel, edit=True, displayLights="all")
cmds.select( 'pSphere1.f[1:200]', r=True )
cmds.refresh()
self.assertSnapshotClose("selectionWithLights" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

if __name__ == '__main__':
fixturesUtils.runTests(globals())
33 changes: 23 additions & 10 deletions test/lib/mayaUsd/render/mayaToHydra/testUsdTextureToggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,37 @@ class TestUsdTextureToggle(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUt
# MayaHydraBaseTestCase.setUpClass requirement.
_file = __file__

IMAGE_DIFF_FAIL_THRESHOLD = 0.2
IMAGE_DIFF_FAIL_PERCENT = 0.55
IMAGE_DIFF_FAIL_THRESHOLD = 0.1
IMAGE_DIFF_FAIL_PERCENT = 1.5

def test_UsdTextureToggle(self):

# open simple Maya scene
def setUp(self):
# Open simple Maya scene
testFile = mayaUtils.openTestScene(
"testUsdTextureToggle",
"testUsdTextureToggle.ma", useTestSettings=False)
"testUsdTextureToggle.ma")
cmds.refresh()

panel = mayaUtils.activeModelPanel()

def setTextureMode(self, enabled):
cmds.modelEditor(mayaUtils.activeModelPanel(), edit=True, displayTextures=enabled)
cmds.refresh()

def test_UsdTextureToggleInitiallyOn(self):
self.setTextureMode(True)
self.setViewport2Renderer()
self.setHdStormRenderer()
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.setTextureMode(False)
self.assertSnapshotClose("usd_texture_off" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

def test_UsdTextureToggleInitiallyOff(self):
self.setTextureMode(False)
self.setViewport2Renderer()
self.setHdStormRenderer()
self.assertSnapshotClose("usd_texture_off" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

self.setTextureMode(True)
self.assertSnapshotClose("usd_texture_on" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

if __name__ == '__main__':
fixturesUtils.runTests(globals())
Loading

0 comments on commit be625bc

Please sign in to comment.