Godot Version
4.2.2
Question
I was following a tutorial on generating meshes from an array, and while the tutorial works I’m still trying to understand the code line by line. The one part I don’t really understand is the use of the enum ARRAY_MAX, I’ve looked at the docs and don’t really understand what I’m suppose to take away here.
Here’s the code.
@tool
extends MeshInstance3D
# Called when the node enters the scene tree for the first time.
func _ready():
gen_mesh()
func gen_mesh():
var a_mesh = ArrayMesh.new()
var vertices = PackedVector3Array(
[
Vector3(1,0,1),
Vector3(1,0,0),
Vector3(0,0,0),
Vector3(0,0,1),
]
)
var indices = PackedInt32Array(
[
0,1,2,
2,3,0
]
)
var array = []
array.resize(Mesh.ARRAY_MAX)
array[Mesh.ARRAY_VERTEX] = vertices
array[Mesh.ARRAY_INDEX] = indices
a_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, array)
mesh = a_mesh
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
Also here’s the video that I was watching