def writeTriIdxs(co):
    face1 = bin_ops.writeUInt32(co[0])
    face2 = bin_ops.writeUInt32(co[1])
    face3 = bin_ops.writeUInt32(co[2])
    faceLoop = bytearray()
    faceLoop.extend(face1)
    faceLoop.extend(face2)
    faceLoop.extend(face3)
    return faceLoop
Beispiel #2
0
def writeTriIdxs(co):
    face1 = bin_ops.writeUInt32(co[0])
    face2 = bin_ops.writeUInt32(co[1])
    face3 = bin_ops.writeUInt32(co[2])
    faceLoop = bytearray()
    faceLoop.extend(face1)
    faceLoop.extend(face2)
    faceLoop.extend(face3)
    return faceLoop
Beispiel #3
0
def writeHeader(header):
    headerArray = bytearray()
    if header:
        # MagicNumber
        headerArray.extend(bin_ops.writeUInt32(header.magic_number))
        # XPS Model Version
        headerArray.extend(bin_ops.writeUInt16(header.version_mayor))
        headerArray.extend(bin_ops.writeUInt16(header.version_minor))
        # XNAaral Name
        headerArray.extend(writeFilesString(header.xna_aral))
        # Settings Len (unit32*4)
        headerArray.extend(bin_ops.writeUInt32(header.settingsLen))
        # MachineName
        headerArray.extend(writeFilesString(header.machine))
        # UserName
        headerArray.extend(writeFilesString(header.user))
        # File-->File
        headerArray.extend(writeFilesString(header.files))
        # settings
        headerArray.extend(header.settings)

    return headerArray
def writeHeader(header):
    headerArray = bytearray()
    if header:
        # MagicNumber
        headerArray.extend(bin_ops.writeUInt32(header.magic_number))
        # XPS Model Version
        headerArray.extend(bin_ops.writeUInt16(header.version_mayor))
        headerArray.extend(bin_ops.writeUInt16(header.version_minor))
        # XNAaral Name
        headerArray.extend(writeFilesString(header.xna_aral))
        # Settings Len (unit32*4)
        headerArray.extend(bin_ops.writeUInt32(header.settingsLen))
        # MachineName
        headerArray.extend(writeFilesString(header.machine))
        # UserName
        headerArray.extend(writeFilesString(header.user))
        # File-->File
        headerArray.extend(writeFilesString(header.files))
        # settings
        headerArray.extend(header.settings)

    return headerArray
Beispiel #5
0
def writeBones(bones):
    bonesArray = bytearray()
    if bones:
        bonesArray.extend(bin_ops.writeUInt32(len(bones)))

        for bone in bones:
            name = bone.name
            parentId = bone.parentId
            co = bone.co
            if parentId is None:
                parentId = -1
            bonesArray.extend(writeFilesString(name))
            bonesArray.extend(bin_ops.writeInt16(parentId))
            bonesArray.extend(writeXYZ(co))
    return bonesArray
def writeBones(bones):
    bonesArray = bytearray()
    if bones:
        bonesArray.extend(bin_ops.writeUInt32(len(bones)))

        for bone in bones:
            name = bone.name
            parentId = bone.parentId
            co = bone.co
            if parentId is None:
                parentId = -1
            bonesArray.extend(writeFilesString(name))
            bonesArray.extend(bin_ops.writeInt16(parentId))
            bonesArray.extend(writeXYZ(co))
    return bonesArray
Beispiel #7
0
def writeMeshes(meshes):
    meshCount = len(meshes)
    meshesArray = bytearray(bin_ops.writeUInt32(meshCount))
    sortedMeshes = sorted(meshes, key=operator.attrgetter('name'))

    for mesh in sortedMeshes:
        # Name
        meshesArray.extend(writeFilesString(mesh.name))
        # uv Count
        meshesArray.extend(bin_ops.writeUInt32(mesh.uvCount))
        # Textures
        meshesArray.extend(bin_ops.writeUInt32(len(mesh.textures)))
        for texture in mesh.textures:
            meshesArray.extend(writeFilesString(texture.file))
            meshesArray.extend(bin_ops.writeUInt32(texture.uvLayer))

        # Vertices
        meshesArray.extend(bin_ops.writeUInt32(len(mesh.vertices)))
        for vertex in mesh.vertices:
            meshesArray.extend(writeXYZ(vertex.co))
            meshesArray.extend(writeXYZ(vertex.norm))
            meshesArray.extend(writeVertexColor(vertex.vColor))

            for uv in vertex.uv:
                meshesArray.extend(writeUvVert(uv))
                # if ????
                # tangent????
                # meshesArray.extend(write4float(xxx))

            # Sort first the biggest weights
            boneWeights = sorted(
                vertex.boneWeights,
                key=lambda bw: bw.weight,
                reverse=True)

            meshesArray.extend(write4UInt16([bw.id for bw in boneWeights]))
            meshesArray.extend(write4Float([bw.weight for bw in boneWeights]))

        # Faces
        meshesArray.extend(bin_ops.writeUInt32(len(mesh.faces)))
        for face in mesh.faces:
            meshesArray.extend(writeTriIdxs(face))

    return meshesArray
def writeMeshes(meshes):
    meshCount = len(meshes)
    meshesArray = bytearray(bin_ops.writeUInt32(meshCount))
    sortedMeshes = sorted(meshes, key=operator.attrgetter('name'))

    for mesh in sortedMeshes:
        # Name
        meshesArray.extend(writeFilesString(mesh.name))
        # uv Count
        meshesArray.extend(bin_ops.writeUInt32(mesh.uvCount))
        # Textures
        meshesArray.extend(bin_ops.writeUInt32(len(mesh.textures)))
        for texture in mesh.textures:
            meshesArray.extend(writeFilesString(texture.file))
            meshesArray.extend(bin_ops.writeUInt32(texture.uvLayer))

        # Vertices
        meshesArray.extend(bin_ops.writeUInt32(len(mesh.vertices)))
        for vertex in mesh.vertices:
            meshesArray.extend(writeXYZ(vertex.co))
            meshesArray.extend(writeXYZ(vertex.norm))
            meshesArray.extend(writeVertexColor(vertex.vColor))

            for uv in vertex.uv:
                meshesArray.extend(writeUvVert(uv))
                # if ????
                # tangent????
                # meshesArray.extend(write4float(xxx))

            # Sort first the biggest weights
            boneWeights = sorted(
                vertex.boneWeights,
                key=lambda bw: bw.weight,
                reverse=True)

            meshesArray.extend(write4UInt16([bw.id for bw in boneWeights]))
            meshesArray.extend(write4Float([bw.weight for bw in boneWeights]))

        # Faces
        meshesArray.extend(bin_ops.writeUInt32(len(mesh.faces)))
        for face in mesh.faces:
            meshesArray.extend(writeTriIdxs(face))

    return meshesArray
def buildHeader(poseString=''):
    invertUserName = getlogin()[::-1]
    invertHostName = gethostname()[::-1]
    header = xps_types.XpsHeader()
    header.magic_number = xps_const.MAGIC_NUMBER
    header.version_mayor = xps_const.XPS_VERSION_MAYOR
    header.version_minor = xps_const.XPS_VERSION_MINOR
    header.xna_aral = xps_const.XNA_ARAL
    header.machine = invertHostName
    header.user = invertUserName
    header.files = invertUserName + '@' + bpy.data.filepath
    # header.settings = bytes([0])*
    #     (xps_const.SETTINGS_LEN * xps_const.ROUND_MULTIPLE)

    boneCount = bonePoseCount(poseString)
    poseBytes = poseString.encode(xps_const.ENCODING_WRITE)
    default_pose = fillPoseString(poseBytes)
    poseLengthUnround = getPoseStringLength(poseString)

    var_1 = bin_ops.writeUInt32(180)  # Hash
    var_2 = bin_ops.writeUInt32(3)  # Items

    var_3 = bin_ops.writeUInt32(1)  # Type
    var_4 = bin_ops.writeUInt32(poseLengthUnround)  # Pose Lenght Unround
    var_5 = bin_ops.writeUInt32(boneCount)  # Pose Bone Counts
    # POSE DATA
    var_6 = bin_ops.writeUInt32(2)  # Type
    var_7 = bin_ops.writeUInt32(4)  # Count
    var_8 = bin_ops.writeUInt32(4)  # Info
    var_9 = bin_ops.writeUInt32(2)  # Count N1
    var_10 = bin_ops.writeUInt32(1)  # Count N2
    var_11 = bin_ops.writeUInt32(3)  # Count N3
    var_12 = bin_ops.writeUInt32(0)  # Count N4
    var_13 = bin_ops.writeUInt32(4)  # Type
    var_14 = bin_ops.writeUInt32(3)  # Count
    var_15 = bin_ops.writeUInt32(5)  # Info
    var_16 = bin_ops.writeUInt32(4)
    var_17 = bin_ops.writeUInt32(0)
    var_18 = bin_ops.writeUInt32(256)

    header_empty = b''
    header_empty += var_6
    header_empty += var_7
    header_empty += var_8
    header_empty += var_9
    header_empty += var_10
    header_empty += var_11
    header_empty += var_12
    header_empty += var_13
    header_empty += var_14
    header_empty += var_15
    header_empty += var_16
    header_empty += var_17
    header_empty += var_18

    header_unk = var_1 + var_2 + var_3
    header_pose = var_4 + var_5 + default_pose
    empty_count = ((xps_const.SETTINGS_LEN - len(header_empty)) // 4)
    header_empty += bin_ops.writeUInt32(0) * empty_count

    settings = header_unk + header_pose + header_empty
    header.settingsLen = len(settings) // 4
    header.settings = settings

    # logHeader(header)
    return header
Beispiel #10
0
def buildHeader(poseString=''):
    invertUserName = getuser()[::-1]
    invertHostName = gethostname()[::-1]
    header = xps_types.XpsHeader()
    header.magic_number = xps_const.MAGIC_NUMBER
    header.version_mayor = xps_const.XPS_VERSION_MAYOR
    header.version_minor = xps_const.XPS_VERSION_MINOR
    header.xna_aral = xps_const.XNA_ARAL
    header.machine = invertHostName
    header.user = invertUserName
    header.files = invertUserName + '@' + bpy.data.filepath
    # header.settings = bytes([0])*
    #     (xps_const.SETTINGS_LEN * xps_const.ROUND_MULTIPLE)

    boneCount = bonePoseCount(poseString)
    poseBytes = poseString.encode(xps_const.ENCODING_WRITE)
    default_pose = fillPoseString(poseBytes)
    poseLengthUnround = getPoseStringLength(poseString)

    var_1 = bin_ops.writeUInt32(180)  # Hash
    var_2 = bin_ops.writeUInt32(3)  # Items

    var_3 = bin_ops.writeUInt32(1)  # Type
    var_4 = bin_ops.writeUInt32(poseLengthUnround)  # Pose Lenght Unround
    var_5 = bin_ops.writeUInt32(boneCount)  # Pose Bone Counts
    # POSE DATA
    var_6 = bin_ops.writeUInt32(2)  # Type
    var_7 = bin_ops.writeUInt32(4)  # Count
    var_8 = bin_ops.writeUInt32(4)  # Info
    var_9 = bin_ops.writeUInt32(2)  # Count N1
    var_10 = bin_ops.writeUInt32(1)  # Count N2
    var_11 = bin_ops.writeUInt32(3)  # Count N3
    var_12 = bin_ops.writeUInt32(0)  # Count N4
    var_13 = bin_ops.writeUInt32(4)  # Type
    var_14 = bin_ops.writeUInt32(3)  # Count
    var_15 = bin_ops.writeUInt32(5)  # Info
    var_16 = bin_ops.writeUInt32(4)
    var_17 = bin_ops.writeUInt32(0)
    var_18 = bin_ops.writeUInt32(256)

    header_empty = b''
    header_empty += var_6
    header_empty += var_7
    header_empty += var_8
    header_empty += var_9
    header_empty += var_10
    header_empty += var_11
    header_empty += var_12
    header_empty += var_13
    header_empty += var_14
    header_empty += var_15
    header_empty += var_16
    header_empty += var_17
    header_empty += var_18

    header_unk = var_1 + var_2 + var_3
    header_pose = var_4 + var_5 + default_pose
    empty_count = ((xps_const.SETTINGS_LEN - len(header_empty)) // 4)
    header_empty += bin_ops.writeUInt32(0) * empty_count

    settings = header_unk + header_pose + header_empty
    header.settingsLen = len(settings) // 4
    header.settings = settings

    # logHeader(header)
    return header