Topic was automatically imported from the old Question2Answer platform.

Asked By

toblin

I’m trying to setup shaders for GPU acceleration on 3D data points. To do so, I need to create a mesh that has vertices uniformly spread out in a 3D cubicle lattice. I.e. for each x,y,z in say [-2, -1, 0, 1, 2], I need a mesh vertex at (x,y,z).

My best approach thus far is to use an ArrayMesh. But what would be the easiest/best way of doing so?

Hi,
when you mean a cube with a certain subdivision.

MeshInstance → mesh: new CubeMesh → click the small image of the cube
edit Size and subdivides

No, that would only give me vertices that lie on the “shell” of the cube, right? I need every volumetric point in the “cube” to have a vertex as well. Hence if x,y,z are in the set {-1,0,1}, then I need a vertex for the interior point (0,0,0) as well, and not just the exterior points.

tool
extends MeshInstance
export(bool) var update setget _update
func _update(value):
if value:
update()
func update():
mesh = ArrayMesh.new()
var st = SurfaceTool.new()
st.clear()
st.begin(Mesh.PRIMITIVE_POINTS)
for x in range(0,10):
for y in range(0,10):
for z in range(0,10):
st.add_vertex(Vector3(x,y,z))
mesh = st.commit()