在三个js中添加相机

时间:2015-11-15 02:16:22

标签: javascript camera three.js add

我有一个对象caradd相机。如何通过此对象访问相机。我试过这个:

car = {};
car.body = new Physijs.BoxMesh(
    new THREE.BoxGeometry( 10, 5, 7 ),
    Physijs.createMaterial(
        new THREE.MeshLambertMaterial({ color: color }), .8, .2 ), 
    1000 );
var camera = new THREE.PerspectiveCamera(50, window.innerWidth/window.innerHeight, 1, 1000);
var pos = car.body.position;
camera.position.set(pos.x + 75, pos.y + 20, pos.z);
camera.lookAt( pos );
car.body.add(camera);

//...

// other function

var camera = car.body.camera;

但我收到错误THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.

这是否可能,或者我是否必须将相机保存在某个全局变量(数组)中?

1 个答案:

答案 0 :(得分:1)

要在car.body中引用相机 使用:

car.body.camera = camera;

而不是:

car.body.add(camera);