How to generate a cube mesh?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By izhvnter

I’m hoping to make a voxel terrain generator similar to minecraft just as a learning experience.
I know there’s a c++ module made by a dev called zylann however compiling it into the engine feels inconvenient. so i went ahead to look for other ways to do it without using 3rd party plugins/modules and i stumbled upon procedural generation using MeshInstance(s)
I tried generating a cube using ArrayMesh but i can’t seem to figure out how to get the faces correctly.

here’s the code i wrote:

tool
extends MeshInstance


func _ready():
    var arr = []
    arr.resize(ArrayMesh.ARRAY_MAX)

    var verts = PoolVector3Array()

    verts.append(Vector3(1, 1, 1))
    verts.append(Vector3(1, 1, -1))
    verts.append(Vector3(-1, 1, 1))
    verts.append(Vector3(-1, 1, -1))

    verts.append(Vector3(1, -1, 1))
    verts.append(Vector3(1, -1, -1))
    verts.append(Vector3(-1, -1, 1))
    verts.append(Vector3(-1, -1, -1))

    arr[ArrayMesh.ARRAY_VERTEX] = verts

    mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)

it’d also be appreciated if anybody suggested any approaches to applying textures to the faces of the cube

all the help is appreciated!

:bust_in_silhouette: Reply From: izhvnter

I’ve found the answer here:
https://forum.godotengine.org/42501/use-of-arraymesh-for-surfacing-meshes