Im using @prisoner849 example InstancedMesh and creating a “currentMesh” wrapper with all the instances inside. Its working fantastically except I dont want to animate (positions, quaternions, scale) inside the render loop directly. I would like to use tweens. I cannot seem to get my InstancedMeshes to animate their positions with TWEEN though. I have created a position array that holds the correct positions that I desire, from an Object3D. I then loop through all the meshes and create a tween to map the positions to the Object3D positions with:
currentMesh.geometry.attributes.instancePosition.array
I get the meshes to go to the correct position, scale, rotation, but they dont animate from their 0,0,0 positions to end positions. They just plop right to the positions. I think I’m just using the Tween wrong. Can anyone help? Banging my head on this. I think that this._valuesEnd.x
is also not giving me the incremented positions. Its just giving me the end positions. How do I get the incremented value of this tween? Any help is greatly appreciated!!
Nearly Working Method:
function transformMeshes( duration ) {
TWEEN.removeAll();
let object,
target,
obLen = oObjects.length,
currentMesh = cache[ getKey() ],
index, posX, posY, posZ,
positions = currentMesh.geometry.attributes.instancePosition.array;
for ( let i = 0; i < obLen; i ++ ) {
object = trsCache[ i ];
target = oObjects[ i ];
posX = posY = posZ = index = 0;
// positions[ index++ ] = posX;
// positions[ index++ ] = posY;
// positions[ index++ ] = posZ;
currentMesh.setQuaternionAt( i , target.quaternion.setFromEuler( target.rotation) );
currentMesh.setScaleAt( i , target.scale );
new TWEEN.Tween( object.position )
.to({ x: target.position.x, y: target.position.y, z: target.position.z }, 3000 )
.onUpdate( function () {
positions[ index++ ] = this._valuesEnd.x;
positions[ index++ ] = this._valuesEnd.y;
positions[ index++ ] = this._valuesEnd.z;
currentMesh.geometry.attributes.position.needsUpdate = true;
}).start();
}
currentMesh.needsUpdate( 'quaternion' );
currentMesh.needsUpdate( 'position' );
currentMesh.needsUpdate( 'scale' );
new TWEEN.Tween( this )
.to( {}, duration )
.onUpdate( render )
.start();
}