#Mesh Renderer Problem

4 messages · Page 1 of 1 (latest)

lapis leaf
#

Hello, I'm trying to create a terrain generator with noise but i can't get anything to render. The noise function works. I know this because it prints out the values but it doesn't seem to render anything. The GDScript for the MeshInstance node is below:

extends MeshInstance3D

var mesh_array = []
var mesh_colors = PackedColorArray()
var mesh_vertices = PackedVector3Array()
var mesh_indices = PackedInt32Array()
var index = 0

var noise = FastNoiseLite.new()

func GenerateRandomTerrain(mapWidth,mapHeight,resolution):
    for x in range(mapWidth):
        for y in range(mapHeight):
            var noiseSample: float = noise.get_noise_2d(x,y)
            print(noiseSample)
            mesh_vertices.append(Vector3(x,y,noiseSample))
            mesh_indices.append(index)
            index+=1

func _ready():
    mesh_array.resize(Mesh.ARRAY_MAX)
    
    GenerateRandomTerrain(16,16,16)
    mesh_array[Mesh.ARRAY_VERTEX] = mesh_vertices
    mesh_array[Mesh.ARRAY_INDEX] = mesh_indices
    
    mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, mesh_array)

#

I tried it without the generator function with simply 3 points and it made a traingle without problems

#

i'm getting the following error in the debugger: