Get THREE.Mesh elements in Autodesk Forge Viewer

3k views Asked by At

I would like to get the THREE.Mesh object of an element in Autodesk Forge Viewer. Here is the code:

var dbId;   // geometry node Id of an element
var viewer; // GuiViewer3D
var mesh = viewer.impl.getRenderProxy(viewer.model, dbId);

The return mesh object is a THREE.Mesh object but with null Geometry and Material, so it is useless. How can I get the real THREE.Mesh object?

Thank you.

1

There are 1 answers

7
Felipe On BEST ANSWER

It depends what you want to do with the mesh: if you want to change the render style, you need to get the renderProxy, if you want to transform the component position or rotation, you need to get the fragmentProxy.

Those methods take as input the fragment ids not the dbId.

Find examples for both at:

Viewing.Extension.Material

Viewing.Extension.Transform

You get the fragment Ids for a given dbId either from the selection event, as illustrated in the above samples, or by using enumNodeFragments:

 var instanceTree = model.getData().instanceTree

 var fragIds = []

 instanceTree.enumNodeFragments(dbId, function(fragId){
     fragIds.push(fragId)
 })

 // to change material or transform, need to iterate all
 // fragments of a given dbId and apply same material/transform

 fragIds.forEach(function(fragId) {

     var renderProxy = viewer.impl.getRenderProxy(viewer.model, fragId)

     var fragmentproxy = viewer.impl.getFragmentProxy(viewer.model, fragId)
 })