How set transparenty of element in autodesk-viewer?

北战南征 提交于 2019-12-13 04:24:40

问题


I'm trying to set the transparency of an element of a model, but I can't do it. I'm looking for a method that will do this, but the methods I tried did not work.


回答1:


Viewer does not really offer anything native/built-in to do this but THREE.js is always your friend in terms of graphical operations so long as you can reference the material of the target element (by its dbid/nodeid) in Viewer:

var fragList = viewer.model.getFragmentList();    

var fragIds = []

model.getData().instanceTree.enumNodeFragments(
  dbid, (fragId) => {
   fragIds.push(fragId)
});

    fragIds.forEach((fragId) => {
      //grab the material
      var material = fragList.getMaterial(fragId);

      if(material) {
        //set transparency
        material.opacity = 0.5;
        material.transparent = true;
        //mark for update
        material.needsUpdate = true
      }
    })
  });
  viewer.impl.invalidate(true, true, true) //notify renderer to update
}


来源:https://stackoverflow.com/questions/55275198/how-set-transparenty-of-element-in-autodesk-viewer

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