pmndrs / drei-vanilla

🍦 drei-inspired helpers for threejs

Home Page:https://pmndrs.github.io/drei-vanilla/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disabling PCSS Shadows Throws a TypeError on Meshes with Multiple Materials

PeteMatterfield opened this issue · comments

  • three version: 0.160.0
  • @pmndrs/vanilla version: 1.14.1
  • node version: 18
  • npm (or yarn) 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();
    }
  });