godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.07k stars 21.18k forks source link

get_debug_mesh doesn't generate any valid surfaces #95938

Open vaner-org opened 2 months ago

vaner-org commented 2 months ago

Tested versions

Reproducible in 4.3

System information

Godot v4.3.stable - Windows 10.0.19044 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080 (NVIDIA; 32.0.15.6094) - AMD Ryzen 9 5950X 16-Core Processor (32 Threads)

Issue description

CollisionShape3D.get_debug_mesh() seems to generate an ArrayMesh that is only useful as a visual reference, i.e. used as the mesh of a MeshInstance3D. It also seems the only straightforward way to extract collision mesh data from a CollisionShape3D generated from any -col's imported from Blender.

However, it doesn't seem to have any surface data of its own accessible via MeshDataTool, and using SurfaceTool generates nonsensical triangles from the debug ArrayMesh.

debug mesh surfacetool mesh
openseam (DEBUG) 22 Aug 24 1_37_20 PM openseam (DEBUG) 22 Aug 24 1_37_34 PM

Is there a something I'm missing here? Is there a reason why the edges of get_debug_mesh() aren't plainly accessible?

Steps to reproduce

  1. Open project and play
  2. Hit spacebar or left mouse button to see the results of surfacetool overlayed on the results of get_debug_mesh()

Minimal reproduction project (MRP)

debug_mrp.zip

smix8 commented 2 months ago

It generates a line mesh for basic shape debug purposes so it has no faces like a full triangle mesh. You can not directly use a line mesh array to make a triangle mesh with the surface tool as they use different array layouts which is why your surface tool example mesh misses triangles.

A shape does not really hold mesh information like a rendering mesh does. It only has basic convex polygon data everything else is discarded on import. So while going from rendering mesh to collision shape is somehow common and supported going the other way is rare. You can still do it with custom scripts and creating procedural meshes but there is no functionality that does it with a single function call or button press.

Line meshes are preferred for shape debug as they are more performant to render and create less visual clutter, e.g. you usually do not want a character be fully covered by a collision debug that has rendered faces or has artifacts from transparency all over the place.

vaner-org commented 2 months ago

I see! I was intent on using get_debug_mesh for my use case but what I really should have been looking to use is get_faces() for ConcavePolygonShape3D, and rasterizing every other kind of shape into a mesh on a case-by-case basis, since they aren't treated like a standard trimesh by physics or debug to begin with. I had a misunderstanding of how Shape3D worked. Thank you for the information, happy to close this.

Calinou commented 2 months ago

Reopening, as this should be documented in the class reference.