コード例 #1
0
ファイル: actionsTest.py プロジェクト: BigMacchia/ngSkinTools
    def testImport(self):
        exampleData = """<?xml version="1.0" encoding="UTF-8"?>
                            <ngstLayerData version="1.0">
                                <layer enabled="yes" mask="" name="imported layer 2" opacity="1"/>
                                <layer enabled="yes" mask="" name="imported layer 1" opacity="1">
                                    <influence index="0" name="joint1" weights="1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0"/>
                                    <influence index="1" name="joint2" weights="0 2.13095271869166e-16 2.13584887749867e-16 0 0 0 0 0 1 1 1 1 1 1 1 1"/>
                                    <influence index="2" name="joint3" weights="0 8.94933305586526e-18 8.45971717509877e-18 0 0 0 0 0 0 0 0 0 0 0 0 0"/>
                                </layer>
                            </ngstLayerData>
                        """
                        
           
        self.writeFile(self.exportName, exampleData)
        
        cmds.select('testMesh')
        
        a = ImportAction(ownerUI=None, ioFormat=Formats.getXmlFormat())
        a.selectFile = lambda *args,**kwargs: self.exportName
        a.getImportOptions = lambda : ImportOptions()
        a.execute()

        # assert that first two layers are imported ones, in a correct order        
        layers = list(self.mll.listLayers())
        self.assertEquals(layers[0][1],'imported layer 2')
        self.assertEquals(layers[1][1],'imported layer 1')
コード例 #2
0
ファイル: actionsTest.py プロジェクト: BigMacchia/ngSkinTools
    def testCleanExistingLayers(self):
        exampleData = """<?xml version="1.0" encoding="UTF-8"?>
                            <ngstLayerData version="1.0">
                                <layer enabled="yes" mask="" name="imported layer 1" opacity="1">
                                    <influence index="0" name="joint1" weights="1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0"/>
                                </layer>
                            </ngstLayerData>
                        """
        self.writeFile(self.exportName, exampleData)

        openMayaFile('normalization.ma')
        cmds.select('testMesh')
        self.mll.setCurrentMesh('testMesh')
        self.mll.initLayers()
        self.mll.createLayer("one")
        self.mll.createLayer("two")
        
        self.assertEquals(len(list(self.mll.listLayers())),2)
        
        options = ImportOptions()
        options.keepExistingLayers = False
        
        a = ImportAction(ownerUI=None, ioFormat=Formats.getXmlFormat())
        a.selectFile = lambda *args,**kwargs: self.exportName
        a.getImportOptions = lambda: options

        a.execute()
        
        newLayers = list(self.mll.listLayers())
        
        self.assertEquals(len(newLayers),1)
        layerId = newLayers[0][0]
        influences = list(self.mll.listLayerInfluences(layerId))
        
        self.assertEqual(len(influences), 1)
コード例 #3
0
    def testImport(self):
        exampleData = """<?xml version="1.0" encoding="UTF-8"?>
                            <ngstLayerData version="1.0">
                                <layer enabled="yes" mask="" name="imported layer 2" opacity="1"/>
                                <layer enabled="yes" mask="" name="imported layer 1" opacity="1">
                                    <influence index="0" name="joint1" weights="1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0"/>
                                    <influence index="1" name="joint2" weights="0 2.13095271869166e-16 2.13584887749867e-16 0 0 0 0 0 1 1 1 1 1 1 1 1"/>
                                    <influence index="2" name="joint3" weights="0 8.94933305586526e-18 8.45971717509877e-18 0 0 0 0 0 0 0 0 0 0 0 0 0"/>
                                </layer>
                            </ngstLayerData>
                        """

        self.writeFile(self.exportName, exampleData)

        cmds.select('testMesh')

        a = ImportAction(ownerUI=None, ioFormat=Formats.getXmlFormat())
        a.selectFile = lambda *args, **kwargs: self.exportName
        a.getImportOptions = lambda: ImportOptions()
        a.execute()

        # assert that first two layers are imported ones, in a correct order
        layers = list(self.mll.listLayers())
        self.assertEquals(layers[0][1], 'imported layer 2')
        self.assertEquals(layers[1][1], 'imported layer 1')
コード例 #4
0
    def testCleanExistingLayers(self):
        exampleData = """<?xml version="1.0" encoding="UTF-8"?>
                            <ngstLayerData version="1.0">
                                <layer enabled="yes" mask="" name="imported layer 1" opacity="1">
                                    <influence index="0" name="joint1" weights="1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0"/>
                                </layer>
                            </ngstLayerData>
                        """
        self.writeFile(self.exportName, exampleData)

        openMayaFile('normalization.ma')
        cmds.select('testMesh')
        self.mll.setCurrentMesh('testMesh')
        self.mll.initLayers()
        self.mll.createLayer("one")
        self.mll.createLayer("two")

        self.assertEquals(len(list(self.mll.listLayers())), 2)

        options = ImportOptions()
        options.keepExistingLayers = False

        a = ImportAction(ownerUI=None, ioFormat=Formats.getXmlFormat())
        a.selectFile = lambda *args, **kwargs: self.exportName
        a.getImportOptions = lambda: options

        a.execute()

        newLayers = list(self.mll.listLayers())

        self.assertEquals(len(newLayers), 1)
        layerId = newLayers[0][0]
        influences = list(self.mll.listLayerInfluences(layerId))

        self.assertEqual(len(influences), 1)
コード例 #5
0
    def testImportAvailableWithNoLayers(self):
        exampleData = """<?xml version="1.0" encoding="UTF-8"?>
                            <ngstLayerData version="1.0">
                                <layer enabled="yes" mask="" name="imported layer 1" opacity="1">
                                    <influence index="0" name="joint1" weights="1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0"/>
                                </layer>
                            </ngstLayerData>
                        """
        self.writeFile(self.exportName, exampleData)

        openMayaFile('normalization.ma')

        a = ImportAction(ownerUI=None, ioFormat=Formats.getXmlFormat())
        a.selectFile = lambda *args, **kwargs: self.exportName
        a.getImportOptions = lambda: ImportOptions()

        cmds.select('persp')
        self.assertFalse(
            a.isEnabled(),
            "import action should be disabled if target mesh is not suitable for skinning"
        )

        cmds.select('testMesh')
        self.assertTrue(
            a.isEnabled(),
            "import action should be available if suitable mesh is selected")

        # should allow execution here
        a.execute()
コード例 #6
0
ファイル: actionsTest.py プロジェクト: BigMacchia/ngSkinTools
    def testImportAvailableWithNoLayers(self):
        exampleData = """<?xml version="1.0" encoding="UTF-8"?>
                            <ngstLayerData version="1.0">
                                <layer enabled="yes" mask="" name="imported layer 1" opacity="1">
                                    <influence index="0" name="joint1" weights="1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0"/>
                                </layer>
                            </ngstLayerData>
                        """
        self.writeFile(self.exportName, exampleData)

        openMayaFile('normalization.ma')

        a = ImportAction(ownerUI=None, ioFormat=Formats.getXmlFormat())
        a.selectFile = lambda *args,**kwargs: self.exportName
        a.getImportOptions = lambda : ImportOptions()

        cmds.select('persp')
        self.assertFalse(a.isEnabled(), "import action should be disabled if target mesh is not suitable for skinning")

        cmds.select('testMesh')
        self.assertTrue(a.isEnabled(), "import action should be available if suitable mesh is selected")

        # should allow execution here
        a.execute()