Javascript 使用 THREE.OBJLoader 渲染 OBJ 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10888479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 03:26:21  来源:igfitidea点击:

render OBJ file using THREE.OBJLoader

javascriptthree.js

提问by Harshal Damle

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

如何使用 THREE.OBJLoader 方法渲染 OBJ 文件,我有一个示例 OBJ 格式,但它不会渲染任何内容,也不会在 chrome 开发工具中看到错误

回答by Ilmari Heikkinen

Check out the OBJLoader usage sample at https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_obj.html#L75

https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_obj.html#L75查看 OBJLoader 使用示例

(In action http://mrdoob.github.com/three.js/examples/webgl_loader_obj.html)

(在行动http://mrdoob.github.com/three.js/examples/webgl_loader_obj.html

var loader = new THREE.OBJLoader();
loader.load( objURL, function ( object ) {
  scene.add( object );
} );

回答by Isilm? O.

Try adding a light into the scene or just assign the Obj a MeshBasicMaterial to see its shape:

尝试在场景中添加一盏灯,或者只为 Obj 指定一个 MeshBasicMaterial 以查看其形状:

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

文档忽略了这一点,因此对于包括我在内的初学者来说,此时似乎很困惑。:)