【问题标题】:three.js hello world example: canvas doesn't renderthree.js hello world 示例:画布不渲染
【发布时间】:2012-10-20 21:40:12
【问题描述】:

我正在尝试让这个 hello world 示例在我自己的计算机上运行:http://jsfiddle.net/GKCx6/

到目前为止,我已经在此处提供了我的努力:https://dl.dropbox.com/u/2070405/wtf/index.html

一切似乎都很好,除了没有渲染的事实。我该如何调试呢?到目前为止,我已经使用了 firebug。

这是index.html的内容:

<!doctype html>
<html>
    <head>
        <title>learningthree.js boiler plate for three.js</title>
        <meta charset="utf-8">
    </head>
<body>
    <!-- three.js container -->
        <div id="container"></div>
    <!-- info on screen display -->

</body>
<script src="three.js"></script>
<script src="main.js"></script>
</html>

这是main.js的内容:

// RequestAnimationFrame.js:
if ( !window.requestAnimationFrame ) {

    window.requestAnimationFrame = ( function() {

        return window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function( callback, element ) {

            window.setTimeout( callback, 1000 / 60 );

        };

    } )();

}


// Hello World1 from https://github.com/mrdoob/three.js

var camera, scene, renderer,
    geometry, material, mesh;

init();
//console.log("renderer defined? ", renderer);
animate();

function init() {

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

    console.log("THREE.Scene available? ", THREE.Scene);
    scene = new THREE.Scene();
    console.log("scene created? ", scene);

    geometry = new THREE.CubeGeometry( 200, 200, 200 );
    material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );

    mesh = new THREE.Mesh( geometry, material );
    scene.add( mesh );

    renderer = new THREE.CanvasRenderer();
    renderer.setSize( 800, 600 );
    //renderer.setSize( window.innerWidth, window.innerHeight );

    container = document.getElementById("container");
    container.appendChild(renderer.domElement);

    }

    function animate() {

        // Include examples/js/RequestAnimationFrame.js for cross-browser compatibility.
        requestAnimationFrame( animate );
        console.log("animate in action");
        render();

    }

    function render() {

        mesh.rotation.x += 0.01;
        mesh.rotation.y += 0.02;
        console.log("renderer in action");
        renderer.render( scene, camera );

    }

【问题讨论】:

    标签: javascript three.js


    【解决方案1】:

    您正在复制适用于旧版 three.js 的代码。从这里的 three.js zip 存储库下载您的示例:https://github.com/mrdoob/three.js

    有关更新的小提琴,请参阅 jsfiddle.net/GKCx6/142/

    【讨论】:

    • 如果你愿意,你可以分叉你自己的 repo。如果您不想这样做,您可以通过单击“zip”按钮将存储库下载为 zip 文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多