子类THREE.Mesh使用原型继承

时间:2013-01-25 06:19:06

标签: javascript three.js

我正在尝试按下面的THREE.Mesh进行子类化(THREE.Mesh继承自THREE.Object3D)。

Planet = function(geometry, material) {
    THREE.Mesh.call(this);

    this.geometry = geometry;
    this.material = material;
};

Planet.prototype = Object.create(THREE.Mesh.prototype);

当我传入SphereGeometry时似乎工作正常,但boundRadius属性未设置,就像我只使用{{}一样1}}。场景绘制正确。

然而,当我传入THREE.Mesh时,渲染循环变得非常不开心。

CubeGeometry

我模仿了Uncaught TypeError: Cannot read property 'radius' of null three.min.js:105 THREE.Frustum.intersectsObject three.min.js:105 render three.min.js:414 starsgl.Application.render Application.js:60 starsgl.Application.animate Application.js:55 starsgl.Application Application.js:50 (anonymous function) Three.jsTHREE.Object3D子类化的方式。我必须遗漏一些东西。

1 个答案:

答案 0 :(得分:2)

未调用半径,因为未设置几何体。

Planet = function(geometry, material) {
  THREE.Mesh.call(this,geometry,material);
};

Planet.prototype = Object.create(THREE.Mesh.prototype);