Ejemplo n.º 1
0
        private void ReadEffectParamString(XFileTokenReader tokenReader)
        {
            tokenReader.ReadAssert(XToken.OpenedBrace);

            string paramName = tokenReader.ReadString();
            string value     = tokenReader.ReadString();

            this.StringParameters.Add(Tuple.Create(paramName, value));

            tokenReader.ReadAssert(XToken.ClosedBrace);
        }
Ejemplo n.º 2
0
        private void ReadEffectParamDWord(XFileTokenReader tokenReader)
        {
            tokenReader.ReadAssert(XToken.OpenedBrace);

            string paramName = tokenReader.ReadString();
            int    value     = tokenReader.ReadIntegerFromList();

            tokenReader.ReadSeparator();

            this.IntegerParameters.Add(Tuple.Create(paramName, value));

            tokenReader.ReadAssert(XToken.ClosedBrace);
        }
Ejemplo n.º 3
0
        private void ReadEffectParamFloats(XFileTokenReader tokenReader)
        {
            tokenReader.ReadAssert(XToken.OpenedBrace);

            string paramName   = tokenReader.ReadString();
            int    valuesCount = tokenReader.ReadIntegerFromList();

            float[] values = tokenReader.ReadFloatArrayFromList(valuesCount);
            tokenReader.ReadSeparator();

            this.FloatParameters.Add(Tuple.Create(paramName, values));

            tokenReader.ReadAssert(XToken.ClosedBrace);
        }
        internal static XSkinWeights Read(XFileTokenReader tokenReader)
        {
            var skin = new XSkinWeights();

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

            tokenReader.ReadAssert(XToken.OpenedBrace);

            skin.TransformNodeName = tokenReader.ReadString();

            int nWeights = tokenReader.ReadIntegerFromList();

            skin.VertexIndices.Capacity = nWeights;
            skin.Weights.Capacity       = nWeights;

            for (int i = 0; i < nWeights; i++)
            {
                skin.VertexIndices.Add(tokenReader.ReadIntegerFromList());
            }

            tokenReader.ReadSeparator();

            for (int i = 0; i < nWeights; i++)
            {
                skin.Weights.Add(tokenReader.ReadFloatFromList());
            }

            tokenReader.ReadSeparator();

            skin.MatrixOffset = new XMatrix4x4
            {
                Matrix = tokenReader.ReadFloatArrayFromList(16)
            };

            tokenReader.ReadAssert(XToken.ClosedBrace);

            return(skin);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
 private void ReadTextureFilename(XFileTokenReader tokenReader)
 {
     tokenReader.ReadAssert(XToken.OpenedBrace);
     this.Filename = tokenReader.ReadString();
     tokenReader.ReadAssert(XToken.ClosedBrace);
 }