Hello, I’ve tried to create a simple waves effect with buffer geometry without success. I have this code working with geometry.
function waves( plane, waveSize, magnitude ){
const theTime = performance.now() * .001 ;
var center = new THREE.Vector2(0,0);
var vLength = plane.geometry.vertices.length;
for (var i = 0; i < vLength; i++) {
var v = plane.geometry.vertices[i];
var dist = new THREE.Vector2(v.x, v.y).sub(center);
v.z = Math.sin(dist.length()/- waveSize + (theTime)) * magnitude;
}
plane.geometry.verticesNeedUpdate = true;
}
I have used as reference the example ‘how to update things’ . I don’t have clear the concept. I tried to put each vector in its position like previous example.
function wavesBuffer( planeBuffer, waveSize, magnitude ){
const theTime = performance.now() * .001 ;
var positions = planeBuffer.geometry.attributes.position.array;
var x, y, z, index;
x = y = z = index = 0;
let center = new THREE.Vector2(0,0);
for ( var i = 0, l = planeBuffer.geometry.attributes.position.array.length; i < l; i ++ ) {
var dist = new THREE.Vector2(x, y).sub(center);
positions[ index ++ ] = x;
positions[ index ++ ] = y;
positions[ index ++ ] = z;
x += dist.x;
y += dist.v;
z += Math.sin( dist.length()/- waveSize + (theTime)) * magnitude;
}
planeBuffer.geometry.attributes.position.needsUpdate = true
}
Does anybody know if is there a basic example of this?
Here a jsfiddle