Hi, I’m a beginner to threejs; due to the examples it was easy to draw cubes, lines, … But I got stuck with the OBJLoader - no error messages, but simply nothing is shown. I used the example WaltHead and according to the debugger every step works well. But something must be wrong here:
import * as THREE from ‘three’;
import { OBJLoader } from ‘three/addons/loaders/OBJLoader.js’;
import {MTLLoader} from ‘three/addons/loaders/MTLLoader.js’;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 90, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var mtlLoader = new MTLLoader();
mtlLoader.load( ‘https://threejs.org/examples/models/obj/walt/WaltHead.mtl’, function( materials ) {
materials.preload();
var objLoader = new OBJLoader();
objLoader.setMaterials( materials );
objLoader.load( ‘https://threejs.org/examples/models/obj/walt/WaltHead.obj’, function ( object ) {
scene.add( object );
camera.lookAt(0, 50, 0);
camera.position.z = 200;
renderer.render( scene, camera );
} );
} );
wich version of three.js do you use?
Loaders may changes depending the version. I highly recommend to follow the official exemple.
it seem you use a very old fashioned way. (no async/await)
try 0,0,0, currently your camera is looking 50 meters into the sky from 200 meters away, the model is likely real world size if pulled from official sources…
Looks like the model is loading fine, the issue is probably scene setup. Try adding lights (Directional + Ambient), use an animation loop instead of rendering once (loading is async and a single render may happen before the model appears), and adjust camera/scale (the model can be too small or out of view).
No, not so far. In the examples there wasn’t any used. I have not used any light source in the cube and line examples, so I thought there would be some default light. Any suggestions?