-1

我一直在尝试制作一个导出代码,以便快速让我纹理立方体并将它们导出到我正在制作的游戏中,但由于某种原因,我无法让我的立方体覆盖整个 128x128我希望它具有的宽度和高度。

我有以下代码:

    function init(){

        if( Detector.webgl ){
            renderer = new THREE.WebGLRenderer({
                antialias       : false,    // to get smoother output
                preserveDrawingBuffer   : true  // to allow screenshot
            });
            renderer.setClearColorHex( 0xBBBBBB, 1 );
        // uncomment if webgl is required
        //}else{
        //  Detector.addGetWebGLMessage();
        //  return true;
        }else{
            renderer    = new THREE.CanvasRenderer();
        }
        renderer.setSize(128,128);
        document.getElementById('container').appendChild(renderer.domElement);

        // add Stats.js - https://github.com/mrdoob/stats.js
        stats = new Stats();
        stats.domElement.style.position = 'absolute';
        stats.domElement.style.bottom   = '0px';
        document.body.appendChild( stats.domElement );

        var zoom = 1.0;

        // create a scene
        scene = new THREE.Scene();

        // put a camera in the scene
        camera = new THREE.OrthographicCamera(WIDTH / -zoom, HEIGHT / zoom, WIDTH / zoom, HEIGHT / -zoom, -2000, 1000);
        //camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 1, 10000 );
        camera.position.set(0.45,0.45,0.45);
        camera.lookAt(scene.position);
        //camera.position.set(0, 0, 5);
        scene.add(camera);

        // create a camera contol
        //cameraControls    = new THREEx.DragPanControls(camera)

        // transparently support window resize
        THREEx.WindowResize.bind(renderer, camera);
        // allow 'p' to make screenshot
        THREEx.Screenshot.bindKey(renderer);
        // allow 'f' to go fullscreen where this feature is supported
        //if( THREEx.FullScreen.available() ){
        //  THREEx.FullScreen.bindKey();        
        //  document.getElementById('inlineDoc').innerHTML  += "- <i>f</i> for fullscreen";
        //}

        // here you add your objects
        // - you will most likely replace this part by your own
        //var geometry  = new THREE.TorusGeometry( 1, 0.42 );
        var cubeSize = 128;

        var geometry = new THREE.CubeGeometry( cubeSize, cubeSize, cubeSize );
        var material    = new THREE.MeshNormalMaterial();
        mesh= new THREE.Mesh( geometry, material );
        mesh.rotation.x = 0;
        mesh.rotation.y = 0;
        mesh.rotation.z = 0;
        scene.add( mesh );
    }

我一直在尝试不同的“缩放”,但最终还是太大或太小。所有这一切的重点是最终得到一个可以生成如下内容的代码:

https://dl.dropboxusercontent.com/u/5256694/cube_ex.png

我究竟做错了什么?

亲切的问候

希亚姆

4

1 回答 1

0

与其将参数THREE.OrthographicCamera视为“缩放”级别,不如将它们视为相机能够看到的边界平面的坐标。

另请参阅Three.js - Orthographic camera的答案,了解有关在 Three.js 中使用正交相机的更多详细信息

于 2013-09-24T15:48:30.003 回答