在 Autodesk Forge Viewer 中获取三个.Mesh 元素 [英] Get THREE.Mesh elements in Autodesk Forge Viewer

查看:33
本文介绍了在 Autodesk Forge Viewer 中获取三个.Mesh 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Autodesk Forge Viewer 中获取元素的 THREE.Mesh 对象.代码如下:

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

返回的mesh对象是一个THREE.Mesh对象,但是Geometry和Material为空,所以没用.我怎样才能得到真正的 THREE.Mesh 对象?

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?

谢谢.

推荐答案

这取决于你想用网格做什么:如果你想改变渲染风格,你需要得到 renderProxy,如果你想变换组件位置或旋转,需要获取fragmentProxy.

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.

这些方法将片段 ID 而非 dbId 作为输入.

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

在以下位置查找两者的示例:

Find examples for both at:

查看.扩展.材料

Viewing.Extension.变换

您可以从选择事件(如上述示例中所示)或使用 enumNodeFragments 获取给定 dbId 的片段 ID:

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

这篇关于在 Autodesk Forge Viewer 中获取三个.Mesh 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆