Пример #1
0
    def testAttributeAliases(self):
        """Tests behavior with the purpose/USD_purpose alias."""
        cmds.file(new=True, force=True)
        cmds.group(name="group1", empty=True)

        cmds.addAttr("group1", longName="USD_purpose", dataType="string")
        cmds.setAttr("group1.USD_purpose", "proxy", type="string")
        self.assertEqual(
            UsdMaya.Adaptor("group1").GetSchema(UsdGeom.Xform).GetAttribute(
                UsdGeom.Tokens.purpose).Get(), UsdGeom.Tokens.proxy)

        cmds.addAttr("group1", longName="USD_ATTR_purpose", dataType="string")
        cmds.setAttr("group1.USD_ATTR_purpose", "render", type="string")
        self.assertEqual(
            UsdMaya.Adaptor("group1").GetSchema(UsdGeom.Xform).GetAttribute(
                UsdGeom.Tokens.purpose).Get(), UsdGeom.Tokens.render)

        cmds.deleteAttr("group1.USD_purpose")
        self.assertEqual(
            UsdMaya.Adaptor("group1").GetSchema(UsdGeom.Xform).GetAttribute(
                UsdGeom.Tokens.purpose).Get(), UsdGeom.Tokens.render)

        cmds.deleteAttr("group1.USD_ATTR_purpose")
        self.assertIsNone(
            UsdMaya.Adaptor("group1").GetSchema(UsdGeom.Xform).GetAttribute(
                UsdGeom.Tokens.purpose).Get())

        UsdMaya.Adaptor("group1")\
                    .GetSchema(UsdGeom.Xform)\
                    .CreateAttribute(UsdGeom.Tokens.purpose)
        self.assertTrue(
            cmds.attributeQuery("USD_ATTR_purpose", node="group1",
                                exists=True))
Пример #2
0
 def testBatching_BatchCount(self):
     """Tests the GetBatchCount() debugging function."""
     count = -1
     with UsdMaya.DiagnosticBatchContext():
         with UsdMaya.DiagnosticBatchContext():
             count = UsdMaya.DiagnosticDelegate.GetBatchCount()
     self.assertEqual(count, 2)
     count = UsdMaya.DiagnosticDelegate.GetBatchCount()
     self.assertEqual(count, 0)
Пример #3
0
    def testAttributes(self):
        """Tests creating and removing schema attributes."""
        cmds.file(new=True, force=True)
        cmds.group(name="group1", empty=True)

        modelAPI = UsdMaya.Adaptor('group1').ApplySchema(UsdGeom.ModelAPI)
        xform = UsdMaya.Adaptor('group1').GetSchema(UsdGeom.Xform)

        # Schema attributes list versus authored attributes list.
        self.assertIn(UsdGeom.Tokens.modelCardTextureXPos,
                modelAPI.GetAttributeNames())
        self.assertNotIn(UsdGeom.Tokens.modelCardTextureXPos,
                modelAPI.GetAuthoredAttributeNames())
        self.assertIn(UsdGeom.Tokens.purpose,
                xform.GetAttributeNames())
        self.assertNotIn(UsdGeom.Tokens.purpose,
                xform.GetAuthoredAttributeNames())

        # Unauthored API attribute.
        self.assertFalse(
                modelAPI.GetAttribute(UsdGeom.Tokens.modelCardTextureXPos))

        # Unauthored schema attribute.
        self.assertFalse(
                xform.GetAttribute(UsdGeom.Tokens.purpose))

        # Non-existent attribute.
        with self.assertRaises(Tf.ErrorException):
            modelAPI.GetAttribute("fakeAttr")

        # Create and set an API attribute.
        attr = modelAPI.CreateAttribute(UsdGeom.Tokens.modelCardTextureXPos)
        self.assertTrue(attr)
        self.assertTrue(attr.Set(Sdf.AssetPath("example.png")))

        attr = modelAPI.GetAttribute(UsdGeom.Tokens.modelCardTextureXPos)
        self.assertTrue(attr)
        self.assertEqual(attr.Get(), Sdf.AssetPath("example.png"))

        self.assertEqual(attr.GetAttributeDefinition().name,
                "model:cardTextureXPos")
        self.assertEqual(modelAPI.GetAuthoredAttributeNames(),
                [UsdGeom.Tokens.modelCardTextureXPos])

        # Existing attrs become invalid when the plug is removed.
        modelAPI.RemoveAttribute(UsdGeom.Tokens.modelCardTextureXPos)
        self.assertFalse(attr)

        # Should return None on invalid attr access.
        self.assertIsNone(attr.Get())

        # Create a typed schema attribute. It should be set to the fallback
        # initially.
        self.assertEqual(xform.CreateAttribute(UsdGeom.Tokens.purpose).Get(),
                UsdGeom.Tokens.default_)
Пример #4
0
    def testConcreteSchemaRegistrations(self):
        """Tests some of the PXRUSDMAYA_REGISTER_ADAPTOR_SCHEMA macros."""
        cmds.file(new=True, force=True)
        cmds.createNode("joint", name="TestJoint")
        self.assertTrue(
            UsdMaya.Adaptor("TestJoint").GetSchema(UsdSkel.Skeleton))
        self.assertFalse(UsdMaya.Adaptor("TestJoint").GetSchema(UsdGeom.Mesh))

        cmds.createNode("camera", name="TestCamera")
        self.assertTrue(
            UsdMaya.Adaptor("TestCamera").GetSchema(UsdGeom.Camera))

        cmds.createNode("mesh", name="TestMesh")
        self.assertTrue(UsdMaya.Adaptor("TestMesh").GetSchema(UsdGeom.Mesh))

        cmds.createNode("instancer", name="TestInstancer")
        self.assertTrue(
            UsdMaya.Adaptor("TestInstancer").GetSchema(UsdGeom.PointInstancer))

        cmds.createNode("nurbsSurface", name="TestNurbsSurface")
        self.assertTrue(
            UsdMaya.Adaptor("TestNurbsSurface").GetSchema(UsdGeom.NurbsPatch))

        cmds.createNode("nurbsCurve", name="TestNurbsCurve")
        self.assertTrue(
            UsdMaya.Adaptor("TestNurbsCurve").GetSchema(UsdGeom.NurbsCurves))

        cmds.createNode("locator", name="TestLocator")
        self.assertTrue(
            UsdMaya.Adaptor("TestLocator").GetSchema(UsdGeom.Xform))

        cmds.createNode("nParticle", name="TestParticles")
        self.assertTrue(
            UsdMaya.Adaptor("TestParticles").GetSchema(UsdGeom.Points))
Пример #5
0
    def testIsolateSelection(self):
        cmds.file(os.path.abspath('IsolateSelectionTest.ma'),
                  open=True,
                  force=True)

        # Isolate selection seems to only apply to the interactive viewports,
        # and not to ogsRenders. However, it's difficult for us to render
        # viewports with exact sizes to do baseline comparisons. Since isolate
        # selection needs to work with selection hit-testing as well, we use
        # that as a proxy for checking that isolate selection draws properly.
        panel1 = self._MakeModelPanel()
        panel2 = self._MakeModelPanel()

        # Load all assemblies.
        UsdMaya.LoadReferenceAssemblies()
        self._HitTest(panel1, True, True, True)
        self._HitTest(panel2, True, True, True)

        # Isolate CubeModel1.
        cmds.select("CubeModel1")
        cmds.isolateSelect(panel1, state=True)
        self._HitTest(panel1, True, False, False)
        self._HitTest(panel2, True, True, True)

        # Isolate CubeModel2 and CubeModel3.
        cmds.select("CubeModel2", "CubeModel3")
        cmds.isolateSelect(panel1, loadSelected=True)
        self._HitTest(panel1, False, True, True)

        # Get out of isolate selection.
        cmds.isolateSelect(panel1, state=False)
        self._HitTest(panel1, True, True, True)

        # Enter isolate selection on panel2 this time.
        cmds.select("CubeModel2", "CubeModel3")
        cmds.isolateSelect(panel2, state=True)
        self._HitTest(panel1, True, True, True)
        self._HitTest(panel2, False, True, True)

        # Then add an isolate selection to panel1 again.
        cmds.select("CubeModel1", "CubeModel2")
        cmds.isolateSelect(panel1, state=True)
        self._HitTest(panel1, True, True, False)
        self._HitTest(panel2, False, True, True)

        # Unload assemblies.
        UsdMaya.UnloadReferenceAssemblies()
        self._HitTest(panel1, False, False, False)
        self._HitTest(panel2, False, False, False)

        # Reload assemblies.
        UsdMaya.LoadReferenceAssemblies()
        self._HitTest(panel1, True, True, False)
        self._HitTest(panel2, False, True, True)
    def testOneSelection(self):
        self._SetSelection('modelingVariant', 'ModVariantB')

        variantSetSelections = UsdMaya.GetVariantSetSelections(
            self.assemblyNodeName)
        self.assertEqual(variantSetSelections,
                         {'modelingVariant': 'ModVariantB'})
Пример #7
0
    def testDrawAndToggleLightingMode(self):
        """
        Tests drawing a USD proxy shape node before and after changing the
        lighting mode between using the default lights and using all scene
        lights.

        This ensures that gamma correction is applied correctly in both
        lighting modes and that there is no additional scene ambient added.
        """
        self._testName = 'ProxyShapeDrawColorAccuracyTest'

        mayaSceneFile = '%s.ma' % self._testName
        mayaSceneFullPath = os.path.abspath(mayaSceneFile)
        cmds.file(mayaSceneFullPath, open=True, force=True)

        UsdMaya.LoadReferenceAssemblies()

        # Force an initial draw to complete by switching frames.
        animStartTime = cmds.playbackOptions(query=True,
                                             animationStartTime=True)
        cmds.currentTime(animStartTime + 1.0, edit=True)

        # Set the lighting mode to using the default lights.
        cmds.setAttr("hardwareRenderingGlobals.lightingMode", 0)

        self._WriteViewportImage(self._testName, 'default_lights')

        # Switch the lighting mode to use all scene lights.
        cmds.setAttr("hardwareRenderingGlobals.lightingMode", 1)

        self._WriteViewportImage(self._testName, 'all_lights')
    def testBogusVariantName(self):
        self._SetSelection('bogusVariant', 'NotARealVariantSet')

        # Invalid variantSet names should not appear in the results.
        variantSetSelections = UsdMaya.GetVariantSetSelections(
            self.assemblyNodeName)
        self.assertEqual(variantSetSelections, {})
    def testBogusSelection(self):
        self._SetSelection('modelingVariant', 'BogusSelection')

        # Selections are NOT validated, so any "selection" for a valid
        # variantSet should appear in the results.
        variantSetSelections = UsdMaya.GetVariantSetSelections(self.assemblyNodeName)
        self.assertEqual(variantSetSelections, {'modelingVariant': 'BogusSelection'})
    def testDrawAndTransformCube(self):
        """
        Tests drawing USD proxy shapes while changing their visibility states.

        This ensures that indirect changes in the proxy shape's visibility
        (e.g. through a display layer) are imaged correctly.
        """
        self._testName = 'ProxyShapeDrawVisibilityTest'

        mayaSceneFile = '%s.ma' % self._testName
        mayaSceneFullPath = os.path.abspath(mayaSceneFile)
        cmds.file(mayaSceneFullPath, open=True, force=True)

        UsdMaya.LoadReferenceAssemblies()

        # Force an initial draw to complete by switching frames.
        animStartTime = cmds.playbackOptions(query=True,
                                             animationStartTime=True)
        cmds.currentTime(animStartTime + 1.0, edit=True)

        self._WriteViewportImage(self._testName, 'initial')

        cmds.setAttr('Cube_1_layer.visibility', False)

        self._WriteViewportImage(self._testName, 'invis_layer_1')

        cmds.setAttr('Cube_1_layer.visibility', True)
        cmds.setAttr('Cube_2_layer.visibility', False)

        self._WriteViewportImage(self._testName, 'invis_layer_2')

        cmds.setAttr('Cube_1_layer.visibility', False)

        self._WriteViewportImage(self._testName, 'invis_layers_1_and_2')
Пример #11
0
    def testBatching(self):
        self._StartRecording()
        with UsdMaya.DiagnosticBatchContext():
            Tf.Warn("spooky warning")
            Tf.Status("informative status")

            for i in xrange(5):
                Tf.Status("repeated status %d" % i)

            for i in xrange(3):
                Tf.Warn("spam warning %d" % i)

            try:
                Tf.RaiseCodingError("coding error!")
            except:
                pass
        log = self._StopRecording()

        # Note: we use assertItemsEqual because coalescing may re-order the
        # diagnostic messages.
        self.assertItemsEqual(
            log,
            [("spooky warning", OM.MCommandMessage.kWarning),
             ("informative status", OM.MCommandMessage.kInfo),
             ("repeated status 0 -- and 4 similar", OM.MCommandMessage.kInfo),
             ("spam warning 0 -- and 2 similar", OM.MCommandMessage.kWarning)])
Пример #12
0
    def testApplySchema(self):
        """Tests schema application."""
        cmds.file(new=True, force=True)
        cmds.group(name="group1", empty=True)

        proxy = UsdMaya.Adaptor('group1')
        self.assertTrue(proxy)
        self.assertEqual(proxy.GetAppliedSchemas(), [])

        modelAPI = proxy.ApplySchema(UsdGeom.ModelAPI)
        self.assertTrue(modelAPI)
        self.assertEqual(proxy.GetAppliedSchemas(), ["GeomModelAPI"])
        self.assertEqual(modelAPI.GetAuthoredAttributeNames(), [])

        motionAPI = proxy.ApplySchema(UsdGeom.MotionAPI)
        self.assertTrue(motionAPI)
        self.assertEqual(proxy.GetAppliedSchemas(),
                ["GeomModelAPI", "MotionAPI"])
        self.assertEqual(motionAPI.GetAuthoredAttributeNames(), [])

        # No support currently for typed schemas.
        with self.assertRaises(Tf.ErrorException):
            proxy.ApplySchema(UsdGeom.Xformable)

        with self.assertRaises(Tf.ErrorException):
            proxy.ApplySchema(UsdGeom.Mesh)

        self.assertEqual(proxy.GetAppliedSchemas(),
                ["GeomModelAPI", "MotionAPI"])
Пример #13
0
    def testUnapplySchema(self):
        """Tests unapplying schemas and effect on existing proxy objects."""
        cmds.file(new=True, force=True)
        cmds.group(name="group1", empty=True)

        proxy = UsdMaya.Adaptor('group1')
        self.assertEqual(proxy.GetAppliedSchemas(), [])

        proxy.ApplySchema(UsdGeom.ModelAPI)
        proxy.ApplySchema(UsdGeom.MotionAPI)
        self.assertEqual(proxy.GetAppliedSchemas(),
                ["GeomModelAPI", "MotionAPI"])

        proxy.UnapplySchema(UsdGeom.ModelAPI)
        self.assertEqual(proxy.GetAppliedSchemas(), ["MotionAPI"])

        # Note that schema objects still remain alive after being
        # unapplied.
        modelAPI = proxy.GetSchema(UsdGeom.ModelAPI)
        self.assertTrue(modelAPI)

        # But they expire once the underlying Maya node is removed.
        cmds.delete("group1")
        self.assertFalse(modelAPI)
        self.assertFalse(proxy)
Пример #14
0
    def testUndoRedo(self):
        """Tests that adaptors work with undo/redo."""
        cmds.file(new=True, force=True)
        cmds.group(name="group1", empty=True)
        adaptor = UsdMaya.Adaptor("group1")
        self.assertEqual(adaptor.GetAppliedSchemas(), [])

        # Do a single operation, then undo, then redo.
        adaptor.ApplySchema(UsdGeom.ModelAPI)
        self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"])
        cmds.undo()
        self.assertEqual(adaptor.GetAppliedSchemas(), [])
        cmds.redo()
        self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"])

        # Do a compound operation, then undo, then redo.
        cmds.undoInfo(openChunk=True)
        adaptor.ApplySchema(UsdGeom.MotionAPI).CreateAttribute(
                UsdGeom.Tokens.motionVelocityScale).Set(0.42)
        self.assertEqual(adaptor.GetAppliedSchemas(),
                ["GeomModelAPI", "MotionAPI"])
        self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute(
                UsdGeom.Tokens.motionVelocityScale).Get(), 0.42)
        cmds.undoInfo(closeChunk=True)
        cmds.undo()
        self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"])
        self.assertFalse(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute(
                UsdGeom.Tokens.motionVelocityScale))
        self.assertIsNone(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute(
                UsdGeom.Tokens.motionVelocityScale).Get())
        cmds.redo()
        self.assertEqual(adaptor.GetAppliedSchemas(),
                ["GeomModelAPI", "MotionAPI"])
        self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute(
                UsdGeom.Tokens.motionVelocityScale).Get(), 0.42)
Пример #15
0
    def testMetadata(self):
        """Tests setting and clearing metadata."""
        cmds.file(new=True, force=True)
        cmds.group(name="group1", empty=True)

        proxy = UsdMaya.Adaptor('group1')
        self.assertEqual(proxy.GetAllAuthoredMetadata(), {})
        self.assertIsNone(proxy.GetMetadata("instanceable"))

        proxy.SetMetadata("instanceable", True)
        self.assertEqual(proxy.GetMetadata("instanceable"), True)

        proxy.SetMetadata("kind", "awesomeKind")
        self.assertEqual(proxy.GetAllAuthoredMetadata(), {
            "instanceable": True,
            "kind": "awesomeKind"
        })

        # Unregistered key.
        with self.assertRaises(Tf.ErrorException):
            proxy.SetMetadata("fakeMetadata", True)

        with self.assertRaises(Tf.ErrorException):
            proxy.GetMetadata("otherFakeMetadata")

        proxy.ApplySchema(UsdGeom.ModelAPI)
        apiSchemas = proxy.GetMetadata("apiSchemas")
        self.assertEqual(apiSchemas.prependedItems, ["GeomModelAPI"])

        # Clear metadata.
        proxy.ClearMetadata("kind")
        self.assertIsNone(proxy.GetMetadata("kind"))
    def testDrawAndChangeCurrentTime(self):
        """
        Tests drawing a USD proxy shape node that references USD with time
        sampled data.

        This test ensures that the shape is redrawn correctly when upstream
        connections are dirtied. The built in "time1" object's "outTime" plug
        is the source of the connection to the assembly node's "time" plug,
        which is then the source of the connection to the proxy shape's "time"
        plug.
        """
        self._testName = 'ProxyShapeDrawTimeSampledTest'

        mayaSceneFile = '%s.ma' % self._testName
        mayaSceneFullPath = os.path.abspath(mayaSceneFile)
        cmds.file(mayaSceneFullPath, open=True, force=True)

        UsdMaya.LoadReferenceAssemblies()

        cmds.currentTime(1.0, edit=True)
        self._WriteViewportImage(self._testName, '1')

        cmds.currentTime(3.0, edit=True)
        self._WriteViewportImage(self._testName, '3')

        cmds.currentTime(5.0, edit=True)
        self._WriteViewportImage(self._testName, '5')
    def testImport_GeomModelAPI(self):
        """Tests importing UsdGeomModelAPI attributes."""
        cmds.file(new=True, force=True)
        usdFile = os.path.abspath('UsdAttrs.usda')
        cmds.usdImport(file=usdFile,
                       shadingMode='none',
                       apiSchema=['GeomModelAPI'])

        worldProxy = UsdMaya.Adaptor('World')
        modelAPI = worldProxy.GetSchema(UsdGeom.ModelAPI)

        # model:cardGeometry
        self.assertTrue(
            cmds.attributeQuery('USD_ATTR_model_cardGeometry',
                                node='World',
                                exists=True))
        self.assertEqual(cmds.getAttr('World.USD_ATTR_model_cardGeometry'),
                         UsdGeom.Tokens.fromTexture)
        self.assertEqual(
            modelAPI.GetAttribute(UsdGeom.Tokens.modelCardGeometry).Get(),
            UsdGeom.Tokens.fromTexture)

        # model:cardTextureXPos
        self.assertTrue(
            cmds.attributeQuery('USD_ATTR_model_cardTextureXPos',
                                node='World',
                                exists=True))
        self.assertEqual(cmds.getAttr('World.USD_ATTR_model_cardTextureXPos'),
                         'right.png')
        self.assertEqual(
            modelAPI.GetAttribute(UsdGeom.Tokens.modelCardTextureXPos).Get(),
            'right.png')
    def testObjectNormal(self):
        """
        Tests that an object created interactively by dragging in the viewport
        has the correct orientation based on the live surface normal.
        """
        from pxr import Gf

        # Load our reference assembly.
        UsdMaya.LoadReferenceAssemblies()

        # Create a new custom viewport.
        window = cmds.window(widthHeight=(500, 400))
        cmds.paneLayout()
        panel = cmds.modelPanel()
        cmds.modelPanel(panel, edit=True, camera='persp')
        cmds.modelEditor(cmds.modelPanel(panel, q=True, modelEditor=True),
                         edit=True,
                         displayAppearance='smoothShaded',
                         rnm='vp2Renderer')
        cmds.showWindow(window)

        # Get the viewport widget.
        view = OMUI.M3dView()
        OMUI.M3dView.getM3dViewFromModelPanel(panel, view)
        viewWidget = wrapInstance(long(view.widget()), QWidget)

        # Make our assembly live.
        cmds.makeLive('Block_2')

        # Enter interactive creation context.
        cmds.setToolTo('CreatePolyConeCtx')

        # Click in the center of the viewport widget.
        QTest.mouseClick(viewWidget, QtCore.Qt.LeftButton,
                         QtCore.Qt.NoModifier,
                         viewWidget.rect().center())

        # Find the cone (it should be called pCone1).
        self.assertTrue(cmds.ls('pCone1'))

        # Check the cone's rotation.
        # Because our scene is Z-axis up, the cone's Z-axis should be aligned
        # with Block_2's surface normal (though it might not necessarily have
        # the same exact rotation).
        rotationAngles = cmds.xform('pCone1', q=True, ro=True)
        rotation = (Gf.Rotation(Gf.Vec3d.XAxis(), rotationAngles[0]) *
                    Gf.Rotation(Gf.Vec3d.YAxis(), rotationAngles[1]) *
                    Gf.Rotation(Gf.Vec3d.ZAxis(), rotationAngles[2]))
        actualZAxis = rotation.TransformDir(Gf.Vec3d.ZAxis())

        expectedRotation = (Gf.Rotation(Gf.Vec3d.XAxis(), 75.0) *
                            Gf.Rotation(Gf.Vec3d.YAxis(), 90.0))
        expectedZAxis = expectedRotation.TransformDir(Gf.Vec3d.ZAxis())

        # Verify that the error angle between the two axes is less than
        # 0.1 degrees (less than ~0.0003 of a revolution, so not bad). That's
        # about as close as we're going to get.
        errorRotation = Gf.Rotation(actualZAxis, expectedZAxis)
        self.assertLess(errorRotation.GetAngle(), 0.1)
    def _LoadAssemblies(self):
        loadStartTime = cmds.timerX()

        UsdMaya.LoadReferenceAssemblies()

        loadElapsedTime = cmds.timerX(startTime=loadStartTime)

        Tf.Status("Load Elapsed Time: %f" % loadElapsedTime)
    def _RunPerfTest(self):
        mayaSceneFile = 'Grid_5_of_CubeGrid%s_10.ma' % self._testName
        mayaSceneFullPath = os.path.abspath(mayaSceneFile)
        cmds.file(mayaSceneFullPath, open=True, force=True)

        Tf.Status("Maya Scene File: %s" % mayaSceneFile)

        # Load all USD reference assemblies.
        profileScopeName = '%s Assemblies Load Time' % self._testName

        with self._ProfileScope(profileScopeName):
            UsdMaya.LoadReferenceAssemblies()

        # Get the QWidget for the viewport window.
        self.assertTrue(self._IsViewportRendererViewport20())
        self._viewWidget = self._GetViewportWidget(self._cameraName,
                                                   'vp2Renderer')
        self.assertTrue(self._viewWidget)

        # Force the initial view to draw so that the viewport size stabilizes.
        animStartTime = cmds.playbackOptions(query=True,
                                             animationStartTime=True)
        cmds.currentTime(animStartTime, edit=True)
        QApplication.processEvents()

        # Render an image and validate that nothing is selected to start.
        self._WriteViewportImage(self._testName, 'before_selection')
        expectedSelection = set()
        actualSelection = set(cmds.ls(selection=True) or [])
        self.assertEqual(actualSelection, expectedSelection)

        self._TestSelectCenterSingle()
        expectedSelection = set(['AssetRef_2_0_2'])
        actualSelection = set(cmds.ls(selection=True) or [])
        self.assertEqual(actualSelection, expectedSelection)

        self._TestSelectCenterArea()
        expectedSelection = set([
            'AssetRef_2_0_2', 'AssetRef_2_1_2', 'AssetRef_2_2_2',
            'AssetRef_2_3_2', 'AssetRef_2_4_2'
        ])
        actualSelection = set(cmds.ls(selection=True) or [])
        self.assertEqual(actualSelection, expectedSelection)

        self._TestUnselect()
        expectedSelection = set()
        actualSelection = set(cmds.ls(selection=True) or [])
        self.assertEqual(actualSelection, expectedSelection)

        self._TestSelectionAppend()
        expectedSelection = set([
            'AssetRef_0_0_4', 'AssetRef_4_0_4', 'AssetRef_4_0_0',
            'AssetRef_0_0_0'
        ])
        actualSelection = set(cmds.ls(selection=True) or [])
        self.assertEqual(actualSelection, expectedSelection)
Пример #21
0
    def testAllSelections(self):
        self._SetSelection('fooVariant', 'FooVariantC')
        self._SetSelection('modelingVariant', 'ModVariantB')
        self._SetSelection('shadingVariant', 'ShadVariantA')

        variantSetSelections = UsdMaya.GetVariantSetSelections(self.assemblyNodeName)
        self.assertEqual(variantSetSelections,
            {'fooVariant': 'FooVariantC',
             'modelingVariant': 'ModVariantB',
             'shadingVariant': 'ShadVariantA'})

        # Verify that selecting a non-registered variant set affects the
        # stage's composition.
        prim = UsdMaya.GetPrim(self.assemblyNodeName)
        geomPrim = prim.GetChild('Geom')
        cubePrim = geomPrim.GetChild('Cube')

        attrValue = cubePrim.GetAttribute('variantAttribute').Get()
        self.assertEqual(attrValue, 'C')
    def testAllSelections(self):
        self._SetSelection('fooVariant', 'FooVariantC')
        self._SetSelection('modelingVariant', 'ModVariantB')
        self._SetSelection('shadingVariant', 'ShadVariantA')

        variantSetSelections = UsdMaya.GetVariantSetSelections(self.assemblyNodeName)
        self.assertEqual(variantSetSelections,
            {'fooVariant': 'FooVariantC',
             'modelingVariant': 'ModVariantB',
             'shadingVariant': 'ShadVariantA'})
Пример #23
0
    def _ValidateCards(self, nodeName):
        """
        Checks that the root prim on the stage has its drawmode properly set.
        """
        drawModeAttr = cmds.getAttr('%s.drawMode' % nodeName)
        self.assertEqual(drawModeAttr, 'cards')

        prim = UsdMaya.GetPrim(nodeName)
        primModelAPI = UsdGeom.ModelAPI(prim)
        self.assertEqual(primModelAPI.ComputeModelDrawMode(), 'cards')
Пример #24
0
    def testObjectPosition(self):
        """
        Tests that an object created interactively is positioned correctly on
        the live surface.
        """
        # Load our reference assembly.
        UsdMaya.LoadReferenceAssemblies()

        # Create a new custom viewport.
        window = cmds.window(widthHeight=(500, 400))
        cmds.paneLayout()
        panel = cmds.modelPanel()
        cmds.modelPanel(panel, edit=True, camera='persp')
        cmds.modelEditor(cmds.modelPanel(panel, q=True, modelEditor=True),
                         edit=True,
                         displayAppearance='smoothShaded',
                         rnm='vp2Renderer')
        cmds.showWindow(window)

        # Force all views to re-draw. This causes us to block until the
        # geometry we're making live has actually been evaluated and is present
        # in the viewport. Otherwise execution of the test may continue and the
        # create tool may be invoked before there's any geometry there, in
        # which case the tool won't create anything.
        cmds.refresh()

        # Get the viewport widget.
        view = OMUI.M3dView()
        OMUI.M3dView.getM3dViewFromModelPanel(panel, view)
        viewWidget = wrapInstance(long(view.widget()), QWidget)

        # Make our assembly live.
        cmds.makeLive('Block_1')

        # Enter interactive creation context.
        cmds.setToolTo('CreatePolyTorusCtx')

        # Click in the center of the viewport widget.
        QTest.mouseClick(viewWidget, QtCore.Qt.LeftButton,
                         QtCore.Qt.NoModifier,
                         viewWidget.rect().center())

        # Find the torus (it should be called pTorus1).
        self.assertTrue(cmds.ls('pTorus1'))

        # Check the torus's transform.
        # The Block_1 is originally 1 unit deep and centered at the origin, so
        # its original top plane is aligned at z=0.5.
        # It is scaled 5x, which makes the top plane aligned at z=2.5.
        # Then it is translated along z by 4.0, so its top plane is finally
        # aligned at z=6.5.
        translate = cmds.xform('pTorus1', q=True, t=True)
        self.assertAlmostEqual(translate[2], 6.5, places=3)
Пример #25
0
    def testDisjointAssembliesVariantSetsChange(self):
        """
        Tests that changing a variant set in a nested assembly |A1|B does not
        affect the variant sets on a different nested assembly |A2|B where
        A1 and A2 reference the same model.
        """
        cmds.file(new=True, force=True)

        usdFile = os.path.abspath("OneCube_set.usda")
        primPath = "/set"

        assemblyNodes = []
        for name in ["assembly1", "assembly2"]:
            assemblyNode = cmds.assembly(name=name,
                                         type=self.ASSEMBLY_TYPE_NAME)
            cmds.setAttr("%s.filePath" % assemblyNode, usdFile, type='string')
            cmds.setAttr("%s.primPath" % assemblyNode, primPath, type='string')
            cmds.assembly(assemblyNode, edit=True, active='Expanded')
            assemblyNodes.append(assemblyNode)

        cube1 = 'NS_%s:Cube_1' % assemblyNodes[0]
        self.assertTrue(cmds.objExists(cube1))

        cube2 = 'NS_%s:Cube_1' % assemblyNodes[1]
        self.assertTrue(cmds.objExists(cube2))

        cmds.setAttr('%s.usdVariantSet_shadingVariant' % cube1,
                     'Blue',
                     type='string')

        prim1 = UsdMaya.GetPrim(cube1)
        self.assertEqual(
            prim1.GetVariantSet('shadingVariant').GetVariantSelection(),
            'Blue')

        prim2 = UsdMaya.GetPrim(cube2)
        self.assertEqual(
            prim2.GetVariantSet('shadingVariant').GetVariantSelection(),
            'Default')
Пример #26
0
    def testPreserveSceneNotModified(self):
        """
        Tests that making scene modifications using a
        UsdMayaBlockSceneModificationContext on a scene that has not been
        modified correctly maintains the modification status after the context
        exits.
        """

        with UsdMaya.BlockSceneModificationContext():
            # Create a cube inside the context manager.
            cmds.polyCube()

        # The scene should NOT be modified.
        self._AssertSceneIsModified(False)
Пример #27
0
    def testUsdChangeProcessingProxy(self):
        """
        Tests that authoring on a USD stage that is referenced by a proxy shape
        invokes drawing refreshes in Maya correctly.
        """
        self._testName = 'UsdChangeProcessingTest_Proxy'

        mayaSceneFile = '%s.ma' % self._testName
        mayaSceneFullPath = os.path.abspath(mayaSceneFile)
        cmds.file(mayaSceneFullPath, open=True, force=True)

        UsdMaya.LoadReferenceAssemblies()

        proxyShapeDagPathName = '|UsdChangeProcessingTest|Primitive|PrimitiveShape'
        self._RunTest(proxyShapeDagPathName)
Пример #28
0
def variantSets_changeCommmand(unused, omg, node, variantSetName):
    val = cmds.optionMenuGrp(omg, q=True, value=True)
    variantAttr = 'usdVariantSet_%s' % variantSetName
    if not cmds.attributeQuery(variantAttr, node=node, exists=True):
        cmds.addAttr(node, ln=variantAttr, dt='string', internalSet=True)
    cmds.setAttr('%s.%s' % (node, variantAttr), val, type='string')

    # Add the resolved variant selection as a UI label
    resolvedVariant = ''
    usdPrim = UsdMaya.GetPrim(node)
    if usdPrim:
        variantSet = usdPrim.GetVariantSet(variantSetName)
        if variantSet:
            resolvedVariant = variantSet.GetVariantSelection()
    cmds.optionMenuGrp(omg, edit=True, extraLabel=resolvedVariant)
Пример #29
0
    def testUsdChangeProcessingAssembly(self):
        """
        Tests that authoring on a USD stage that is referenced by an assembly
        node (in "Collapsed" representation with a proxy shape underneath)
        invokes drawing refreshes in Maya correctly.
        """
        self._testName = 'UsdChangeProcessingTest_Assembly'

        mayaSceneFile = '%s.ma' % self._testName
        mayaSceneFullPath = os.path.abspath(mayaSceneFile)
        cmds.file(mayaSceneFullPath, open=True, force=True)

        UsdMaya.LoadReferenceAssemblies()

        assemblyDagPathName = '|UsdChangeProcessingTest|Primitive'
        self._RunTest(assemblyDagPathName)
Пример #30
0
    def _RunTest(self, dagPathName):
        rootPrim = UsdMaya.GetPrim(dagPathName)
        self.assertTrue(rootPrim)

        prim = rootPrim.GetChild('Geom').GetChild('Primitive')
        self.assertTrue(prim)
        self.assertEqual(prim.GetTypeName(), 'Cube')
        self._WriteViewportImage(self._testName, 'initial')

        prim.SetTypeName('Sphere')
        self.assertEqual(prim.GetTypeName(), 'Sphere')
        self._WriteViewportImage(self._testName, 'Sphere')

        prim.SetTypeName('Cube')
        self.assertEqual(prim.GetTypeName(), 'Cube')
        self._WriteViewportImage(self._testName, 'Cube')