Godot Version
V4.2.2
Hello everyone,
I was going over some older code I wrote for my game to get the vertex values from a mesh. I remember I followed a tutorial for it but I didn’t fully understand the syntax.
Here’s my code.
func get_mesh_vertices():
surface_tool.create_from(terrain_mesh_reference.mesh,0)
mesh_data = surface_tool.commit_to_arrays()
vertices = mesh_data[ArrayMesh.ARRAY_VERTEX]
normals = mesh_data[ArrayMesh.ARRAY_NORMAL]
So this works perfectly, I get the Vertex coordinates and vertex normals in those two variables. What I don’t understand is how this syntax works.
mesh_data seems to be a large array from understanding. So what is “mesh_data[ArrayMesh.ARRAY_VERTEX]” actually doing? I don’t think I have seen something written inside the [ ] part of an array doing something before.
So what does ArrayMesh.ARRAY_VERTEX do?
And why does it happen inside of square brackets?
How am I able to get different information out by putting in a different value in the [ ]?
Is this a common thing?
Where can I learn more about this type of syntax?
I did check the documentation and while I learned more about the SurfaceMesh tool and how the ArrayMesh API kind of works, I couldn’t find this square bracket syntax anywhere. Maybe this is a common array function I am unaware of.
Thank you so much!