Beispiel #1
0
        /// <summary>
        /// Parse the specified DXS file.
        /// </summary>
        /// <param name="name">Stream containing the dxs file</param>
        /// <returns>Dxs model tree</returns>
        public DxsNode Parse(Stream stream, String name)
        {
            //Import the XML in document form
            document.Load(stream);
            //Create the root for the model
            DxsNode scene = new DxsNode(Path.GetFileNameWithoutExtension(name));
            //Now parse the children
            XmlNode root = document.FirstChild;

            foreach (XmlNode node in root.ChildNodes)
            {
                switch (node.Name)
                {
                //Materials are listed first and picked up first
                case "materials":
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        ParseMaterials(node.ChildNodes[i]);
                    }
                    break;

                //All primitives get added to the scene root
                //TODO: Create nodes for groups?
                case "primitives":
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        ParsePrimitive(node.ChildNodes[i], scene);
                    }
                    break;
                }
            }
            return(scene);
        }
Beispiel #2
0
        /// <summary>
        /// Parse the specified DXS file.
        /// </summary>
        /// <param name="name">Absolute file path</param>
        /// <returns>Dxs model tree</returns>
        public DxsNode Parse(String name)
        {
            //Import the XML in document form
            document.Load(name);
            //Create the root for the model
            String  s     = name.Substring(name.LastIndexOf("\\"));
            DxsNode scene = new DxsNode(s.Substring(0, s.LastIndexOf(".dxs")));
            //Now parse the children
            XmlNode root = document.FirstChild;

            foreach (XmlNode node in root.ChildNodes)
            {
                switch (node.Name)
                {
                //Materials are listed first and picked up first
                case "materials":
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        ParseMaterials(node.ChildNodes[i]);
                    }
                    break;

                //All primitives get added to the scene root
                //TODO: Create nodes for groups?
                case "primitives":
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        ParsePrimitive(node.ChildNodes[i], scene);
                    }
                    break;
                }
            }
            return(scene);
        }
Beispiel #3
0
        /// <summary>
        /// Parse a xml primitive node. Result is attached to the specified
        /// Dxs node.
        /// </summary>
        /// <param name="xmlNode">Xml Primitive Node</param>
        /// <param name="dxsNode">Parent Dxs Node</param>
        private void ParsePrimitive(XmlNode xmlNode, DxsNode dxsNode)
        {
            //Process attributes
            String name       = xmlNode.Attributes["name"].Value;
            int    groupID    = -1; // int.Parse(xmlNode.Attributes["groupID"].Value);
            int    skeletonID = -1; // int.Parse(xmlNode.Attributes["skeletonID"].Value);

            //Create a new DXS primitive
            DxsPrimitive prim = new DxsPrimitive(name, groupID, skeletonID);

            //Go through its children - first process the master vertex list,
            //then the polygon list
            foreach (XmlNode node in xmlNode.ChildNodes)
            {
                switch (node.Name)
                {
                case "vertices":
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        ParseMasterVertex(node.ChildNodes[i], prim);
                    }
                    break;

                case "polygons":
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        ParsePolygon(node.ChildNodes[i], prim);
                    }
                    break;
                }
            }
            dxsNode.AddChild(prim);
        }
Beispiel #4
0
        public void RemoveChild(String name)
        {
            DxsNode node = null;

            for (int i = 0; i < _children.Count; i++)
            {
                if (_children[i].Name.Equals(name))
                {
                    node = _children[i];
                    break;
                }
            }
            if (node != null)
            {
                node.Parent = null;
                _children.Remove(node);
            }
        }
Beispiel #5
0
 public void AddChild(DxsNode node)
 {
     _children.Add(node);
     node.Parent = this;
 }