【问题标题】:Constructor issues with threejs npm and Browserifythreejs npm 和 Browserify 的构造函数问题
【发布时间】:2016-08-30 08:39:11
【问题描述】:

我似乎无法使用 threejs npm build 和 browserify 实例化 THREEjs 对象。

var THREE = require("three-js");
var camera = new THREE.PerspectiveCamera( 75, 1, 20, 2250 );

这会引发错误

bundle.js:24 Uncaught TypeError: THREE.PerspectiveCamera is not a constructor

可以看到bundle.js中存在构造函数

    THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {

    THREE.Camera.call( this );

    this.type = 'PerspectiveCamera';

    this.fov = fov !== undefined ? fov : 50;
    this.zoom = 1;

    this.near = near !== undefined ? near : 0.1;
    this.far = far !== undefined ? far : 2000;
    this.focus = 10;

    this.aspect = aspect !== undefined ? aspect : 1;
    this.view = null;

    this.filmGauge = 35;    // width of the film (default in millimeters)
    this.filmOffset = 0;    // horizontal film offset (same unit as gauge)

    this.updateProjectionMatrix();

};

当我从工作版本中移植这段代码时,我怀疑我可能在 Browserify 上做错了什么。

npm Threejs 构建版本 79

【问题讨论】:

    标签: constructor npm three.js browserify


    【解决方案1】:

    问题是没有正确构造三js对象。来自https://www.npmjs.com/package/three-js

    var THREE = require("three-js")();
    

    我的示例中缺少额外的括号。

    仅供参考:要让插件正常工作,请使用此结构

    var oc = require("three-js/addons/OrbitControls");
    var anotherAddon = require("three-js/addons/anotherAddon");
    var THREE = require('three-js')([oc,anotherAddon]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 1970-01-01
      • 2011-08-23
      • 2021-04-05
      相关资源
      最近更新 更多