我正在更新Three.js,我发现当我升级到r125时,由于缺少方法,试图在BufferGeometry上设置vertices失败了。它似乎还删除了verticesNeedUpdate。迁移指南似乎没有对此发出警告,而变化量g似乎没有从我所能看到的范围内解决这个问题。
不幸的是,我没有编写原始代码,所以我不知道如何解决它。代码如下所示:
this.geometry.vertices[0].x = this.geometry.vertices[2].x = -this.canvas.width / 2;
this.geometry.vertices[1].x = this.geometry.vertices[3].x = this.canvas.width / 2;
this.geometry.vertices[0].y = this.geometry.vertices[1].y = this.canvas.height / 2;
this.geometry.vertices[2].y = this.geometry.vertices[3].y = -this.canvas.height / 2;
this.geometry.verticesNeedUpdate = true;使用Don的以下答案进行更新
在应用Don的建议更改后,我们最终得出如下结论:
const negativeWidth = -this.canvas.width / 2;
const positiveWidth = this.canvas.width / 2;
const positiveHeight = this.canvas.height / 2;
const negativeHeight = -this.canvas.height / 2;
this.geometry.attributes.position.setXY(0, negativeWidth, positiveHeight);
this.geometry.attributes.position.setXY(1, positiveWidth, positiveHeight);
this.geometry.attributes.position.setXY(2, negativeWidth, negativeHeight);
this.geometry.attributes.position.setXY(3, positiveWidth, negativeHeight);
this.geometry.attributes.position.needsUpdate = true;发布于 2021-03-30 16:20:00
three.js r125的第一个changelog条目是相关的:
几何学已从核中移除。它现在位于
examples/jsm/deprecated/Geometry.js。
THREE.Geometry类已经被废弃了一段时间,但是项目存储库之外的一些旧代码和示例仍然引用它。推荐的替代方法是THREE.BufferGeometry,它具有更好的性能。BufferGeometry类没有.vertices属性,所以这可能是您所看到的特定错误的原因。相反,您可以这样更新顶点:
geometry.attributes.position.setXYZ( index, x, y, z );
geometry.attributes.position.needsUpdate = true;https://stackoverflow.com/questions/66874065
复制相似问题