Example #1
0
        public static WTSpline ReadBinary(BinaryReader reader)
        {
            var spline = new WTSpline
            {
                Name = reader.ReadNullTerminatedString()
            };

            spline.Position = reader.ReadVector3();

            int subSplineCount = reader.ReadUInt16();

            for (int j = 0; j < subSplineCount; j++)
            {
                var subspline = WTSubSpline.ReadBinary(reader);
                spline.SubSplines.Add(subspline);
            }

            bool additionalString = reader.ReadUInt16() != 0;

            if (additionalString)
            {
                string additionalStringval = reader.ReadNullTerminatedString();
                spline.Reference = additionalStringval;
            }

            return(spline);
        }
Example #2
0
        public static WTModel ReadBinary(Stream stream)
        {
            var reader      = new BinaryReader(stream);
            var returnModel = new WTModel();

            //determine filetype
            bool isSceneFile = false;

            reader.BaseStream.Seek(24, SeekOrigin.Begin);

            float version = reader.ReadSingle();

            if (version == 1f)
            {
                isSceneFile = true;
            }
            else
            {
                reader.BaseStream.Seek(0, SeekOrigin.Begin);
                version = reader.ReadSingle();
                if (version != 1f)
                {
                    throw new System.Exception($"Expected version 1.0, got version {version}. Either not a MDL/SCN file, or wrong version.");
                }
            }

            //read data
            int meshCount   = reader.ReadInt32();
            int lightCount  = reader.ReadInt32();
            int helperCount = reader.ReadInt32();
            int splineCount = reader.ReadInt32();

            int materialCount = reader.ReadInt32();
            int textureCount  = reader.ReadInt32();

            //textures
            for (int i = 0; i < textureCount; i++)
            {
                string tex = reader.ReadNullTerminatedString();
                int    id  = reader.ReadInt32();
                returnModel.Textures.Add(id, tex);
            }

            //materials
            for (int i = 0; i < materialCount; i++)
            {
                var material = WTMaterial.ReadBinary(reader);
                returnModel.Materials.Add(material.ID, material);
            }

            //meshes
            for (int i = 0; i < meshCount; i++)
            {
                returnModel.Meshes.Add(WTMesh.ReadBinary(reader, isSceneFile));
            }

            //lights
            for (int i = 0; i < lightCount; i++)
            {
                returnModel.Lights.Add(WTLight.ReadBinary(reader));
            }

            //helpers
            for (int i = 0; i < helperCount; i++)
            {
                returnModel.Helpers.Add(WTHelper.ReadBinary(reader));
            }

            //splines
            for (int i = 0; i < splineCount; i++)
            {
                returnModel.Splines.Add(WTSpline.ReadBinary(reader));
            }

            reader.Dispose();
            return(returnModel);
        }