我正在更新Three.js,我发现当我升级到r125时,由于缺少方法,尝试在BufferGeometry上设置vertices
失败。它似乎也删除了verticesNeedUpdate
。迁移指南似乎没有对此发出警告,从我所看到的情况来看,变更日志似乎也没有解决这个问题。
不幸的是,我没有写原始代码,所以我不确定如何解决它。代码看起来像这样:
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's Answer更新
在应用了唐建议的更改后,我们最终得到了这个:
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;
three.js r125的第一个变更日志条目是相关的:
几何体已从核心中删除。它现在位于
examples/jsm/deprecated/Geometry.js
。
THREE.Geometry
类已经被弃用一段时间了,但项目存储库之外的一些旧代码和示例仍然引用它。建议替换为THREE。BufferGeometry,性能更高。BufferGeometry
类没有.vertices
属性,所以这可能是您看到的特定错误的原因。相反,您可以更新如下顶点:
geometry.attributes.position.setXYZ( index, x, y, z );
geometry.attributes.position.needsUpdate = true;