Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to quickly update a large BufferGeometry?
    primarykey
    data
    text
    <p>I'm using a BufferGeometry to draw thousands of cubes which makes up the terrain, but having a hard time finding out how to update the geometry if I need to change the position of one of the cubes. For example, I have this code to initialize my geometry: (I'm doing my testing on an updated version of <a href="http://alteredqualia.com/three/examples/webgl_cubes.html">this example</a>)</p> <pre><code>// 12 triangles per cube (6 quads) var triangles = 12 * 150000; var geometry = new THREE.BufferGeometry(); geometry.attributes = { position: { itemSize: 3, array: new Float32Array( triangles * 3 * 3 ), numItems: triangles * 3 * 3 }, normal: { itemSize: 3, array: new Float32Array( triangles * 3 * 3 ), numItems: triangles * 3 * 3 }, color: { itemSize: 3, array: new Float32Array( triangles * 3 * 3 ), numItems: triangles * 3 * 3 } } positions = geometry.attributes.position.array; normals = geometry.attributes.normal.array; colors = geometry.attributes.color.array; </code></pre> <p>If I move a cube, it won't appear to be moved until I do: </p> <pre><code>geometry.attributes.position.needsUpdate = true; </code></pre> <p>This causes the FPS to drop while it's being updated. Is there another way I could do this? Seems a bit unnecessary when I'm only changing one cube (12 triangles/36 vertices). Although it might be - I haven't checked what <code>needsUpdate</code> actually does. Guessing it sends the array to the shader again.</p> <p>I was thinking I could split the geometry into separate smaller BufferGeometries but I'm not sure if that would help the performance overall. From what I understand, more geometries = less FPS.</p> <p>If anyone has any ideas how I would do this, it would be appreciated! :) Besides the updating issue, BufferGeometry seems to be exactly what I need. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload