# Acess GLTF Values

**URL:** <https://discourse.threejs.org/t/acess-gltf-values/33092>\
**Category:** Questions\
**Tags:** materials\
**Created:** [December 28, 2021, 6:23pm UTC](https://discourse.threejs.org/t/acess-gltf-values/33092 "2021-12-28T18:23:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruno\_Ramos](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/bruno_ramos/32/23110_2.png) [@Bruno\_Ramos](https://discourse.threejs.org/u/Bruno_Ramos)\
**Post date:** [December 28, 2021, 6:23pm UTC](https://discourse.threejs.org/t/acess-gltf-values/33092/1 "2021-12-28T18:23:59Z")

</div>

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

 ![2](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/0/1/01decf57360d79b7708c4954be2bc26630286406.png)  
 ![1](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/f/d/fdbec3979addb9c2a502516af23d06d97368df8e.png)

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

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [December 28, 2021, 8:04pm UTC](https://discourse.threejs.org/t/acess-gltf-values/33092/2 "2021-12-28T20:04:28Z")

</div>

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](https://threejs.org/docs/?q=mesh#api/en/objects/Mesh) instances.

---

<div class="post-metadata">

**Author:** ![Bruno\_Ramos](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/bruno_ramos/32/23110_2.png) [@Bruno\_Ramos](https://discourse.threejs.org/u/Bruno_Ramos)\
**Post date:** [December 28, 2021, 8:42pm UTC](https://discourse.threejs.org/t/acess-gltf-values/33092/3 "2021-12-28T20:42:57Z")

</div>

So how can i change between materials?

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [December 28, 2021, 9:20pm UTC](https://discourse.threejs.org/t/acess-gltf-values/33092/4 "2021-12-28T21:20:39Z")

</div>

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

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

```

See [THREE.MeshStandardMaterial](https://threejs.org/docs/?q=meshstand#api/en/materials/MeshStandardMaterial) documentation for available properties.

---

<div class="post-metadata">

**Author:** ![Bruno\_Ramos](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/bruno_ramos/32/23110_2.png) [@Bruno\_Ramos](https://discourse.threejs.org/u/Bruno_Ramos)\
**Post date:** [December 28, 2021, 9:47pm UTC](https://discourse.threejs.org/t/acess-gltf-values/33092/5 "2021-12-28T21:47:27Z")

</div>

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

 ![Captura de ecrã 2021-12-28, às 21.44.54](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/3/b/3bf4f354d9895df516a1e431db7f7c2643d43d98.png)

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

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [December 28, 2021, 9:56pm UTC](https://discourse.threejs.org/t/acess-gltf-values/33092/6 "2021-12-28T21:56:55Z")

</div>

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:

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

...

mesh.material = materials['Marmore1'];

```
