Acess GLTF Values

I need to acess the value of a mesh material, so i can change it with a variable throw a button
This is my code


I try:
Var target=scene.getobjectbyname(“Mesh”).primitives.material

After you’ve loaded a glTF file with GLTFLoader, the original content of the .gltf is not relevant – there is no .primitives.material to find. From then on, it’s a three.js scene graph with Object3D, Group, and Mesh instances.

1 Like

So how can i change between materials?

If you’ve found the mesh whose material you want to change, reassign its mesh.material property to a different material.

const mesh = scene.getObjectByName('MyMesh');
mesh.material = new MeshStandardMaterial({
  ...
});

See THREE.MeshStandardMaterial documentation for available properties.

I have the materials name of the glft, can i do this?

const mesh = scene.getObjectByName(‘Mesh’);
mesh.material = new MeshStandardMaterial({
“name” : “Marmore1”
});

That would create a new material with the same name, but not the same appearance. If you traverse the scene you could perhaps find the material you’re looking for:

const materials = {};
scene.traverse((object) => {
  const material = object.material;
  if (material) {
    materials[material.name] = material;
  }
});

...

mesh.material = materials['Marmore1'];