internal static XAnimationKey Read(XFileTokenReader tokenReader)
        {
            var key = new XAnimationKey();

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

            tokenReader.ReadAssert(XToken.OpenedBrace);

            key.KeyType = (XAnimationKeyType)tokenReader.ReadIntegerFromList();

            int keysCount = tokenReader.ReadIntegerFromList();

            key.Keys.Capacity = keysCount;

            for (int i = 0; i < keysCount; i++)
            {
                int     time        = tokenReader.ReadIntegerFromList();
                int     valuesCount = tokenReader.ReadIntegerFromList();
                float[] values      = tokenReader.ReadFloatArrayFromList(valuesCount);

                tokenReader.ReadSeparator();

                key.Keys.Add(Tuple.Create(time, values));
            }

            tokenReader.ReadAssert(XToken.ClosedBrace);

            return(key);
        }
Пример #2
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);
        }
Пример #4
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);
        }