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

Add tests for sets command and for isolate select in Vp2RenderDelegate. #1678

Merged
merged 4 commits into from
Sep 22, 2021
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
6 changes: 6 additions & 0 deletions test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ if (CMAKE_WANT_MATERIALX_BUILD)
)
endif()

if(MAYA_MRENDERITEM_UFE_IDENTIFIER_SUPPORT)
list(APPEND TEST_SCRIPT_FILES
testVP2RenderDelegateIsolateSelect.py
)
endif()

add_custom_target(${TARGET_NAME} ALL)

# Copy all the resources and Python scripts to build directory
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.
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.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/usr/bin/env mayapy
#
# Copyright 2021 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 fixturesUtils
import imageUtils
import mayaUtils
import unittest
import usdUtils
import testUtils

from mayaUsd import lib as mayaUsdLib
from mayaUsd import ufe as mayaUsdUfe

from maya import cmds
import maya.api.OpenMayaRender as omr

from pxr import Usd

import ufe

import os


class testVP2RenderDelegateIsolateSelect(imageUtils.ImageDiffingTestCase):
"""
Tests imaging using the Viewport 2.0 render delegate when using per-instance
inherited data on instances.
"""

@classmethod
def setUpClass(cls):
inputPath = fixturesUtils.setUpClass(__file__,
initializeStandalone=False, loadPlugin=False)

cls._baselineDir = os.path.join(inputPath,
'VP2RenderDelegateIsolateSelectTest', 'baseline')

cls._testDir = os.path.abspath('.')

@classmethod
def tearDownClass(cls):
panel = mayaUtils.activeModelPanel()
cmds.modelEditor(panel, edit=True, useDefaultMaterial=False)

def assertSnapshotClose(self, imageName):
cmds.undoInfo(stateWithoutFlush=False) # disable the undo queue during the snapshot
baselineImage = os.path.join(self._baselineDir, imageName)
snapshotImage = os.path.join(self._testDir, imageName)
imageUtils.snapshot(snapshotImage, width=960, height=540)
retVal = self.assertImagesClose(baselineImage, snapshotImage)
cmds.undoInfo(stateWithoutFlush=True)
return retVal

def testIsolateSelect(self):
cmds.file(force=True, new=True)
mayaUtils.loadPlugin("mayaUsdPlugin")
panel = mayaUtils.activeModelPanel()
usdaFile = testUtils.getTestScene("setsCmd", "5prims.usda")
proxyDagPath, sphereStage = mayaUtils.createProxyFromFile(usdaFile)
usdCube = proxyDagPath + ",/Cube1"
usdCylinder = proxyDagPath + ",/Cylinder1"
usdCapsule = proxyDagPath + ",/Capsule1"
usdCone = proxyDagPath + ",/Cone1"
usdXform = proxyDagPath + ",/Xform1"

cmds.move(-4, -24, 0, "persp")
cmds.rotate(90, 0, 0, "persp")

globalSelection = ufe.GlobalSelection.get()
globalSelection.clear()
self.assertSnapshotClose('unselected.png')

# Turn on isolate select for cube
cmds.select(usdCube)
cmds.isolateSelect("modelPanel4", state=1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this function use the result of mayaUtils.activeModelPanel() as first parameter? Would it make the test more robust?

self.assertSnapshotClose('cube.png')

# Replace isolate select cube with cylinder
cmds.select(usdCylinder)
cmds.isolateSelect("modelPanel4", loadSelected=True)
self.assertSnapshotClose('cylinder.png')

# Add capsule to isolate select
cmds.select(usdCapsule)
cmds.isolateSelect("modelPanel4", addSelected=True)
self.assertSnapshotClose('cylinderAndCapsule.png')

# Remove capsule from isolate select
cmds.isolateSelect("modelPanel4", removeSelected=True)
self.assertSnapshotClose('cylinderAfterCapsuleRemove.png')

# Undo, Redo
cmds.undo() # Undo remove capsule from isolate select
self.assertSnapshotClose('undoCapsuleRemove.png')
cmds.redo() # Redo remove capsule from isolate select
self.assertSnapshotClose('redoCapsuleRemove.png')
cmds.undo() # Undo remove capsule from isolate select
cmds.undo() # Undo add capsule to isolate select
self.assertSnapshotClose('undoCapsuleAdd.png')

# Turn off isolate select
cmds.isolateSelect("modelPanel4", state=0)
self.assertSnapshotClose('isolateSelectOff.png')

# Create an isolate select set, then add something directly to it
cmds.isolateSelect("modelPanel4", state=1)
isolateSelectSet = "modelPanel4ViewSelectedSet"
cmds.sets(usdCube, add=isolateSelectSet)
cmds.isolateSelect("modelPanel4", update=True)
self.assertSnapshotClose('capsuleAndCube.png')

# The flags addDagObject and removeDagObject don't
# work with USD items.

# Add the cone to the isolate select
# different from addSelected because it filters out components
cmds.select(usdCone)
cmds.isolateSelect("modelPanel4", addSelectedObjects=True)
self.assertSnapshotClose('capsuleAndCubeAndCone.png')

# Translate Xform1 and reparent Cube1 under Xform1
cmds.select(usdXform)
cmds.move( 0, 0, 1, relative=True)
cmds.select(clear=True)
cmds.parent(usdCube, usdXform, relative=True)
cmds.isolateSelect("modelPanel4", update=True)
usdCube = usdXform + "/Cube1"
self.assertSnapshotClose('reparentedCube.png')

# Reparent Cube1 back
cmds.parent(usdCube, proxyDagPath, relative=True)
cmds.isolateSelect("modelPanel4", update=True)
usdCube = proxyDagPath + ",/Cube1"
self.assertSnapshotClose('reparentedCubeBack.png')

#reparent the proxy shape
locatorShape = cmds.createNode("locator")
locator = "|" + cmds.listRelatives(locatorShape, parent=True)[0]
cmds.move( 0, 0, 5, locator)
cmds.parent("|stage", locator, relative=True)
usdCube = locator + usdCube
self.assertSnapshotClose('reparentedProxyShape.png')


if __name__ == '__main__':
fixturesUtils.runTests(globals())
5 changes: 5 additions & 0 deletions test/lib/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ if (MAYA_API_VERSION VERSION_GREATER_EQUAL 20220100)
)
endif()

if(MAYA_MRENDERITEM_UFE_IDENTIFIER_SUPPORT)
list(APPEND TEST_SCRIPT_FILES
testSetsCmd.py
)
endif()

# copy ufe tests to ${CMAKE_CURRENT_BINARY_DIR} and run them from there
add_custom_target(${TARGET_NAME} ALL)
Expand Down
116 changes: 116 additions & 0 deletions test/lib/ufe/testSetsCmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env python

#
# Copyright 2021 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 fixturesUtils
import mayaUtils
import testUtils

from maya import cmds
from maya import standalone

import unittest


class SetsCmdTestCase(unittest.TestCase):
'''Verify the Maya sets command
'''

pluginsLoaded = False

@classmethod
def setUpClass(cls):
fixturesUtils.readOnlySetUpClass(__file__, loadPlugin=False)

if not cls.pluginsLoaded:
cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded()

@classmethod
def tearDownClass(cls):
standalone.uninitialize()

def setUp(self):
''' Called initially to set up the Maya test environment '''
# Load plugins
self.assertTrue(self.pluginsLoaded)

# Clear selection to start off
cmds.select(clear=True)

def testSetsCmd(self):
usdaFile = testUtils.getTestScene("setsCmd", "5prims.usda")
proxyDagPath, sphereStage = mayaUtils.createProxyFromFile(usdaFile)
usdCube = proxyDagPath + ",/Cube1"
usdCylinder = proxyDagPath + ",/Cylinder1"
usdXform = proxyDagPath + ",/Xform1"

cmds.select(usdCube)
set1 = cmds.sets()
cmds.select(usdCylinder)
set2 = cmds.sets()

# set contents
self.assertEqual(usdCube, *cmds.sets( set1, q=True ))

# select set
cmds.select( set1 )
self.assertEqual(usdCube, *cmds.ls( selection=True, ufe=True ))

# set of sets
setOfSets = cmds.sets( set1, set2, n="setOfSets")
cmds.select( setOfSets )
self.assertEqual([usdCube, usdCylinder], sorted(cmds.ls( selection=True, ufe=True)))

# union of the sets
self.assertEqual([usdCube, usdCylinder], sorted(cmds.sets( set2, un=set1 )))
self.assertFalse(cmds.sets( set2, ii=set1 )) # do the sets have common members

# query set contents, remove from set, add to set
self.assertTrue(cmds.sets( usdCube, im=set1 )) # Test if Cube1 is in set1
self.assertFalse(cmds.sets( usdCube, im=set2 )) # Test if Cube1 is in set2
cmds.sets( usdCube, rm=set1 ) # Remove Cube1 from set1
self.assertFalse(cmds.sets( usdCube, im=set1 )) # Test if Cube1 is in set1
cmds.sets( usdCube, add=set1 ) # Add Cube1 to set1
self.assertTrue(cmds.sets( usdCube, im=set1 )) # Test if Cube1 is in set1

# Undo, Redo
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like redo() never actually made it into the file :)

cmds.undo() # Undo Add Cube1 to set1
self.assertFalse(cmds.sets( usdCube, im=set1 ))
cmds.redo() # Redo Add Cube1 to set1
self.assertTrue(cmds.sets( usdCube, im=set1 ))
cmds.undo() # Undo Add Cube1 to set1
self.assertFalse(cmds.sets( usdCube, im=set1 ))
cmds.undo() # Undo Remove Cube1 from set1
self.assertTrue(cmds.sets( usdCube, im=set1 ))

#reparent Cube1 under Xform1
cmds.parent(usdCube, usdXform, relative=True)
usdCube = usdXform + "/Cube1"
self.assertTrue(cmds.sets( usdCube, im=set1 )) # Test if Cube1 is in set1
cmds.parent(usdCube, proxyDagPath, relative=True)
usdCube = proxyDagPath + ",/Cube1"
self.assertTrue(cmds.sets( usdCube, im=set1 )) # Test if Cube1 is in set1

#reparent the proxy shape
locatorShape = cmds.createNode("locator")
locator = "|" + cmds.listRelatives(locatorShape, parent=True)[0]
cmds.parent("|stage", locator, relative=True)
usdCube = locator + usdCube
self.assertTrue(cmds.sets( usdCube, im=set1 )) # Test if Cube1 is in set1

if __name__ == '__main__':
unittest.main(verbosity=2)
40 changes: 40 additions & 0 deletions test/testSamples/setsCmd/5prims.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#usda 1.0

reorder rootPrims = ["Capsule1", "Cone1", "Cube1", "Cylinder1", "Sphere1", "Xform1"]

def Capsule "Capsule1"
{
double3 xformOp:translate = (-13.855604588157764, 0, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

def Cone "Cone1"
{
double3 xformOp:translate = (-8.725335979971176, 0, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

def Cylinder "Cylinder1"
{
double3 xformOp:translate = (1.7859601980783193, 0, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

def Sphere "Sphere1"
{
double3 xformOp:translate = (6.180355031854263, 0, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

def Xform "Xform1"
{
}

def Cube "Cube1"
{
float3 xformOp:rotateXYZ = (0, -0, 0)
float3 xformOp:scale = (1, 1, 1)
double3 xformOp:translate = (-2.1084769730574147, 0, 0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
}