Esempio n. 1
0
        internal static XEffectInstance Read(XFileTokenReader tokenReader)
        {
            var effect = new XEffectInstance();

            if (tokenReader.FileReader.GetNextToken() == XToken.Name)
            {
                effect.Name = tokenReader.ReadName();
            }

            tokenReader.ReadAssert(XToken.OpenedBrace);

            effect.EffectFilename = tokenReader.ReadString();

            while (tokenReader.FileReader.GetNextToken() != XToken.ClosedBrace)
            {
                string identifier = tokenReader.ReadName();

                switch (identifier)
                {
                case "EffectParamDWord":
                    effect.ReadEffectParamDWord(tokenReader);
                    break;

                case "EffectParamFloats":
                    effect.ReadEffectParamFloats(tokenReader);
                    break;

                case "EffectParamString":
                    effect.ReadEffectParamString(tokenReader);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            tokenReader.ReadAssert(XToken.ClosedBrace);

            return(effect);
        }
        internal static XMaterial Read(XFileTokenReader tokenReader)
        {
            var material = new XMaterial();

            if (tokenReader.FileReader.GetNextToken() == XToken.Name)
            {
                material.Name = tokenReader.ReadName();
            }

            tokenReader.ReadAssert(XToken.OpenedBrace);

            material.FaceColor = new XColorRgba
            {
                Red   = tokenReader.ReadFloatFromList(),
                Green = tokenReader.ReadFloatFromList(),
                Blue  = tokenReader.ReadFloatFromList(),
                Alpha = tokenReader.ReadFloatFromList()
            };

            material.Power = tokenReader.ReadFloatFromList();

            material.SpecularColor = new XColorRgb
            {
                Red   = tokenReader.ReadFloatFromList(),
                Green = tokenReader.ReadFloatFromList(),
                Blue  = tokenReader.ReadFloatFromList()
            };

            material.EmissiveColor = new XColorRgb
            {
                Red   = tokenReader.ReadFloatFromList(),
                Green = tokenReader.ReadFloatFromList(),
                Blue  = tokenReader.ReadFloatFromList()
            };

            bool textureFilenameRead = false;
            bool effectInstanceRead  = false;

            while (tokenReader.FileReader.GetNextToken() != XToken.ClosedBrace)
            {
                string identifier = tokenReader.ReadName();

                switch (identifier)
                {
                case "TextureFilename":
                    if (textureFilenameRead)
                    {
                        throw new InvalidDataException();
                    }

                    material.ReadTextureFilename(tokenReader);
                    textureFilenameRead = true;
                    break;

                case "EffectInstance":
                    if (effectInstanceRead)
                    {
                        throw new InvalidDataException();
                    }

                    material.EffectInstance = XEffectInstance.Read(tokenReader);
                    effectInstanceRead      = true;
                    break;

                default:
                    throw new InvalidDataException();
                }
            }

            tokenReader.ReadAssert(XToken.ClosedBrace);

            return(material);
        }