Hi I’m new to Three JS and I’m really struggling with getting a model to display in it. I have created a simple bench in Sketch Ups and can export it as gltf, glb, obj, fbx and dae. It also exports the materials in jpg format. Here is a quick piccy of the model.
For now all I want to do is load it and it’s texture / material and be able to pan around it or spin the object around. I’ve tried using the colladaLoader with the dae file and had limited success in bringing the model into the scene but without material. I have tried many other examples since using different file formats but no success whatsoever. I decided to go back to the drawing board and follow the instructions to install modular Three JS and webpack hoping that I could follow some more examples but still I cannot load anything. I just get a blank screen with a different error message in the console depending on what example I have used. I have tried following best I can the Three JS documentation but I cannot find anywhere that takes me through the steps of installing Three JS all the way through to loading a simple model. The examples they supply become very complex and I have difficulty seeing how the script provided can relate to my project.
Here is the script from the last example I tried:
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
const scene = new THREE.Scene();
var loader = new THREE.GLTFLoader();
loader.load( 'bench.glb', function ( gltf ) {
scene.add( gltf.scene );
}, undefined, function ( error ) {
console.error( error );
} );
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 );
camera.position.z = 5;
var animate = function () {
requestAnimationFrame( animate );
renderer.render( scene, camera );
};
animate();
Here I get is a blank screen with the error : TypeError: (void 0) is not a constructor
That error only appears when I try and load the model:
var loader = new THREE.GLTFLoader();
loader.load( 'box.glb', function ( gltf ) {
scene.add( gltf.scene );
}, undefined, function ( error ) {
console.error( error );
} );
Can anyone see what the problem is? I did a bit of searching regarding that error and allthough I couldn’t find anything relating to Three JS I did find that the problem seemed to be associated with Webpack. Is there a better way to manage the modular elements of Three JS. Alternatively are there any tutorials that can take you through the steps from install all the way to importing stuff into your scene? I’ve spent so so much time on trying to access Three JS and I’m really surprised by how little progress I have made so any help or if anyone could point me in the right direction then that would be much appreciated. Thanks in advance.