在 Three.js 中动态地将顶点添加到一行 [英] Dynamically Adding Vertices to a Line in Three.js

查看:57
本文介绍了在 Three.js 中动态地将顶点添加到一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出了如何在threejs中画一条线,问题是我需要动态地给这条线添加顶点.当我动态地向线条添加顶点时,场景不会更新.

I figured out how to draw a line in threejs, the problem is that I need to dynamically add vertices to the line. When I add vertices to the line dynamically the scene doesn't update.

我试过 geometry.verticesNeedUpdate = true,但似乎不起作用.

I've tried geometry.verticesNeedUpdate = true, which doesn't seem to work.

推荐答案

使用 BufferGeometrydrawcalls,您现在可以实现等效的功能.请参阅使用three.js动态绘制线条.

Using BufferGeometry and drawcalls you can now implement equivalent functionality. See Drawing a line with three.js dynamically.

three.js r.71

three.js r.71

不支持动态地向线添加顶点.如维基所述:

Dynamically adding vertices to a line is not supported. As stated in the Wiki:

只能更新缓冲区的内容,不能调整缓冲区的大小(这个代价很大,基本上相当于创建新的几何体).

You can only update content of buffers, you cannot resize buffers (this is very costly, basically equivalent to creating new geometry).

您可以通过预先分配更大的缓冲区来模拟调整大小,然后将不需要的顶点折叠/隐藏起来.

You can emulate resizing by pre-allocating a larger buffer and then keeping unneeded vertices collapsed / hidden.

three.js r.55

three.js r.55

这篇关于在 Three.js 中动态地将顶点添加到一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆