我正在尝试对 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
属性未设置,就像我那样我们只使用了 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.js
使用 THREE.Mesh
子类化 THREE.Object3D
的方式。但我一定错过了一些东西。
最佳答案
由于未设置几何图形,因此未调用半径。
Planet = function(geometry, material) {
THREE.Mesh.call(this,geometry,material);
};
Planet.prototype = Object.create(THREE.Mesh.prototype);
关于javascript - 使用原型(prototype)继承子类 THREE.Mesh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14516425/