0 votes

I'm trying to make a cube by using ArrayMesh. But whenever I try to make one a weird black shadow appears on the cube.
The code I used to generate this is below:

extends Spatial

var verts = PoolVector3Array()
var normals = PoolVector3Array()
var indices = PoolIntArray()

func _ready():
    var arr_mesh = ArrayMesh.new()
    var mesh_arrays = []
    mesh_arrays[Mesh.ARRAY_VERTEX] = verts
    mesh_arrays[Mesh.ARRAY_NORMAL] = normals
    mesh_arrays[Mesh.ARRAY_INDEX] = indices
    arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, mesh_arrays)
    get_node("MeshInstance").mesh = arr_mesh

func make_cube(x,y,z):
    make_quad(Vector3(x,y,z), Vector3(x,y+1,z), Vector3(x,y+1,z+1), Vector3(x,y,z+1))
    make_quad(Vector3(x+1,y,z+1), Vector3(x+1,y+1,z+1), Vector3(x+1,y+1,z), Vector3(x+1,y,z))
    make_quad(Vector3(x+1,y,z), Vector3(x,y,z), Vector3(x,y,z+1), Vector3(x+1,y,z+1))
    make_quad(Vector3(x+1,y+1,z+1), Vector3(x,y+1,z+1), Vector3(x,y+1,z), Vector3(x+1,y+1,z))
    make_quad(Vector3(x+1,y,z), Vector3(x+1,y+1,z), Vector3(x,y+1,z), Vector3(x,y,z))
    make_quad(Vector3(x,y,z+1), Vector3(x,y+1,z+1), Vector3(x+1,y+1,z+1), Vector3(x+1,y,z+1))

func make_quad(a,b,c,d):
    var length = len(verts)
    indices.append_array([length, length+1, length+2, length, length+2, length+3])

The weird thing is that this only happens when I try to make a cube at 0,0,0 not at any other point. How can I fix this?

asked Jul 9 in Projects by jujumumu (408 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.