render OBJ file using THREE.OBJLoader

前端 未结 2 997
谎友^
谎友^ 2020-12-31 13:42

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条回答
  • 2020-12-31 14:31

    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 );
    } );
    
    0 讨论(0)
  • 2020-12-31 14:32

    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. :)

    0 讨论(0)
提交回复
热议问题