How do I extract instancedMesh rotations, to increment them, and update them once done?

This is what I have figured out so far (i can move the instances, that works)
but i’m stumped at getting the instances to rotate continuously (say) on the X axis?

Any help appreciated !

    whatToAnimate = scene.getObjectByName("loadedInstancedMeshGroup");
    for ( var m = 0; m < whatToAnimate.count; m ++ ) {
        loadedInstancedMeshGroup.getMatrixAt( m, loadedInstancesMatrix );
        
        // extract position from instancedMeshGroupMatrix
        vector3PositionFromMatrix.setFromMatrixPosition( loadedInstancesMatrix );
        // change the z position
        vector3PositionFromMatrix.z =  vector3PositionFromMatrix.z + 0.1;
        // write the new positon back
        loadedInstancesMatrix.setPosition( vector3PositionFromMatrix ); 
        finalPosition = vector3PositionFromMatrix;
        
        // extract rotation from instancedMeshGroupMatrix ?
        
        // increment the rotation ? (any would do, just to show me one example)
        
        // write the rotation back ?
        
        whatToAnimate.setMatrixAt( m, loadedInstancesMatrix );
        whatToAnimate.instanceMatrix.needsUpdate = true;
    }

Hi!
I used .decompose() method and a dummy object here: Hexagonal grid formation
Look for the line mat4.decompose(dummy.position, dummy.quaternion, dummy.scale); in both codepens from that topic.

1 Like

Hi prisoner849, thanks for lending a hand!

I’ve looked at the code you pointed me at, I understand at least one thing from that, then i’m more confused than I was:

1.extract rotation from instancedMeshGroupMatrix ?
ok using decompose I get a 4 rotation values (x,y,z,w) from the dummy.quaternion
2.increment one…(wait which one and how?) of the dummy.rotation quaternion ( so that the instances rotate continuously on the x axis as this “for loop” is in my animate() function, so it does that continously)
… errr… :astonished:
3.overwrite the matrix rotation value using this dummy.rotation (i guess?) in the instancedMeshGroupMatrix
… double errrr… :astonished:

Here is a simplified example: https://jsfiddle.net/prisoner849/L9sr46d2/

изображение

1 Like