gpt4 book ai didi

javascript - 使用原型(prototype)继承的子类 THREE.Mesh

转载 作者:行者123 更新时间:2023-11-29 22:17:05 25 4
gpt4 key购买 nike

我正在尝试子类化 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com