Here's an example of reading various fragment properties: const frags = viewer.model. Petr is a senior developer advocate at Autodesk.
#How to use autodesk viewer code
Note: the FragmentList class unfortunately isn't documented on (yet), but you can explore the various methods it provides in the non-minified source code of Forge Viewer, for example, in. Similarly to the instance tree, fragment lists are retrieved from individual models loaded in the viewer using model.getFragmentList(), and can be used to read or modify various fragment properties such as visibility flags, transformations, linked materials, etc. See the Pen Forge Viewer v7: Enumerate Fragments by Petr Broz ( on CodePen.įragments in both 3D and 2D models are encapsulated in class.
Here's an example of recursively traversing the entire hierarchy starting from the root object, and logging the ID and child count of each object along the way: viewer.addEventListener(_TREE_CREATED_EVENT, function () ,Ĭonsole.log('dbId:', dbId, 'fragIds:', fragIds) Note: the instance tree is loaded asynchronously, independently from actual geometry data, so wait until it's available by waiting for the OBJECT_TREE_CREATED_EVENT event. Instances of this class - retrieved from individual models in the viewer using model.getInstanceTree() - can be queried for information like parent-children relationships between objects, or object-fragment mappings. Model hierarchy of 3D models is encapsulated in class. Generally, the relationship between objects and fragments is many-to-many: one object may consist of multiple fragments (usually for 3D objects with large number of triangles or multiple materials), and many objects may be consolidated in a single fragment (usually in 2D models). When working with Viewer APIs, you typically reference fragments using fragment IDs (or fragIds), and objects using database IDs (or dbIds).