def prettyPrintSkl(filename, start=0, stop=-1, returnStr=True, **options): header, boneDict = lolSkeleton.importSKL(filename) headerStr = "" if(options['PRINT_HEADER']): headerStr += \ "Filetype:%s\nnumObjects:%d\nskeletonHash:%d\nnumElements:%d\n\n" % (header['fileType'], header['numObjects'], header['skeletonHash'], header['numElements']) boneStr = "" if(options['PRINT_BONES']): if stop == -1: stop = len(boneDict) for id in range(start,stop): bone = boneDict[id] if bone['parent'] != -1: parentName = boneDict[bone['parent']]['name'] else: parentName = "None" boneStr += "%d\t%s\tparent id:%d\t(%s)\n" %(id, bone['name'], bone['parent'], parentName) boneStr += "\tscale: %f\n" %(bone['scale'],) boneStr += "\tmatrix:\t %7.4f %7.4f %7.4f %7.4f\n" %(bone['matrix'][0][0], bone['matrix'][0][1], bone['matrix'][0][2], bone['matrix'][0][3]) boneStr += "\t\t %7.4f %7.4f %7.4f %7.4f\n" %(bone['matrix'][1][0], bone['matrix'][1][1],bone['matrix'][1][2],bone['matrix'][1][3]) boneStr += "\t\t %7.4f %7.4f %7.4f %7.4f\n\n" %(bone['matrix'][2][0], bone['matrix'][2][1], bone['matrix'][2][2], bone['matrix'][2][3]) if returnStr == True: return headerStr+boneStr else: print(headerStr+boneStr)
def run(): dataBase = '/var/tmp/downloads/lol/DATA/Characters/' sknFile = 'Ryze/Ryze.skn' sklFile = 'Ryze/Ryze.skl' sklHeader, boneDict = lolSkeleton.importSKL(dataBase + sklFile) lolSkeleton.buildSKL(boneDict) sknHeader, materials, indices, vertices = lolMesh.importSKN(dataBase + sknFile) lolMesh.buildMesh(dataBase + sknFile) meshObj = bpy.data.objects['Mesh'] armObj = bpy.data.objects['Armature'] lolMesh.addDefaultWeights(boneDict, vertices, armObj, meshObj)
def cvsPrintSkl(filename, start=0, stop=-1, returnStr=True, **options): header, boneDict = lolSkeleton.importSKL(filename) headerStr = "" if (options['PRINT_HEADER']): headerStr += "#fileType, numObjects, skeletonHash, numElements\n" headerStr += \ "%s,%d,%d,%d\n" % (header['fileType'], header['numObjects'], header['skeletonHash'], header['numElements']) boneStr = "" if (options['PRINT_BONES']): boneStr += "#boneID, name, parentID, scale," boneStr += "matrix[0][0], matrix[0][1], matrix[0][2], matrix[0][3]," boneStr += "matrix[1][0], matrix[1][1], matrix[1][2], matrix[1][3]," boneStr += "matrix[2][0], matrix[2][1], matrix[2][2], matrix[2][3]\n" if end == -1: end = len(boneDict) for id in range(start, stop): bone = boneDict[id] if bone['parent'] != -1: parentName = boneDict[bone['parent']]['name'] else: parentName = "None" boneStr += "%d,%s,%d," % (id, bone['name'], bone['parent']) boneStr += "%f," % (bone['scale'], ) boneStr += "%e,%e,%e,%e," % ( bone['matrix'][0][0], bone['matrix'][0][1], bone['matrix'][0][2], bone['matrix'][0][3]) boneStr += "%e,%e,%e,%e," % ( bone['matrix'][1][0], bone['matrix'][1][1], bone['matrix'][1][2], bone['matrix'][1][3]) boneStr += "%e,%e,%e,%e\n" % ( bone['matrix'][2][0], bone['matrix'][2][1], bone['matrix'][2][2], bone['matrix'][2][3]) if returnStr == True: return headerStr + boneStr else: print(headerStr + boneStr)
def cvsPrintSkl(filename, start=0, stop=-1, returnStr=True, **options): header, boneDict = lolSkeleton.importSKL(filename) headerStr = "" if(options['PRINT_HEADER']): headerStr += "#fileType, numObjects, skeletonHash, numElements\n" headerStr += \ "%s,%d,%d,%d\n" % (header['fileType'], header['numObjects'], header['skeletonHash'], header['numElements']) boneStr = "" if(options['PRINT_BONES']): boneStr+="#boneID, name, parentID, scale," boneStr+="matrix[0][0], matrix[0][1], matrix[0][2], matrix[0][3]," boneStr+="matrix[1][0], matrix[1][1], matrix[1][2], matrix[1][3]," boneStr+="matrix[2][0], matrix[2][1], matrix[2][2], matrix[2][3]\n" if end == -1: end = len(boneDict) for id in range(start,stop): bone = boneDict[id] if bone['parent'] != -1: parentName = boneDict[bone['parent']]['name'] else: parentName = "None" boneStr += "%d,%s,%d," %(id, bone['name'],bone['parent']) boneStr += "%f," %(bone['scale'],) boneStr += "%e,%e,%e,%e," %(bone['matrix'][0][0], bone['matrix'][0][1], bone['matrix'][0][2], bone['matrix'][0][3]) boneStr += "%e,%e,%e,%e," %(bone['matrix'][1][0], bone['matrix'][1][1],bone['matrix'][1][2],bone['matrix'][1][3]) boneStr += "%e,%e,%e,%e\n" %(bone['matrix'][2][0], bone['matrix'][2][1], bone['matrix'][2][2], bone['matrix'][2][3]) if returnStr == True: return headerStr+boneStr else: print(headerStr+boneStr)
def prettyPrintSkl(filename, start=0, stop=-1, returnStr=True, **options): header, boneDict = lolSkeleton.importSKL(filename) headerStr = "" if (options['PRINT_HEADER']): headerStr += \ "Filetype:%s\nnumObjects:%d\nskeletonHash:%d\nnumElements:%d\n\n" % (header['fileType'], header['numObjects'], header['skeletonHash'], header['numElements']) boneStr = "" if (options['PRINT_BONES']): if stop == -1: stop = len(boneDict) for id in range(start, stop): bone = boneDict[id] if bone['parent'] != -1: parentName = boneDict[bone['parent']]['name'] else: parentName = "None" boneStr += "%d\t%s\tparent id:%d\t(%s)\n" % ( id, bone['name'], bone['parent'], parentName) boneStr += "\tscale: %f\n" % (bone['scale'], ) boneStr += "\tmatrix:\t %7.4f %7.4f %7.4f %7.4f\n" % ( bone['matrix'][0][0], bone['matrix'][0][1], bone['matrix'][0][2], bone['matrix'][0][3]) boneStr += "\t\t %7.4f %7.4f %7.4f %7.4f\n" % ( bone['matrix'][1][0], bone['matrix'][1][1], bone['matrix'][1][2], bone['matrix'][1][3]) boneStr += "\t\t %7.4f %7.4f %7.4f %7.4f\n\n" % ( bone['matrix'][2][0], bone['matrix'][2][1], bone['matrix'][2][2], bone['matrix'][2][3]) if returnStr == True: return headerStr + boneStr else: print(headerStr + boneStr)
def import_char(MODEL_DIR="", SKN_FILE="", SKL_FILE="", DDS_FILE="", CLEAR_SCENE=True, APPLY_WEIGHTS=True, APPLY_TEXTURE=True): '''Import a LoL Character MODEL_DIR: Base directory of the model you wish to import. SKN_FILE: .skn mesh file for the character SKL_FILE: .skl skeleton file for the character DDS_FILE: .dds texture file for the character CLEAR_SCENE: remove existing meshes, armatures, surfaces, etc. before importing APPLY_WEIGHTS: Import bone weights from the mesh file APPLY_TEXTURE: Apply the skin texture !!IMPORTANT!!: If you're running this on a windows system make sure to escape the backslashes in the model directory you give. BAD: c:\\path\\to\\model GOOD: c:\\\\path\\\\to\\\\model ''' import bpy import lolMesh, lolSkeleton from os import path if CLEAR_SCENE: for type in ['MESH', 'ARMATURE', 'LATTICE', 'CURVE', 'SURFACE']: bpy.ops.object.select_by_type(extend=False, type=type) bpy.ops.object.delete() if SKL_FILE: SKL_FILEPATH=path.join(MODEL_DIR, SKL_FILE) print(SKL_FILEPATH) sklHeader, boneDict = lolSkeleton.importSKL(SKL_FILEPATH) lolSkeleton.buildSKL(boneDict) armObj = bpy.data.objects['Armature'] armObj.name ='lolArmature' if SKN_FILE: SKN_FILEPATH=path.join(MODEL_DIR, SKN_FILE) sknHeader, materials, indices, vertices = lolMesh.importSKN(SKN_FILEPATH) lolMesh.buildMeshNative(SKN_FILEPATH) meshObj = bpy.data.objects['lolMesh'] #meshObj.name = 'lolMesh' #Presently io_scene_obj.load() does not import vertex normals, #so do it ourselves #for id, vtx in enumerate(meshObj.data.vertices): # vtx.normal = vertices[id]['normal'] if SKN_FILE and SKL_FILE and APPLY_WEIGHTS: lolMesh.addDefaultWeights(boneDict, vertices, armObj, meshObj) if DDS_FILE and APPLY_TEXTURE: DDS_FILEPATH=path.join(MODEL_DIR, DDS_FILE) bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.select_all(action='DESELECT') #bpy.data.objects['lolMesh'].select = True #bpy.ops.object.mode_set(mode='EDIT') img = bpy.data.images.new(DDS_FILE) img.filepath=DDS_FILEPATH img.source = 'FILE' tex = bpy.data.textures.new('lolTexture', type='IMAGE') tex.image = img mat = bpy.data.materials.new(name=tex.name) mtex = mat.texture_slots.add() mtex.texture = tex mtex.texture_coords = 'UV' mtex.use_map_color_diffuse = True meshObj.data.materials.append(mat) meshObj.data.uv_textures[0].data[0].image = img meshObj.data.uv_textures[0].data[0].use_image = True meshObj.data.uv_textures[0].data[0].blend_type = 'ALPHA'