Textures not showing up when using GLTFLoader

I can load the model but not the textures in the scene. Textures are not showing in gltfviewer as well as checked. I am a beginner. Need help on this.

Sword_Shark.fbx (1.1 MB) Sword_Shark.gltf (727.6 KB)

Below is my code:

    let loader = new THREE.GLTFLoader();
    loader.load('assets1/Sword_Shark.gltf', function(gltf){
      sharkMesh = gltf.scene.children[0];
      scene.add(sharkMesh);
      camera.lookAt(sharkMesh.position);
      loader.load('Sword_Shark.gltf', onLoad, undefined, onError);
    });
  }
  function animate() {
    requestAnimationFrame(animate);
    renderer.render(scene,camera);
  }

It looks like you need to reformat your question, the text is either code, or not.

Check you browsers developer tools window. Look for errors in the console tab, or network tab.
There are plenty of clues in those 2 developer tools tabs.

I have edited my question here is the code.Pls check. Also getting an error in console, PFA. Is this is an error related to loader library? I have placed all the texture and .gltf file in a folder assets1.

you have a second loader.load inside loader.load

Yes corrected it, now the same issue with only warnings.Here is the structure of images I have used.

try loading your gltf like this

loader.load('assets1/Sword_Shark.gltf', function (gltf) {
	scene.add(gltf.scene);
}

Try loading your model into https://www.gltfviewer.com/ or https://gltf-viewer.donmccurdy.com/
If the textures are not visible, then use your 3d modelling program to assign the textures and then re export your gltf.

1 Like

I tried downloading the 3d model from sketchfab and implemented. Still facing the same issue The model worked fine with gltfviewer as checked.

index.html (2.0 KB) Here is the index file and I am using Xampp as local server and chrome as web browser.Below is the file structure of assets usedCapture4

It looks like your model has no textures assigned. Unless those white and pink sections in your images are your textures.

view source on this page.

https://sbcode.net/extra_html/textured-gltf.html

  1. I created a monkey head in blender,
  2. assigned a texture to it,
  3. exported it as gltf,
  4. loaded it using this html script.

But in gltfviewer the model is loading with textures as expected. Changing the 3d models , implemanting it and checking, again the pink and blue model in the scene appears with out proper display.

Am I loading it properly? Please check the code in index.html and asset structure.

I don’t see any textures on your model.

I have added it but still facing the issue.

attach the version of the gltf with the textures include in the export. I want to try it in the gltfviewer

In your second screen capture, it looks like you might have a lighting issue.
Try adding
renderer.physicallyCorrectLights = true

Below are the texture images…

you will fix your problem, I know you will

how did you put textures in this viewer? was is a different gltf file to the one provided above with integrated texture images?