问题
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