Display OBJ file using THREE.OBJLoader

How to visualize an OBJ file using the THREE.OBJLoader method, I have a sample OBJ format, but it does not display anything, I do not see an error in the chrome dev tool

+6
source share
2 answers

Check out an example of using OBJLoader 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 ); } ); 
+8
source

Try adding light to the scene or simply assign 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 can see that the model is already loaded. If not, try adjusting the position of your camera.

There is no light in the documentation, so it seems rather confusing at this point for beginners, including me. :)

+3
source

Source: https://habr.com/ru/post/917400/


All Articles