How to scale instances in a multimesh? Is it possible?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By toblin

I want to have a MultiMesh with sphere as instances. For reasons explained here, it seems better for my application to scale the spheres rather than changing their radii. Since all instances are intended to be spheres, the only difference being their 3D position and their radius, I’m wondering if it is possible to scale mesh instances in a multimesh.

So, as the headline reads: how do I (differently) scale mesh instances of a multimesh? Is it possible?

:bust_in_silhouette: Reply From: toblin

Ok, so I found the anwer. You can scale the multimesh instances by setting their transforms. So if you have a MultiMeshInstance added to the node tree with the following script attached to it:

extends MultiMeshInstance

func _ready():
	multimesh =
	multimesh.transform_format = MultiMesh.TRANSFORM_3D
	multimesh.mesh =
	multimesh.instance_count = 10
	multimesh.visible_instance_count = 4
	multimesh.set_instance_transform(1, Transform(Basis(), Vector3(5,0,0)) )
	multimesh.set_instance_transform(2, Transform(Basis(), Vector3(-5,0,0)) )
	multimesh.set_instance_transform(3, Transform(Basis(), Vector3(0,0,0)) )
	multimesh.set_instance_transform(0, Transform(Basis(), Vector3(0,5,0)) )

You can scale one of the instances, for example instance 3, by changing its Transform Basis, like this:

multimesh.set_instance_transform(3, Transform( Vector3(0.5,0,0), Vector3(0,0.5,0), Vector3(0,0,0.5), Vector3(0,0,0)))

which would scale instance 3 by 0.5 in all axes directions (x,y,z).