ThreeJS ObjectLoader-无法读取未定义的属性'fog'

时间:2014-12-03 00:42:53

标签: javascript three.js

我正在使用ThreeJS来加载这样的场景:

$(document).ready(function(){
    var scene = new THREE.ObjectLoader().load("scene.js");
    var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
    var renderer = new THREE.WebGLRenderer();
    var fly = new THREE.OrbitControls(camera);
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );

   var gui = new dat.GUI();
gui.add(controls, 'rotationSpeed',0,100);
    camera.position.z = 5;
    camera.position.z = 32;
    function render() {
        requestAnimationFrame( render );
        renderer.render( scene, camera );
    }
    render();
});
    var controls = new function() {
            this.rotationSpeed = 0.02;
            this.bouncingSpeed = 0.03;
    };

这里是场景(从ThreeJS编辑器导出):http://www.codepixl.net/experiments/threejs/scene.js
但是当我尝试加载场景时:它反复抛出无法读取属性'雾'的未定义和未定义对我来说不是一个函数。发生了什么?会发生什么:

1 个答案:

答案 0 :(得分:1)

load()是异步的。 它不是返回值,而是将结果传递给回调。尝试这样的事情:

var loader = new ObjectLoader();
loader.load('scene.js', function(object) {
    scene.add(object); // load the object into your scene here
});