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-970 : Test single picking #145

Merged
merged 2 commits into from
Jul 11, 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
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
)

#Add this test only if the MayaUsd_FOUND (so also MAYAUSDAPI_LIBRARY) has been found during compile time.
Expand Down
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
)

# -----------------------------------------------------------------------------
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())
Loading