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

Implementing testVP2RenderDelegateCameras autotest #2383

Merged
merged 1 commit into from
Jun 1, 2022
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
8 changes: 8 additions & 0 deletions test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ if (MAYA_APP_VERSION VERSION_GREATER 2022)
)
endif()

if(CMAKE_UFE_V4_FEATURES_AVAILABLE)
if (${UFE_PREVIEW_VERSION_NUM} GREATER_EQUAL 4007)
list(APPEND TEST_SCRIPT_FILES
testVP2RenderDelegateCameras.py
)
endif()
endif()

if (CMAKE_WANT_MATERIALX_BUILD)
# We want modern OCIO for the MaterialX test:
mayaUsd_get_unittest_target(target testVP2RenderDelegateMaterialX.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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env mayapy
#
# Copyright 2022 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 usdUtils
import testUtils
import ufeUtils

from mayaUsd import ufe as mayaUsdUfe

from maya import cmds

import ufe
import os

class testVP2RenderDelegateCameras(imageUtils.ImageDiffingTestCase):
"""
Tests imaging using the Viewport 2.0 render delegate when using cameras
"""

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

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

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

def assertSnapshotClose(self, imageName):
baselineImage = os.path.join(self._baselineDir, imageName)
snapshotImage = os.path.join(self._testDir, imageName)
imageUtils.snapshot(snapshotImage, width=960, height=540)
return self.assertImagesClose(baselineImage, snapshotImage)

def _StartTest(self, testName):
cmds.file(force=True, new=True)
mayaUtils.loadPlugin("mayaUsdPlugin")
mayaUtils.loadPlugin("drawUfe")
self._testName = testName
testFile = testUtils.getTestScene("camera", self._testName + ".usda")
mayaUtils.createProxyFromFile(testFile)

def _RunTest(self):
cmds.setAttr('stageShape.cplx', 1)

# reparent one of the cameras to verify that the proxy camera handles this properly
# !this check is temporarily disabled because of a bug in PathSubject::addRemoveAllCallbackHelper
#cmds.parent('|stage|stageShape,/cameras/cam1', '|stage|stageShape,/cameras2')

# unselect all and compare images
globalSelection = ufe.GlobalSelection.get()
globalSelection.clear()
self.assertSnapshotClose('%s_unselected.png' % (self._testName))

# select all 2 cameras and compare images
selection = ufe.Selection()
selection.append(self._GetSceneItem('|stage|stageShape', '/cameras/cam1'))
selection.append(self._GetSceneItem('|stage|stageShape', '/cameras/cam2'))
globalSelection.replaceWith(selection)
self.assertSnapshotClose('%s_selected.png' % (self._testName))

# change attributes that affect the camera image
ufeItem = ufeUtils.createItem('|stage|stageShape,/cameras/cam2')
cameraPrim = usdUtils.getPrimFromSceneItem(ufeItem)
cameraPrim.GetAttribute('horizontalAperture').Set(100000)
cameraPrim.GetAttribute('verticalAperture').Set(100000)
cameraPrim.GetAttribute('focalLength').Set(100000)

# move all 2 cameras and compare images
cmds.move(-2, -2, -2, relative=True)
self.assertSnapshotClose('%s_moved.png' % (self._testName))

# rename the stage to verify that the proxy camera handles this properly
cmds.rename('|stage', 'stage2')

# switch color management view transfrom to verify that the proxy camera handles this properly
cmds.modelEditor('modelPanel4', edit=True, viewTransformName='Log')

# select the stage and compare images
globalSelection.clear()
cmds.select('|stage2')
self.assertSnapshotClose('%s_stage_selected.png' % (self._testName))

# delete one of the cameras to verify that the proxy camera handles this properly
cmds.delete('|stage2|stage2Shape,/cameras/cam2')

# move the stage and compare images
cmds.move(4, 4, 4, absolute=True)
self.assertSnapshotClose('%s_stage_moved.png' % (self._testName))

# add a new USD camera and compare images
stage = mayaUsdUfe.getStage("|stage2|stage2Shape")
stage.DefinePrim('/cameras2/cam3', "Camera")
cmds.select( clear=True )
self.assertSnapshotClose('%s_with_new_camera.png' % (self._testName))

def _GetSceneItem(self, mayaPathString, usdPathString):
mayaPathSegment = mayaUtils.createUfePathSegment(mayaPathString)
usdPathSegment = usdUtils.createUfePathSegment(usdPathString)
ufePath = ufe.Path([mayaPathSegment, usdPathSegment])
ufeItem = ufe.Hierarchy.createItem(ufePath)
return ufeItem

def testCameras(self):
self._StartTest('RenderCameras')

cmds.move(-10, 15, 20, 'persp')
cmds.rotate(-30, -30, 0, 'persp')
cmds.modelEditor('modelPanel4', edit=True, grid=False)
cmds.displayColor('camera', 21, active=True)

self._RunTest()



if __name__ == '__main__':
fixturesUtils.runTests(globals())
33 changes: 33 additions & 0 deletions test/testSamples/camera/RenderCameras.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#usda 1.0
(
)

def Xform "cameras"
{
def Camera "cam1"
{
float2 clippingRange = (0.1, 10000)
float focalLength = 35
float focusDistance = 5
float fStop = 5.6
float horizontalAperture = 35.999928
float verticalAperture = 23.999952

double3 xformOp:translate = (3, 3, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

def Camera "cam2"
{
float2 clippingRange = (0.1, 10000)
float focalLength = 35
float focusDistance = 5
float fStop = 5.6
float horizontalAperture = 35.999928
float verticalAperture = 23.999952
}
}

def Xform "cameras2"
{
}