Get THREE.Mesh elements in Autodesk Forge Viewer

亡梦爱人 提交于 2019-11-30 09:50:19

问题


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:


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)
 })


来源:https://stackoverflow.com/questions/41232207/get-three-mesh-elements-in-autodesk-forge-viewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!