Godot Version
4.2.1
Question
Hi, I’m trying to make a MultiMeshInstance3D with gdscript but I don’t get how it works. Nothing is displaying. What is wrong with my code ?
4.2.1
Hi, I’m trying to make a MultiMeshInstance3D with gdscript but I don’t get how it works. Nothing is displaying. What is wrong with my code ?
Did you red the docs?
I think you need to set the positions of the instances like
# Create the multimesh.
multimesh = MultiMesh.new()
# Set the format first.
multimesh.transform_format = MultiMesh.TRANSFORM_3D
# Then resize (otherwise, changing the format is not allowed).
multimesh.instance_count = 10000
# Maybe not all of them should be visible at first.
multimesh.visible_instance_count = 1000
# Set the transform of the instances.
for i in multimesh.visible_instance_count:
multimesh.set_instance_transform(i, Transform3D(Basis(), Vector3(i * 20, 0, 0)))
(from the docs)
Yes, i already tried that and also read all the docs and tutorials I could find but stil no success
Have you set any size to the boxmesh?
(Don’t know if it’s needed - just throwing ideas)
And also as mentioned byTitusio you need to go through your instance count to set transform indexes so it knows where to place the mesh.
My code looks like this now, but nothing changed And it seems the default for boxmesh is a size of 1 when no value is specified (But I still tried).
Because you delete the rendering instance with an invalid set_base()
call that is not needed here.
That function is inherited from VisualInstance3D.set_base() and used to set the RID of a RenderingServer instance to the node, in this case the instance of a multimesh object. If you set it with an invalid parameter like here with the self
Node you set it to null and without an instance nothing will render.
Everything else like to set the transform for each instance was already mentioned by others or is part of the documentation script example.
From lookin in some working code with multimesh instance i can see that i dont set_base.
I also set owner, tho that should only be about showing it in editor and binding it to the scene
private void CreateMultiArray()
{
MultiMesh _MultiMesh = new()
{
TransformFormat = MultiMesh.TransformFormatEnum.Transform3D,
Mesh = _ModelInstance.Mesh,
InstanceCount = _Amount,
};
MultiMeshInstance3D _MultiMeshInstance = new()
{
Multimesh = _MultiMesh
};
List<Vector3> positions = new List<Vector3>();
for( int i = 0; i < _Amount; i++)
{
Transform3D Trans = _ModelInstance.Transform;
float ExtraOffsetX = 0;
float ExtraOffsetY = 0;
float ExtraOffsetZ = 0;
if( OffsetBySize )
{
Aabb ModelAabb = _ModelInstance.GetAabb();
if( OffsetByXAngle )
{
ExtraOffsetX += ModelAabb.Size.X;
}
if( OffsetByZAngle )
{
ExtraOffsetZ += ModelAabb.Size.Z;
}
}
Trans.Origin.X = ( OffsetX * i) + ( ExtraOffsetX * i ) + Trans.Origin.X;
Trans.Origin.Y = ( OffsetY * i) + ( ExtraOffsetY * i ) + Trans.Origin.Y;
Trans.Origin.Z = ( OffsetZ * i) + ( ExtraOffsetZ * i ) + Trans.Origin.Z;
_MultiMesh.SetInstanceTransform(i, Trans);
positions.Add(Trans.Origin);
}
AddChild(_MultiMeshInstance);
_MultiMeshInstance.Owner = GetTree().EditedSceneRoot;
_MultiMeshInstance.Name = _ModelInstance.Name + "/multiMesh";
if( ShouldAddCollision() && _NoCollisions == false || _ForceCollisions )
{
Aabb _aabb = _ASMesh.GetAabb();
_AddMultiCollisions(_MultiMeshInstance, positions, _aabb);
}
Randomnize();
}
Thank you, this was the problem !
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.