我正在Uncaught TypeError: undefined is not a function
使用 Three.js。我正在创建THREE.PerspectiveCamera
. 脚本是
window.requestAnimFrame = (function(callback){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 60);
};
})();
function animate(lastTime, angularSpeed, three){
// update
var date = new Date();
var time = date.getTime();
lastTime = time;
// render
three.renderer.render(three.scene, three.camera);
// request new frame
requestAnimFrame(function(){
animate(lastTime, angularSpeed, three);
});
}
$(window).bind('load',function(){
var angularSpeed = 0.2; // revolutions per second
var lastTime = 0;
$container = $("#container");
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
$container.append(renderer.domElement);
// camera - Uncaught Type Error on the below line
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.y = -450;
camera.position.z = 400;
camera.rotation.x = 45 * (Math.PI / 180);
// scene
var scene = new THREE.Scene();
var material = new THREE.LineBasicMaterial({
color: 0x0000ff,
});
var geometry = new THREE.Geometry();
for(var i=0;i<100;i++){
geometry.vertices.push(new THREE.Vector3(i-100,i-100,i-100));
geometry.vertices.push(new THREE.Vector3(i+100,i+100,i+100));
var line = new Three.Line(geometry,material);
scene.add(line);
geometry=new THREE.Geometry();
}
// create wrapper object that contains three.js objects
var three = {
renderer: renderer,
camera: camera,
scene: scene,
};
animate(lastTime, angularSpeed, three);
});
这是因为我声明相机的方式是错误的吗?我检查了three.js 文档和给出的示例基本相同。所以我被困在做什么。
更新:当我遇到最后一个错误时,我正在使用 Three.js 的本地副本。我用链接http://www.html5canvastutorials.com/libraries/Three.js切换了它。现在,PerspectiveCamera 错误消失了,但它在 Three.js 脚本中产生了一个新错误。错误Uncaught TypeError: Cannot read property 'x' of undefined
在 Three.js 脚本的第 337 行
谢谢。