def testLoadModel(self):
     import ngSkinTools.importExport as ie
     ie.cmds = self.cmds
     ie.mel = self.mel
     model = LayerData()
     model.loadFrom('pSphere1')
     print model.layers[0].influences[0].weights
 def testLoad2(self):
     openMayaFile('simplemirror.ma')
     mll = MllInterface()
     mll.setCurrentMesh('testMesh')
     mll.initLayers()
     mll.createLayer("Initial Weights")
     
     model = LayerData()
     model.loadFrom('testMesh')
     
     self.assertEqual(model.layers[0].name, "Initial Weights")
     self.assertEquals(model.layers[0].influences[0].influenceName, "|x_axis|root")
 def testLoad2(self):
     openMayaFile('simplemirror.ma')
     mll = MllInterface()
     mll.setCurrentMesh('testMesh')
     mll.initLayers()
     mll.createLayer("Initial Weights")
     
     model = LayerData()
     model.loadFrom('testMesh')
     
     self.assertEqual(model.layers[0].name, "Initial Weights")
     self.assertEquals(model.layers[0].influences[0].influenceName, "|x_axis|root")
Exemple #4
0
    def testLoad(self):
        skinCluster = 'skinCluster1'

        mll = flexmock()
        mll.should_receive('setCurrentMesh').once()
        mll.should_receive('listLayers').and_return(
            ((123, "layer1"), (456, "layer2"))).once()
        mll.should_receive('getLayerOpacity').with_args(123).and_return(0.9)
        mll.should_receive('getLayerOpacity').with_args(456).and_return(1.0)
        mll.should_receive('isLayerEnabled').with_args(123).and_return(True)
        mll.should_receive('isLayerEnabled').with_args(456).and_return(False)
        mll.should_receive('getLayerMask').with_args(123).and_return(
            [1.2, 1.1, 1.0, 0])
        mll.should_receive('getLayerMask').with_args(456).and_return(
            [1.2, 1.1, 1.0, 0])
        mll.should_receive('listLayerInfluences').with_args(123).and_return(
            (('infl1', 0), ('infl2', 1)))
        mll.should_receive('listLayerInfluences').with_args(456).and_return(
            (('infl3', 0), ('infl4', 1)))
        mll.should_receive('getInfluenceWeights').with_args(123, 0).and_return(
            [0, 0, 0, 0])
        mll.should_receive('getInfluenceWeights').with_args(123, 1).and_return(
            [0, 0, 0, 0])
        mll.should_receive('getInfluenceWeights').with_args(456, 0).and_return(
            [0, 0, 0, 0])
        mll.should_receive('getInfluenceWeights').with_args(456, 1).and_return(
            [0, 0, 0, 0])
        mll.should_receive('listManualMirrorInfluenceAssociations').and_return(
            {"a": "b"})

        model = LayerData()
        model.getFullNodePath = lambda a: a
        model.mll = mll
        model.loadFrom(skinCluster)

        self.assertEquals(model.layers[0].name, "layer1")
        self.assertEquals(model.layers[1].name, "layer2")
        self.assertEquals(model.layers[0].opacity, 0.9)
        self.assertEquals(model.layers[0].enabled, True)
        self.assertEquals(model.layers[1].enabled, False)

        self.assertEquals(model.layers[1].influences[0].influenceName, "infl3")
        self.assertEquals(model.layers[1].influences[1].influenceName, "infl4")

        self.assertEquals(model.layers[0].influences[0].logicalIndex, 0)
        self.assertEquals(model.layers[0].influences[1].logicalIndex, 1)
    def testLoad(self):
        skinCluster = 'skinCluster1'
        
        mll = flexmock()
        mll.should_receive('setCurrentMesh').once()
        mll.should_receive('listLayers').and_return(((123,"layer1"),(456,"layer2"))).once()
        mll.should_receive('getLayerOpacity').with_args(123).and_return(0.9)
        mll.should_receive('getLayerOpacity').with_args(456).and_return(1.0)
        mll.should_receive('isLayerEnabled').with_args(123).and_return(True)
        mll.should_receive('isLayerEnabled').with_args(456).and_return(False)
        mll.should_receive('getLayerMask').with_args(123).and_return([1.2,1.1,1.0,0])
        mll.should_receive('getLayerMask').with_args(456).and_return([1.2,1.1,1.0,0])
        mll.should_receive('listLayerInfluences').with_args(123).and_return((('infl1',0),('infl2',1)))
        mll.should_receive('listLayerInfluences').with_args(456).and_return((('infl3',0),('infl4',1)))
        mll.should_receive('getInfluenceWeights').with_args(123,0).and_return([0,0,0,0])
        mll.should_receive('getInfluenceWeights').with_args(123,1).and_return([0,0,0,0])
        mll.should_receive('getInfluenceWeights').with_args(456,0).and_return([0,0,0,0])
        mll.should_receive('getInfluenceWeights').with_args(456,1).and_return([0,0,0,0])
        mll.should_receive('listManualMirrorInfluenceAssociations').and_return({"a":"b"})
        
        
        model = LayerData()
        model.getFullNodePath = lambda a: a
        model.mll = mll
        model.loadFrom(skinCluster)
        
        self.assertEquals(model.layers[0].name, "layer1")
        self.assertEquals(model.layers[1].name, "layer2")
        self.assertEquals(model.layers[0].opacity, 0.9)
        self.assertEquals(model.layers[0].enabled, True)
        self.assertEquals(model.layers[1].enabled, False)

        self.assertEquals(model.layers[1].influences[0].influenceName, "infl3")
        self.assertEquals(model.layers[1].influences[1].influenceName, "infl4")
        
        self.assertEquals(model.layers[0].influences[0].logicalIndex, 0)
        self.assertEquals(model.layers[0].influences[1].logicalIndex, 1)
Exemple #6
0
def save_weights(weight_dir, geo_list=[]):

    """
    save geometry weights for character
    """

    for obj in geo_list:
        # save dir and save file

        weight_file = os.path.join(weight_dir, obj + '.json')

        layerData = LayerData()
        try:
            layerData.loadFrom(obj + 'Shape')
        except:
            try:
                mll = MllInterface()
                mll.setCurrentMesh(obj+'Shape')
                ass = mll.initLayers()
                layer = mll.createLayer('Base Weights')
            except:
                pass
        exporter = JsonExporter()
        jsonContents = exporter.process(layerData)
        # string "jsonContents" can now be saved to an external file

        with open(weight_file, 'w') as f:
            f.write(jsonContents)
            #json.dump(jsonContents, f)
        # save skin weight file

        #mc.select(obj)
        #bSkinSaver2.bSaveSkinValues(weight_file)

        print "Saved to: " + weight_file
        mc.select(d=True)