2

I'm having a little issue here. I have a THREE.Line object, with a material and a geometry. The init method pushes 2 vertices to the geometry, add the Line to the scene, the line is rendered just fine.

But I have an event listener... Every click in the canvas will add another vertex. But when the scene is rendered, only the original 2 vertices are rendered. I've output a dump of scene.children and I'm sure that the Line is in the scene, and the geometry has changed.

In the documentation it says something about applying:

geometry.dynamic = true
geometry.verticesNeedUpdate = true 

But these didn't work either.

nickhar
  • 19,981
  • 12
  • 60
  • 73
Leprosy
  • 1,085
  • 4
  • 14
  • 36
  • Have you tried rerunning any of the `compute` methods? http://mrdoob.github.com/three.js/docs/52/#Reference/Core/Geometry – Chad Nov 07 '12 at 14:45

1 Answers1

4

See the three.js Wiki: https://github.com/mrdoob/three.js/wiki/Updates

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 larger buffer and then keeping unneeded vertices collapsed / hidden.

Geometries are specified via vertex buffer objects, which have fixed sizes. You can create and delete buffers, but you cannot resize them.

As a workaround, you could create a geometry with extra vertices and collapse the unwanted ones into a single point.

three.js r.52


EDIT: A newer approach is described in Drawing a line with three.js dynamically.

Community
  • 1
  • 1
WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • What the heck. Does the size of a buffer = the number of points it has? how is size of buffer relevant here? – Jack Franzen Apr 25 '13 at 16:43
  • What's the best way to keep unneeded vertices collapsed / hidden? Since vertices don't have individual `visible` properties, nor individual alpha coloring, do they just need to be strategically positioned over another vertex? – Toph Feb 03 '14 at 20:14
  • A more elegant solution is there with r72 now - http://stackoverflow.com/a/31411794/1027058 – Agniva De Sarker Oct 22 '15 at 08:48