Successfully tested planar worldgen, starting spherical worldgen
This commit is contained in:
@ -2,25 +2,36 @@ class_name TerrainGeneration
|
||||
extends Node
|
||||
|
||||
var mesh : MeshInstance3D
|
||||
var size_depth : int = 100
|
||||
var size_width : int = 100
|
||||
var mesh_res : int = 2
|
||||
var planet_radius : float = 1
|
||||
|
||||
@export var noise : FastNoiseLite
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
generate()
|
||||
|
||||
func generate():
|
||||
var plane_mesh = PlaneMesh.new()
|
||||
plane_mesh.size = Vector2(size_width, size_depth)
|
||||
plane_mesh.subdivide_depth = size_depth * mesh_res
|
||||
plane_mesh.subdivide_width = size_width * mesh_res
|
||||
plane_mesh.material = preload("res://ProceduralGeneration/Materials/terrain.tres")
|
||||
var sphere_mesh = SphereMesh.new()
|
||||
sphere_mesh.material = preload("res://ProceduralGeneration/Materials/terrain.tres")
|
||||
|
||||
|
||||
var surface = SurfaceTool.new()
|
||||
var data = MeshDataTool.new()
|
||||
surface.create_from(sphere_mesh, 0)
|
||||
|
||||
surface.create_from(plane_mesh, 0)
|
||||
var plane_array = surface.commit()
|
||||
data.create_from_surface(plane_array, 0)
|
||||
|
||||
for i in range(data.get_vertex_count()):
|
||||
var vert = data.get_vertex(i)
|
||||
data.set_vertex(i, vert)
|
||||
|
||||
plane_array.clear_surfaces()
|
||||
data.commit_to_surface(plane_array)
|
||||
|
||||
surface.begin(Mesh.PRIMITIVE_TRIANGLES)
|
||||
surface.create_from(plane_array, 0)
|
||||
surface.generate_normals()
|
||||
|
||||
mesh = MeshInstance3D.new()
|
||||
mesh.mesh = surface.commit()
|
||||
|
Reference in New Issue
Block a user