8

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.

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).

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.

What am I doing wrong?

lharper71
  • 111
  • 1
  • 6

1 Answers1

9

I assume you are using WebGLRenderer.

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

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • Ah, I hadn't seen that page, thanks. So basically this is unsupported. I can't really pre-allocate buffers in this case, as I don't know in advance how large they would need to be. At this point, I'm removing the mesh from the scene and instantiating a new mesh+geometry on each render, which works but probably isn't very efficient... I'll have to think about a way to pre-allocate in blocks and only re-create the geometry when I pass the pre-allocated buffer sizes, or something. – lharper71 Jul 25 '13 at 22:39
  • Hey -- I'm doing something similar. I'm wondering, did you ever figure this out? Thanks @lharper71! – mostsquares Apr 16 '16 at 18:41
  • 1
    @C.Windolf [This](http://stackoverflow.com/questions/36426139/incrementally-display-three-js-tubegeometry/36439563#36439563) related answer and [this](http://stackoverflow.com/questions/31399856/drawing-a-line-with-three-js-dynamically/31411794#31411794) similar answer may be helpful. – WestLangley Apr 16 '16 at 18:49
  • Thanks @WestLangley! Really helpful answers – mostsquares Apr 17 '16 at 02:19