1

I follow some tutorials on the internet and try to override the opacity/transparent of elements on the Viewer. This is what i got but it work only for a few element like slab and staircase. For the other elements like column, beam... nothing happen at all. Is there something wrong ? Thank in advance.

 const nodeIdToFragIds = (model, nodeId) => {
    var instanceTree = model.getData().instanceTree;

    var fragIds = [];
    instanceTree.enumNodeFragments(nodeId, (fragId) => {
      fragIds = [...fragIds, fragId];
    });

    return fragIds;
  } 

 const overrideOpacity = (model, dbIds) => {
    const fragList = model.getFragmentList();
    
    dbIds.forEach((dbId) => {
      const fragIds = nodeIdToFragIds(model, dbId);
  
      fragIds.forEach((fragId) => {
        const material = fragList.getMaterial(fragId);

        if (material) {
          material.opacity = 0.5;
          material.transparent = true;
          material.needsUpdate = true;
        }
      });
    });
    this.viewer.impl.invalidate(true);

    return true;
  };
Trung Tran
  • 63
  • 7
  • Could you please check if the material of those objects happen to be PrismMaterial? I'm told those cannot be made transparent. I guess you could just create a new transparent material for them. – Adam Nagy Jul 08 '20 at 19:25
  • Hi, i checked all type of materials is "MeshPhongMaterial". I also try to make new material . ``newMaterial = () => { var color = new THREE.Color(0xff0000); var material = new THREE.MeshPhongMaterial({ color: color, opacity: 0.3, transparent: true, }); this.viewer.impl.matman().addMaterial("ColorMaterial-" + new Date().getDate(), material, true); return material; }; `` and set ``fragList.setMaterial(fragId, this.material)``. Nothing work for me – Trung Tran Jul 09 '20 at 04:03
  • I noted that with some elements were overrided, they have the "__webglShader" property in their own material, but i not sure exactly what is it. All of my model are come from Revit. – Trung Tran Jul 09 '20 at 04:09
  • Are you just trying to achieve what the "Isolate" functionality is doing? Why are you not using that? – Adam Nagy Jul 09 '20 at 16:48
  • 1
    Sorry, I don't know what you mean about "Isolate functionality" is, but actually I try to change the opacity of elements. For "Isolate" function it make all elements almost transparent and it's not what i want. The opacity i try to achieve is around 0.5 – Trung Tran Jul 10 '20 at 03:21
  • I just find another way to do it by overlay scene and it work fine. Thank a lot for your support ! – Trung Tran Jul 10 '20 at 07:34
  • Thank you for letting us know how you got around the issue! Maybe you could add your solution as an answer with details so that it's easier for others to see that you found a workaround? – Adam Nagy Jul 10 '20 at 11:04
  • Sorry for that. I just following exactly the same as the second solution on this topic [here](https://stackoverflow.com/questions/45947925/changing-materials-in-forge) – Trung Tran Jul 10 '20 at 14:56

0 Answers0