diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-09-18 08:32:29 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-09-18 08:32:29 -0400 |
commit | ffc92ed12c6e680776d355ff9fcef70e5e28d7c8 (patch) | |
tree | 11060de6eee066442dcbca1babcf0f69dac525b2 | |
parent | 3dfcc3706f5dcb4b8150e027a02d0eb84c929b26 (diff) | |
download | godot_wildjam_49-ffc92ed12c6e680776d355ff9fcef70e5e28d7c8.tar.gz godot_wildjam_49-ffc92ed12c6e680776d355ff9fcef70e5e28d7c8.zip |
Prototype levels of detail per chunk
-rw-r--r-- | Chunk.gd | 16 | ||||
-rw-r--r-- | Chunk.tscn | 2 | ||||
-rw-r--r-- | Rock.gd | 18 | ||||
-rw-r--r-- | Rock.tscn | 14 | ||||
-rw-r--r-- | World.gd | 29 | ||||
-rw-r--r-- | World.tscn | 27 |
6 files changed, 103 insertions, 3 deletions
diff --git a/Chunk.gd b/Chunk.gd new file mode 100644 index 0000000..7c5c1c3 --- /dev/null +++ b/Chunk.gd @@ -0,0 +1,16 @@ +extends Area + +enum LOD {DISTANCE,MID,CLOSE} +var lod = -1 + +func lod_update(): + for obj in $"gen_tree".get_children(): + match lod: + LOD.CLOSE: + obj.lod_close() + LOD.MID: + obj.lod_mid() + LOD.DISTANCE: + obj.lod_distance() + _: + obj.lod_distance() @@ -1,5 +1,6 @@ [gd_scene load_steps=7 format=2] +[ext_resource path="res://Chunk.gd" type="Script" id=1] [ext_resource path="res://ChunkedCSGMesh.gd" type="Script" id=3] [sub_resource type="SphereShape" id=1] @@ -19,6 +20,7 @@ size = Vector2( 98, 98 ) [node name="Chunk" type="Area"] collision_layer = 32 collision_mask = 0 +script = ExtResource( 1 ) [node name="Size" type="CollisionShape" parent="."] shape = SubResource( 1 ) @@ -0,0 +1,18 @@ +extends StaticBody + +onready var collision_enabled = self.collision_layer + +func lod_distance(): + $"MeshInstance".visible = false + $"MeshInstance2".visible = true + self.collision_layer = 0 + +func lod_mid(): + $"MeshInstance".visible = true + $"MeshInstance2".visible = false + self.collision_layer = 0 + +func lod_close(): + $"MeshInstance".visible = true + $"MeshInstance2".visible = false + self.collision_layer = collision_enabled @@ -1,5 +1,6 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=10 format=2] +[ext_resource path="res://Rock.gd" type="Script" id=1] [ext_resource path="res://ChunkedMeshInstance.gd" type="Script" id=2] [sub_resource type="ConvexPolygonShape" id=2] @@ -28,14 +29,25 @@ normal_texture = SubResource( 5 ) [sub_resource type="PrismMesh" id=1] size = Vector3( 5, 10, 5 ) +[sub_resource type="CubeMesh" id=9] +size = Vector3( 5, 10, 5 ) + [node name="Rock" type="StaticBody"] collision_layer = 8 collision_mask = 0 +script = ExtResource( 1 ) [node name="CollisionShape" type="CollisionShape" parent="."] shape = SubResource( 2 ) [node name="MeshInstance" type="MeshInstance" parent="."] +visible = false material_override = SubResource( 6 ) script = ExtResource( 2 ) _mesh = SubResource( 1 ) + +[node name="MeshInstance2" type="MeshInstance" parent="."] +visible = false +material_override = SubResource( 6 ) +script = ExtResource( 2 ) +_mesh = SubResource( 9 ) @@ -4,7 +4,11 @@ export(NodePath) var traveler = null onready var _traveler = get_node(traveler) export var acceleration = 10.0 -onready var chunk_render_distance = $"ChunkRenderDistance/Radius".shape.radius +onready var lod_distance = $"ChunkRenderDistance" +onready var lod_mid = $"ChunkRenderMid" +onready var lod_close = $"ChunkRenderClose" + +onready var chunk_render_distance = lod_distance.get_node("Radius").shape.radius onready var chunk_half_size = $"Chunks/Chunk/Size".shape.radius onready var chunk_size = chunk_half_size * 2.0 @@ -13,9 +17,32 @@ func _ready(): ChunkLoader.world = self ChunkGen.chunk_half_size = self.chunk_half_size +func _on_ChunkRenderDistance_area_entered(area:Area): + if area.lod < area.LOD.DISTANCE: + area.lod = area.LOD.DISTANCE + area.lod_update() + +func _on_ChunkRenderMid_area_entered(area:Area): + if area.lod < area.LOD.MID: + area.lod = area.LOD.MID + area.lod_update() + +func _on_ChunkRenderClose_area_entered(area:Area): + if area.lod < area.LOD.CLOSE: + area.lod = area.LOD.CLOSE + area.lod_update() + func _on_ChunkRenderDistance_area_exited(area:Area): area.queue_free() +func _on_ChunkRenderMid_area_exited(area:Area): + area.lod = area.LOD.DISTANCE + area.lod_update() + +func _on_ChunkRenderClose_area_exited(area:Area): + area.lod = area.LOD.MID + area.lod_update() + func travel(direction:Vector3): var heading = _traveler.global_transform.basis heading = Basis(Vector3.UP*heading.get_euler().y) @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://World.gd" type="Script" id=1] [ext_resource path="res://Chunk.tscn" type="PackedScene" id=3] @@ -6,6 +6,12 @@ [sub_resource type="SphereShape" id=24] radius = 500.0 +[sub_resource type="SphereShape" id=25] +radius = 300.0 + +[sub_resource type="SphereShape" id=26] +radius = 150.0 + [sub_resource type="BoxShape" id=23] [node name="World" type="Spatial"] @@ -19,6 +25,20 @@ collision_mask = 32 [node name="Radius" type="CollisionShape" parent="ChunkRenderDistance"] shape = SubResource( 24 ) +[node name="ChunkRenderMid" type="Area" parent="."] +collision_layer = 0 +collision_mask = 32 + +[node name="Radius" type="CollisionShape" parent="ChunkRenderMid"] +shape = SubResource( 25 ) + +[node name="ChunkRenderClose" type="Area" parent="."] +collision_layer = 0 +collision_mask = 32 + +[node name="Radius" type="CollisionShape" parent="ChunkRenderClose"] +shape = SubResource( 26 ) + [node name="Chunks" type="RigidBody" parent="."] collision_layer = 0 collision_mask = 0 @@ -36,4 +56,9 @@ shape = SubResource( 23 ) visible = false collision_layer = 0 +[connection signal="area_entered" from="ChunkRenderDistance" to="." method="_on_ChunkRenderDistance_area_entered"] [connection signal="area_exited" from="ChunkRenderDistance" to="." method="_on_ChunkRenderDistance_area_exited"] +[connection signal="area_entered" from="ChunkRenderMid" to="." method="_on_ChunkRenderMid_area_entered"] +[connection signal="area_exited" from="ChunkRenderMid" to="." method="_on_ChunkRenderMid_area_exited"] +[connection signal="area_entered" from="ChunkRenderClose" to="." method="_on_ChunkRenderClose_area_entered"] +[connection signal="area_exited" from="ChunkRenderClose" to="." method="_on_ChunkRenderClose_area_exited"] |