0 votes

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?

in Engine by (141 points)

1 Answer

+1 vote

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.new()
    multimesh.transform_format = MultiMesh.TRANSFORM_3D
    multimesh.mesh = SphereMesh.new()
    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).

by (141 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.