Alisa Bondarchuk
Alisa Bondarchuk

Reputation: 67

How set transparenty of element in autodesk-viewer?

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.

Upvotes: 0

Views: 599

Answers (1)

Bryan Huang
Bryan Huang

Reputation: 5342

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
}

Upvotes: 1

Related Questions