0

I have a 3d Grid (sparse octree) where each leaf (deepest node) stores a 3d point with color. I would like to convert the whole octree to a linear array of 3d points (vertex buffer), which can be uploaded to OpenGL directly.

In a naiive way, I can just iterate through all the nodes of the octree and fill the linear array.

Now, the issue I faced is that when I add new 3d points to the sparse octree and would like to update the vertex buffer, I have to iterate over the complete octree in order to get the data into OpenGL.

Does anyone have an idea how to avoid the full iteration when only a few points have been updated/added?

The only approach I can think of is to remember which elements in the octree have been added and append them to the vertex buffer array directly. this would work better, but would not work when I delete an element from the octree.

I use c++.

mojovski
  • 581
  • 7
  • 21

1 Answers1

0

Maybe you can keep an index (its position in your vertex buffer) inside the sample. This would allow you to remove the sample from your array when you remove it from your octree.

So the whole algorithm would proceed as follow:

vertex_array

  • Insert(point, sample)

    • sample.idx = vertex_array.push(point)
    • InsertToOctree(point, sample)
  • Remove(sample)

    • RemoveFromOctree(sample)
    • vertex_array.remove(sample.idx)
Seb Maire
  • 132
  • 8