Skip to content

Commit 5a58101

Browse files
committed
Implement drawing, fixing bugs, drawing not working as intended.
1 parent 59209c0 commit 5a58101

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

FPSDebug.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ extends Control
44
func _process(_delta):
55
$Label.text = "FPS: %d\n" % Engine.get_frames_per_second()
66
$Label.text += "Memory: %d\n" % OS.get_static_memory_usage()
7-
$Label.text += "Position: %s\n" % $"../Tools/TerrainTool".translation
8-
var aabb = $"../Tools/TerrainTool".get_transformed_aabb()
9-
aabb.position.y -= 50
10-
aabb.size.y += 100
11-
$Label.text += "Nearby Chunks + Current Chunk: %s" % [$"../Terrain".quad_tree.query(aabb)]
7+
# $Label.text += "Position: %s\n" % $"../Tools/TerrainTool".translation
8+
# var aabb = $"../Tools/TerrainTool".get_transformed_aabb()
9+
# aabb.position.y -= 50
10+
# aabb.size.y += 100
11+
# $Label.text += "Nearby Chunks + Current Chunk: %s" % [$"../Terrain".quad_tree.query(aabb)]

Terrain.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func _ready() -> void:
1717
quadtree.add_body(spatial_vertex, _get_common_bounds(vertex))
1818
if i % 100 == 0:
1919
yield(get_tree(), "idle_frame")
20+
print(mesh_data_tool.get_vertex_count())
2021
quadtree.draw()
2122
terrain_tool.show()
2223

TerrainChunked.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func _ready():
5757
for i in range((-_size+chunk_size)/2, (_size+chunk_size)/2, chunk_size):
5858
for j in range((-_size+chunk_size)/2, (_size+chunk_size)/2, chunk_size):
5959
var image_offset: Vector2 = Vector2(range_lerp(i, -_size/2, _size/2, 0, _size), range_lerp(j, -_size/2, _size/2, 0, _size))
60-
var chunk = Chunk.new(Vector3(i, 0, j), chunk_size, 2, height_map, image_offset)
60+
var chunk = Chunk.new(Vector3(i, 0, j), chunk_size, 0, height_map, image_offset)
6161
add_child(chunk)
6262
chunks[Vector3(i, 0, j)] = chunk
6363
chunk.translation = Vector3(i, 0, j)
@@ -98,10 +98,10 @@ func _process(delta):
9898
aabb.size.y += 100
9999
var queried_chunks = quad_tree.query(aabb)
100100
for chunk in queried_chunks:
101-
# var new_aabb = chunk.get_transformed_aabb().intersection(aabb)
102-
var old_aabb = (chunk.global_transform as Transform).xform_inv(aabb)
103-
# old_aabb.position.y -= 50
104-
# old_aabb.size.y += 100
101+
var new_aabb = aabb.intersection(chunk.get_transformed_aabb())
102+
var old_aabb = (chunk.global_transform as Transform).xform_inv(new_aabb)
103+
old_aabb.position.y -= 50
104+
old_aabb.size.y += 100
105105
(chunk as Chunk)._process_chunk(delta, terrain_tool, old_aabb)
106106

107107
terrain_tool.reset_values()

World.tscn

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
[ext_resource path="res://CircleAttenuation.gd" type="Script" id=6]
99
[ext_resource path="res://TerrainTool.gd" type="Script" id=7]
1010
[ext_resource path="res://addons/sairam.quadtree/AABBUtils.gd" type="Script" id=8]
11-
12-
[sub_resource type="SpatialMaterial" id=1]
13-
albedo_color = Color( 0.0862745, 0.439216, 0.156863, 1 )
11+
[ext_resource path="res://Materials/Terrain.material" type="Material" id=9]
1412

1513
[sub_resource type="SpatialMaterial" id=2]
1614
albedo_color = Color( 0, 1, 1, 1 )
@@ -39,7 +37,7 @@ script = ExtResource( 8 )
3937
[node name="Terrain" type="Spatial" parent="."]
4038
script = ExtResource( 1 )
4139
terrain_tool_node = NodePath("../Tools/TerrainTool")
42-
terrain_material = SubResource( 1 )
40+
terrain_material = ExtResource( 9 )
4341
size = 64
4442

4543
[node name="Camera" parent="." instance=ExtResource( 2 )]

addons/sairam.quadtree/QuadTreeNode.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func clear():
3333
func query(bounds: AABB):
3434
return _quad_tree.query(bounds)
3535

36-
func draw(height: float = 1, clear_drawing: bool = true, draw_outlines: bool = true, draw_tree_bounds: bool = true):
36+
func draw(height: float = 1, clear_drawing: bool = true, draw_outlines: bool = true, draw_tree_bounds: bool = true, _transform: Transform = Transform.IDENTITY):
3737
return _quad_tree.draw(height, clear_drawing, draw_outlines, draw_tree_bounds)
3838

3939
func set_bounds(value):

chunking/Chunk.gd

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ func _init(p_position, p_size, p_lod_level, p_image: Image, p_image_offset):
1818
image = p_image
1919

2020
quad_tree = QuadTreeNode.new()
21-
quad_tree.max_levels = 15
22-
quad_tree.extents = Vector3(1, 0, 1) * size
21+
quad_tree.max_levels = 50
22+
quad_tree.extents = Vector3(1, 0, 1) * size + Vector3.UP * 2
2323
quad_tree.capacity = 10
24-
add_child(quad_tree)
2524

2625
if range(0, 10+1).has(lod_level):
2726
lod_level = p_lod_level
@@ -30,6 +29,9 @@ func _init(p_position, p_size, p_lod_level, p_image: Image, p_image_offset):
3029

3130

3231
func generate_mesh():
32+
quad_tree.immediate_geo_node_path = get_tree().get_root().find_node("ImmediateGeometry", true, false).get_path()
33+
add_child(quad_tree)
34+
3335
mesh = PlaneMesh.new()
3436
mesh.size = Vector2(size, size)
3537

@@ -56,7 +58,8 @@ func setup_quadtree():
5658
mesh_data_tool.set_vertex(i, Vector3(vertex.x, 0, vertex.z))
5759
spatial_vertex.set_meta("i", i)
5860
quad_tree.add_body(spatial_vertex, _get_common_bounds(vertex))
59-
61+
quad_tree.draw(1, true, true, true, global_transform)
62+
print(mesh_data_tool.get_vertex_count())
6063

6164
func _get_common_bounds(vertex):
6265
return AABB(Vector3(vertex.x-0.25, vertex.y, vertex.z-0.25), Vector3(0.5, 0, 0.5))
@@ -68,7 +71,7 @@ func _process_chunk(delta, terrain_tool, aabb: AABB):
6871
var old_vertex = body.get_translation()
6972
var i = body.get_meta("i")
7073
if !terrain_tool.current_state == terrain_tool.TerrainToolStates.SLOPE_FLATTEN:
71-
vertex.y += terrain_tool.get_strength_at_position(old_vertex, true) * ((2.0 * int(!terrain_tool.current_state == terrain_tool.TerrainToolStates.SLOPE_DOWN)) - 1) * delta
74+
vertex.y += terrain_tool.get_strength_at_position(old_vertex, false) * ((2.0 * int(!terrain_tool.current_state == terrain_tool.TerrainToolStates.SLOPE_DOWN)) - 1) * delta
7275
else:
7376
if int(vertex.y) == 0:
7477
vertex.y = lerp(vertex.y, 0, delta*5)

0 commit comments

Comments
 (0)