How to render OBJ file using THREE.OBJLoader method, I've a sample OBJ format but it won't render anything nor I see error in chrome dev tool
2 Answers
Check out the OBJLoader usage sample at https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_obj.html#L75
(In action http://mrdoob.github.com/three.js/examples/webgl_loader_obj.html )
var loader = new THREE.OBJLoader();
loader.load( objURL, function ( object ) {
scene.add( object );
} );
Comments
Try adding a light into the scene or just assign the Obj a MeshBasicMaterial to see its shape:
var objLoader = new THREE.OBJLoader();
var material = new THREE.MeshBasicMaterial({color: 'yellow', side: THREE.DoubleSide});
objLoader.load('file.obj', function (obj) {
obj.traverse(function (child) {
if (child instanceof THREE.Mesh) {
child.material = material;
}
});
scene.add(obj);
});
Then you are able to see that the model has actually already been loaded. If not, try adjusting the position of your camera.
The documentation has left out the light so that it seems quite confusing at this point for beginners including me. :)
2 Comments
stefannew
I know this is a fairly old answer, but do you know if there's a way to add the object to the scene outside of the callback function in loader.load()?
Isilmë O.
@stefannew Then I'm afraid you have to embed the Obj model in the same script so that the browser won't need to AJAX get it and consequently no callback is needed.