Example #1
0
        public Material(SectionHeader header, Stream stream)
            : base(header, stream)
        {
            SectionHeader.Read(stream);
            var reader = new BinaryReader(stream);

            Flags = reader.ReadUInt32();
            Colour = new Color4(reader);
            reader.ReadUInt32();
            TextureCount = reader.ReadUInt32();
            Textures = new Texture[TextureCount];
            Ambient = reader.ReadSingle();
            Smoothness = reader.ReadSingle();
            Specular = 1f - reader.ReadSingle();

            for (var i = 0; i < TextureCount; ++i) {
                Textures[i] = ReadSection<Texture>();
            }

            var extensions = ReadSection<Extension>();

            var smoothness = Smoothness;
            var specular = Specular;

            extensions.ForEach<ReflectionMaterial>(x => specular = x.Intensity);
            extensions.ForEach<SpecularMaterial>(x => smoothness = x.SpecularLevel);

            Smoothness = smoothness;
            Specular = specular;
        }
Example #2
0
 public static Color32 Convert(Color4 clr)
 {
     return new Color32(clr.R, clr.G, clr.B, clr.A);
 }
Example #3
0
        public Geometry(SectionHeader header, Stream stream)
            : base(header, stream)
        {
            var dataHeader = SectionHeader.Read(stream);
            var reader = new BinaryReader(stream);

            Flags = (GeometryFlag) reader.ReadUInt16();
            var uvCount = reader.ReadByte(); // uv count
            reader.ReadByte(); // native flags
            FaceCount = reader.ReadUInt32();
            VertexCount = reader.ReadUInt32();
            FrameCount = reader.ReadUInt32();

            if (dataHeader.Version == 4099) {
                Ambient = reader.ReadSingle();
                Diffuse = reader.ReadSingle();
                Specular = reader.ReadSingle();
            }

            if ((Flags & GeometryFlag.Colors) != 0) {
                Colours = new Color4[VertexCount];
                for (var i = 0; i < VertexCount; ++i) {
                    Colours[i] = new Color4(reader);
                }
            }

            if ((Flags & (GeometryFlag.TexCoords | GeometryFlag.TexCoords2)) != 0) {
                TexCoords = new Vector2[uvCount][];
                for (var j = 0; j < uvCount; ++j) {
                    var uvs =  TexCoords[j] = new Vector2[VertexCount];
                    for (var i = 0; i < VertexCount; ++i) {
                        uvs[i] = new Vector2(reader);
                    }
                }
            }

            Faces = new FaceInfo[FaceCount];
            for (var i = 0; i < FaceCount; ++i) {
                Faces[i] = new FaceInfo(reader);
            }

            BoundingSphere = new BoundingSphere(reader);

            HasPosition = reader.ReadUInt32();
            HasNormals = reader.ReadUInt32();

            if (HasPosition > 1 || HasNormals > 1) {
                throw new Exception("Well there you go");
            }

            if ((Flags & GeometryFlag.VertexTranslation) != 0)
            {
                Vertices = new Vector3[VertexCount];
                for (var i = 0; i < VertexCount; ++i)
                {
                    Vertices[i] = new Vector3(reader);
                }
            }

            if ((Flags & GeometryFlag.Normals) != 0)
            {
                Normals = new Vector3[VertexCount];
                for (var i = 0; i < VertexCount; ++i)
                {
                    Normals[i] = new Vector3(reader);
                }
            }

            Materials = ReadSection<MaterialList>().Materials;

            var extensions = ReadSection<Extension>();

            MaterialSplits = extensions.FirstOrDefault<MaterialSplitList>().MaterialSplits;
            Skinning = extensions.FirstOrDefault<Skin>();
        }