如何为特定的dbId设置独立的材料 [英] How to set independent material for specific dbId

查看:60
本文介绍了如何为特定的dbId设置独立的材料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码为具有特定dbId的元素设置材料.

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

getFragIdListFromGuid 是我实现的从某些dbId检索fragIdList的功能.但是我发现这实际上改变了场景中所有片段的材质.他们是否共享材料?

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

推荐答案

该素材有可能在不同的片段之间共享.要在处理之前解决原始材料的克隆问题并应用克隆,请执行以下操作:

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

这篇关于如何为特定的dbId设置独立的材料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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