def applyNgSkin(file_path, mesh): with open(file_path) as f: skin_str = ''.join(f.read().split()) ngs_importer = JsonImporter() ngs_data = ngs_importer.process(skin_str) ngs_data.saveTo(mesh.name())
def testUnserializeJsonManualInfluences(self): ''' verify there's no errors in parsing v1 json ''' json = '{"layers": [{"opacity": 1e-05, "mask": [1.0, 1.0, 0, 0], "enabled": false, "name": "base layer", "influences": []}, {"opacity": 0.9000000000009, "mask": [1.0, 1.0, 0, 0], "enabled": true, "name": "layer 2", "influences": [{"index": 0, "weights": [0.1, 0.2, 0.3, 0.4], "name": "root|L_Joint1"}]}]}' importer = JsonImporter() importer.process(json)
def testJson(self): model1 = self.createSampleModel() exporter = JsonExporter() json = exporter.process(model1) importer = JsonImporter() model2 = importer.process(json) self.assertModelsEqual(model1, model2)
def testManualInfluencesToJson(self): ''' test serialize to XML and back ''' model1 = self.createSampleModel() model1.addMirrorInfluenceAssociationOverride("A", "b") exporter = JsonExporter() json = exporter.process(model1) importer = JsonImporter() model2 = importer.process(json) self.assertModelsEqual(model1, model2)
def load_weights(weight_dir, geo_list=[], joint_list=[]): """ load geometry weights for character """ # weights folder weight_files = os.listdir(weight_dir) # load skin weights # alternatively, if you don't want such a long line of code: for geo in geo_list: kwargs = { 'toSelectedBones': True, 'bindMethod': 0, 'skinMethod': 2, 'name': geo.replace('geo', 'scls'), 'normalizeWeights': 1, 'maximumInfluences': 4 } try: scls = mc.skinCluster(joint_list, geo, **kwargs)[0] except RuntimeError: print 'bad bind' +str(RuntimeError) for wt_file in weight_files: ext_res = os.path.splitext(wt_file) # check extension format if not ext_res > 1: continue # check skin weight file if not ext_res[1] == '.json': continue # check geometry list if geo_list and not ext_res[0] in geo_list: continue # check if objects exist if not mc.objExists(ext_res[0]): continue fullpath_weight_file = os.path.join(weight_dir, wt_file) if ".json" in ext_res[1]: with open(fullpath_weight_file, 'r') as f: data = f.read() #with open(fullpath_weight_file) as json_file: #data = json.load(json_file) importer = JsonImporter() layerData = importer.process(data) try: layerData.saveTo(wt_file.replace('.json', 'Shape')) except Exception as e: print 'warning:' + str(e)