- Edited
I'm using ArrayMesh in hopes of generating some procedural geometry, but right now it looks like this:
I would prefer that it look something like this:
In case you're wondering, that's from Sebastian Lague's fantastic video on Marching Cubes.
I would like to have sharper edge shadows so I can more accurately see where the geometry is once I have something more complex. I know I'm still learning to use ArrayMesh properly, but here's my code:
extends MeshInstance
var vertices = PoolVector3Array()
var uvs = PoolVector2Array()
var normals = PoolVector3Array()
var indices = PoolIntArray()
func add_triangle(Vone, Vtwo, Vthree):
vertices.push_back(Vone)
normals.append(Vone)
vertices.push_back(Vtwo)
normals.append(Vtwo)
vertices.push_back(Vthree)
normals.append(Vthree)
func _ready():
add_triangle(Vector3(-1,0,1), Vector3(0,1,0), Vector3(1,0,1))
add_triangle(Vector3(1,0,1), Vector3(0,1,0), Vector3(1,0,-1))
add_triangle(Vector3(1,0,-1), Vector3(0,1,0), Vector3(-1,0,-1))
add_triangle(Vector3(-1,0,-1), Vector3(0,1,0), Vector3(-1,0,1))
add_triangle(Vector3(-1,0,1), Vector3(1,0,1), Vector3(0,-1,0))
add_triangle(Vector3(1,0,1), Vector3(1,0,-1), Vector3(0,-1,0))
add_triangle(Vector3(1,0,-1), Vector3(-1,0,-1), Vector3(0,-1,0))
add_triangle(Vector3(-1,0,-1), Vector3(-1,0,1), Vector3(0,-1,0))
var tmpMesh = ArrayMesh.new()
var arrays = Array()
arrays.resize(ArrayMesh.ARRAY_MAX)
arrays[ArrayMesh.ARRAY_NORMAL] = normals
arrays[ArrayMesh.ARRAY_VERTEX] = vertices
tmpMesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
mesh = tmpMesh