【问题标题】:combining node.js and three.js on server side在服务器端结合 node.js 和 three.js
【发布时间】: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

【问题讨论】:

    标签: node.js three.js


    【解决方案1】:

    使用three.js 的原始实现解决。首先是你:
    npm install three
    然后替换:
    var THREE = require('three.js');
    与:
    var THREE = require('three');

    【讨论】:

      猜你喜欢
      • 2018-01-12
      • 2021-07-30
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多