2

我正在使用下面的代码来渲染一个 Blender 模型(默认的立方体模型刚刚开始)并且没有显示任何内容:

<html>
    <head>
        <title>Test page for the </title>
        <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    </head>
    <body>
        <div id="container"></div>
        <script src="src/three.min.js"></script>
        <script src="src/Stats.js"></script>
        <script>
        var camera, scene, renderer, loader;
            init();
            render();
            function init(){

                var container = document.getElementById('container');

                camera = new THREE.PerspectiveCamera(10, window.innerWidth/window.innerHeight, 1, 500);
                camera.position.y = 100;
                camera.position.z = 100;

                controls = new THREE.TrackballControls( camera );

                scene = new THREE.Scene();

                loader = new THREE.JSONLoader();
                loader.load('obj/one.js', function (geometry){
                    mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial({overdraw: true}));
                    scene.add(mesh);
                });

                renderer = new THREE.CanvasRenderer();
                renderer.setSize(window.innerWidth, window.innerHeight);
                container.appendChild(renderer.domElement);

                stats = new Stats();
                stats.domElement.style.position = 'absolute';
                stats.domElement.style.top = '0px';
                container.appendChild( stats.domElement );

                window.addEventListener( 'resize', onWindowResize, false );


            }

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

            function onWindowResize() {

                camera.aspect = window.innerWidth / window.innerHeight;
                camera.updateProjectionMatrix();

                renderer.setSize( window.innerWidth, window.innerHeight );

            }

        </script>
    </body>
</html>

一切都正确放置在他们的路径中,我得到的只是一个空白屏幕。建议?

4

1 回答 1

2

这是因为您没有制作动画。collada 加载器是一个回调函数,因此它会在初始页面渲染后完成加载,然后将对象添加到场景中。由于没有动画循环,一旦模型完成加载,页面将永远不会重绘。

于 2012-10-04T02:14:04.560 回答