0 votes

Hello everyone, I am just playing around with mesh creations and I am trying to make a terrain mesh, but I have hit two issues, that I will talk about now.

the first issue, is the terrain/triangles that I am creating seem to stop near the end of the amount specified and I am not sure why I kinda understand this code I have written it is based of unity but I know it isnt a copy and paste.

the second issue is that the other side of the triangles are still getting rendered obviously I am doing something wrong but I am not high skilled yet to understand why it does this.

Picture of the mesh in question:https://pasteall.org/pic/e05cc1381a054d61984adeaa12676d84

this code should be able to copy and paste it to your project as well just give a simple scene for the cube that acts as a guide for now.

extends Spatial

onready var cube = preload("res://Cube.tscn")
export var xsize = 20
export var zsize = 20

var new_verts = PoolVector3Array()
var new_tris:Array = []#[0,xsize + 1,1,xsize +1,1, xsize + 2]

var mesh_instance = MeshInstance.new()
var noise = OpenSimplexNoise.new()
var surface_tool = SurfaceTool.new()
var mesh = Mesh.new()

func _ready():

func _process(delta):

func generate_triangle():
    mesh_instance.translation = Vector3(0,0,0)

    mesh_instance.mesh = mesh

func terrain():
    for x in xsize + 1: # Creates the positions for the triangles
        for z in zsize + 1:
            new_verts.append(Vector3(x,0,z)) # Actually adds the verts into the world space
        for n in xsize + 1: # Creates the positions for the triangles
            for s in zsize + 1:
                for a in 6:
                    new_tris.append(0) # Create an empty array so that I dont get a invalid index

    var tri_int = 0
    var vert_int = 0
    for z in zsize : # Creates the rows 
        for x in xsize: # Creates all the triangles needed
            new_tris[tri_int + 0] = vert_int + 0
            new_tris[tri_int + 1] = vert_int + xsize + 1
            new_tris[tri_int + 2] = vert_int + 1
            new_tris[tri_int + 3] = vert_int + xsize + 1
            new_tris[tri_int + 4] = vert_int + 1
            new_tris[tri_int + 5] = vert_int + xsize + 2

            vert_int += 1
            tri_int += 6 # this is so that it doesnt duplicate triangles
    vert_int += 1

    for i in new_tris.size(): # Adds triangles

    for s in new_verts.size(): #Creates a cube at each position
        var new_cube = cube.instance()
        new_cube.translation = new_verts[s] - Vector3(0,1,0)
Godot version 3.3.2
in Engine by (162 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.