Exemple #1
0
        protected void FilterHierarchy(Node node)
        {
            // if the node has just a single unnamed child containing a mesh, remove
            // the anonymous node inbetween. The 3DSMax kwXport plugin seems to produce this
            // mess in some cases
            if (node.Children.Count == 1 && node.Meshes.Count == 0)
            {
                Node child = node.Children[0];
                if (child.Name.Length == 0 && (child.Meshes.Count > 0))
                {
                    // transfer its meshes to us
                    for (uint a = 0; a < child.Meshes.Count; a++)
                        node.Meshes.Add(child.Meshes[(int)a]);
                    child.Meshes.Clear();

                    // transfer the transform as well
                    node.TrafoMatrix = node.TrafoMatrix * child.TrafoMatrix;
                    // then kill it
                    node.Children.Clear();
                }
            }

            // recurse
            for (uint a = 0; a < node.Children.Count; a++)
                FilterHierarchy(node.Children[(int)a]);
        }
Exemple #2
0
        protected void ParseDataObjectFrame(Node parent)
        {
            string name;
            ReadHeadOfDataObject(out name);

            // create a named node and place it at its parent, if given
            Node node = new Node(parent);
            node.Name = name;
            if (parent != null)
            {
                parent.Children.Add(node);
            }
            else
            {
                // there might be multiple root nodes
                if (scene.RootNode != null)
                {
                    if (scene.RootNode.Name != "$dummy_root")
                    {
                        // place a dummy root if not there
                        Node exroot = scene.RootNode;
                        scene.RootNode = new Node(null);
                        scene.RootNode.Name = "$dummy_root";
                        scene.RootNode.Children.Add(exroot);
                        exroot.Parent = scene.RootNode;
                    }
                    // put the new node as its child instead
                    scene.RootNode.Children.Add(node);
                    node.Parent = scene.RootNode;
                }
                else
                {
                    // it's the first node imported. place it as root
                    scene.RootNode = node;
                }
            }

            // Now inside a frame.
            // read tokens until closing brace is reached.
            bool running = true;
            while (running)
            {
                string objectName = GetNextToken();
                if (objectName.Length == 0)
                {
                    ThrowException("Unexpected end of file reached while parsing frame");
                }

                if (objectName == "}")
                {
                    break; // frame finished
                }
                else if (objectName == "Frame")
                {
                    ParseDataObjectFrame(node); // child frame
                }
                else if (objectName == "FrameTransformMatrix")
                {
                    ParseDataObjectTransformationMatrix(out node.TrafoMatrix);
                }
                else if (objectName == "Mesh")
                {
                    Mesh mesh;
                    ParseDataObjectMesh(out mesh);
                    node.Meshes.Add(mesh);
                }
                else
                {
                    Debug.WriteLine("Unknown data object in frame in x file");
                    ParseUnknownDataObject();
                }
            }
        }
Exemple #3
0
 public Node(Node parent = null)
 {
     this.Parent = parent;
 }