diff options
Diffstat (limited to 'world/chunk/ChunkGen.gd')
-rw-r--r-- | world/chunk/ChunkGen.gd | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/world/chunk/ChunkGen.gd b/world/chunk/ChunkGen.gd index d60b2e5..75d3736 100644 --- a/world/chunk/ChunkGen.gd +++ b/world/chunk/ChunkGen.gd @@ -12,8 +12,9 @@ onready var rng = RandomNumberGenerator.new() var _seed func _ready(): - randomize() - self._seed = randi() + #randomize() + #self._seed = randi() + self._seed = 0 self.noise.seed = self._seed self.noise.seed = 0 self.noise.period = 16 @@ -27,7 +28,7 @@ func gen_chunk(chunk): var gen_tree = Spatial.new() gen_tree.name = "gen_tree" chunk.add_child(gen_tree) - iterate_chunk(chunk, Vector2(10.0,10.0), funcref(self,"gen_rocks")) + gen_rocks(chunk) func v2_coords(coords:Vector3): return Vector2(coords.x,coords.z) @@ -41,14 +42,9 @@ func iterate_chunk(chunk,step:Vector2,cb:FuncRef): for y in range(-chunk_size_rounded.y,chunk_size_rounded.y,step.y): cb.call_func(chunk,Vector2(x,y)) -onready var Rock = preload("res://world/obstacles/Rock.tscn") -const rock_size = 5.0 -func make_rock(chunk,xform:Transform): - var rock = Rock.instance() - rock.transform = xform - chunk.get_node("gen_tree").add_child(rock) - -func gen_rocks(chunk,chunk_coords:Vector2): +var rock_mesh = preload("res://world/obstacles/Rock_mesh.tres") +var rock_mat = preload("res://world/obstacles/Rock_mat.tres") +func make_rock(chunk,chunk_coords:Vector2): var coords = v3_coords(chunk_coords) var basis = Basis() var world_coords = chunk_coords + v2_coords(chunk.transform.origin) @@ -64,4 +60,20 @@ func gen_rocks(chunk,chunk_coords:Vector2): noise_val = lerp(1.0,4.0,noise_val) basis = basis.scaled(Vector3.ONE*noise_val) coords.y += (noise_val*5.0)-5.0 - make_rock(chunk,Transform(basis,coords)) + var gen_tree = chunk.get_node("gen_tree") + var rocks = gen_tree.get_node("rocks").multimesh + rocks.visible_instance_count += 1 + rocks.set_instance_transform(rocks.visible_instance_count-1, Transform(basis,coords)) + +func gen_rocks(chunk): + var multi_inst = MultiMeshInstance.new() + multi_inst.name = "rocks" + var multi = MultiMesh.new() + multi_inst.multimesh = multi + chunk.get_node("gen_tree").add_child(multi_inst) + multi.transform_format = MultiMesh.TRANSFORM_3D + multi.instance_count = 1000 + multi.visible_instance_count = 0 + multi.mesh = rock_mesh + rock_mesh.material = rock_mat + iterate_chunk(chunk, Vector2(10.0,10.0), funcref(self,"make_rock")) |