I'm trying to create a dynamic mesh using ArrayMesh but my mesh isn't visible unless I turn on wireframe debug mode. Here is a minimal example of a plane mesh consisting of 2 triangles (this script is currently placed on a Spatial node):
func _ready():
# With these two lines added I can see the wireframe of the mesh (picture below) otherwise I see nothing.
VisualServer.set_debug_generate_wireframes(true)
get_viewport().set_debug_draw(Viewport.DEBUG_DRAW_WIREFRAME)
var ve : PoolVector3Array = PoolVector3Array()
ve.push_back(Vector3(0, 0, 0))
ve.push_back(Vector3(10, 0, 0))
ve.push_back(Vector3(0, 0, 10))
ve.push_back(Vector3(10, 0, 10))
var uv: PoolVector2Array = PoolVector2Array()
uv.push_back(Vector2(0, 0))
uv.push_back(Vector2(1, 0))
uv.push_back(Vector2(0, 1))
uv.push_back(Vector2(1, 1))
var co : PoolColorArray = PoolColorArray()
co.push_back(Color(1, 1, 1))
co.push_back(Color(1, 1, 1))
co.push_back(Color(1, 1, 1))
co.push_back(Color(1, 1, 1))
var id: PoolIntArray = PoolIntArray()
id.push_back(0)
id.push_back(2)
id.push_back(1)
id.push_back(1)
id.push_back(2)
id.push_back(3)
var no: PoolVector3Array = PoolVector3Array()
no.push_back(Vector3(0, 1, 0))
no.push_back(Vector3(0, 1, 0))
no.push_back(Vector3(0, 1, 0))
no.push_back(Vector3(0, 1, 0))
var array_mesh = ArrayMesh.new()
var arrays = []
arrays.resize(ArrayMesh.ARRAY_MAX)
arrays[ArrayMesh.ARRAY_VERTEX] = ve
arrays[ArrayMesh.ARRAY_COLOR] = co
arrays[ArrayMesh.ARRAY_INDEX] = id
arrays[ArrayMesh.ARRAY_NORMAL] = no
arrays[ArrayMesh.ARRAY_TEX_UV] = uv
var m_i = MeshInstance.new()
array_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
m_i.mesh = array_mesh
add_child(m_i)
Now with wireframe debug mode on I see the following:
Otherwise, I can't see anything. If I add an albedo_color
to the material_override
then the lines will change to be that color. I'm pretty new into procedural generation but I've found that a similar thing will work in Unity so I'm not sure what I'm missing here.