Why does my cube look... wrong? (surface_tool)

Godot Version

v4.2.2.stable.official [15073afe3]

Question

So, I’m trying to use surfacetool to build a cube and can’t get it to look… normal. Its using the default material with culling disable, whats going on here?

func _ready():
	var surface_tool = SurfaceTool.new()
	surface_tool.begin(Mesh.PRIMITIVE_TRIANGLES)

	# Define the vertices of the cube
	var vertices = [
		Vector3(-1, -1, -1), Vector3(1, -1, -1), Vector3(1, 1, -1), Vector3(-1, 1, -1),  # Back face
		Vector3(-1, -1, 1), Vector3(1, -1, 1), Vector3(1, 1, 1), Vector3(-1, 1, 1)   # Front face
	]

	# Define the indices for the triangles
	var indices = [
		0, 1, 2, 0, 2, 3,  # Back face
		4, 5, 6, 4, 6, 7,  # Front face
		0, 3, 7, 0, 7, 4,  # Left face
		1, 5, 6, 1, 6, 2,  # Right face
		3, 2, 6, 3, 6, 7,  # Top face
		0, 4, 5, 0, 5, 1   # Bottom face
	]

	# Add vertices and indices to the SurfaceTool
	for i in indices:
		surface_tool.add_vertex(vertices[i])

	# Optionally, you can add normals and UVs here if needed
	# For simplicity, we will skip adding normals and UVs in this example

	# Commit the mesh
	var mesh = surface_tool.commit()
	
	# Create a MeshInstance and assign the mesh
	$"MeshInstance3D".mesh = mesh

You probably need to add normals.

If you don’t want to manually set them, you can call generate_normals() before commiting.

I just added that, Now it looks weird but different


I figured it out, you have to add surface_tool.set_smooth_group(-1) before you add the verts, cool beans

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.