OK so let’s say I create a Points object with 10,000 points:
this.positions = new Float32Array(this.total * 3);
this.colors = new Float32Array(this.total * 4);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(this.positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(this.colors, 4));
geometry.computeBoundingSphere();
this.points = new THREE.Points(geometry, material);
this.container.add(this.points);
I have an animation loop…
animate: function() {
if(!this.points && !this.points.geometry)
return;
for(let i = 0; i < Particles.total; i++) {
//do work here
}
this.points.geometry.getAttribute('position').needsUpdate = true;
this.points.geometry.getAttribute('color').needsUpdate = true;
}
In general, what is the fastest and most performant way to constantly get each point’s position data? I’ve seen three different ways:
I could use fromBufferAttribute…
const vertex = new THREE.Vector3();
vertex.fromBufferAttribute(Particles.points.geometry.attributes.position, i);
I could refer back to my Float32Array which I’m already storing…
i *= 3;
const x = this.positions[i];
const y = this.positions[i + 1];
const z = this.positions[i + 2];
return new THREE.Vector3(x,y,z);
I could also do this…
var vertex = Particles.points.geometry.vertices[i];
All three seem so similar. But are they exactly the same? Is one faster than the other? Considering I’ll be doing this on ~10,000 points every animation frame, what’s the most performant way?