예제 #1
0
        public void LoadModel(Stream stream)
        {
            BinaryReader data = new BinaryReader(stream);

            // Magic check.
            MDXChunks magic = (MDXChunks)data.ReadUInt32();

            if (magic != MDXChunks.MDLX)
            {
                throw new Exception(string.Format("Invalid MDX header? Got {0}, expected {1}", magic.ToString("X"), MDXChunks.MDLX.ToString("X")));
            }

            long pos = 4; // Start just ahead of magic.

            while (pos < stream.Length)
            {
                stream.Position = pos;

                MDXChunks chunkID     = (MDXChunks)data.ReadUInt32();
                uint      chunkLength = data.ReadUInt32();

                // Ensure that reading of the next chunk will start in the right place
                // regardless of where we stop parsing this one.
                pos = stream.Position + chunkLength;

                switch (chunkID)
                {
                case MDXChunks.VERS: ParseChunk_VERS(data); break;

                case MDXChunks.MODL: ParseChunk_MODL(data); break;

                case MDXChunks.GEOS: ParseChunk_GEOS(data, stream, chunkLength); break;

                case MDXChunks.MTLS: ParseChunk_MTLS(data, stream, chunkLength); break;

                case MDXChunks.TEXS: ParseChunk_TEXS(data, chunkLength); break;

                default:
                    Console.WriteLine("Skipping unknown MDX chunk: {0}", chunkID.ToString("X"));
                    break;
                }
            }
        }
예제 #2
0
        private Geoset ParseGeoset(BinaryReader data, Stream stream, long end)
        {
            Geoset geoset = new Geoset {
            };

            while (stream.Position < end)
            {
                MDXChunks chunkID = (MDXChunks)data.ReadUInt32();
                switch (chunkID)
                {
                case MDXChunks.VRTX: ParseChunk_VRTX(data, ref geoset); break;

                case MDXChunks.NRMS: ParseChunk_NRMS(data, ref geoset); break;

                case MDXChunks.PTYP: ParseChunk_PTYP(data); break;

                case MDXChunks.PCNT: ParseChunk_PCNT(data); break;

                case MDXChunks.PVTX: ParseChunk_PVTX(data, ref geoset); break;

                case MDXChunks.GNDX: ParseChunk_GNDX(data); break;

                case MDXChunks.MTGC: ParseChunk_MTGC(data); break;

                case MDXChunks.MATS: ParseChunk_MATS(data, ref geoset); break;

                case MDXChunks.TANG: ParseChunk_TANG(data); break;

                case MDXChunks.SKIN: ParseChunk_SKIN(data); break;

                case MDXChunks.UVAS: ParseChunk_UVAS(data, stream, ref geoset); break;

                default:
                    // Unknown/unimplemented geoset data. Breakpoint here to evaluate.
                    stream.Position = end;
                    break;
                }
            }
            return(geoset);
        }