How does autodesk forge get the file tree of model browser functionality?

1. The official has the function of viewing the file tree, that is, the file tree of the model browser. What is the api for getting this file tree?


you can get the component tree in the following ways:

var it = viewer.model.getData().instanceTree;

//
viewer.getObjectTree(function( instanceTree ) {
   console.log( instanceTree );
});

due to data optimization, all data are flattened. To reconstruct the data structure, you can use:

function buildModelTree( model ) {

    //builds model tree recursively
   function _buildModelTreeRec( node ) {
         it.enumNodeChildren( node.dbId, function(childId) {
                 node.children = node.children || [];

                 var childNode = {
                   dbId: childId,
                   name: it.getNodeName( childId )
                 };

                 node.children.push( childNode );

                 _buildModelTreeRec( childNode );
           });

   }

   //get model instance tree and root component
   var it = model.getData().instanceTree;

   var rootId = it.getRootId();

   var rootNode = {
         dbId: rootId,
         name: it.getNodeName( rootId )
   };

   _buildModelTreeRec( rootNode );

   return rootNode;
 }

 var root = buildModelTree( viewer.model );
Menu