InstancedMesh - Matrix4 resp. dummy Object3D

While completing my beginner example at * with InstancedMesh (// … step 13: instanced mesh), I noticed that in some examples a dummy object is created instead of Matrix4.

const dummy = new THREE.Object3D();

In my simple case is enough

const M4 = new THREE.Matrix4( ); 

for( let instance = 0; instance < slatCount; instance ++ ) {
	slats.setMatrixAt( instance, M4.setPosition( ( instance - slatCount / 2 ) * slatGrid, 0, 0 ) );

If I see it correctly, the reason for the extra object is that not all operations can be realized directly with the Matrix4.

For example there are for the position

.setPosition ( v : Vector3 ) : this
.setPosition ( x : Float, y : Float, z : Float ) : this // optional API

Sets the position component for this matrix from vector v, without affecting the rest of the matrix

but e.g. for rotation only .makeRotationY but no .setRotationY without changing the rest of the matrix?

Would this not be possible or is there some other reason for this :question:

1 Like

Actually, it’s better if users do not work with matrices. Hence the usage of THREE.Object3D. This class provides a proper interface for configuring transformation in 3D space. It would be surely not good to shift this task to Matrix4.

1 Like