GLTFLoader - 404 not found

Hello,

I’ve got problems with gltf loader. I have a problems with loading local glb file. I’m using angular.
I am using this sample code:

import * as THREE from 'three';
import GLTFLoader from 'three-gltf-loader';
 
const loader = new GLTFLoader();
loader.load(
    'path/to/your/file.gltf',
    ( gltf ) => {
        // called when the resource is loaded
        scene.add( gltf.scene );
    },
    ( xhr ) => {
        // called while loading is progressing
        console.log( `${( xhr.loaded / xhr.total * 100 )}% loaded` );
    },
    ( error ) => {
        // called when loading has errors
        console.error( 'An error happened', error );
    },
);

when I use path like https://rawcdn.githack.com/mrdoob/three.js/7249d12dac2907dac95d36227d62c5415af51845/examples/models/gltf/Flamingo.glb

It is working without any problems.
But when I download this file and put it into /src/Flamingo.glb then I use url like: ‘http://localhost:4200/flamingo.glb’ or './Flamingo.glb it doesn’t work.
In console there is an error: GET http://localhost:4200/flamingo.glb 404 (Not Found)
I have no idea what could be wrong

Thanks in advance

1 Like

I found solution. Maybe someone will have similar problem.
I put my file into assets folder and then use url :’…/…/assets/flamingo.glb’

Please do not use three-gltf-loader. Always import the loader and other examples files from the three package like so:

import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';

Hey there, do not know if you will see this, But I desperately hope you do. I have the same problem, it loads from external links. I tried your solution and wrote …/…/assets/models/burger.gltf. It didnt work. Was I not supposed to type …?

  1. Do not use three-gltf-loader package. Import GLTFLoader directly from three package (three/examples/jsm/loaders/GLTFLoader.)
  2. Make sure the path you pass to the loader is correctly pointing to assets on your webserver (local or remote) - there’s no point in copying someone else’s paths, since they always depend on your own project structure.
1 Like

did you find a solution?