render OBJ file using THREE.OBJLoader

二次信任 提交于 2019-12-18 13:22:18

问题


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


回答1:


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 );
} );



回答2:


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



来源:https://stackoverflow.com/questions/10888479/render-obj-file-using-three-objloader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!