Texture isnt working in my code

Hi Everyone.
Im wondering why texture isnt working for mesh. Is there any mistake in coding? and how can i have UV mapping for this mesh(glb) which im importing from Github repo?
Please help

addModels = () => {

BABYLON.SceneLoader.ImportMesh("",
"https://raw.githubusercontent.com/pavankulkarni11/3D_Meshes/main/",
"mug_glb_itr4.glb", scene, function (newMeshes) {

    console.log(newMeshes)

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

    console.log(scene.getMeshByName("pollow_poly").material)

    scene.getMeshByName("pollow_poly").material.albedoTexture = newTexture
    scene.createDefaultEnvironment({createGround:false, createSkybox:false})
});
// BABYLON.SceneLoader.ImportMesh("", "https://raw.githubusercontent.com/pavankulkarni11/3D_Meshes/main/","mug_glb_itr4.glb", this.scene);   

};

Want to share a playground?

Yes please and Thanks for response

I think you misunderstood me.
YOU need to share a playground. show us what doesn’t work.

Im sorry, Here is the playground link. I trying to add texture to it but not able to add and one more query i have, how can i do UV mapping texture to it

A few issues about your playground:

  1. There are runtime errors.
  2. There is no mesh called pollow_poly in the mesh
  3. in order to apply a texture you need to create a material.

This is a simple example of how to fix those issue, but this is just an example. you need to apply the material to the right mesh:

Different Images on Each Face of a Box | Babylon.js Playground (babylonjs.com)

2 Likes

So this point is clear for me now that i need to have material to apply texture.
But I’m confused :confused: like how can i implement UV mapping texture to it. In this code i have a photo frame and i want to add image texture in middle of frame. Any clue please. Im trying to learn by implementing basic scenes, camera, lights and basic models with texture to it.

You would normally do this in an edition tool like blender but can also do it programmatically as long as you understand pretty well how meshes are represented in 3d: Create Custom Meshes From Scratch | Babylon.js Documentation

2 Likes