Exemple #1
0
        public static Face[] ParseFaceArray(NodeIterator it)
        {
            int length = 0;

            int.TryParse(it.Name(), out length);
            NodeIterator itItem = it.GetChildren();

            Face[] faces = new Face[length];

            int  i    = 0;
            Face face = null;

            for (; !itItem.IsEnd(); itItem.Next())
            {
                NodeIterator itChild = itItem.GetChildren();
                if (itChild.Nodes.Count <= 0)
                {
                    if (face != null)
                    {
                        faces[i] = face;
                        i++;
                    }

                    int nbVertices = 0;
                    int.TryParse(itItem.Name(), out nbVertices);
                    face = new Face(nbVertices);
                    continue;
                }
                else
                {
                    System.Reflection.FieldInfo fieldInfo = FindFieldInfo(face.GetType().GetFields(), itItem.Name());
                    if (fieldInfo == null)
                    {
                        continue;
                    }
                    else
                    {
                        if (fieldInfo.FieldType.IsArray)
                        {
                            fieldInfo.SetValue(face, ParseArrayValues(fieldInfo.FieldType, itItem.GetChildren(), face.Vertices));
                        }
                        else
                        {
                            fieldInfo.SetValue(face, ParseValue(fieldInfo.FieldType, itItem.GetChildren()));
                        }
                    }
                }
            }

            if (0 < length)
            {
                faces[i] = face;
            }

            return(faces);
        }
Exemple #2
0
        public static Float3[] ParseVertexArray(NodeIterator it)
        {
            int length = 0;

            int.TryParse(it.Name(), out length);
            return((Float3[])ParseArrayValues(typeof(Float3[]), it.GetChildren(), length));
        }
Exemple #3
0
        public static Document ParseDocument(NodeIterator it)
        {
            Document document = new Document();

            var fieldInfos = document.GetType().GetFields();

            for (; !it.IsEnd(); it.Next())
            {
                System.Reflection.FieldInfo fieldInfo = FindFieldInfo(document.GetType().GetFields(), it.Name());
                if (fieldInfo == null)
                {
                    continue;
                }

                Type type = fieldInfo.FieldType;
                if (type == typeof(Scene))
                {
                    fieldInfo.SetValue(document, ParseScene(it.GetChildren()));
                }
                else if (type == typeof(Material[]))
                {
                    it.Next();
                    fieldInfo.SetValue(document, ParseMaterialArray(it));
                }
                else if (type == typeof(List <Object>))
                {
                    it.Next();
                    document.Object.Add(ParseObject(it));
                }
            }

            return(document);
        }
Exemple #4
0
        public static Light ParseLight(NodeIterator it)
        {
            if (it.Name() != "light")
            {
                return(null);
            }

            Light light = new Light();

            NodeIterator itItem = it.GetChildren();

            for (; !itItem.IsEnd(); itItem.Next())
            {
                System.Reflection.FieldInfo fieldInfo = FindFieldInfo(light.GetType().GetFields(), itItem.Name());
                if (fieldInfo == null)
                {
                    continue;
                }

                itItem.Next();
                fieldInfo.SetValue(light, ParseValue(fieldInfo.FieldType, itItem));
            }

            return(light);
        }
Exemple #5
0
        public static Light[] ParseLightArray(NodeIterator it)
        {
            int length = 0;

            int.TryParse(it.Name(), out length);
            NodeIterator itItem = it.GetChildren();

            Light[] lights = new Light[length];

            for (int i = 0; i < length; i++)
            {
                for (; !itItem.IsEnd(); itItem.Next())
                {
                    lights[i] = ParseLight(itItem);
                }
            }

            return(lights);
        }
Exemple #6
0
        public static Material[] ParseMaterialArray(NodeIterator it)
        {
            int length = 0;

            int.TryParse(it.Name(), out length);
            NodeIterator itItem = it.GetChildren();

            Material[] materials = new Material[length];

            int      i        = 0;
            Material material = null;

            for (; !itItem.IsEnd(); itItem.Next())
            {
                string name = itItem.Name();
                if (name[0] == '"' && name[name.Length - 1] == '"')
                {
                    if (material != null)
                    {
                        materials[i] = material;
                        i++;
                    }

                    material      = new Material();
                    material.Name = name.Substring(1, name.Length - 2);
                    itItem.Next();
                }

                System.Reflection.FieldInfo fieldInfo = FindFieldInfo(material.GetType().GetFields(), itItem.Name());
                if (fieldInfo == null)
                {
                    continue;
                }

                fieldInfo.SetValue(material, ParseValue(fieldInfo.FieldType, itItem.GetChildren()));
            }

            materials[i] = material;

            return(materials);
        }
Exemple #7
0
        public static Object ParseObject(NodeIterator it)
        {
            string name = it.Name();
            Object obj  = new Object();

            if (name[0] != '"' || name[name.Length - 1] != '"')
            {
                return(obj);
            }

            obj.Name = name.Substring(1, name.Length - 2);
            NodeIterator itItem = it.GetChildren();

            for (; !itItem.IsEnd(); itItem.Next())
            {
                System.Reflection.FieldInfo fieldInfo = FindFieldInfo(obj.GetType().GetFields(), itItem.Name());
                if (fieldInfo == null)
                {
                    continue;
                }

                if (fieldInfo.FieldType == typeof(Float3[]))
                {
                    itItem.Next();
                    fieldInfo.SetValue(obj, ParseVertexArray(itItem));
                }
                else if (fieldInfo.FieldType == typeof(Face[]))
                {
                    itItem.Next();
                    fieldInfo.SetValue(obj, ParseFaceArray(itItem));
                }
                else
                {
                    itItem.Next();
                    fieldInfo.SetValue(obj, ParseValue(fieldInfo.FieldType, itItem));
                }
            }

            return(obj);
        }