godot icon indicating copy to clipboard operation
godot copied to clipboard

Mesh built with SurfaceTool not rendering

Open Jools64 opened this issue 10 months ago • 2 comments

Tested versions

  • Reproducible in v4.4.rc1.official [8ed125b42]
  • Not Reproducible in v4.3.stable.official [77dcf97d8]

System information

Godot v4.4.rc1 - Windows 11 (build 22631) - Multi-window, 1 monitor - OpenGL 3 (Compatibility) - AMD Radeon(TM) Vega 8 Graphics (Advanced Micro Devices, Inc.; 30.0.13044.8001) - AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx (8 threads)

Issue description

Using SurfaceTool to build a mesh that is then applied to a CSGMesh3D and added to the scene renders in 4.3, but not in 4.4r1

In 4.4r1 it does not render at all:

Image

How it used to render in 4.3:

Image

Steps to reproduce

I have used the following code to build a mesh via SurfaceTool and add it as a CSGMesh3D child node:

extends Node3D

func _ready():
	var surface_tool: SurfaceTool = SurfaceTool.new()
	surface_tool.begin(Mesh.PRIMITIVE_TRIANGLES)
	
	surface_tool.add_vertex(Vector3(-1, -1, 0))
	surface_tool.add_vertex(Vector3(-1,  1, 0))
	surface_tool.add_vertex(Vector3( 1, -1, 0))
	
	surface_tool.add_vertex(Vector3( 1, -1, 0))
	surface_tool.add_vertex(Vector3(-1,  1, 0))
	surface_tool.add_vertex(Vector3( 1,  1, 0))
	
	var mesh = CSGMesh3D.new()
	mesh.material = load("res://new_standard_material_3d.tres")
	mesh.mesh = surface_tool.commit()
	add_child(mesh)

Minimal reproduction project (MRP)

surface-mesh-issue.zip

Jools64 avatar Feb 22 '25 17:02 Jools64

Confirmed the observed behavior in 4.3 and 4.4rc1.

This looks like an expected limitation after https://github.com/godotengine/godot/pull/94321. In 4.4, meshes used by CSGMesh3D are expected to be manifold. See https://github.com/godotengine/godot/issues/100014 for previous discussion of using a quad in CSGMesh3D.

For just rendering a quad mesh (or any other non-manifold mesh), you should use a MeshInstance3D, not a CSGMesh3D.

However, it looks like in your case of setting the mesh at runtime, you don't get any useful errors or node configuration warnings like you do when setting a CSGMesh3D in the editor:

Image

Perhaps we need some runtime errors or warnings for non-manifoldness?

CC @fire

tetrapod00 avatar Feb 22 '25 20:02 tetrapod00

Confirmed the observed behavior in 4.3 and 4.4rc1.

This looks like an expected limitation after #94321. In 4.4, meshes used by CSGMesh3D are expected to be manifold. See #100014 for previous discussion of using a quad in CSGMesh3D.

For just rendering a quad mesh (or any other non-manifold mesh), you should use a MeshInstance3D, not a CSGMesh3D.

However, it looks like in your case of setting the mesh at runtime, you don't get any useful errors or node configuration warnings like you do when setting a CSGMesh3D in the editor:

Image

Perhaps we need some runtime errors or warnings for non-manifoldness?

CC @fire

Ah, I see. Thanks for looking into it. I definitely think runtime error would be helpful.

Jools64 avatar Feb 22 '25 20:02 Jools64

This was documented in the migration documentation in https://github.com/godotengine/godot-docs/pull/10546, and there's a warning in the editor, is there anything more that needs to be done here?

AThousandShips avatar Mar 03 '25 17:03 AThousandShips

I wonder if we can fetch node errors at runtime without the error print.

Pretty terrified of per frame spamming csg errors.

fire avatar Mar 03 '25 17:03 fire

This was documented in the migration documentation in godotengine/godot-docs#10546, and there's a warning in the editor, is there anything more that needs to be done here?

Seeing as this is now well-documented and no one else seems to be stumbling on the same thing, I think we can say that there is nothing more that needs to be done and go ahead with closing this.

clayjohn avatar Jul 16 '25 13:07 clayjohn