渲染后将几何图形添加到 three.js 网格 [英] Adding geometry to a three.js mesh after render

查看:29
本文介绍了渲染后将几何图形添加到 three.js 网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 THREE.Geometry 实例创建一个网格,然后动态填充几何的 verticesfaces 数组.几何图形被迭代细化,在每次迭代中添加额外的顶点和面.如果我在将网格添加到场景之前优化几何,它会正确渲染.但是,如果我将网格添加到场景中并对其进行渲染,然后对其进行修改,则只会显示第一次渲染中包含的几何图形的初始 N 个面.对这些面使用的顶点位置的更改会生效,但只会渲染这 N 个面.

I'm creating a mesh with a THREE.Geometry instance, then populating the geometry's vertices and faces arrays dynamically. The geometry is iteratively refined, adding additional vertices and faces at each iteration. If I refine the geometry before adding the mesh to the scene, it renders correctly. However, if I add the mesh to the scene and render it, then modify it, only the initial N faces the geometry contained on first render are shown. Changes to the position of the vertices used by those faces are honored, but only those N faces are rendered.

几何实例标记为dynamic = true,我每次设置verticesNeedUpdateelementsNeedUpdatebuffersNeedUpdate修改几何后.我也尝试过设置所有其他脏"标志,尽管我只希望设置这三个(即使这样,我也不确定是否需要 buffersNeedUpdate).

The geometry instance is marked dynamic = true, and I set verticesNeedUpdate, elementsNeedUpdate and buffersNeedUpdate each time after modifying the geometry. I've also tried setting all the other 'dirty' flags, though I only expect to need to set those three (and even then, I'm not certain I should need buffersNeedUpdate).

据我所见,几何的 geometryGroupgeometryGroupList 属性正在构建并从首次渲染网格时存在的面填充,但不是正在重建以包括随后添加的面.

As far as I can see, the geometry's geometryGroup and geometryGroupList properties are being built and populated from the faces that exist when the mesh is first rendered, but are not being rebuilt to include the faces added subsequently.

我做错了什么?

推荐答案

我假设你使用的是 WebGLRenderer.

正如three.js wiki文章如何更新事物中所述,您只能更新缓冲区的内容,您不能调整缓冲区的大小.

As stated in the three.js wiki article How to Update Things, you can only update the content of buffers, you cannot resize buffers.

three.js r.59

three.js r.59

这篇关于渲染后将几何图形添加到 three.js 网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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