コード例 #1
0
ファイル: eluparser.py プロジェクト: webdes27/raiderz-library
 def LoadFace(self, Node, FileStream, Offset):
     try:
         Node.FaceCount = binaryreader.ReadInt(FileStream, 1)[0]
         if (Node.FaceCount):
             if globalvars.CurrentEluFileVersion < raidflags.EXPORTER_MESH_VER12:
                 for i in range(Node.FaceCount):
                     MeshPolygonData = datatypes.FMeshPolygonData()
                     MeshPolygonData.Vertices = 3
                     for j in range(j):
                         UnsignedShorts = binaryreader.ReadUShort(
                             FileStream, 5)
                         FaceSubData = datatypes.FFaceSubData()
                         FaceSubData.p = UnsignedShorts[0]
                         FaceSubData.uv = UnsignedShorts[1]
                         FaceSubData.n = UnsignedShorts[2]
                         FaceSubData.uv2 = -1
                         FaceSubData.n_tan = UnsignedShorts[3]
                         FaceSubData.n_bin = UnsignedShorts[4]
                         MeshPolygonData.FaceSubDatas.append(FaceSubData)
                     MeshPolygonData.MaterialID = binaryreader.ReadShort(
                         FileStream, 1)[0]
                     Node.PolygonTable.append(MeshPolygonData)
                 Node.TotalDegrees = Node.FaceCount * 3
                 Node.TotalTriangles = Node.FaceCount
             else:
                 Node.TotalDegrees = binaryreader.ReadInt(FileStream, 1)[0]
                 Node.TotalTriangles = binaryreader.ReadInt(FileStream,
                                                            1)[0]
                 for i in range(Node.FaceCount):
                     MeshPolygonData = datatypes.FMeshPolygonData()
                     MeshPolygonData.Vertices = binaryreader.ReadInt(
                         FileStream, 1)[0]
                     for j in range(MeshPolygonData.Vertices):
                         UnsignedShorts = binaryreader.ReadUShort(
                             FileStream, 5)
                         FaceSubData = datatypes.FFaceSubData()
                         FaceSubData.p = UnsignedShorts[0]
                         FaceSubData.uv = UnsignedShorts[1]
                         FaceSubData.n = UnsignedShorts[2]
                         FaceSubData.uv2 = -1
                         FaceSubData.n_tan = UnsignedShorts[3]
                         FaceSubData.n_bin = UnsignedShorts[4]
                         MeshPolygonData.FaceSubDatas.append(FaceSubData)
                     MeshPolygonData.MaterialID = binaryreader.ReadShort(
                         FileStream, 1)[0]
                     Node.PolygonTable.append(MeshPolygonData)
                 try:
                     assert Node.TotalDegrees == sum(len(MeshPolygonData.FaceSubDatas) \
                     for MeshPolygonData in Node.PolygonTable), \
                     "Assertion Failed: TotalDegrees value does not match expected value for node - {}".format(Node.NodeName)
                 except AssertionError as err:
                     errorhandling.HandleAssertionError(err)
     except struct.error as err:
         errorhandling.HandleStructUnpackError(err)
コード例 #2
0
    def LoadBoneAni(self, Node, FileStream, Offset=None):
        try:
            Node.Name = binaryreader.ReadWord(FileStream)

            Node.BaseTranslation = datatypes.FVector(
                binaryreader.ReadFloat(FileStream, 3))
            Node.BaseRotation = datatypes.FQuaternion(
                binaryreader.ReadFloat(FileStream, 4))
            Node.BaseScale = datatypes.FVector(
                binaryreader.ReadInt(FileStream, 3))

            AnimType_1 = datatypes.FAnimType(
                binaryreader.ReadInt(FileStream, 3))
            if AnimType_1.Count > 0:
                Node.PositionKeyTrack.Count = AnimType_1.Count + 1
                if AnimType_1.CountType == 10:
                    for i in range(AnimType_1.Count):
                        Frame = binaryreader.ReadInt(FileStream, 1)[0]
                        ShortTuple = binaryreader.ReadUShort(FileStream, 3)
                        FloatTuple = datatypes.ConvertShortToFloat(ShortTuple)
                        PosKey = datatypes.FVecKey()
                        PosKey.Frame = Frame
                        PosKey.Vector = datatypes.FVector(FloatTuple)
                        Node.PositionKeyTrack.Data.append(PosKey)
                    LastPosKey = Node.PositionKeyTrack.Data[AnimType_1.Count -
                                                            1]
                    Node.PositionKeyTrack.Data.append(LastPosKey)
                elif AnimType_1.CountType == 16:
                    for i in range(AnimType_1.Count):
                        PosKey = datatypes.FVecKey()
                        PosKey.Vector = datatypes.FVector(
                            binaryreader.ReadFloat(FileStream, 3))
                        PosKey.Frame = binaryreader.ReadInt(FileStream, 1)[0]
                        Node.PositionKeyTrack.Data.append(PosKey)
                    LastPosKey = Node.PositionKeyTrack.Data[AnimType_1.Count -
                                                            1]
                    Node.PositionKeyTrack.Data.append(LastPosKey)
                else:
                    Message = "{0} node error: RAnimType_1.CountType is incorrect.".format(
                        Node.Name)
                    filelogger.AddLog(globalvars.LogFileStream, Message,
                                      filelogger.ELogMessageType.Log_Error)
                    return

            AnimType_2 = datatypes.FAnimType(
                binaryreader.ReadInt(FileStream, 3))
            if AnimType_2.Count > 0:
                Node.RotationKeyTrack.Count = AnimType_2.Count + 1
                if AnimType_2.CountType == 10:
                    for i in range(AnimType_2.Count):
                        Frame = binaryreader.ReadInt(FileStream, 1)[0]
                        ShortTuple = binaryreader.ReadUShort(FileStream, 3)
                        X, Y, Z = datatypes.ConvertShortToFloat(ShortTuple)
                        W = 0
                        FTol = X * X + Y * Y + Z * Z
                        if FTol <= 1.0:
                            Sub1 = 1.0 - FTol
                            FSqrt = math.sqrt(Sub1)
                            W = FSqrt
                        QuatKey = datatypes.FQuatKey()
                        QuatKey.Frame = Frame
                        QuatKey.Quat = datatypes.FQuaternion((X, Y, Z, W))
                        Node.RotationKeyTrack.Data.append(QuatKey)
                    LastQuatKey = Node.RotationKeyTrack.Data[AnimType_2.Count -
                                                             1]
                    Node.RotationKeyTrack.Data.append(LastQuatKey)
                elif AnimType_2.CountType == 16:
                    for i in range(AnimType_2.Count):
                        Frame = binaryreader.ReadInt(FileStream, 1)[0]
                        X, Y, Z = binaryreader.ReadFloat(FileStream, 3)
                        W = 0
                        FTol = X * X + Y * Y + Z * Z
                        if FTol <= 1.0:
                            Sub1 = 1.0 - FTol
                            FSqrt = math.sqrt(Sub1)
                            W = FSqrt
                        QuatKey = datatypes.FQuatKey()
                        QuatKey.Frame = Frame
                        QuatKey.Quat = datatypes.FQuaternion((X, Y, Z, W))
                        Node.RotationKeyTrack.Data.append(QuatKey)
                    LastQuatKey = Node.RotationKeyTrack.Data[AnimType_2.Count -
                                                             1]
                    Node.RotationKeyTrack.Data.append(LastQuatKey)
                elif AnimType_2.CountType == 20:
                    for i in range(AnimType_2.Count):
                        QuatKey = datatypes.FQuatKey()
                        QuatKey.Quat = datatypes.FQuaternion(
                            binaryreader.ReadFloat(FileStream, 4))
                        QuatKey.Frame = binaryreader.ReadInt(FileStream, 1)[0]
                        Node.RotationKeyTrack.Data.append(QuatKey)
                    LastQuatKey = Node.RotationKeyTrack.Data[AnimType_2.Count -
                                                             1]
                    Node.RotationKeyTrack.Data.append(LastQuatKey)
                else:
                    Message = "{0} node error: RAnimType_2.CountType is incorrect.".format(
                        Node.Name)
                    filelogger.AddLog(globalvars.LogFileStream, Message,
                                      filelogger.ELogMessageType.Log_Error)
                    return

            AnimType_3 = datatypes.FAnimType(
                binaryreader.ReadInt(FileStream, 3))
            if AnimType_3.Count > 0:
                Node.ScaleKeyTrack.Count = AnimType_3.Count
                for i in range(AnimType_3.Count):
                    ScaleKey = datatypes.FVecKey()
                    ScaleKey.Vector = datatypes.FVector(
                        binaryreader.ReadFloat(FileStream, 3))
                    ScaleKey.Frame = binaryreader.ReadInt(FileStream, 1)[0]
                    Node.ScaleKeyTrack.Data.append(ScaleKey)

        except struct.error as err:
            errorhandling.HandleStructUnpackError(err)
コード例 #3
0
ファイル: eluparser.py プロジェクト: webdes27/raiderz-library
    def LoadEtc(self, Node, FileStream, Offset):
        try:
            PrimitiveType = binaryreader.ReadInt(FileStream, 1)[0]

            Node.VertexIndexCount = binaryreader.ReadInt(FileStream, 1)[0]
            for i in range(Node.VertexIndexCount):
                VertexIndex = datatypes.FVertexIndex()
                UnsignedShorts = binaryreader.ReadUShort(FileStream, 6)
                VertexIndex.p = UnsignedShorts[0]
                VertexIndex.n = UnsignedShorts[1]
                VertexIndex.uv = UnsignedShorts[2]
                VertexIndex.uv2 = UnsignedShorts[3]
                VertexIndex.n_tan = UnsignedShorts[4]
                VertexIndex.n_bin = UnsignedShorts[5]
                Node.VertexIndexTable.append(VertexIndex)

            Node.BoneCount = binaryreader.ReadInt(FileStream, 1)[0]
            for i in range(Node.BoneCount):
                Matrix = datatypes.FMatrix(
                    binaryreader.ReadFloat(FileStream, 16))
                Node.BoneTable.append(Matrix)

            for i in range(Node.BoneCount):
                BoneIndex = binaryreader.ReadUShort(FileStream, 1)[0]
                Node.BoneTableIndices.append(BoneIndex)

            Node.MaterialInfoCount = binaryreader.ReadInt(FileStream, 1)[0]
            for i in range(Node.MaterialInfoCount):
                MtrlTableInfo = datatypes.FMtrlTableInfo()
                if globalvars.CurrentEluFileVersion < raidflags.EXPORTER_MESH_VER9:
                    MtrlTableInfo.MaterialID = binaryreader.ReadInt(
                        FileStream, 1)[0]
                    MtrlTableInfo.Offset = binaryreader.ReadUShort(
                        FileStream, 1)[0]
                    MtrlTableInfo.Count = binaryreader.ReadUShort(
                        FileStream, 1)[0]
                    MtrlTableInfo.SubMaterialIDForDrawMasking = binaryreader.ReadInt(
                        FileStream, 1)[0]
                else:
                    MtrlTableInfo.MaterialID = binaryreader.ReadInt(
                        FileStream, 1)[0]
                    MtrlTableInfo.Offset = binaryreader.ReadUShort(
                        FileStream, 1)[0]
                    MtrlTableInfo.Count = binaryreader.ReadUShort(
                        FileStream, 1)[0]
                    MtrlTableInfo.SubMaterialIDForDrawMasking = binaryreader.ReadInt(
                        FileStream, 1)[0]
                Node.MaterialInfoTable.append(MtrlTableInfo)

            Node.FaceIndexCount = binaryreader.ReadInt(FileStream, 1)[0]
            for i in range(Node.FaceIndexCount):
                FaceIndex = binaryreader.ReadUShort(FileStream, 1)[0]
                Node.FaceIndexTable.append(FaceIndex)

            # @todo GetBipID
            Node.BoundingBox.vmin = datatypes.FVector(
                binaryreader.ReadFloat(FileStream, 3))
            Node.BoundingBox.vmax = datatypes.FVector(
                binaryreader.ReadFloat(FileStream, 3))

            # @todo fix bounding box
        except struct.error as err:
            errorhandling.HandleStructUnpackError(err)
コード例 #4
0
ファイル: eluparser.py プロジェクト: webdes27/raiderz-library
    def LoadVertexInfo(self, Node, FileStream, Offset):
        try:
            Node.PointColorCount = binaryreader.ReadInt(FileStream, 1)[0]
            for i in range(Node.PointColorCount):
                Vec = datatypes.FVector(binaryreader.ReadFloat(FileStream, 3))
                Node.PointColorTable.append(Vec)

            if Node.PointsCount == 0 or Node.FaceCount == 0:
                Node.AddFlag(raidflags.RM_FLAG_DUMMY_MESH)

            Node.MaterialID = binaryreader.ReadInt(FileStream, 1)[0]
            Node.PhysiqueCount = binaryreader.ReadInt(FileStream, 1)[0]

            if Node.PhysiqueCount:
                try:
                    assert Node.PointsCount == Node.PhysiqueCount, \
                    "Assertion Failed: Points Count is not same as Physique Count - {0}".format(Node.NodeName)
                except AssertionError as err:
                    errorhandling.HandleAssertionError(err)
                for i in range(Node.PhysiqueCount):
                    Size = binaryreader.ReadInt(FileStream, 1)[0]
                    PhysiqueInfo = datatypes.FPhysiqueInfo()
                    for j in range(Size):
                        PhysiqueSubData = datatypes.FPhysiqueSubData()
                        PhysiqueSubData.cid = binaryreader.ReadUShort(
                            FileStream, 1)[0]
                        PhysiqueSubData.pid = binaryreader.ReadUShort(
                            FileStream, 1)[0]
                        PhysiqueSubData.weight = binaryreader.ReadFloat(
                            FileStream, 1)[0]
                        PhysiqueInfo.PhysiqueSubDatas.append(PhysiqueSubData)
                    PhysiqueInfo.Num = len(PhysiqueInfo.PhysiqueSubDatas)
                    Node.PhysiqueTable.append(PhysiqueInfo)

                    if Size > raidflags.PHYSIQUE_MAX_WEIGHT:
                        for m in range(Size):
                            for n in range(m + 1, Size):
                                if PhysiqueInfo.PhysiqueSubDatas[
                                        m].weight < PhysiqueInfo.PhysiqueSubDatas[
                                            n].weight:
                                    Temp = datatypes.FPhysiqueSubData()
                                    Temp = PhysiqueInfo.PhysiqueSubDatas[m]
                                    PhysiqueInfo.PhysiqueSubDatas[
                                        m] = PhysiqueInfo.PhysiqueSubDatas[n]
                                    PhysiqueInfo.PhysiqueSubDatas[n] = Temp

                        fSum3 = sum(PhysiqueSubData.weight for PhysiqueSubData
                                    in PhysiqueInfo.PhysiqueSubDatas)
                        PhysiqueInfo.PhysiqueSubDatas[
                            0].weight = PhysiqueInfo.PhysiqueSubDatas[
                                0].weight / fSum3
                        PhysiqueInfo.PhysiqueSubDatas[
                            1].weight = PhysiqueInfo.PhysiqueSubDatas[
                                1].weight / fSum3
                        PhysiqueInfo.PhysiqueSubDatas[
                            2].weight = PhysiqueInfo.PhysiqueSubDatas[
                                2].weight / fSum3
                        PhysiqueInfo.Num = 3

        except struct.error as err:
            errorhandling.HandleStructUnpackError(err)