我正在尝试制作一个简单的应用程序,在node.js上使用three.js渲染一个立方体,为此我尝试了node-three.js,它基本上包装了three.js,创建了一个模拟的浏览器窗口,并公开了THREE变量,以便您可以使用它。
问题是我一直收到“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