Search code examples
autodeskautodesk-forgeautodesk-viewer

Nodes and fragids data structre


Does the nodes and fragids of the viewer represent a directed graph data structure?

If so, how is an edge represented?

What does an edge between two nodes represent?

Does it always represent a tree or there could be more than one connected component?

Is there a visual example map between the integer array to the graph it represents?


Solution

  • What is the essence of your question? What are you trying to achieve? The nodes and fragments are being crunched in an array to save memory when dealing with large models with an important number of components. The viewer API exposes methods that lets you iterate through the children of a node given a nodeId or its fragments:

    -instanceTree.enumNodeChildren

    -instanceTree.enumNodeFragments

    var instanceTree = viewer.model.getData().instanceTree;
    
    var rootId = this.rootId = instanceTree.getRootId();
    var rootName = instanceTree.getNodeName(rootId);
    var childCount = 0;
    
    instanceTree.enumNodeChildren(rootId, function(childId) {
    
       var childName = instanceTree.getNodeName(childId);
    
       console.log(childName);
    
       childCount++;
    });
    

    Starting from the root node, you can build the kind of data structure you want. This article I wrote may be helpful.