我正在编写一个代码来创建一个平面并通过three.js将对象放在其上 以下是我的代码。 当我尝试运行它时,获取
未捕获的ReferenceError:未定义mythree
为最后一行。
未捕获的SyntaxError:意外的令牌)js / myassn3.js:60
以下是JS代码:
(function (mythree , $, undefined) {
mythree.init = function (hook) {
var checkerBoard = undefined;
var WIDTH = 600,
HEIGHT = 500;
var renderer = new THREE.WebGLRenderer();
renderer.setSize(WIDTH, HEIGHT);
hook.append(renderer.domElement);
// CAMERA SETUP
var VIEW_ANGLE = 65,
ASPECT = WIDTH / HEIGHT,
NEAR = 0.1, // these elements are needed for cameras to
FAR = 10000; // partition space correctly
var camera = new THREE.PerspectiveCamera(
VIEW_ANGLE,
ASPECT,
NEAR,
FAR);
camera.position.z = 300;
var controls = new THREE.TrackballControls(camera);
controls.target.set(0, 0, 0)
// SCENE SETUP
var scene = new THREE.Scene();
scene.add(camera);
// PLAIN SETUP & APPLYING TEXTURE TO IT
var plane = new THREE.Mesh(new THREE.PlaneGeometry(300, 300), material);
plane.overdraw = true;
scene.add(plane);
// TEXTURE SETUP
var texture =THREE.ImageUtils.loadTexture('./images/chessboard.jpg');
var material = new THREE.MeshLambertMaterial({
map: texture
});
var loader = new THREE.JSONLoader();
var pointLight = new THREE.PointLight(0xFFFFFF);
pointLight.position = new THREE.Vector3(-10, 30, 100);
scene.add(pointLight);
for (i = 0; i < 4; i++) {
var a = -130;
loader.load("piece.json", function (geometry) {
mesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({ color: 0x000000 }));
mesh.scale.set(30, 30, 30);
mesh.position = new THREE.Vector3(a, -130, 15);
mesh.rotation.x += 1.5;
a = a + 75;
scene.add(mesh);
});
}
var render = function () {
renderer.render(scene, camera);
controls.update();
requestAnimationFrame(render);
};
render();
window.requestAnimationFrame(renderLoop);
})(window.mythree = window.mythree || {}, jQuery)
有人可以帮忙解决这个问题吗?
答案 0 :(得分:7)
首先:请学习缩进代码。请!
如果您的代码是可读的,或者您只是使用IDE(任何为您计算括号,括号和括号的IDE),则无需向我们寻求帮助。
所以,问题是你的mythree.init
函数定义块缺少右括号(}
)。我不知道你的mythree.init
在哪里结束(只是因为你的代码没有缩进而且真的很混乱),所以自己修复它。