-2
var container, stats;
            var camera, scene, renderer;
            var arr = new Array();
            var windowHalfX = window.innerWidth / 2;
            var windowHalfY = window.innerHeight / 2;
            init();
            animate();

            function init() {

                container = document.createElement( 'div' );
                document.body.appendChild( container );

                camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
                camera.position.z = 1000;

                scene = new THREE.Scene();

                var geometry = new THREE.CubeGeometry( 10, 10, 10 );

                for ( var i = 0; i < geometry.faces.length; i ++ ) 
                {

                    geometry.faces[ i ].color.setHex( Math.random() * 0xffffff );

                }

                var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors } );

                for ( var i = 0; i < 20; i ++ )
                {

                    arr[i] = new THREE.Mesh( geometry, material );

                    arr[i].position.set( Math.random() * scale, Math.random() * scale, Math.random() * scale ); 
                    scene.add( arr[i] );

                }

                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 onWindowResize() 
            {

                windowHalfX = window.innerWidth / 2;
                windowHalfY = window.innerHeight / 2;

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

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

            }

            function animate() {

                requestAnimationFrame( animate );

                render();
                stats.update();

            }

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

            }

我的意图是根据 for 循环中提供的数量来定位整个视图空间中的立方体数量。但这似乎在这里不起作用,事实上我看到整个空白屏幕。我什至看不到左上角的fps。请有人帮助我。

4

1 回答 1

2

您需要学习如何使用调试器和/或检查控制台是否有错误。

您必须声明变量scale并为其赋值。

var scale = 500;

您还必须包括 Stats 库,如:

<script src="Stats.js"></script>

请不要太快寻求帮助。有很多例子供你学习。

于 2012-11-09T19:38:20.193 回答