#Update index buffer for index-geometry hight GPU impact

3 messages · Page 1 of 1 (latest)

gusty basin
#

I’m making a dynamic mesh and need to update vertex position and triangles topology at time (every frame a small part of the buffers is updated, around 5%)
But if i update BufferAttribute that i use for geometry index, i have big impact for GPU. Other buffers are updated faster.
There is a decrease in performance even if I do not change the size of the index buffer.

const geom = new BufferGeometry()
const mesh = new Mesh(geom, new MeshBasicMaterial({
  color: 0xff0000,
  side: DoubleSide,
}))

const positionAttribute = new BufferAttribute(new Float32Array(50000 * 3), 3)
const indexAttribute = new BufferAttribute(new Uint16Array(200000), 1)
positionAttribute.setUsage(DynamicDrawUsage)
indexAttribute.setUsage(DynamicDrawUsage)

geom.setAttribute('position', positionAttribute)
geom.setIndex(indexAttribute)

scene.add(mesh)
geom.setDrawRange(0, 200000)

First variant (works fast):

const updating = () => {
  requestAnimationFrame(updating)
  // indexAttribute.needsUpdate = true
  positionAttribute.needsUpdate = true

}

updating()

Second variant (slow):

const updating = () => {
  requestAnimationFrame(updating)
  indexAttribute.needsUpdate = true
  positionAttribute.needsUpdate = true

}

updating()
#

Should this be the case or am I doing something wrong?

#

if i limit updateRange nothing changes

const updating = () => {
  requestAnimationFrame(updating)
  indexAttribute.updateRange = {
    offset: 0,
    count: 1
  }
  indexAttribute.needsUpdate = true
  positionAttribute.needsUpdate = true
  }
    updating()