Is it possible to dynamically add vertices to a geometry?

Hi all,

It seems it’s not possible to add vertices to a geometry after it’s been added to a scene – or am I doing something wrong?
Here is a simple codepen to illustrate my approach.

geometry.vertices.push(new THREE.Vector3(x, y, z));
geometry.verticesNeedUpdate = true;

Some questions on SO seem to suggest that it’s just not possible and you have to use a BufferGeometry (here and here)

However the documentation for Geometry makes it sound like, since they store information directly, they are easier to update than BufferGeometries…? And .verticesNeedUpdate exists, which seems to indicate that, well, vertices can be updated?

What am I missing here? (if Geometries can’t be updated, I can’t think of a scenario where they’d be preferable over BGs?)

Cheers :slight_smile:

Sorry to reply so quickly to my own post – I’m guessing, based on this: https://threejs.org/docs/#manual/introduction/How-to-update-things

that indeed there’s no way to add vertices to a Geometry and I need to use BufferGeometry and set the maximum size beforehand. Oh well.

Seems to be working here. Hmmm

The top line is sprites which do show up, the bottom line is the Geometry and the new vertices don’t appear on my end…

Yep, that’s the correct solution.

4 Likes

Thanks, I’ll do that. :slight_smile: