Texture on imported glb from github

Hi everyone.
I have a question like How to have a texture on imported mesh using url from github.

Here is how i imported glb file from github.

addModels = () => {

BABYLON.SceneLoader.ImportMesh(“”, “https://raw.githubusercontent.com/pavankulkarni11/3D_Meshes/main/Pillow.glb”, this.scene);


This is how im trying to add texture on it but its not working for me

addModels = () => {
var myMaterial = BABYLON.SceneLoader.ImportMesh(“”, “https://raw.githubusercontent.com/pavankulkarni11/3D_Meshes/main/Pillow.glb”, this.scene);
myMaterial.diffuseTexture = new BABYLON.Texture(“https://www.babylonjs-playground.com/textures/floor.png”, this.scene);


Mine works, when I set it by:

new BABYLON.Texture(“/textures/filename.png", scene)

Here are Docs:

1 Like

Let’s put more logic.

First, you import GLB

        "Pillow.glb", scene, function (newMeshes) {

and it goes fine like here - Babylon.js Playground
If you would open the Inspector it shows that your model has 2 meshes:

Now you need to create a new Texture which you will apply to the material of the desired mesh.

const newTexture = new BABYLON.Texture("https://www.babylonjs-playground.com/textures/floor.png")

You use GLB, so all materials there will be PBR materials. They have no diffuse texture, they have albedo texture
So you need to find the desired mesh material and change albedoTexture:

scene.getMeshByName("pollow_poly").material.albedoTexture = newTexture

And, finally, because you are using GLB, you better set up the environment lighting:

scene.createDefaultEnvironment({createGround:false, createSkybox:false})

Example - https://playground.babylonjs.com/#NYUG5R#3

More information about environment lighting and PBR materials here - Introduction to Physically Based Rendering | Babylon.js Documentation


Thanks labris, Its working for me.

1 Like