Example #1
0
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)
Example #2
0
def cvsPrintSkn(filename, start=0, stop=-1, returnStr = True, **options):
    header, materials, indices, vertices = lolMesh.importSKN(filename)
    headerStr = ""
    if(options['PRINT_HEADER']):
        headerStr+="#magic, numMaterials, numObjects\n"
        headerStr += "%d,%d,%d\n" % (header['magic'], 
            header['numMaterials'], header['numObjects']) 

    materialStr = ""
    if(options['PRINT_MATERIALS']):
        materialStr += "#matIndex, name, startVertex, numVertices,"
        materialStr += "startIndex, numIndices\n"
        for material in materials:
            materialStr += \
            "%d,%s,%d,%d,%d,%d\n" %\
            (material['matIndex'], bytes.decode(material['name']).strip('\x00'),material['startVertex'], \
            material['numVertices'], material['startIndex'], material['numIndices'])

    indexStr = ""
    if(options['PRINT_INDICES']):
        indexStr+="#Index list"
        for indx in indices:
            indexStr += "%d," %(indx[0],)

        indexStr+="\n"

    vertexStr = ""
    if(options['PRINT_VERTICES']):
        vertexStr+="#pos_x, pos_y, pos_z,"
        vertexStr+="boneIndex_0, boneIndex_1, boneIndex_2, boneIndex_3,"
        vertexStr+="norm_x, norm_y, norm_z,"
        vertexStr+="boneWeight_0, boneWeight_1, boneWeight_2, boneWeight_3,"
        vertexStr+="uv_u, uv_v\n"
        for indx, vtx in enumerate(vertices[start:stop]):
            vertexStr += \
                "%d,%f,%f,%f,%d,%d,%d,%d,"%(start+indx, 
                    vtx['position'][0], vtx['position'][1],vtx['position'][2],
                    vtx['boneIndex'][0],vtx['boneIndex'][1],vtx['boneIndex'][2],vtx['boneIndex'][3])
            vertexStr += \
                "%f,%f,%f,%f,%f,%f,%f,"%\
                (vtx['normal'][0],vtx['normal'][1],vtx['normal'][2],\
                vtx['weights'][0],vtx['weights'][1],vtx['weights'][2],vtx['weights'][3])
            vertexStr += "%f,%f\n"%(vtx['texcoords'][0],vtx['texcoords'][1])

    if returnStr == True:
        return headerStr+materialStr+indexStr+vertexStr
    else:
        print(headerStr+materialStr+indexStr+vertexStr)
Example #3
0
def cvsPrintSkn(filename, start=0, stop=-1, returnStr=True, **options):
    header, materials, indices, vertices = lolMesh.importSKN(filename)
    headerStr = ""
    if (options['PRINT_HEADER']):
        headerStr += "#magic, numMaterials, numObjects\n"
        headerStr += "%d,%d,%d\n" % (header['magic'], header['numMaterials'],
                                     header['numObjects'])

    materialStr = ""
    if (options['PRINT_MATERIALS']):
        materialStr += "#matIndex, name, startVertex, numVertices,"
        materialStr += "startIndex, numIndices\n"
        for material in materials:
            materialStr += \
            "%d,%s,%d,%d,%d,%d\n" %\
            (material['matIndex'], bytes.decode(material['name']).strip('\x00'),material['startVertex'], \
            material['numVertices'], material['startIndex'], material['numIndices'])

    indexStr = ""
    if (options['PRINT_INDICES']):
        indexStr += "#Index list"
        for indx in indices:
            indexStr += "%d," % (indx[0], )

        indexStr += "\n"

    vertexStr = ""
    if (options['PRINT_VERTICES']):
        vertexStr += "#pos_x, pos_y, pos_z,"
        vertexStr += "boneIndex_0, boneIndex_1, boneIndex_2, boneIndex_3,"
        vertexStr += "norm_x, norm_y, norm_z,"
        vertexStr += "boneWeight_0, boneWeight_1, boneWeight_2, boneWeight_3,"
        vertexStr += "uv_u, uv_v\n"
        for indx, vtx in enumerate(vertices[start:stop]):
            vertexStr += \
                "%d,%f,%f,%f,%d,%d,%d,%d,"%(start+indx,
                    vtx['position'][0], vtx['position'][1],vtx['position'][2],
                    vtx['boneIndex'][0],vtx['boneIndex'][1],vtx['boneIndex'][2],vtx['boneIndex'][3])
            vertexStr += \
                "%f,%f,%f,%f,%f,%f,%f,"%\
                (vtx['normal'][0],vtx['normal'][1],vtx['normal'][2],\
                vtx['weights'][0],vtx['weights'][1],vtx['weights'][2],vtx['weights'][3])
            vertexStr += "%f,%f\n" % (vtx['texcoords'][0], vtx['texcoords'][1])

    if returnStr == True:
        return headerStr + materialStr + indexStr + vertexStr
    else:
        print(headerStr + materialStr + indexStr + vertexStr)
Example #4
0
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)
Example #5
0
def prettyPrintSkn(filename, start=0, stop=-1, returnStr=True, **options):
    header, materials, indices, vertices = lolMesh.importSKN(filename)
    headerStr = ""
    if (options['PRINT_HEADER']):
        headerStr += "magic:%d\nnumMaterials:%d\nnumObjects:%d\n\n" % (
            header['magic'], header['numMaterials'], header['numObjects'])

    materialStr = ""
    if (options['PRINT_MATERIALS']):
        if header['numMaterials'] == 0:
            materialStr += "No material blocks present\n\n"
        else:
            for material in materials:
                materialStr += \
                "matIndex:%d\nname:%s\nstartVertex:%d\tnumVertices:%d\nstartIndex:%d\tnumIndices:%d\n\n" %\
                (material['matIndex'], bytes.decode(material['name']).strip('\x00'),material['startVertex'], \
                material['numVertices'], material['startIndex'], material['numIndices'])

    indexStr = ""
    if (options['PRINT_INDICES']):
        for indx in indices:
            indexStr += "%d\n" % (indx[0], )

    vertexStr = ""
    if (options['PRINT_VERTICES']):
        for indx, vtx in enumerate(vertices[start:stop]):
            vertexStr += \
                "%d\tpos:(%f,%f,%f)\tboneIndx:(%d,%d,%d,%d)\n"%(start+indx,
                    vtx['position'][0], vtx['position'][1],vtx['position'][2],
                    vtx['boneIndex'][0],vtx['boneIndex'][1],vtx['boneIndex'][2],vtx['boneIndex'][3])
            vertexStr += \
                "\tnorm:(%f,%f,%f)\tweights:(%f,%f,%f,%f)\n"%\
                (vtx['normal'][0],vtx['normal'][1],vtx['normal'][2],\
                vtx['weights'][0],vtx['weights'][1],vtx['weights'][2],vtx['weights'][3])
            vertexStr += "\tuvs:(%f, %f)\n" % (vtx['texcoords'][0],
                                               vtx['texcoords'][1])

    if returnStr == True:
        return headerStr + materialStr + indexStr + vertexStr
    else:
        print(headerStr + materialStr + indexStr + vertexStr)
Example #6
0
def prettyPrintSkn(filename, start=0, stop=-1, returnStr = True, **options):
    header, materials, indices, vertices = lolMesh.importSKN(filename)
    headerStr = ""
    if(options['PRINT_HEADER']):
        headerStr += "magic:%d\nnumMaterials:%d\nnumObjects:%d\n\n" % (header['magic'], 
            header['numMaterials'], header['numObjects']) 

    materialStr = ""
    if(options['PRINT_MATERIALS']):
        if header['numMaterials'] == 0:
            materialStr +="No material blocks present\n\n"
        else:
            for material in materials:
                materialStr += \
                "matIndex:%d\nname:%s\nstartVertex:%d\tnumVertices:%d\nstartIndex:%d\tnumIndices:%d\n\n" %\
                (material['matIndex'], bytes.decode(material['name']).strip('\x00'),material['startVertex'], \
                material['numVertices'], material['startIndex'], material['numIndices'])

    indexStr = ""
    if(options['PRINT_INDICES']):
        for indx in indices:
            indexStr += "%d\n" %(indx[0],)

    vertexStr = ""
    if(options['PRINT_VERTICES']):
        for indx, vtx in enumerate(vertices[start:stop]):
            vertexStr += \
                "%d\tpos:(%f,%f,%f)\tboneIndx:(%d,%d,%d,%d)\n"%(start+indx, 
                    vtx['position'][0], vtx['position'][1],vtx['position'][2],
                    vtx['boneIndex'][0],vtx['boneIndex'][1],vtx['boneIndex'][2],vtx['boneIndex'][3])
            vertexStr += \
                "\tnorm:(%f,%f,%f)\tweights:(%f,%f,%f,%f)\n"%\
                (vtx['normal'][0],vtx['normal'][1],vtx['normal'][2],\
                vtx['weights'][0],vtx['weights'][1],vtx['weights'][2],vtx['weights'][3])
            vertexStr += "\tuvs:(%f, %f)\n"%(vtx['texcoords'][0],vtx['texcoords'][1])

    if returnStr == True:
        return headerStr+materialStr+indexStr+vertexStr
    else:
        print(headerStr+materialStr+indexStr+vertexStr)
Example #7
0
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'