예제 #1
0
 public MODL(BinaryReader br, uint version) : base(br, version)
 {
     Name          = br.ReadCString(Constants.SizeName);
     AnimationFile = br.ReadCString(Constants.SizeFileName);
     Bounds        = new CExtent(br);
     BlendTime     = br.ReadUInt32();
 }
예제 #2
0
 public SEQS(BinaryReader br)
 {
     Name       = br.ReadString(80).TrimEnd('\0');
     Time       = br.ReadStruct <CiRange>();
     MoveSpeed  = br.ReadSingle();
     NonLooping = br.ReadInt32() == 1;
     Bounds     = br.ReadStruct <CExtent>();
     Frequency  = br.ReadSingle();
     Replay     = br.ReadStruct <CiRange>();
     BlendTime  = br.ReadUInt32();
 }
예제 #3
0
        public Sequence(BinaryReader br)
        {
            Name      = br.ReadCString(Constants.SizeName);
            MinTime   = br.ReadInt32();
            MaxTime   = br.ReadInt32();
            MoveSpeed = br.ReadSingle();

            NonLooping = br.ReadInt32() == 1;
            Frequency  = br.ReadSingle();
            SyncPoint  = br.ReadUInt32();
            Bounds     = new CExtent(br);
        }
예제 #4
0
 public M2Sequence(BinaryReader br, uint build)
 {
     Id             = br.ReadUInt16();
     VariationIndex = br.ReadUInt16();
     Time           = br.ReadStruct <CiRange>();
     MoveSpeed      = br.ReadSingle();
     Flags          = br.ReadEnum <M2Sequence_Flags>();
     Frequency      = br.ReadInt16();
     Pad            = br.ReadInt16();
     Replay         = br.ReadStruct <CiRange>();
     BlendTime      = br.ReadUInt32();
     Bounds         = br.ReadStruct <CExtent>();
     NextVariation  = br.ReadInt16();
     NextVariation  = br.ReadInt16();
 }
예제 #5
0
        public M2(BinaryReader br)
        {
            Magic   = br.ReadString(4);
            Version = br.ReadUInt32();

            InternalName             = br.ReadM2Array <byte>(Version)?.AsString();
            GlobalFlags              = br.ReadEnum <GlobalFlags>();
            GlobalSequenceTimestamps = br.ReadM2Array <uint>(Version);
            Sequences               = br.ReadM2Array <M2Sequence>(Version);
            SequenceLookup          = br.ReadM2Array <short>(Version);
            PlayableAnimationLookup = br.ReadM2Array <M2PlayableAnimationLookup>(Version);
            Bones                    = br.ReadM2Array <M2Bone>(Version);
            KeyBoneLookup            = br.ReadM2Array <KeyBone>(Version);
            Vertices                 = br.ReadM2Array <M2Vertex>(Version);
            SkinProfiles             = br.ReadM2Array <M2SkinProfile>(Version);
            Colors                   = br.ReadM2Array <M2Color>(Version);
            Textures                 = br.ReadM2Array <M2Texture>(Version);
            TextureWeights           = br.ReadM2Array <FixedPoint_0_15>(Version);
            TextureFlipbook          = br.ReadM2Array <byte>(Version);
            TextureTransforms        = br.ReadM2Array <M2TextureTransform>(Version);
            TextureReplacementLookup = br.ReadM2Array <short>(Version);
            Materials                = br.ReadM2Array <M2Material>(Version);
            BoneLookup               = br.ReadM2Array <short>(Version);
            TextureLookup            = br.ReadM2Array <short>(Version);
            TexUnitLookup            = br.ReadM2Array <short>(Version);
            TransparencyLookup       = br.ReadM2Array <short>(Version);
            TexTransformsLookup      = br.ReadM2Array <short>(Version);
            BoundingBox              = br.ReadStruct <CExtent>();
            CollisionBox             = br.ReadStruct <CExtent>();
            CollisionTriangles       = br.ReadM2Array <ushort>(Version);
            CollisionVertices        = br.ReadM2Array <C3Vector>(Version);
            CollisionNormals         = br.ReadM2Array <C3Vector>(Version);
            Attachments              = br.ReadM2Array <M2Attachment>(Version);
            AttachmentLookupTable    = br.ReadM2Array <ushort>(Version);
            Events                   = br.ReadM2Array <M2Event>(Version);
            Lights                   = br.ReadM2Array <M2Light>(Version);
            Cameras                  = br.ReadM2Array <M2Camera>(Version);
            CameraLookupTable        = br.ReadM2Array <short>(Version);
            Ribbons                  = br.ReadM2Array <M2Ribbon>(Version);
            Particles                = br.ReadM2Array <M2Particle>(Version);

            if (TextureFlipbook != null)
            {
                throw new Exception("TextureFlipbook has data");
            }
        }
예제 #6
0
        public Geoset1300(BinaryReader br)
        {
            TotalSize = br.ReadUInt32();
            long end = TotalSize + br.BaseStream.Position;

            //Vertices
            if (br.HasTag("VRTX"))
            {
                NrOfVertices = br.ReadUInt32();
                for (int i = 0; i < NrOfVertices; i++)
                {
                    Vertices.Add(new CVector3(br));
                }
            }

            //Normals
            if (br.HasTag("NRMS"))
            {
                NrOfNormals = br.ReadUInt32();
                for (int i = 0; i < NrOfNormals; i++)
                {
                    Normals.Add(new CVector3(br));
                }
            }

            //TexCoords
            if (br.HasTag("UVAS"))
            {
                NrOfTexCoords = br.ReadUInt32();                 //Amount of groups
                for (int i = 0; i < NrOfNormals * NrOfTexCoords; i++)
                {
                    TexCoords.Add(new CVector2(br));
                }
            }

            //Face Group Type
            if (br.HasTag("PTYP"))
            {
                NrOfFaceTypeGroups = br.ReadUInt32();
                FaceTypes.AddRange(br.ReadBytes((int)NrOfFaceTypeGroups));
            }

            //Face Groups
            if (br.HasTag("PCNT"))
            {
                NrOfFaceGroups = br.ReadUInt32();
                for (int i = 0; i < NrOfFaceGroups; i++)
                {
                    FaceGroups.Add(br.ReadUInt32());
                }
            }

            //Indexes
            if (br.HasTag("PVTX"))
            {
                NrOfFaceVertices = br.ReadUInt32();
                for (int i = 0; i < NrOfFaceVertices / 3; i++)
                {
                    FaceVertices.Add(new CVertex(br));
                }
            }

            //Vertex Groups
            if (br.HasTag("GNDX"))
            {
                NrOfVertexGroupIndices = br.ReadUInt32();
                VertexGroupIndices.AddRange(br.ReadBytes((int)NrOfVertexGroupIndices));
            }

            //Matrix Groups
            if (br.HasTag("MTGC"))
            {
                NrOfMatrixGroups = br.ReadUInt32();
                for (int i = 0; i < NrOfMatrixGroups; i++)
                {
                    MatrixGroups.Add(br.ReadUInt32());
                }
            }

            //Matrix Indexes
            if (br.HasTag("MATS"))
            {
                NrOfMatrixIndexes = br.ReadUInt32();
                for (int i = 0; i < NrOfMatrixIndexes; i++)
                {
                    MatrixIndexes.Add(br.ReadUInt32());
                }
            }

            //Bone Indexes
            if (br.HasTag("BIDX"))
            {
                NrOfBoneIndexes = br.ReadUInt32();
                for (int i = 0; i < NrOfBoneIndexes; i++)
                {
                    BoneIndexes.Add(br.ReadUInt32());
                }
            }

            //Bone Weights
            if (br.HasTag("BWGT"))
            {
                NrOfBoneWeights = br.ReadUInt32();
                for (int i = 0; i < NrOfBoneWeights; i++)
                {
                    BoneWeights.Add(br.ReadUInt32());
                }
            }

            MaterialId     = br.ReadUInt32();
            SelectionGroup = br.ReadUInt32();
            Unselectable   = br.ReadUInt32() == 1;
            Bounds         = new CExtent(br);

            //Extents
            NrOfExtents = br.ReadUInt32();
            for (int i = 0; i < NrOfExtents; i++)
            {
                Extents.Add(new CExtent(br));
            }

            //Grouped Vertices
            for (int i = 0; i < NrOfVertices; i++)
            {
                if (!GroupedVertices.ContainsKey(VertexGroupIndices[i]))
                {
                    GroupedVertices.Add(VertexGroupIndices[i], new List <CVector3>());
                }

                GroupedVertices[VertexGroupIndices[i]].Add(Vertices[i]);
            }
        }
예제 #7
0
        public GEOS(BinaryReader br)
        {
            Size = br.ReadUInt32();

            if (br.HasTag("VRTX"))
            {
                Vertices = br.ReadStructArray <C3Vector>(br.ReadInt32());
            }

            if (br.HasTag("NRMS"))
            {
                Normals = br.ReadStructArray <C3Vector>(br.ReadInt32());
            }

            if (br.HasTag("UVAS"))
            {
                TextureCoords = br.ReadStructArray <C2Vector>(br.ReadInt32() * Normals.Length);
            }

            if (br.HasTag("PTYP"))
            {
                PrimitiveTypes = br.ReadBytes(br.ReadInt32());
            }

            if (br.HasTag("PCNT"))
            {
                PrimitiveGroups = br.ReadStructArray <int>(br.ReadInt32());
            }

            if (br.HasTag("PVTX"))
            {
                PrimitiveVertices = br.ReadStructArray <CVertex>(br.ReadInt32() / 3);
            }

            if (br.HasTag("GNDX"))
            {
                VertexGroupIndices = br.ReadBytes(br.ReadInt32());
            }

            if (br.HasTag("MTGC"))
            {
                GroupMatrixCounts = br.ReadStructArray <int>(br.ReadInt32());
            }

            if (br.HasTag("MATS"))
            {
                Matrices = br.ReadStructArray <int>(br.ReadInt32());
            }

            if (br.HasTag("BIDX"))
            {
                BoneIndices = br.ReadStructArray <int>(br.ReadInt32());
            }

            if (br.HasTag("BWGT"))
            {
                BoneWeights = br.ReadStructArray <int>(br.ReadInt32());
            }

            MaterialId     = br.ReadInt32();
            SelectionGroup = br.ReadInt32();
            Unselectable   = br.ReadUInt32() == 1;
            Bounds         = br.ReadStruct <CExtent>();
            SequenceBounds = br.ReadStructArray <CExtent>(br.ReadInt32());
        }
예제 #8
0
        public Geoset(BinaryReader br, uint version)
        {
            _ = br.BaseStream.Position + (TotalSize = br.ReadUInt32());

            //Vertices
            if (br.HasTag("VRTX"))
            {
                NrOfVertices = br.ReadUInt32();
                for (int i = 0; i < NrOfVertices; i++)
                {
                    Vertices.Add(new CVector3(br));
                }
            }

            //Normals
            if (br.HasTag("NRMS"))
            {
                NrOfNormals = br.ReadUInt32();
                for (int i = 0; i < NrOfNormals; i++)
                {
                    Normals.Add(new CVector3(br));
                }
            }

            //Face Group Type
            if (br.HasTag("PTYP"))
            {
                NrOfFaceTypeGroups = br.ReadUInt32();
                for (int i = 0; i < NrOfFaceTypeGroups; i++)
                {
                    FaceTypes.Add(br.ReadUInt32());
                }
            }

            //Face Groups
            if (br.HasTag("PCNT"))
            {
                NrOfFaceGroups = br.ReadUInt32();
                for (int i = 0; i < NrOfFaceGroups; i++)
                {
                    FaceGroups.Add(br.ReadUInt32());
                }
            }

            //Indexes
            if (br.HasTag("PVTX"))
            {
                NrOfFaceVertices = br.ReadUInt32();
                for (int i = 0; i < NrOfFaceVertices / 3; i++)
                {
                    FaceVertices.Add(new CVertex(br));
                }
            }

            //Vertex Groups
            if (br.HasTag("GNDX"))
            {
                NrOfVertexGroupIndices = br.ReadUInt32();
                VertexGroupIndices.AddRange(br.ReadBytes((int)NrOfVertexGroupIndices));
            }

            //Matrix Groups
            if (br.HasTag("MTGC"))
            {
                NrOfMatrixGroups = br.ReadUInt32();
                for (int i = 0; i < NrOfMatrixGroups; i++)
                {
                    MatrixGroups.Add(br.ReadUInt32());
                }
            }

            //Matrix Indexes
            if (br.HasTag("MATS"))
            {
                NrOfMatrixIndexes = br.ReadUInt32();
                for (int i = 0; i < NrOfMatrixIndexes; i++)
                {
                    MatrixIndexes.Add(br.ReadUInt32());
                }
            }

            MaterialId     = br.ReadUInt32();
            SelectionGroup = br.ReadUInt32();
            Unselectable   = br.ReadUInt32() == 1;

            if (version >= 900)
            {
                LevelOfDetail = br.ReadUInt32();
                FilePath      = br.ReadCString(Constants.SizeName);
            }

            Bounds = new CExtent(br);

            //Extents
            NrOfExtents = br.ReadUInt32();
            for (int i = 0; i < NrOfExtents; i++)
            {
                Extents.Add(new CExtent(br));
            }

            //Tangents
            if (br.HasTag("TANG"))
            {
                NrOfTangents = br.ReadUInt32();
                for (int i = 0; i < NrOfTangents; i++)
                {
                    Tangents.Add(new CVector4(br));
                }
            }

            //Skin
            if (br.HasTag("SKIN"))
            {
                SkinSize = br.ReadUInt32();
                for (int i = 0; i < SkinSize / 8; i++)
                {
                    // looks like a C2iVector
                    BoneIndexes.Add(br.ReadUInt32());
                    BoneWeights.Add(br.ReadUInt32());
                }
            }

            //TexCoordSets
            if (br.HasTag("UVAS"))
            {
                NrOfTexCoordSets = br.ReadUInt32();
                TexCoords        = new List <CVector2> [NrOfTexCoordSets];
            }

            //TexCoords
            for (int i = 0; i < NrOfTexCoordSets && br.HasTag("UVBS"); i++)
            {
                int NrOfTexCoords = br.ReadInt32();
                TexCoords[i] = new List <CVector2>(NrOfTexCoords);

                for (int j = 0; j < NrOfTexCoords; j++)
                {
                    TexCoords[i].Add(new CVector2(br));
                }
            }
        }
예제 #9
0
        public MDX(BinaryReader br)
        {
            Magic = br.ReadString(4);

            while (br.BaseStream.Position < br.BaseStream.Length - 8) // some files are aligned?
            {
                var(Token, Size) = br.ReadIffChunk();
                if (Size <= 0)
                {
                    continue;
                }

                int count = 0;
                switch (Token)
                {
                case "VERS":
                    Version = br.ReadUInt32();
                    break;

                case "MODL":
                    Name          = br.ReadString(80).TrimEnd('\0');
                    AnimationFile = br.ReadString(260).TrimEnd('\0');
                    Bounds        = br.ReadStruct <CExtent>();
                    BlendTime     = br.ReadUInt32();
                    Flags         = br.ReadEnum <Model_Flags>();
                    break;

                case "SEQS":
                    count     = br.ReadInt32();
                    Sequences = br.ReadArray(count, () => new SEQS(br));
                    break;

                case "MTLS":
                    count = br.ReadInt32();
                    br.ReadInt32();     // unused
                    Materials = br.ReadArray(count, () => new MTLS(br));
                    break;

                case "TEXS":
                    Textures = br.ReadArray(Size / 268, () => new TEXS(br));
                    break;

                case "GEOS":
                    Geosets = ReadGeoSets(br);
                    break;

                case "BONE":
                    count = br.ReadInt32();
                    Bones = br.ReadArray(count, () => new BONE(br));
                    break;

                case "HELP":
                    count   = br.ReadInt32();
                    Helpers = br.ReadArray(count, () => new HELP(br));
                    break;

                case "ATCH":
                    count = br.ReadInt32();
                    br.ReadInt32();     // unused
                    Attachments = br.ReadArray(count, () => new ATCH(br));
                    break;

                case "PIVT":
                    Pivots = br.ReadStructArray <C3Vector>(Size / 12);
                    break;

                case "CAMS":
                    count   = br.ReadInt32();
                    Cameras = br.ReadArray(count, () => new CAMS(br));
                    break;

                case "EVTS":
                    count  = br.ReadInt32();
                    Events = br.ReadArray(count, () => new EVTS(br));
                    break;

                case "HTST":
                    count         = br.ReadInt32();
                    HitTestShapes = br.ReadArray(count, () => new HTST(br));
                    break;

                case "CLID":
                    Collision = new CLID(br);
                    break;

                case "GLBS":
                    GlobalSequences = br.ReadStructArray <uint>(Size / 4);
                    break;

                case "GEOA":
                    count            = br.ReadInt32();
                    GeosetAnimations = br.ReadArray(count, () => new GEOA(br));
                    break;

                case "PRE2":
                    count            = br.ReadInt32();
                    ParticleEmitters = br.ReadArray(count, () => new PRE2(br));
                    break;

                case "RIBB":
                    count   = br.ReadInt32();
                    Ribbons = br.ReadArray(count, () => new RIBB(br));
                    break;

                case "LITE":
                    count  = br.ReadInt32();
                    Lights = br.ReadArray(count, () => new LITE(br));
                    break;

                case "TXAN":
                    count             = br.ReadInt32();
                    TextureAnimations = br.ReadArray(count, () => new TXAN(br));
                    break;

                default:
                    throw new NotImplementedException("Unknown token " + Token);
                }
            }
        }