Disabling PCSS Shadows Throws a TypeError on Meshes with Multiple Materials
PeteMatterfield opened this issue · comments
Peter Sekula commented
three
version: 0.160.0@pmndrs/vanilla
version: 1.14.1node
version: 18npm
(oryarn
) version: 8.6
Problem description:
I have a scene that contains a Mesh with multiple materials. The mesh.child.material value is an array in these cases. Otherwise, it's just a three material type. The reset code when disabling PCSS shadows doesn't support the material array.
Relevant code:
// node_modules/@pmndrs/vanilla/core/pcss.js
function reset(gl, scene, camera) {
scene.traverse((object) => {
if (object.material) {
gl.properties.remove(object.material);
object.material.dispose();
}
});
Suggested solution:
I'm not much of a programmer, but:
function reset(gl, scene, camera) {
scene.traverse(object => {
if(object.material instanceof Array)
{
object.material.forEach(material => {
gl.properties.remove(material);
material.dispose();
});
}
else if (object.material) {
gl.properties.remove(object.material);
object.material.dispose();
}
});