The data displayed on the model browser panel is actually from the instance tree of the loaded model. Here are two ways to obtain the instance tree:
//To get the instance tree
var it = viewer.model.getData().instanceTree;
//or
viewer.getObjectTree(function( instanceTree ) {
console.log( instanceTree );
});
After obtaining the instance tree, you might have to use some tricks to rebuild the tree hierarchy like the below, since Forge Viewer store instance relationships in a flattened data structure.
// To rebuild node tree hierarchy
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 );
But the above is only the data part. If you want to display them like a tree on somewhere, you can try to use Tree UI libraries such as jstree to get it done.
Hope it helps.