Skip to content

Commit

Permalink
HYDRA-783 : Curve tools unit tests (#60)
Browse files Browse the repository at this point in the history
* HYDRA-783 : Create curve tests
  • Loading branch information
debloip-adsk authored Feb 16, 2024
1 parent 9df3f11 commit f977535
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 0 deletions.
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 @@ -23,6 +23,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
testFlowViewportAPI.py
testStageVariants.py
testNurbsPrimitives.py
testCurveTools.py
testPolygonPrimitives.py
cpp/testColorPreferences.py
cpp/testCppFramework.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.
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.
148 changes: 148 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/testCurveTools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# 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 mtohUtils

import platform

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

POINTS = [(0,-5,10), (-10, 0, 0), (0, 5, -10), (10, 0, 0), (0, -5, 5), (-5,0,0), (0,5,-5), (5, 0, 0), (0,0,0)]
CUSTOM_KNOTS = [0,1,2,3,4,5,6,7,8,9,10]

@property
def imageDiffFailThreshold(self):
return 0.05

@property
def imageDiffFailPercent(self):
# HYDRA-837 : Wireframes seem to have a slightly different color on macOS. We'll increase the thresholds
# for that platform specifically for now, so we can still catch issues on other platforms.
if platform.system() == "Darwin":
return 2
return 0.5

def compareSnapshot(self, referenceFilename, cameraDistance=15):
self.setBasicCam(cameraDistance)
cmds.refresh()
self.assertSnapshotClose(referenceFilename, self.imageDiffFailThreshold, self.imageDiffFailPercent)

def setUp(self):
super(TestCurveTools, self).setUp()
self.setHdStormRenderer()
cmds.refresh()

def createCircularArc(self, makeCircularArcNodeType):
arcNode = cmds.createNode(makeCircularArcNodeType)
curveNode = cmds.createNode("nurbsCurve")
cmds.connectAttr(arcNode + ".oc", curveNode + ".cr")
return arcNode

def test_CurveControlVertices(self):
curve = cmds.curve(point=self.POINTS)
self.compareSnapshot("curveControlVertices_basic.png")
cmds.delete(curve)

curve = cmds.curve(point=self.POINTS, knot=self.CUSTOM_KNOTS)
self.compareSnapshot("curveControlVertices_customKnots.png")
cmds.delete(curve)

curve = cmds.curve(point=self.POINTS, degree=1)
self.compareSnapshot("curveControlVertices_degree1.png")
cmds.delete(curve)

curve = cmds.curve(point=self.POINTS, degree=2)
self.compareSnapshot("curveControlVertices_degree2.png")
cmds.delete(curve)

curve = cmds.curve(point=self.POINTS, degree=5)
self.compareSnapshot("curveControlVertices_degree5.png")
cmds.delete(curve)

curve = cmds.curve(point=self.POINTS, bezier=True)
self.compareSnapshot("curveControlVertices_bezier.png")
cmds.delete(curve)

def test_CurveEditPoints(self):
curve = cmds.curve(editPoint=self.POINTS)
self.compareSnapshot("curveEditPoints_basic.png")
cmds.delete(curve)

curve = cmds.curve(editPoint=self.POINTS, degree=1)
self.compareSnapshot("curveEditPoints_degree1.png")
cmds.delete(curve)

curve = cmds.curve(editPoint=self.POINTS, degree=2)
self.compareSnapshot("curveEditPoints_degree2.png")
cmds.delete(curve)

curve = cmds.curve(editPoint=self.POINTS, degree=5)
self.compareSnapshot("curveEditPoints_degree5.png")
cmds.delete(curve)

curve = cmds.curve(editPoint=self.POINTS, bezier=True)
self.compareSnapshot("curveEditPoints_bezier.png")
cmds.delete(curve)

def test_TwoPointCircularArc(self):
arcNode = self.createCircularArc("makeTwoPointCircularArc")
self.compareSnapshot("twoPointCircularArc_fresh.png", 5)

cmds.setAttr(arcNode + ".point1X", 0)
cmds.setAttr(arcNode + ".point1Y", 0)
cmds.setAttr(arcNode + ".point1Z", 5)
cmds.setAttr(arcNode + ".point2X", 5)
cmds.setAttr(arcNode + ".point2Y", 0)
cmds.setAttr(arcNode + ".point2Z", -5)
cmds.setAttr(arcNode + ".directionVectorX", -1)
cmds.setAttr(arcNode + ".directionVectorY", 0)
cmds.setAttr(arcNode + ".directionVectorZ", 0)
cmds.setAttr(arcNode + ".radius", 6)
cmds.setAttr(arcNode + ".toggleArc", False)
cmds.setAttr(arcNode + ".degree", 1)
cmds.setAttr(arcNode + ".sections", 4)
self.compareSnapshot("twoPointCircularArc_linear.png")

cmds.setAttr(arcNode + ".toggleArc", True)
self.compareSnapshot("twoPointCircularArc_toggleArc.png")

cmds.setAttr(arcNode + ".degree", 3)
self.compareSnapshot("twoPointCircularArc_cubic.png")

def test_ThreePointCircularArc(self):
arcNode = self.createCircularArc("makeThreePointCircularArc")
self.compareSnapshot("threePointCircularArc_fresh.png", 5)

cmds.setAttr(arcNode + ".point1X", -1)
cmds.setAttr(arcNode + ".point1Y", -1)
cmds.setAttr(arcNode + ".point1Z", 1)
cmds.setAttr(arcNode + ".point2X", 2)
cmds.setAttr(arcNode + ".point2Y", 2)
cmds.setAttr(arcNode + ".point2Z", -2)
cmds.setAttr(arcNode + ".point3X", 3)
cmds.setAttr(arcNode + ".point3Y", -3)
cmds.setAttr(arcNode + ".point3Z", 3)
cmds.setAttr(arcNode + ".degree", 1)
cmds.setAttr(arcNode + ".sections", 5)
self.compareSnapshot("threePointCircularArc_linear.png")

cmds.setAttr(arcNode + ".degree", 3)
self.compareSnapshot("threePointCircularArc_cubic.png")

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

0 comments on commit f977535

Please sign in to comment.