예제 #1
0
        public static WTLight ReadBinary(BinaryReader reader)
        {
            var light = new WTLight()
            {
                Name = reader.ReadNullTerminatedString(),
                Type = (WTLightType)reader.ReadUInt16()
            };

            //matrix?
            light.Position = reader.ReadVector3();
            light.Matrix   = reader.ReadMatrix3x3();

            //color?
            light.Color = reader.ReadColor();

            //intensity?
            light.Unknown = reader.ReadSingle();

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

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

            return(light);
        }
예제 #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);
        }