Why are my instances rotated positionned but not scaled here?

What am i missing?

:flushed:

var xPos = -110;
   for ( var count = 0; count < codedInstancedMeshGroup.count; count ++ ) {  
       
       // scale
       var randomScale = (Math.random() * (2.0 - 1.0) + 0.1).toFixed(2);
       codedInstancesMatrix.makeScale( randomScale, randomScale, randomScale );
       
       //rotation
       var tempRotationAngleForMatrix = Math.floor(Math.random()*359+1);
       rx = Math.random().toFixed(2);
       ry = Math.random().toFixed(2);
       rz = Math.random().toFixed(2);
       var tempVector3AxisForMatrix = new THREE.Vector3(rx, ry, rz).normalize();
       codedInstancesMatrix.makeRotationAxis ( tempVector3AxisForMatrix, tempRotationAngleForMatrix);
       
       // position
       xPos = xPos + 50;
       codedInstancesMatrix.setPosition( xPos, 20, 0 );
       
       // update
       codedInstancedMeshGroup.setMatrixAt( count , codedInstancesMatrix );  
   }

note:
I have
codedInstancedMeshGroup.instanceMatrix.setUsage( THREE.DynamicDrawUsage );
also set …

This method will produce a pure rotation matrix and thus overwrite the transformation which was previously set via makeScale().

I suggest you change your code a bit and compute your transformation matrix with a single call of Matrix4.compose(). I have not tested this code but I think it should be:

var xPos = -110;

var scale = new THREE.Vector3();
var position = new THREE.Vector3();
var rotation = new THREE.Quaternion();

for ( var count = 0; count < codedInstancedMeshGroup.count; count ++ ) {  
   
   // scale
   var randomScale = (Math.random() * (2.0 - 1.0) + 0.1).toFixed(2);
   scale.set( randomScale, randomScale, randomScale );
   
   //rotation
   var tempRotationAngleForMatrix = Math.floor(Math.random()*359+1);
   rx = Math.random().toFixed(2);
   ry = Math.random().toFixed(2);
   rz = Math.random().toFixed(2);
   var tempVector3AxisForMatrix = new THREE.Vector3(rx, ry, rz).normalize();
   rotation.setFromAxisAngle(tempVector3AxisForMatrix, tempRotationAngleForMatrix)
   
   // position
   xPos = xPos + 50;
   position.set( xPos, 20, 0 );

   codedInstancesMatrix.compose( position, rotation, scale );
   
   // update
   codedInstancedMeshGroup.setMatrixAt( count , codedInstancesMatrix );  
}
1 Like

You sir, kick arses!

thanks a million!

:slight_smile: :grin:

1 Like