Replace old book mesh with LOD system on warcraft scene

This commit is contained in:
stilobique-i7
2021-05-23 15:28:08 +02:00
parent 7cb01db654
commit 96ba39ae91
13 changed files with 2733 additions and 60 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+119
View File
@@ -0,0 +1,119 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://assets/props/book/sm_book_lod0.mesh" type="ArrayMesh" id=1]
[ext_resource path="res://assets/props/book/sm_book_lod1.mesh" type="ArrayMesh" id=2]
[ext_resource path="res://assets/props/book/sm_book_lod2.mesh" type="ArrayMesh" id=3]
[sub_resource type="GDScript" id=1]
script/source = "# Copyright © 2020 Hugo Locurcio and contributors - MIT License
# See `LICENSE.md` included in the source distribution for details.
extends Spatial
class_name LODSpatial, \"res://addons/lod/lod_spatial.svg\"
# If `false`, LOD won't update anymore. This can be used for performance comparison
# purposes.
export var enable_lod := true
# The maximum LOD 0 (high quality) distance in units.
export(float, 0.0, 1000.0, 0.1) var lod_0_max_distance := 10
# The maximum LOD 1 (medium quality) distance in units.
export(float, 0.0, 1000.0, 0.1) var lod_1_max_distance := 25
# The maximum LOD 2 (low quality) distance in units.
# Past this distance, all LOD variants are hidden.
export(float, 0.0, 1000.0, 0.1) var lod_2_max_distance := 100
# The rate at which LODs will be updated (in seconds). Lower values are more reactive
# but use more CPU, which is especially noticeable with large amounts of LOD-enabled nodes.
# Set this accordingly depending on your camera movement speed.
# The default value should suit most projects already.
# Note: Slow cameras don't need to have LOD-enabled objects update their status often.
# This can overridden by setting the project setting `lod/refresh_rate`.
var refresh_rate := 0.25
# The LOD bias in units.
# Positive values will decrease the detail level and improve performance.
# Negative values will improve visual appearance at the cost of performance.
# This can overridden by setting the project setting `lod/bias`.
var lod_bias := 0.0
# The internal refresh timer.
var timer := 0.0
func _ready() -> void:
if ProjectSettings.has_setting(\"lod/spatial_bias\"):
lod_bias = ProjectSettings.get_setting(\"lod/spatial_bias\")
if ProjectSettings.has_setting(\"lod/refresh_rate\"):
refresh_rate = ProjectSettings.get_setting(\"lod/refresh_rate\")
# Add random jitter to the timer to ensure LODs don't all swap at the same time.
randomize()
timer += rand_range(0, refresh_rate)
# Despite LOD not being related to physics, we chose to run in `_physics_process()`
# to minimize the amount of method calls per second (and therefore decrease CPU usage).
func _physics_process(delta: float) -> void:
if not enable_lod:
return
# We need a camera to do the rest.
var camera := get_viewport().get_camera()
if camera == null:
return
if timer <= refresh_rate:
timer += delta
return
timer = 0.0
var distance := camera.global_transform.origin.distance_to(global_transform.origin) + lod_bias
# The LOD level to choose (lower is more detailed).
var lod: int
if distance < lod_0_max_distance:
lod = 0
elif distance < lod_1_max_distance:
lod = 1
elif distance < lod_2_max_distance:
lod = 2
else:
# Hide the LOD object entirely.
lod = 3
for node in get_children():
# `-lod` also matches `-lod0`, `-lod1`, `-lod2`, …
if node.has_method(\"set_visible\"):
if \"-lod0\" in node.name:
node.visible = lod == 0
if \"-lod1\" in node.name:
node.visible = lod == 1
if \"-lod2\" in node.name:
node.visible = lod == 2
"
[node name="sm_book" type="Spatial"]
script = SubResource( 1 )
lod_0_max_distance = 1.0
lod_1_max_distance = 5.0
lod_2_max_distance = 10.0
[node name="sm_book-lod0" type="MeshInstance" parent="."]
use_in_baked_light = true
mesh = ExtResource( 1 )
material/0 = null
[node name="sm_book-lod1" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00205189, 0, -0.0098635 )
visible = false
use_in_baked_light = true
mesh = ExtResource( 2 )
material/0 = null
[node name="sm_book-lod2" type="MeshInstance" parent="."]
visible = false
use_in_baked_light = true
mesh = ExtResource( 3 )
material/0 = null
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+17 -35
View File
@@ -17,7 +17,6 @@
[ext_resource path="res://assets/props/rock floor/ground_library.tres" type="MeshLibrary" id=15]
[ext_resource path="res://scenes/levels/warcraft/WarCraft.lmbake" type="BakedLightmapData" id=16]
[ext_resource path="res://assets/props/candle/sm_candle_d.mesh" type="ArrayMesh" id=17]
[ext_resource path="res://assets/props/book/sm_book.mesh" type="ArrayMesh" id=18]
[ext_resource path="res://assets/props/dagger/materials/MA_dagger.material" type="Material" id=19]
[ext_resource path="res://assets/props/misc/sm_gabarit_male.mesh" type="ArrayMesh" id=20]
[ext_resource path="res://assets/props/weapon gun/sm_weapon_gun.mesh" type="ArrayMesh" id=21]
@@ -45,6 +44,7 @@
[ext_resource path="res://assets/props/spyglass/materials/MA_spyglass.material" type="Material" id=43]
[ext_resource path="res://scenes/UI/list_ho/UI_list_ho.tscn" type="PackedScene" id=44]
[ext_resource path="res://scenes/UI/UI_back.tscn" type="PackedScene" id=45]
[ext_resource path="res://assets/props/book/sm_book.tscn" type="PackedScene" id=46]
[sub_resource type="PanoramaSky" id=1]
panorama = ExtResource( 11 )
@@ -374,37 +374,28 @@ material/0 = null
[node name="Main Scene Props" type="Spatial" parent="."]
[node name="Book" type="MeshInstance" parent="Main Scene Props"]
transform = Transform( 0.259561, 0, 0.965727, 0.0582327, 0.99818, -0.0156514, -0.963969, 0.0602995, 0.259089, 0.13025, 0.92072, -0.458817 )
use_in_baked_light = true
mesh = ExtResource( 18 )
material/0 = null
[node name="sm_book" parent="Main Scene Props" instance=ExtResource( 46 )]
transform = Transform( 0.259561, 0, 0.965727, 0.0582327, 0.99818, -0.0156514, -0.963969, 0.0602995, 0.259089, 0.13025, 0.960907, -0.456389 )
[node name="Book" type="MeshInstance" parent="Main Scene Props/Book"]
[node name="sm_book2" parent="Main Scene Props/sm_book" instance=ExtResource( 46 )]
transform = Transform( 0.0229641, -0.00339183, -0.999731, 0.0393653, 0.999223, -0.00248598, 0.998961, -0.0392976, 0.0230803, 0.00279957, 0.066205, -0.000443451 )
use_in_baked_light = true
mesh = ExtResource( 18 )
material/0 = null
[node name="Book2" type="MeshInstance" parent="Main Scene Props/Book/Book"]
transform = Transform( 0.86032, -0.0497817, -0.507318, 0.0471006, 0.998725, -0.0181282, 0.507573, -0.00829895, 0.861568, 0.00110056, 0.070618, -0.00503534 )
use_in_baked_light = true
mesh = ExtResource( 18 )
material/0 = null
[node name="sm_book3" parent="Main Scene Props/sm_book/sm_book2" instance=ExtResource( 46 )]
transform = Transform( 0.86032, -0.0497817, -0.507318, 0.0471006, 0.998725, -0.0181282, 0.507573, -0.00829895, 0.861568, 0.00110056, 0.070618, -0.00503528 )
[node name="sm_candlestick2" type="MeshInstance" parent="Main Scene Props/Book/Book/Book2"]
transform = Transform( 1.0543, -0.0109484, 1.03432, -0.0329634, 1.4758, 0.0492217, -1.03385, -0.0582193, 1.05321, 0.0299356, 0.0326171, -0.0690778 )
[node name="sm_candlestick2" type="MeshInstance" parent="Main Scene Props/sm_book/sm_book2/sm_book3"]
transform = Transform( 1.0543, -0.0109484, 1.03432, -0.0329634, 1.4758, 0.0492217, -1.03385, -0.0582193, 1.05321, 0.0299356, 0.0326169, -0.0690778 )
use_in_baked_light = true
mesh = ExtResource( 4 )
material/0 = null
[node name="sm_candle_top2" type="MeshInstance" parent="Main Scene Props/Book/Book/Book2/sm_candlestick2"]
[node name="sm_candle_top2" type="MeshInstance" parent="Main Scene Props/sm_book/sm_book2/sm_book3/sm_candlestick2"]
transform = Transform( 1.16981, 7.45037e-09, -2.27374e-13, 7.45058e-09, 1.63542, -1.42109e-14, 3.55271e-15, -2.84217e-14, 1.16981, 0.00268283, 0.168278, -5.96046e-08 )
use_in_baked_light = true
mesh = ExtResource( 1 )
material/0 = null
[node name="OmniLight" type="OmniLight" parent="Main Scene Props/Book/Book/Book2/sm_candlestick2/sm_candle_top2"]
[node name="OmniLight" type="OmniLight" parent="Main Scene Props/sm_book/sm_book2/sm_book3/sm_candlestick2/sm_candle_top2"]
transform = Transform( 0.578774, -3.72536e-09, -3.47774e-07, -3.72529e-09, 0.413993, -3.75217e-08, -1.15463e-13, 7.10543e-15, 0.578773, -0.00229338, 0.0614615, 2.98023e-08 )
light_color = Color( 0.960784, 0.611765, 0.00784314, 1 )
light_energy = 12.0
@@ -456,23 +447,14 @@ use_in_baked_light = true
mesh = ExtResource( 6 )
material/0 = null
[node name="Book3" type="MeshInstance" parent="Main Scene Props"]
transform = Transform( 0.5, 0, 0.866025, 0, 1, 0, -0.866025, 0, 0.5, 0.0106606, 0.96499, 0.981535 )
use_in_baked_light = true
mesh = ExtResource( 18 )
material/0 = null
[node name="Book" type="MeshInstance" parent="Main Scene Props/Book3"]
transform = Transform( 0.992026, 0, 0.592682, 0, 1.15559, 0, -0.592682, 0, 0.992026, -0.000832438, 0.0791223, -0.012241 )
use_in_baked_light = true
mesh = ExtResource( 18 )
material/0 = null
[node name="Book2" type="MeshInstance" parent="Main Scene Props"]
[node name="sm_book2" parent="Main Scene Props" instance=ExtResource( 46 )]
transform = Transform( 0.122577, 0.0288089, -0.992041, -0.0361233, 0.999045, 0.0245489, 0.991801, 0.0328267, 0.1235, 0.493202, 0.942654, -0.0854386 )
use_in_baked_light = true
mesh = ExtResource( 18 )
material/0 = null
[node name="sm_book3" parent="Main Scene Props" instance=ExtResource( 46 )]
transform = Transform( 0.5, 0, 0.866025, 0, 1, 0, -0.866025, 0, 0.5, 0.0106606, 0.96499, 0.981535 )
[node name="sm_book" parent="Main Scene Props/sm_book3" instance=ExtResource( 46 )]
transform = Transform( 0.992026, 0, 0.592682, 0, 1.15559, 0, -0.592682, 0, 0.992026, -0.000832498, 0.0791223, -0.012241 )
[node name="sm_godet2" type="MeshInstance" parent="Main Scene Props"]
transform = Transform( 0.875311, 0.480987, 0.0498184, 0.0206958, 0.0656668, -0.997627, -0.483117, 0.874265, 0.0475244, -0.191043, 0.95253, 0.11484 )