How to get started with three.js and glTF?


im trying to load a 3d model into my scene but it doesn’t work?

	<title>My first three.js app</title>
		body { margin: 0; }
		canvas { width: 100%; height: 100% }
	<script src="js/three.js"></script>
	<script src="js/GLTFLoader.js"></script>
	       var scene = new THREE.Scene();
		var camera = new THREE.PerspectiveCamera( 75,      window.innerWidth/window.innerHeight, 0.1, 1000 );

		var renderer = new THREE.WebGLRenderer();
		renderer.setSize( window.innerWidth, window.innerHeight );
		document.body.appendChild( renderer.domElement );

		var loader = new THREE.GLTFLoader();
		loader.load( 'Models/Model.gltf', function ( gltf )

			scene.add( gltf.scene );

			gltf.animations; // Array<THREE.AnimationClip>
			gltf.scene; // THREE.Scene
			gltf.scenes; // Array<THREE.Scene>
			gltf.cameras; // Array<THREE.Camera>
			gltf.asset; // Object

		}, function ( xhr ) {
			console.log( ( xhr.loaded / * 100 ) + '% loaded' );
		function ( error ) {

			console.log( 'error' );

Thanks in advance

Some essential components of a basic three.js app like an animation loop are missing in your scene. I suggest you carefully study the following guide in order to get familiar with basic three.js entities. After that, use the beneath glTF example as a code template for you own scene.

1 Like

Thanks for the answer.

I used the template for my scene and now using a local python server as described in the docs. But when I try to load the html with that server, I can only save it.


There seems to be a problem with your web server’s configuration. Please try it with node.js and http-server.

Tried it with node.js, same result / error in the console.

Can you please share the error message here.

“GET /index.html” “Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0”
“GET /index.html” Error (404): “Not found”

Have you actually put your source files in the root directory of the server?

I started the server in my project folder where the html file is located. Is that wrong?

No, that sounds correct. Unfortunately, it’s a bit hard to provide support in such cases. Consider to carefully study tutorials like this one in order to do things right:

1 Like

It works now, but I still can’t load an 3d model.

here is the error from the browser console and the code:

    <!DOCTYPE html>
<html lang="en">
		<title>three.js webgl - glTF loader</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
			body {
				font-family: Monospace;
				background-color: #b1b1b1;
				color: #fff;
				margin: 0px;
				overflow: hidden;
			#info {
				color: #fff;
				position: absolute;
				top: 10px;
				width: 100%;
				text-align: center;
				z-index: 100;
			#info a {
				color: #75ddc1;
				font-weight: bold;


		<script src="js/three.js"></script>

		<script src="js/OrbitControls.js"></script>
		<script src="js/GLTFLoader.js"></script>

		<script src="js/WebGL.js"></script>
		<script src="js/stats.min.js"></script>

			if ( WEBGL.isWebGLAvailable() === false ) {
				document.body.appendChild( WEBGL.getWebGLErrorMessage() );
			var container, stats, controls;
			var camera, scene, renderer, light;
			function init() {
				container = document.createElement( 'div' );
				document.body.appendChild( container );
				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
				camera.position.set( - 1.8, 0.9, 2.7 );
				controls = new THREE.OrbitControls( camera ); 0, - 0.2, - 0.2 );

				scene = new THREE.Scene();

				light = new THREE.HemisphereLight( 0xbbbbff, 0x444422 );
				light.position.set( 0, 1, 0 );
				scene.add( light );
				// model
				var loader = new THREE.GLTFLoader().setPath( 'Models/Model.gltf' );
				loader.load( 'Models/Model.gltf', function ( gltf ) {
					gltf.scene.traverse( function ( child ) {
						if ( child.isMesh ) {
							// child.material.envMap = background;
					} );
					scene.add( gltf.scene );
				}, undefined, function ( e ) {
					console.error( e );
				} );
				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				renderer.gammaOutput = true;
				container.appendChild( renderer.domElement );
				window.addEventListener( 'resize', onWindowResize, false );
				// stats
				stats = new Stats();
				container.appendChild( stats.dom );
			function onWindowResize() {
				camera.aspect = window.innerWidth / window.innerHeight;
				renderer.setSize( window.innerWidth, window.innerHeight );
			function animate() {
				requestAnimationFrame( animate );
				renderer.render( scene, camera );



This statement does not look correct. Just try it like so:

var loader = new THREE.GLTFLoader();

Loading works now. How can I add XR functionality?

name: 'myawesomeapp',
onStart: ({canvasWidth, canvasHeight}) => {
const {scene, camera} = XR.Threejs.xrScene()
myInitXrScene({scene, camera})
      origin: camera.position,
      facing: camera.quaternion,

How do I add that code correctly to my code?


What API or library are you using? I’ve never seen methods like addCameraPipelineModule()?

It’s from 8thwall

I’m afraid this forum is not a good place for question about this project. You might have more success right here:

8th wall community:

Ok, thanks for your help.