generated from krampus/template-godot4
Utility component to automatically set visibility range based on defined LOD boundaries
This commit is contained in:
parent
3a12e8218d
commit
ae4f4dba0c
25
src/util/auto_range.gd
Normal file
25
src/util/auto_range.gd
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
class_name AutoRange extends Node
|
||||||
|
## Component that automatically adjusts the visibility range of its parent to match LOD bounds
|
||||||
|
|
||||||
|
enum LODLevel {
|
||||||
|
LOW,
|
||||||
|
MEDIUM,
|
||||||
|
HIGH,
|
||||||
|
}
|
||||||
|
|
||||||
|
@export var lod_level: LODLevel
|
||||||
|
@export_range(0.0, 1.0) var end_margin_pct := 0.05
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
var target: GeometryInstance3D = get_parent()
|
||||||
|
match lod_level:
|
||||||
|
LODLevel.LOW:
|
||||||
|
target.visibility_range_end = WorldGenManager.low_detail_radius
|
||||||
|
LODLevel.MEDIUM:
|
||||||
|
target.visibility_range_end = WorldGenManager.med_detail_radius
|
||||||
|
LODLevel.HIGH:
|
||||||
|
target.visibility_range_end = WorldGenManager.high_detail_radius
|
||||||
|
|
||||||
|
target.visibility_range_end_margin = end_margin_pct * target.visibility_range_end
|
||||||
|
queue_free()
|
||||||
1
src/util/auto_range.gd.uid
Normal file
1
src/util/auto_range.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://cv0o1lirqeq44
|
||||||
@ -1,9 +1,10 @@
|
|||||||
[gd_scene load_steps=7 format=3 uid="uid://nllc8ljmn37g"]
|
[gd_scene load_steps=8 format=3 uid="uid://nllc8ljmn37g"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://drk82eeqk2mjs" path="res://src/world/generation/feature/generation_feature.gd" id="1_ek7o7"]
|
[ext_resource type="Script" uid="uid://drk82eeqk2mjs" path="res://src/world/generation/feature/generation_feature.gd" id="1_ek7o7"]
|
||||||
[ext_resource type="Material" uid="uid://0ja682cfcvu3" path="res://assets/materials/shaders/megalith_base.material" id="2_pko82"]
|
[ext_resource type="Material" uid="uid://0ja682cfcvu3" path="res://assets/materials/shaders/megalith_base.material" id="2_pko82"]
|
||||||
[ext_resource type="Material" uid="uid://bjbctidts4k5b" path="res://assets/materials/shaders/megalith_interior.material" id="3_yw1ox"]
|
[ext_resource type="Material" uid="uid://bjbctidts4k5b" path="res://assets/materials/shaders/megalith_interior.material" id="3_yw1ox"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cwygxhknl2h8r" path="res://src/world/generation/layer/metro_grid_layer/metro_grid_layer.tscn" id="4_fy7wq"]
|
[ext_resource type="PackedScene" uid="uid://cwygxhknl2h8r" path="res://src/world/generation/layer/metro_grid_layer/metro_grid_layer.tscn" id="4_fy7wq"]
|
||||||
|
[ext_resource type="Script" uid="uid://cv0o1lirqeq44" path="res://src/util/auto_range.gd" id="4_kox75"]
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id="PlaneMesh_pko82"]
|
[sub_resource type="PlaneMesh" id="PlaneMesh_pko82"]
|
||||||
size = Vector2(100000, 100000)
|
size = Vector2(100000, 100000)
|
||||||
@ -19,8 +20,6 @@ metadata/_custom_type_script = "uid://drk82eeqk2mjs"
|
|||||||
[node name="InnerPyramid" type="CSGCylinder3D" parent="."]
|
[node name="InnerPyramid" type="CSGCylinder3D" parent="."]
|
||||||
transform = Transform3D(0.70710677, 0, 0.70710677, 0, 1, 0, -0.70710677, 0, 0.70710677, 50000, 30000, 50000)
|
transform = Transform3D(0.70710677, 0, 0.70710677, 0, 1, 0, -0.70710677, 0, 0.70710677, 50000, 30000, 50000)
|
||||||
layers = 4
|
layers = 4
|
||||||
visibility_range_end = 100000.0
|
|
||||||
visibility_range_end_margin = 64.0
|
|
||||||
visibility_range_fade_mode = 1
|
visibility_range_fade_mode = 1
|
||||||
use_collision = true
|
use_collision = true
|
||||||
radius = 60000.0
|
radius = 60000.0
|
||||||
@ -62,6 +61,11 @@ layers = 4
|
|||||||
size = Vector3(100000, 30000, 10000)
|
size = Vector3(100000, 30000, 10000)
|
||||||
material = ExtResource("3_yw1ox")
|
material = ExtResource("3_yw1ox")
|
||||||
|
|
||||||
|
[node name="AutoRange" type="Node" parent="InnerPyramid"]
|
||||||
|
script = ExtResource("4_kox75")
|
||||||
|
end_margin_pct = 0.01
|
||||||
|
metadata/_custom_type_script = "uid://cv0o1lirqeq44"
|
||||||
|
|
||||||
[node name="WorldFloor" type="MeshInstance3D" parent="."]
|
[node name="WorldFloor" type="MeshInstance3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 50000, 0, 50000)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 50000, 0, 50000)
|
||||||
layers = 4
|
layers = 4
|
||||||
@ -72,6 +76,11 @@ mesh = SubResource("PlaneMesh_pko82")
|
|||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"]
|
||||||
shape = SubResource("ConcavePolygonShape3D_ek7o7")
|
shape = SubResource("ConcavePolygonShape3D_ek7o7")
|
||||||
|
|
||||||
|
[node name="AutoRange" type="Node" parent="WorldFloor"]
|
||||||
|
script = ExtResource("4_kox75")
|
||||||
|
end_margin_pct = 0.01
|
||||||
|
metadata/_custom_type_script = "uid://cv0o1lirqeq44"
|
||||||
|
|
||||||
[node name="MetroGridLayer" parent="." instance=ExtResource("4_fy7wq")]
|
[node name="MetroGridLayer" parent="." instance=ExtResource("4_fy7wq")]
|
||||||
simple_construct_threshold = 0.3
|
simple_construct_threshold = 0.3
|
||||||
bounding_box = AABB(0, 0, 0, 99497, 100, 503)
|
bounding_box = AABB(0, 0, 0, 99497, 100, 503)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://dawv6mbpr4d3c"]
|
[gd_scene load_steps=5 format=3 uid="uid://dawv6mbpr4d3c"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://drk82eeqk2mjs" path="res://src/world/generation/feature/generation_feature.gd" id="1_ydt4o"]
|
[ext_resource type="Script" uid="uid://drk82eeqk2mjs" path="res://src/world/generation/feature/generation_feature.gd" id="1_ydt4o"]
|
||||||
|
[ext_resource type="Script" uid="uid://cv0o1lirqeq44" path="res://src/util/auto_range.gd" id="2_q70le"]
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id="PlaneMesh_ydt4o"]
|
[sub_resource type="PlaneMesh" id="PlaneMesh_ydt4o"]
|
||||||
size = Vector2(100000, 100000)
|
size = Vector2(100000, 100000)
|
||||||
@ -21,3 +22,8 @@ mesh = SubResource("PlaneMesh_ydt4o")
|
|||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"]
|
||||||
shape = SubResource("ConcavePolygonShape3D_q70le")
|
shape = SubResource("ConcavePolygonShape3D_q70le")
|
||||||
|
|
||||||
|
[node name="AutoRange" type="Node" parent="WorldFloor"]
|
||||||
|
script = ExtResource("2_q70le")
|
||||||
|
lod_level = 1
|
||||||
|
metadata/_custom_type_script = "uid://cv0o1lirqeq44"
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://beno0v5dxtwqs"]
|
[gd_scene load_steps=5 format=3 uid="uid://beno0v5dxtwqs"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dq5xadqwyspyh" path="res://src/world/generation/feature/metro/metro_construct_simple/metro_construct_simple.gd" id="1_jv74y"]
|
[ext_resource type="Script" uid="uid://dq5xadqwyspyh" path="res://src/world/generation/feature/metro/metro_construct_simple/metro_construct_simple.gd" id="1_jv74y"]
|
||||||
|
[ext_resource type="Script" uid="uid://cv0o1lirqeq44" path="res://src/util/auto_range.gd" id="2_74b57"]
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id="PlaneMesh_lhl33"]
|
[sub_resource type="PlaneMesh" id="PlaneMesh_lhl33"]
|
||||||
size = Vector2(64, 64)
|
size = Vector2(64, 64)
|
||||||
@ -24,9 +25,19 @@ mesh = SubResource("PlaneMesh_lhl33")
|
|||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"]
|
||||||
shape = SubResource("ConvexPolygonShape3D_y2o1w")
|
shape = SubResource("ConvexPolygonShape3D_y2o1w")
|
||||||
|
|
||||||
|
[node name="AutoRange" type="Node" parent="WorldFloor"]
|
||||||
|
script = ExtResource("2_74b57")
|
||||||
|
lod_level = 1
|
||||||
|
metadata/_custom_type_script = "uid://cv0o1lirqeq44"
|
||||||
|
|
||||||
[node name="ConstructBox" type="CSGBox3D" parent="."]
|
[node name="ConstructBox" type="CSGBox3D" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 32, 24, 32)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 32, 24, 32)
|
||||||
layers = 2
|
layers = 2
|
||||||
use_collision = true
|
use_collision = true
|
||||||
size = Vector3(48, 48, 48)
|
size = Vector3(48, 48, 48)
|
||||||
|
|
||||||
|
[node name="AutoRange" type="Node" parent="ConstructBox"]
|
||||||
|
script = ExtResource("2_74b57")
|
||||||
|
lod_level = 1
|
||||||
|
metadata/_custom_type_script = "uid://cv0o1lirqeq44"
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://cgvg7n525g18l"]
|
[gd_scene load_steps=5 format=3 uid="uid://cgvg7n525g18l"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://drk82eeqk2mjs" path="res://src/world/generation/feature/generation_feature.gd" id="1_e5j5s"]
|
[ext_resource type="Script" uid="uid://drk82eeqk2mjs" path="res://src/world/generation/feature/generation_feature.gd" id="1_e5j5s"]
|
||||||
|
[ext_resource type="Script" uid="uid://cv0o1lirqeq44" path="res://src/util/auto_range.gd" id="2_xbnbu"]
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id="PlaneMesh_e5j5s"]
|
[sub_resource type="PlaneMesh" id="PlaneMesh_e5j5s"]
|
||||||
size = Vector2(64, 64)
|
size = Vector2(64, 64)
|
||||||
@ -22,3 +23,8 @@ mesh = SubResource("PlaneMesh_e5j5s")
|
|||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldFloor/StaticBody3D"]
|
||||||
shape = SubResource("ConvexPolygonShape3D_e5j5s")
|
shape = SubResource("ConvexPolygonShape3D_e5j5s")
|
||||||
|
|
||||||
|
[node name="AutoRange" type="Node" parent="WorldFloor"]
|
||||||
|
script = ExtResource("2_xbnbu")
|
||||||
|
lod_level = 1
|
||||||
|
metadata/_custom_type_script = "uid://cv0o1lirqeq44"
|
||||||
|
|||||||
@ -6,9 +6,9 @@ class_name WorldGenManagerType extends Node
|
|||||||
## Generate features with the lowest detail, like large distant structures, within this radius
|
## Generate features with the lowest detail, like large distant structures, within this radius
|
||||||
@export var low_detail_radius := 100000.0
|
@export var low_detail_radius := 100000.0
|
||||||
## Generate features with medium detail, like buildings, within this radius
|
## Generate features with medium detail, like buildings, within this radius
|
||||||
@export var med_detail_radius := 1024.0
|
@export var med_detail_radius := 8192.0
|
||||||
## Generate features with high detail, like small complicated objects, within this radius
|
## Generate features with high detail, like small complicated objects, within this radius
|
||||||
@export var high_detail_radius := 64.0
|
@export var high_detail_radius := 128.0
|
||||||
|
|
||||||
|
|
||||||
## Get the world-space coordinate to generate around.
|
## Get the world-space coordinate to generate around.
|
||||||
|
|||||||
@ -10,5 +10,4 @@ offset = Vector3(1024, 1024, 1024)
|
|||||||
[node name="WorldGenManager" type="Node"]
|
[node name="WorldGenManager" type="Node"]
|
||||||
script = ExtResource("1_7xvag")
|
script = ExtResource("1_7xvag")
|
||||||
noise = SubResource("FastNoiseLite_7xvag")
|
noise = SubResource("FastNoiseLite_7xvag")
|
||||||
med_detail_radius = 8192.0
|
|
||||||
metadata/_custom_type_script = "uid://7frynyj4vspc"
|
metadata/_custom_type_script = "uid://7frynyj4vspc"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user