# Changing Textures on Imported GLB

**URL:** https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257
**Category:** Questions
**Created:** [December 23, 2021, 12:29am UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257 "2021-12-23T00:29:53Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![jgonzosan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jgonzosan/32/10007_2.png) [@jgonzosan](https://forum.babylonjs.com/u/jgonzosan)
#### Post date: [December 23, 2021, 12:29am UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/1 "2021-12-23T00:29:53Z")

</div>

I’ve seen this in a few forum posts, but I wanted to change the textures on an imported GLB file. I’ve seen in most examples that a new material is created and the GLB file then gets that new material. Is this best practice?

When I import a GLB file I tried to change the texture map (color map) as such:

```auto
mesh.material.albedoTexture = new Texture('texture path', scene);

```

or

```auto
mesh.material.diffuseTexture = new Texture('texture path', scene);

```

In both those scenarios, the albedo/diffuse texture does not pop up as being part of that mesh’s material. So is it safe to assume that I cannot change the textures of the GLB file but instead must create a new material and assign that to the GLB (with the new textures)?

---

<div class="post-metadata">

### Author: ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)
#### Post date: [December 23, 2021, 8:55am UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/2 "2021-12-23T08:55:43Z")

</div>

The repro would be helpful. It seems that probably you either don’t find the right mesh or don’t assign a texture properly.  
Did you try to have a look at your model in the Inspector?  
You don’t need to create new material if you want to change the texture of existing one.  
Here is one of examples - [Mu-so 2nd Generation 3D](https://mu-so.ru/3d/v2/) , you may change texture with click.

---

<div class="post-metadata">

### Author: ![Treedbox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/treedbox/32/20615_2.png) [@Treedbox](https://forum.babylonjs.com/u/Treedbox)
#### Post date: [December 24, 2021, 2:59pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/4 "2021-12-24T14:59:16Z")

</div>

Seems to be the same question answered here:

> [@Add texture/color to all meshes imported as glb file](https://forum.babylonjs.com/t/add-texture-color-to-all-meshes-imported-as-glb-file/17470/6):
>
> So, after load the glb file, we can get meshes and the root mesh const mesh = meshes[0]; Then we can get all childrenMeshes from this mesh and set material or color for each one. A color is applied to each child mesh, except the t-shirt one wich receives a texture. mesh.getChildMeshes().forEach((childMesh, index) =\> { console.log("childMesh.name:", childMesh.name); const material = new BABYLON.StandardMaterial('material', scene); // HVGirl\_prim…

---

<div class="post-metadata">

### Author: ![jgonzosan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jgonzosan/32/10007_2.png) [@jgonzosan](https://forum.babylonjs.com/u/jgonzosan)
#### Post date: [December 24, 2021, 4:05pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/5 "2021-12-24T16:05:34Z")

</div>

It’s somewhat the same. I know how to swap out the textures. My question is how would I directly change the texture on the material that comes with the GLB file? In the link you provided, the solution included creating a new material and assigning that to the mesh then assigning a texture to that new material. That’s the approach I’ve seen in most examples, but I haven’t seen any yet that just directly change the texture on the GLB file.

Here is a playground ([https://playground.babylonjs.com/#JUKXQD#1944](https://playground.babylonjs.com/#JUKXQD#1944)) that includes some models I’ve created in Blender with some textures. It’s fairly simple and _should_ be easy to modify but I can’t seem to change the textures directly. In the code I reference the cube after importing. When I start typing out:

`cube.material`

I don’t see anything regarding the ability to change any kind of texture, albedo or diffuse. So is this something that can’t be done directly? Do I need to create a new material, assign it to the cube, then change the texture?

To add to this, why can’t I access the diffuse texture of a material when I chain it as such?:  
`sphere0.material.diffuseTexture`

Here is the playground for that (I included the code snippet above)

> **[Babylon.js Playground](https://playground.babylonjs.com/#20OAV9%236354)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

I can access the diffuse texture just fine if I reference the material directly, but not if I reference the material through the mesh. Is there some other way I’m supposed to access this? A while back I was trying to change the uv scale of the texture and was having a hard time understanding why I couldn’t change this through the material. I had to create a texture separately then I could access it.

---

<div class="post-metadata">

### Author: ![nogalo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nogalo/32/120_2.png) [@nogalo](https://forum.babylonjs.com/u/nogalo)
#### Post date: [December 24, 2021, 4:31pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/6 "2021-12-24T16:31:28Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#20OAV9%236356)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

I am not sure what is your issue here and why you seem not to be able to access it. You can see that I took your example playground here and changed the texture directly on existing material without any issue.

---

<div class="post-metadata">

### Author: ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)
#### Post date: [December 24, 2021, 4:40pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/7 "2021-12-24T16:40:13Z")

</div>

Maybe this simple example will suit your needs - [https://playground.babylonjs.com/#QCU8DJ#166](https://playground.babylonjs.com/#QCU8DJ#166)  
And here all other old textures are disposed too - [https://playground.babylonjs.com/#QCU8DJ#167](https://playground.babylonjs.com/#QCU8DJ#167)

---

<div class="post-metadata">

### Author: ![nogalo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nogalo/32/120_2.png) [@nogalo](https://forum.babylonjs.com/u/nogalo)
#### Post date: [December 24, 2021, 4:48pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/8 "2021-12-24T16:48:51Z")

</div>

Also note that GLB file will always come in with PBRMaterials. So diffuseTexture on GLB files doesn’t exists and you cannot access it as it is not part of the PBR workflow. Instead you can access albedoTexture.

---

<div class="post-metadata">

### Author: ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)
#### Post date: [December 24, 2021, 4:50pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/9 "2021-12-24T16:50:41Z")

</div>

And you always can check all PBRMaterial methods and properties here - [PBRMaterial | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/babylon.pbrmaterial)

---

<div class="post-metadata">

### Author: ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)
#### Post date: [December 24, 2021, 5:18pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/10 "2021-12-24T17:18:18Z")

</div>

I think the problem is just that when you create the material and assign it to a variable then the editor knows what type it is, but when you use the material property, which is of type Material, then the editor doesn’t know what sub class the accessed object is and so can’t provide proper type checking and code completion…

---

<div class="post-metadata">

### Author: ![jgonzosan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jgonzosan/32/10007_2.png) [@jgonzosan](https://forum.babylonjs.com/u/jgonzosan)
#### Post date: [December 24, 2021, 5:19pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/11 "2021-12-24T17:19:36Z")

</div>

I get everything you all are saying but for some reason, it doesn’t work on my end. Here is the updated playground ([https://playground.babylonjs.com/#JUKXQD#1946](https://playground.babylonjs.com/#JUKXQD#1946)). As far as I know, everything is the same as the examples provided but nothing changes.

I even changed the way I grabbed the mesh, I used the scene.getMeshByName(“Cube”) thinking that was the issue, but it doesn’t do anything then either. I saved it and reloaded it multiple times. What am I doing wrong here?

I uploaded a new texture to test out as well and was able to use it just fine here: [https://playground.babylonjs.com/#QCU8DJ#168](https://playground.babylonjs.com/#QCU8DJ#168)

On my own GLB files it just doesn’t seem to work. I don’t get why this wouldn’t work on my end, feels like I’m taking crazy pills here.

I also added went into the Sandbox to see if I could manually change the texture and that seems to work fine.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/2/32055464b97a3509a6424a51807b879307e7c9fd.jpeg)

---

<div class="post-metadata">

### Author: ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)
#### Post date: [December 24, 2021, 5:29pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/12 "2021-12-24T17:29:25Z")

</div>

Looks like it’s using the emissive texture, changing that to the brick works with your model. 🙂

> **[Babylon.js Playground](https://playground.babylonjs.com/#JUKXQD%231947)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

### Author: ![jgonzosan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jgonzosan/32/10007_2.png) [@jgonzosan](https://forum.babylonjs.com/u/jgonzosan)
#### Post date: [December 24, 2021, 5:36pm UTC](https://forum.babylonjs.com/t/changing-textures-on-imported-glb/26257/13 "2021-12-24T17:36:23Z")

</div>

Thank you. I was noticing that I could see a “glint” of the brick texture and started swapping out some textures and finally started to see it come through. That combined with what you mentioned earlier about the material not being referenced previously (and not showing material properties) threw me off.

Thanks to everyone for helping out with this, I know it’s frustrating when it seems so simple and straightforward but sometimes small things end up causing unforeseen issues.
