Exemplo n.º 1
0
def exportMeshes(selectedArmature, selectedMeshes, modProtected):
    xpsMeshes = []
    if modProtected:
        xpsMesh = xps_types.XpsMesh('p_dummyobject_0_0_0', [], [], [], 0)
        xpsMeshes.append(xpsMesh)
    for mesh in selectedMeshes:
        print('Exporting Mesh:', mesh.name)
        meshName = makeNamesFromMesh(mesh)
        # meshName = makeNamesFromMaterials(mesh)
        meshTextures = getXpsMatTextures(mesh)
        meshVerts, meshFaces = getXpsVertices(selectedArmature, mesh)
        meshUvCount = len(mesh.data.uv_layers)

        materialsCount = len(mesh.data.materials)
        if (materialsCount > 0):
            for idx in range(materialsCount):
                xpsMesh = xps_types.XpsMesh(meshName[idx], meshTextures[idx],
                                            meshVerts[idx], meshFaces[idx],
                                            meshUvCount)
                xpsMeshes.append(xpsMesh)
        else:
            dummyTexture = [xps_types.XpsTexture(0, 'dummy.png', 0)]
            xpsMesh = xps_types.XpsMesh(meshName[0], dummyTexture,
                                        meshVerts[0], meshFaces[0],
                                        meshUvCount)
            xpsMeshes.append(xpsMesh)

    return xpsMeshes
Exemplo n.º 2
0
def makeXpsTexture(mesh, material, textureSlot):
    texFilePath = textureSlot.texture.image.filepath
    absFilePath = bpy.path.abspath(texFilePath)
    # texFilePath = bpy.path.relpath(texFilePath)
    texturePath, textureFile = os.path.split(absFilePath)
    uvLayerName = textureSlot.uv_layer
    uvLayerIdx = mesh.data.uv_layers.find(uvLayerName)
    if uvLayerIdx == -1:
        uv_active_render = next((uv_texture
                                 for uv_texture in mesh.data.uv_textures
                                 if uv_texture.active_render))
        uvLayerIdx = mesh.data.uv_layers.find(uv_active_render.name)

    id = material.texture_slots.find(textureSlot.name)

    xpsTexture = xps_types.XpsTexture(id, textureFile, uvLayerIdx)
    return xpsTexture
Exemplo n.º 3
0
def readMeshes(file, xpsHeader, hasBones):
    meshes = []
    meshCount = bin_ops.readUInt32(file)
    hasHeader = bool(xpsHeader)
    hasTangent = False
    if hasHeader:
        hasTangent = hasTangentHeader(xpsHeader)

    for meshId in range(meshCount):
        # Name
        meshName = readFilesString(file)
        if not meshName:
            meshName = 'unnamed'
        # print('Mesh Name:', meshName)
        # uv Count
        uvLayerCount = bin_ops.readUInt32(file)
        # Textures
        textures = []
        textureCount = bin_ops.readUInt32(file)
        for texId in range(textureCount):
            textureFile = ntpath.basename(readFilesString(file))
            # print('Texture file', textureFile)
            uvLayerId = bin_ops.readUInt32(file)

            xpsTexture = xps_types.XpsTexture(texId, textureFile, uvLayerId)
            textures.append(xpsTexture)

        # Vertices
        vertex = []
        vertexCount = bin_ops.readUInt32(file)

        for vertexId in range(vertexCount):
            coord = readXYZ(file)
            normal = readXYZ(file)
            vertexColor = readVertexColor(file)

            uvs = []
            for uvLayerId in range(uvLayerCount):
                uvVert = readUvVert(file)
                uvs.append(uvVert)
                if not hasHeader or hasTangent:
                    tangent = read4Float(file)

            boneWeights = []
            if hasBones:
                # if cero bones dont have weights to read
                boneIdx = read4Int16(file)
                boneWeight = read4Float(file)

                for idx in range(len(boneIdx)):
                    boneWeights.append(
                        xps_types.BoneWeight(boneIdx[idx], boneWeight[idx]))
            xpsVertex = xps_types.XpsVertex(vertexId, coord, normal,
                                            vertexColor, uvs, boneWeights)
            vertex.append(xpsVertex)

        # Faces
        faces = []
        triCount = bin_ops.readUInt32(file)
        for i in range(triCount):
            triIdxs = readTriIdxs(file)
            faces.append(triIdxs)
        xpsMesh = xps_types.XpsMesh(meshName, textures, vertex, faces,
                                    uvLayerCount)
        meshes.append(xpsMesh)
    return meshes
Exemplo n.º 4
0
def readMeshes(file, hasBones):
    meshes = []
    meshCount = ascii_ops.readInt(file)

    for meshId in range(meshCount):
        # Name
        meshName = ascii_ops.readString(file)
        if not meshName:
            meshName = 'xxx'
        # print('Mesh Name:', meshName)
        # uv Count
        uvLayerCount = ascii_ops.readInt(file)
        # Textures
        textures = []
        textureCount = ascii_ops.readInt(file)
        for texId in range(textureCount):
            textureFile = ntpath.basename(ascii_ops.readString(file))
            # print('Texture file', textureFile)
            uvLayerId = ascii_ops.readInt(file)

            xpsTexture = xps_types.XpsTexture(texId, textureFile, uvLayerId)
            textures.append(xpsTexture)

        # Vertices
        vertex = []
        vertexCount = ascii_ops.readInt(file)
        for vertexId in range(vertexCount):
            coord = readXYZ(file)
            normal = readXYZ(file)
            vertexColor = read4Int(file)

            uvs = []
            for uvLayerId in range(uvLayerCount):
                uvVert = readUvVert(file)
                uvs.append(uvVert)
                # if ????
                # tangent????
                # tangent = read4float(file)

            boneWeights = []
            if hasBones:
                # if cero bones dont have weights to read
                boneIdx = readBoneId(file)
                boneWeight = readBoneWeight(file)

                for idx in range(len(boneIdx)):
                    boneWeights.append(
                        xps_types.BoneWeight(boneIdx[idx], boneWeight[idx]))
            xpsVertex = xps_types.XpsVertex(vertexId, coord, normal,
                                            vertexColor, uvs, boneWeights)
            vertex.append(xpsVertex)

        # Faces
        faces = []
        triCount = ascii_ops.readInt(file)
        for i in range(triCount):
            triIdxs = readTriIdxs(file)
            faces.append(triIdxs)
        xpsMesh = xps_types.XpsMesh(meshName, textures, vertex, faces,
                                    uvLayerCount)
        meshes.append(xpsMesh)
    return meshes
Exemplo n.º 5
0
def buildMeshes():
    meshes = []
    meshName = 'Mesh1'
    uvLayerCount = 1

    # Textures
    textures = []
    texId = 0
    textureFile = 'textutefile1.png'
    uvLayerId = 0
    xpsTexture = xps_types.XpsTexture(texId, textureFile, uvLayerId)
    textures.append(xpsTexture)

    texId = 1
    textureFile = 'textutefile2.png'
    uvLayerId = 0
    xpsTexture = xps_types.XpsTexture(texId, textureFile, uvLayerId)
    textures.append(xpsTexture)

    # Vertices
    vertex = []

    # Vertex1
    vertexId = 0
    coord = (1, 0, 0)
    normal = (0, 0, 1)
    vertexColor = (255, 255, 255, 0)
    uvs = []
    uvs.append((.2, .4))
    boneWeights = (xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0),
                   xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0))
    xpsVertex = xps_types.XpsVertex(vertexId, coord, normal, vertexColor, uvs,
                                    boneWeights)

    # Vertex2
    vertexId = 1
    coord = (0, 1, 0)
    normal = (0, 1, 0)
    vertexColor = (255, 255, 255, 0)
    uvs = []
    uvs.append((.3, .5))
    boneWeights = (xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0),
                   xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0))
    xpsVertex = xps_types.XpsVertex(vertexId, coord, normal, vertexColor, uvs,
                                    boneWeights)
    vertex.append(xpsVertex)

    # Vertex3
    vertexId = 2
    coord = (0, 0, 1)
    normal = (1, 0, 0)
    vertexColor = (255, 255, 255, 0)
    uvs = []
    uvs.append((.3, .9))
    boneWeights = (xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0),
                   xps_types.BoneWeight(0, 0), xps_types.BoneWeight(0, 0))
    xpsVertex = xps_types.XpsVertex(vertexId, coord, normal, vertexColor, uvs,
                                    boneWeights)
    vertex.append(xpsVertex)

    faces = []
    face = (0, 1, 2)
    faces.append(face)

    xpsMesh = xps_types.XpsMesh(meshName, textures, vertex, faces,
                                uvLayerCount)
    meshes.append(xpsMesh)

    return meshes