three.js JsonLoader 未显示 JSON 从 .obj 转换而来的对象

three.js JsonLoader is not showing JSON object converted from .obj

我有这个代码:

var camera, scene, controls, renderer;

            init();
            animate();

            function init() {
                scene = new THREE.Scene();
                camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);

                camera.position.z = 10;

                //lights
                var light = new THREE.DirectionalLight(0xffffff, 1);
                light.position.set(10, 10, 10);
                scene.add(light);


                controls = new THREE.OrbitControls(camera);
                controls.addEventListener('change', render);

                renderer = new THREE.WebGLRenderer({alpha: true});
                renderer.setClearColor(0x000000, 0); // the default
                renderer.setSize(window.innerWidth, window.innerHeight);
                document.body.appendChild(renderer.domElement);

                var jsonLoader = new THREE.JSONLoader();
                var mesh;
                jsonLoader.load('corona.js',
                        function (geometry, materials) {

                            console.log(JSON.stringify(materials));
                            console.log(JSON.stringify(geometry));

                            var material = new THREE.MeshFaceMaterial(materials);
                            mesh = new THREE.Mesh(geometry, material);

                            scene.add(mesh);

                        }
                );

            }

            function animate() {

                requestAnimationFrame(animate);
                controls.update();

                render();
            }

            function render() {
                renderer.render(scene, camera);
            }

如您所见,我正在使用 JSONLoader 来显示 Corona 啤酒,但由于某种原因它没有显示任何内容。您可以在此处查看实时代码 http://xsportfit.com/corona/index.html 这些是我用于此示例的文件列表:

- http://xsportfit.com/corona/corona.obj
- http://xsportfit.com/corona/corona.mtl
- http://xsportfit.com/corona/corona.js

我已经使用 convert_obj_three.py 脚本将 corona.obj 转换为 corona.js 文件

JSON 中出现错误。你可以通过直接写你的 material 来显示它。例如

new THREE.MeshLambertMaterial({
    color:0xffffff,
    map:THREE.ImageUtils.loadTexture('BotellaText.jpg')
});