0

我正在使用以下代码,并且已经浏览了帖子,当然还有所有的 wiki 等等。无论我使用什么 .js JSON 对象,浏览器窗口中都不会出现任何内容。浏览器控制台中没有任何标志,我准备在本地运行。缺少什么/做错了什么?

<body>

    <script src="http://threejs.org/build/three.js"></script>
    <script>

        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);

        var geometry;

        var renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);

        var material = new THREE.MeshBasicMaterial({color: 0x00ff00});

        loader = new THREE.JSONLoader();

        loader.load( "LeePerrySmith.js", function( geometry ) {

            mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial() );
            mesh.scale.set( 10, 10, 10 );
            mesh.position.y = 0;
            mesh.position.x = 0;
            mesh.scale.set( 100, 100, 100 );
            scene.add( mesh );
            mesh.side = THREE.DoubleSide;
            alert("hit");

            } );


        camera.position.z = 5;

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

        render();

    </script>
</body>


新代码

<script src="http://threejs.org/build/three.js"></script>
<script>

    var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);

    var geometry;

    var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
    var mesh = new THREE.Mesh( geometry, material );

    loader = new THREE.JSONLoader();

    loader.load( "LeePerrySmith.js", function( geometry ) {

        mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial() );
        mesh.scale.set( 10, 10, 10 );
        mesh.position.y = 0;
        mesh.position.x = 0;
        mesh.scale.set( 100, 100, 100 );
        scene.add( mesh );
        mesh.side = THREE.DoubleSide;
        alert("hit");
        render();

        } );


    camera.position.z = 1000;

    var renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

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



</script>

4

1 回答 1

1

加载是异步的。这就是为什么你有一个回调函数。您render()在模型加载之前调用。

  1. 移动render()到回调函数的最后一行。或者做大多数用户做的事情并添加一个动画循环。

  2. 将您的相机移回 z = 1000。它可能在模型内部。

  3. 您没有使用原始的红色材料。这样做:`var mesh = new THREE.Mesh(geometry, material);

  4. side是 的属性material,而不是mesh: set mesh.material.side = THREE.DoubleSide,如果您觉得需要的话。

于 2013-09-13T14:33:29.390 回答