【发布时间】:2014-02-25 18:03:27
【问题描述】:
我正在尝试制作一个简单的应用程序,该应用程序在 node.js 上呈现带有three.js 的立方体,为此我尝试了node-three.js,它基本上包装了three.js,创建了一个模拟浏览器窗口,并公开了三个变量,以便您可以使用它。
问题是我不断收到“TypeError:无法读取未定义的属性'x'”,所以我将其缩小到以下代码:
var THREE = require('three.js');
firstVec = new THREE.Vector3(2,2,2);
secondVec = new THREE.Vector3(1,1,1);
clonedVec = firstVec.clone();
clonedVec.sub(secondVec); //this line is where the error occurs
错误信息是:
undefined:818
this.x = a.x - b.x;
^
TypeError: Cannot read property 'x' of undefined
(据我了解)这表明第二个向量无法被 THREE 模块识别。
任何尝试过这种方法的人:你能让它工作吗?
*为了让它在 Linux 下工作,你应该编辑 /lib/three.js 文件:
应该编辑第 10 行:
, src = fs.readFileSync(__dirname + '/../deps/three.js/build/three.js') //three.js instead of Three.js
【问题讨论】: