Sending mesh from RayCast3D to MeshDataTool

Godot Version

v4.4.1.stable

Question

Hi all,

Just wondering, how you would go about getting the collision mesh from a raycast collision? I’d like to use it in the mesh data tool.

The RayCast is hitting the StaticBody3D from this model fine.

But I can’t find a way to get the ArrayMesh from the collider to send to the MeshDataTool.

Is there a way to do that?

Thanks,
Pete

You could try using Shape3D.get_debug_mesh() from its CollisionShape3D.shape property

1 Like

Hey thanks!

I just tried this -

            ArrayMesh arrayMesh = collisionShape3D.Shape.GetDebugMesh();
            meshDataTool.CreateFromSurface(arrayMesh, 0);

But I’m getting this error sadly :confused:
surface_get_primitive_type(p_surface) != Mesh::PRIMITIVE_TRIANGLES" is true. Returning: ERR_INVALID_PARAMETER

This prints “Lines”. Maybe the debug collision mesh is stored as something other than a normal mesh.
GD.Print(arrayMesh.SurfaceGetPrimitiveType(0));