0

I've added gui options for my globe to change textures but I get the error "TypeError: Attempted to set a non-object key in a WeakMap" I think the error is related to the textures I'm using. what can I do to fix the gui error? enter image description here

here is my code:

 const gui = new GUI();

const textureLoader = new THREE.TextureLoader();
const myTexture = [
  textureLoader.load("//unpkg.com/three-globe/example/img/earth-blue-marble.jpg"),
  textureLoader.load("//unpkg.com/three-globe/example/img/earth-night.jpg"
  ),
  textureLoader.load("//unpkg.com/three-globe/example/img/earth-day.jpg"),
  textureLoader.load(
    "//unpkg.com/three-globe/example/img/earth-dark.jpg"
  ),
];


const parameters = {
  Theme: 0,
};

    const updateAllMaterials = () => {
      scene.traverse((child) => {
        if (
          child instanceof Globe() &&
          child.material instanceof THREE.MeshPhongMaterial
        ) {
          //child.material = myTexture[parameters.Theme];
          child.material.needsUpdate = true;
          child.material.map = textureLoader.load("//unpkg.com/three-globe/example/img/earth-blue-marble.jpg");
        }
      });
    };

gui
  .add(parameters, "Theme", {
    day: 0,
    night: 1,
    basic: 2,
    dark: 3,
  })
  .onFinishChange(() => {
    updateAllMaterials();
  });

gui.open();

   
       
        
    const elem = document.getElementById("globeViz");
    const globe = Globe()
      .globeImageUrl(
       parameters.Theme
      )(elem)
      //.globeMaterial([MeshPhongMaterial])
shange
  • 77
  • 7
  • At `child.material = myTexture[parameters.Theme];`, you're setting a `Texture` into a property that expects a `Material`. You need to create a `Material`, assign that to `child.material`, and then change `child.material.map` to reflect the newly-selected texture. – Phil N. Dec 01 '22 at 00:20
  • please see the question for updated code, still not fully working – shange Dec 02 '22 at 09:41
  • I set the material map but gui still not fully working, any ideas? – shange Dec 05 '22 at 09:49

0 Answers0