示例#1
0
        internal static XAnimation Read(XFileTokenReader tokenReader)
        {
            var animation = new XAnimation();

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

            tokenReader.ReadAssert(XToken.OpenedBrace);

            XToken token;

            while ((token = tokenReader.FileReader.GetNextToken()) != XToken.ClosedBrace)
            {
                if (token == XToken.OpenedBrace)
                {
                    if (animation.FrameReference != null)
                    {
                        throw new InvalidDataException();
                    }

                    tokenReader.ReadAssert(XToken.OpenedBrace);
                    animation.FrameReference = tokenReader.ReadName();
                    tokenReader.ReadAssert(XToken.ClosedBrace);
                    continue;
                }

                string identifier = tokenReader.ReadName();

                switch (identifier)
                {
                case "AnimationKey":
                {
                    XAnimationKey key = XAnimationKey.Read(tokenReader);
                    animation.Keys.Add(key);
                    break;
                }

                case "AnimationOptions":
                {
                    if (tokenReader.FileReader.GetNextToken() == XToken.Name)
                    {
                        tokenReader.ReadName();
                    }

                    tokenReader.ReadAssert(XToken.OpenedBrace);

                    animation.OpenClosedOption      = tokenReader.ReadIntegerFromList();
                    animation.PositionQualityOption = tokenReader.ReadIntegerFromList();

                    tokenReader.ReadAssert(XToken.ClosedBrace);
                    break;
                }

                default:
                    throw new NotImplementedException();
                }
            }

            tokenReader.ReadAssert(XToken.ClosedBrace);

            return(animation);
        }
示例#2
0
        private void ReadFile(IXFileReader fileReader)
        {
            var tokenReader    = new XFileTokenReader(fileReader);
            var templateReader = new XFileTemplateReader(tokenReader);

            while (fileReader.GetNextToken() == XToken.Template)
            {
                Tuple <string, Guid> template = templateReader.ReadTemplate();
                this.Templates.Add(template);
            }

            bool headerRead             = false;
            bool animTicksPerSecondRead = false;

            while (fileReader.GetNextToken() == XToken.Name)
            {
                string identifier = tokenReader.ReadName();

                switch (identifier)
                {
                case "Header":
                {
                    if (headerRead)
                    {
                        throw new InvalidDataException();
                    }

                    tokenReader.ReadAssert(XToken.OpenedBrace);

                    int majorVersion = tokenReader.ReadIntegerFromList();
                    int minorVersion = tokenReader.ReadIntegerFromList();
                    this.FileVersion = new Version(majorVersion, minorVersion);

                    this.FileFlags = tokenReader.ReadIntegerFromList();

                    tokenReader.ReadAssert(XToken.ClosedBrace);
                    headerRead = true;
                    break;
                }

                case "Material":
                {
                    XMaterial material = XMaterial.Read(tokenReader);
                    this.Materials.Add(material);
                    break;
                }

                case "Mesh":
                {
                    XMesh mesh = XMesh.Read(tokenReader);
                    this.Meshes.Add(mesh);
                    break;
                }

                case "Frame":
                {
                    XFrame frame = XFrame.Read(tokenReader);
                    this.Frames.Add(frame);
                    break;
                }

                case "AnimationSet":
                {
                    XAnimationSet animationSet = XAnimationSet.Read(tokenReader);
                    this.AnimationSets.Add(animationSet);
                    break;
                }

                case "AnimTicksPerSecond":
                {
                    if (animTicksPerSecondRead)
                    {
                        throw new InvalidDataException();
                    }

                    tokenReader.ReadAssert(XToken.OpenedBrace);
                    this.AnimTicksPerSecond = tokenReader.ReadIntegerFromList();
                    tokenReader.ReadAssert(XToken.ClosedBrace);
                    animTicksPerSecondRead = true;
                    break;
                }

                default:
                    throw new NotImplementedException();
                }
            }
        }
示例#3
0
        internal static XFrame Read(XFileTokenReader tokenReader)
        {
            var frame = new XFrame();

            if (tokenReader.FileReader.GetNextToken() == XToken.Name || tokenReader.FileReader.GetNextToken() == XToken.None)
            {
                frame.Name = tokenReader.ReadName();

                if (string.IsNullOrEmpty(frame.Name))
                {
                    if (tokenReader.FileReader is XFileBinaryReader binaryReader)
                    {
                        frame.Name = binaryReader.ReadNullTerminatedString();
                    }
                }
            }

            tokenReader.ReadAssert(XToken.OpenedBrace);

            bool frameTransformMatrixRead = false;

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

                if (string.IsNullOrEmpty(identifier))
                {
                    if (tokenReader.FileReader is XFileBinaryReader binaryReader)
                    {
                        identifier = binaryReader.ReadNullTerminatedString();
                    }
                }

                switch (identifier)
                {
                case "FrameMeshName":
                {
                    tokenReader.ReadAssert(XToken.OpenedBrace);
                    int    renderPass = tokenReader.ReadIntegerFromList();
                    string meshName   = tokenReader.ReadString();
                    tokenReader.ReadAssert(XToken.ClosedBrace);
                    frame.MeshesNames.Add(renderPass, meshName);
                    break;
                }

                case "FrameTransformMatrix":
                {
                    if (frameTransformMatrixRead)
                    {
                        throw new InvalidDataException();
                    }

                    tokenReader.ReadAssert(XToken.OpenedBrace);

                    frame.TransformMatrix = new XMatrix4x4
                    {
                        Matrix = tokenReader.ReadFloatArrayFromList(16)
                    };

                    tokenReader.ReadAssert(XToken.ClosedBrace);
                    frameTransformMatrixRead = true;
                    break;
                }

                case "FrameCamera":
                {
                    if (frame.FrameCamera != null)
                    {
                        throw new InvalidDataException();
                    }

                    var camera = new XFrameCamera();

                    tokenReader.ReadAssert(XToken.OpenedBrace);
                    camera.RotationScaler = tokenReader.ReadFloatFromList();
                    camera.MoveScaler     = tokenReader.ReadFloatFromList();
                    tokenReader.ReadAssert(XToken.ClosedBrace);

                    frame.FrameCamera = camera;
                    break;
                }

                case "Mesh":
                {
                    XMesh mesh = XMesh.Read(tokenReader);
                    frame.Meshes.Add(mesh);
                    break;
                }

                case "Frame":
                {
                    XFrame subFrame = XFrame.Read(tokenReader);
                    frame.Frames.Add(subFrame);
                    break;
                }

                case "":
                    throw new InvalidDataException();

                default:
                    throw new NotImplementedException();
                }
            }

            tokenReader.ReadAssert(XToken.ClosedBrace);

            return(frame);
        }
        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);
        }