Search code examples
javascripthtmlthree.jsgltf

Three.js GLTFLoader cant load gltf files on my computer


I am new to using three.js, JavaScript, html, and CSS and I am working on loading a 3d model. I have a program that is working when I pull a gltf file online, ex:

loader.load('https://threejsfundamentals.org/threejs/resources/models/cartoon_lowpoly_small_city_free_pack/scene.gltf', function ( gltf ) 
{console.log(gltf);
scene.add( gltf.scene );
}, undefined, function ( error ) {console.error( error );} );

But when I try and pull a gltf file of my computer it doesn't work, ex:

loader.load('C:\Models\scene.gltf', function ( gltf ) 
{console.log(gltf);
scene.add( gltf.scene );
}, undefined, function ( error ) {console.error( error );} );

Any idea of what I am doing wrong? I am using dreamweaver as well.


Solution

  • Web browsers cannot load files like images or models from local disk (unless you disable security restrictions). To get around this you must run a local server during development, see how to run things locally in the three.js documentation.