简体   繁体   English

无法在Autodesk Forge Viewer中检索碎片ID

[英]Unable to retrieve frag IDs in autodesk forge viewer

I am currently looking at trying to get a very simple solution working as a proof of concept before going any further with forge. 我目前正在尝试获得一个非常简单的解决方案,作为概念验证,然后再进行任何伪造。 I have gone through the basic application quick start guide and the basic extension guide and the viewer it self works perfectly with a file I created using Autodesk pipe 3D (tried both as a dwg file and a dwfx). 我已经阅读了基本的应用程序快速入门指南,基本的扩展指南以及查看器,它与我使用Autodesk Pipe 3D创建的文件(分别作为dwg文件和dwfx都尝试过)完美兼容。

All I am trying to do is change the colour of the model, all the guides I could find all use similar methods but they all require you to get the list of FragIDs to apply a material 我要做的就是更改模型的颜色,所有可以找到的指南都使用类似的方法,但是它们都需要您获取FragID列表才能应用材料

 var it = viewer.model.getData().instanceTree;

 var allDbIds = Object.keys(it.nodeAccess.dbIdToIndex);
 for (var i=0; i<allDbIds.length; i++) {
     var dbid = allDbIds[i];
     var fragIds = []
     try {
       it.enumNodeFragments(dbid, function(fragId){
       fragIds.push(fragId)
     })
    }catch(error) {  
    console.error(error);
    }


 fragIds.forEach(function(fragId) {
    //code to actually change colour
 })

It manages to get the dbid fine and brings back many however when it tries to get the frag ids it doesnt bring back anything. 它设法获得dbid罚款并带回很多,但是当它尝试获取碎片ID时却什么也没带回来。 It does not break it just brings back nothing but am having trouble finding where to actually look in to why or where to even start 它不会破坏它,什么也不会带回来,但是很难找到从哪里真正寻找原因或从哪里开始

First thing would be to define the fragIds array outside of the for loop, so it's not getting overridden at each iteration. 第一件事是在for循环之外定义fragIds数组,因此它不会在每次迭代时被覆盖。

You can use the following code to set a specific material to a fragId: 您可以使用以下代码将特定材料设置为fragId:

fragIds.forEach((fragId) => {

  model.getFragmentList().setMaterial(
    fragId, material)
})

Take a look at this thread for more info how the topic: 查看此线程以获取有关该主题的更多信息:

Forge Viewer THREE.MeshLambertMaterial 伪造查看器THREE.MeshLambertMaterial

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM