three.js - Three.js r125 BufferGeometry `vertices` 不存在
问题描述
我正在更新 Three.js,我发现当我升级到 r125 时,vertices
由于缺少方法,尝试设置 BufferGeometry 失败。它似乎也已删除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 更新
应用 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
.
该类THREE.Geometry
已被弃用一段时间,但项目存储库之外的一些旧代码和示例仍然引用它。推荐的替代品是THREE.BufferGeometry,它的性能更高。该类BufferGeometry
没有.vertices
属性,因此这可能是您看到的特定错误的原因。相反,您可以像这样更新顶点:
geometry.attributes.position.setXYZ( index, x, y, z );
geometry.attributes.position.needsUpdate = true;
推荐阅读
- java - 在 Fragment 中使用 Kotlin ViewBinding 时出现 NullPointerException
- saxon - Java中的撒克逊扩展函数返回节点
- sql - 加入两列
- restructuredtext - 如何在 reStructuredText 中旋转图像?
- ffmpeg - 在 ffmpeg 中:无法获得 HLS 播放列表文件 10% 容错范围内的峰值比特率值
- ruby-on-rails - DropboxAuthError:获取请求令牌时出错。您的应用密钥和密码设置正确吗?服务器返回 400:错误请求
- java - 线程不会死,其中两个一直重叠
- c++ - Visual Studio 1.38.0 版中的 __gcd 函数
- c# - 如何使用实体框架代码优先方法进行查询、结果分组和选择数据
- php - 使用 php 邮件表单发送 DIV 的内容