Esempio n. 1
0
        public static MqScene Parse(MqChunk chunk)
        {
            var rt = new MqScene
            {
                baseChunk = chunk,
            };

            foreach (var i in chunk.Children)
            {
                switch (i.Name.ToLower())
                {
                case "pos":
                    rt.Position = i.Arguments.Select(float.Parse).ToArray();

                    break;

                case "lookat":
                    rt.LookAt = i.Arguments.Select(float.Parse).ToArray();

                    break;

                case "head":
                    rt.Head = float.Parse(i.Arguments.First());

                    break;

                case "pich":
                    rt.Pitch = float.Parse(i.Arguments.First());

                    break;

                case "bank":
                    rt.Bank = float.Parse(i.Arguments.First());

                    break;

                case "ortho":
                    rt.Ortho = i.Arguments.First() == "1";

                    break;

                case "zoom2":
                    rt.Zoom2 = float.Parse(i.Arguments.First());

                    break;

                case "amb":
                    rt.Ambient = i.Arguments.Select(float.Parse).ToArray();

                    break;

                case "dirlights":
                    rt.DirectionalLights = i.Children.Select(MqDirectionalLight.Parse).ToList();

                    break;
                }
            }

            return(rt);
        }
Esempio n. 2
0
        public static MqDocument Parse(string text)
        {
            var rt        = new MqDocument();
            var tokenizer = new MqTokenizer(text);
            var header    = new[] { "Metasequoia", "Document", "\n", "Format", "Text", "Ver" };

            if (!tokenizer.Take(header.Length).Select(_ => _.Text).SequenceEqual(header))
            {
                throw new InvalidOperationException("invalid format");
            }

            rt.Version = float.Parse(tokenizer.MoveNext().EnsureKind(MqTokenizer.DigitTokenKind).Text);

            if (rt.Version >= 2)
            {
                throw new NotSupportedException("specified format version not supported");
            }

            foreach (var i in tokenizer)
            {
                if (i.Kind == MqTokenizer.IdentifierTokenKind)
                {
                    var chunk = MqChunk.Parse(tokenizer);

                    switch (chunk.Name.ToLower())
                    {
                    case "includexml":
                        rt.IncludeXml = chunk.Arguments.First().Trim('"');

                        break;

                    case "scene":
                        rt.Scene = MqScene.Parse(chunk);

                        break;

                    case "material":
                        rt.Materials = chunk.Children.Select(MqMaterial.Parse).ToList();

                        break;

                    case "object":
                        rt.Objects.Add(MqObject.Parse(chunk));

                        break;

                    case "eof":
                        break;

                    default:
                        rt.CustomChunks.Add(chunk);

                        break;
                    }
                }
            }

            return(rt);
        }
Esempio n. 3
0
        public static MqScene Parse(MqChunk chunk)
        {
            var rt = new MqScene
            {
                baseChunk = chunk,
            };

            foreach (var i in chunk.Children)
                switch (i.Name.ToLower())
                {
                    case "pos":
                        rt.Position = i.Arguments.Select(float.Parse).ToArray();

                        break;
                    case "lookat":
                        rt.LookAt = i.Arguments.Select(float.Parse).ToArray();

                        break;
                    case "head":
                        rt.Head = float.Parse(i.Arguments.First());

                        break;
                    case "pich":
                        rt.Pitch = float.Parse(i.Arguments.First());

                        break;
                    case "bank":
                        rt.Bank = float.Parse(i.Arguments.First());

                        break;
                    case "ortho":
                        rt.Ortho = i.Arguments.First() == "1";

                        break;
                    case "zoom2":
                        rt.Zoom2 = float.Parse(i.Arguments.First());

                        break;
                    case "amb":
                        rt.Ambient = i.Arguments.Select(float.Parse).ToArray();

                        break;
                    case "dirlights":
                        rt.DirectionalLights = i.Children.Select(MqDirectionalLight.Parse).ToList();

                        break;
                }

            return rt;
        }