This was quite straightforward on Geometry, but seems v difficult on BufferGeometry. I am trying to animate the vertices on a low budget river and make the surface modulate a bit.
init:
var position = child.geometry.attributes.position;
var v = new THREE.Vector3();
console.log("river verticies:"+position.count);
for ( var i = 0; i<position.count; i ++ ){
v.fromBufferAttribute( position, i );
v.applyMatrix4( child.matrixWorld ); //???
if(0){ //can we check if this is a duplicate?
continue;
}else{
this.river_vertices.push(v);
this.river_waves.push({
y: v.y,
x: v.x,
z: v.z,
ang: 0, //already put random angles into model
amp: this.river_settings.amplitude + (Math.random()*this.river_settings.amplitude),
speed: this.river_settings.speed + (Math.random()*this.river_settings.noise)
});
}
}
update loop:
if(this.river && this.river_waves.length>0){
var v = new THREE.Vector3();
for ( var i=0;i<this.river_waves.length;i++ ){
v.fromBufferAttribute( this.river.geometry.attributes.position, i );
var vprops = this.river_waves[i];
v.x = vprops.x + Math.cos(vprops.ang)*this.river_settings.amplitude;
v.y = vprops.y + Math.sin(vprops.ang)*(this.river_settings.amplitude*1.2);
v.z = vprops.z + Math.sin(vprops.ang)*this.river_settings.amplitude;
vprops.ang += this.river_settings.speed;
this.river.geometry.setAttribute( 'position', new THREE.BufferAttribute( v, 3 ) );
}
this.river.geometry.attributes.position.needsUpdate = true;
}
- The river seems to be gone, assumed to be blasted off-world somewhere. Any idea where I went wrong?
- In blender the river has around 3k vertices however in threejs it says there is around 6k. Is this because of duplicates?