Three.js 中的 verticesNeedUpdate [英] verticesNeedUpdate in Three.js
问题描述
我想使用 dat.GUI 来操作网格顶点的坐标.
I want to use dat.GUI to manipulate the coordinates of a mesh vertices.
起初我以为我可以删除我的网格的每一帧来重新创建它们,但后来我看到了 此处 这不是一个好方法.
At first I thought I could have removed every frame my meshes to recreate them anew, but then I saw here that it's not a good way.
我应该使用 verticesNeedUpdate 吗?Three.js文档上好像没有
Is verticesNeedUpdate that I should use? It seems not to be on Three.js documentation
推荐答案
如果您的几何图形是 THREE.Geometry
,那么您可以使用这样的模式更新顶点:
If your geometry is THREE.Geometry
, then your can update the vertices by using a pattern like so:
geometry.vertices[ 0 ].set( x, y, z );
geometry.verticesNeedUpdate = true;
如果你的几何是THREE.BufferGeometry
,那么你可以使用这个模式:
If your geometry is THREE.BufferGeometry
, then you can use this pattern:
geometry.attributes.position.setXYZ( index, x, y, z );
geometry.attributes.position.needsUpdate = true;
在任何一种情况下,如果几何体之前已经渲染过,您只需要设置 needsUpdate
标志.
In either case, you only need to set the needsUpdate
flag if the geometry has been previously-rendered.
此外,您不能调整缓冲区大小;您只能更改数据值.有关其他信息,请参阅 Wiki 文章如何更新事物.
Also, you cannot resize buffers; you can only change the data values. See the Wiki article How to Update Things for additional information.
three.js r.85
three.js r.85
这篇关于Three.js 中的 verticesNeedUpdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!