我正在更新 Three.js,我发现当我升级到 r125 时,尝试设置vertices
由于缺少方法,BufferGeometry 失败。似乎也已删除verticesNeedUpdate
. The 迁移指南似乎没有对此发出警告并且变更日志据我所知,似乎没有解决这个问题。
不幸的是,我没有编写原始代码,所以我不确定如何解决它。代码如下所示:
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 建议的更改后,我们得到以下结果:
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
.
The THREE.Geometry
类已被弃用一段时间,但项目存储库之外的一些旧代码和示例仍然引用它。推荐的替代品是三.BufferGeometry,性能更高。这BufferGeometry
类没有.vertices
属性,因此这可能是您看到的特定错误的原因。相反,您可以像这样更新顶点:
geometry.attributes.position.setXYZ( index, x, y, z );
geometry.attributes.position.needsUpdate = true;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)