How to set independent material for specific dbId

╄→гoц情女王★ 提交于 2021-01-29 19:51:10

问题


I am setting up material for an element with a particular dbId with the following code.

getFragIdListFromGuid is a function I implemented to retrieve fragIdList from certain dbId. But I found this one actually changing all of the fragment material in the scene. Do they share the material together?

const fragIdList = await getFragIdListFromDBId(this.dataComponents, this.instanceTree, dbId)
fragIdList.forEach((fragId) => {
  let material = fragList.getMaterial(fragId)
  if (material) {
    material.opacity = opacity
    material.transparent = true
    material.needsUpdate = true
  }
})

回答1:


There's a chance that the material is shared amongst different fragments. To work around clone the original material before processing and apply the clone:

  let material = fragList.getMaterial(fragId).clone();
  if (material) {
    material.opacity = opacity
    material.transparent = true
    material.needsUpdate = true
  }
        viewer.impl.matman().addMaterial ('myCustomMaterial', material, true);
        viewer.model.getFragmentList().setMaterial(fragId, material);
        viewer.impl.invalidate(true);



来源:https://stackoverflow.com/questions/56225152/how-to-set-independent-material-for-specific-dbid

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