Reputation: 67
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
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