Load GLTF with Texture

Hello, im trying to load a GLTF file with some textures, i. already have a function to create the gltf model but i dont know what i need to do to load the textures with it.
What i dont understand is that when i load this https://threejs.org/examples/?q=gltf#webgl_loader_gltf with my code it works and the textures appears, but when i load my model it doesnt come with texture.
When i load it with https://gltf-viewer.donmccurdy.com/ it works so my code is probably missing something
Here is the model with texture: https://drive.google.com/drive/folders/1T9xir6Z5HRNce-VwXeMQhFo1wSYABAoQ?usp=sharing

Here is my code:

function setModelPreformatted text(positionX, positionY, positionZ, rotationX, rotationY, rotationZ, scaleX, scaleY, scaleZ) {
      // Directory to the gltf model 
      // called when the resource is loaded
      function (gltf) {
         gltf.scene.position.x = positionX;
         gltf.scene.position.y = positionY;
         gltf.scene.position.z = positionZ;
         gltf.scene.rotation.x = rotationX;
         gltf.scene.rotation.y = rotationY;
         gltf.scene.rotation.z = rotationZ;
         gltf.scene.scale.set(scaleX, scaleY, scaleZ) // scale here 

Hopefully there’s more code than that.
What do you see in the console?
If you get a model without textures, it may be a path that needs setting.
You should see where your browser is trying to load them and get a 404.
Try using all the code from the example, and change out your model.
Then add your positioning code :slight_smile:

There is much more code beside that but i thought that it wouldnt be necessary so i just showed the main part.
The console doesnt show any error, but when i delete the images it shows a lot of 404 errors so the textures are being loaded but they arent being placed in the 3d model.
Maybe i have to change something in the model when i create it to allow the textures to appear or something like that.
Thanks for the response!

What do you see in the browser window? Even better, do you have a link?

i can see the model but it is all black, it works fine except the texture. And i dont have a link to show you, sorry

Are you sure it’s not a lack of lighting?
Try adding an ambient light to your scene, of you haven’t tried already :wink:

1 Like

If the model is metallic — and this one appears to be almost 100% metallic — you’ll need more than ambient lighting. Try disabling the environment map in my viewer and you’ll see it becomes black, too.

You’ll need to include an environment map, as shown in the https://threejs.org/examples/?q=gltf#webgl_loader_gltf example you linked to above.

1 Like

Thank you guys so much for trying to help me, now it works fine :smile: :smile: :smile:

And another thanks for your GLTF viewer, it has been helping a lot lately, thanks!

1 Like