Quellcode durchsuchen

Merge pull request #1138 from Calinou/truck-town-add-moods

Add moods (times of day) to Truck Town demo
Aaron Franke vor 9 Monaten
Ursprung
Commit
51a7d389af

+ 1 - 0
3d/truck_town/README.md

@@ -11,6 +11,7 @@ Controls:
 - <kbd>Right Arrow</kbd>, <kbd>Gamepad Left Stick</kbd>, <kbd>Gamepad D-Pad Right</kbd>: Steer right
 - <kbd>U</kbd>, <kbd>Gamepad Select</kbd>, left-click speedometer: Change speedometer unit (m/s, km/h, mph)
 - <kbd>C</kbd>, <kbd>Gamepad Y/Triangle</kbd>: Change camera (exterior, interior, top-down)
+- <kbd>M</kbd>, <kbd>Gamepad D-Pad Down</kbd>: Change mood (sunrise, day, sunset, night)
 - <kbd>Escape</kbd>, <kbd>Gamepad D-Pad Up</kbd>: Go back to menu (press again to exit)
 
 On mobile platforms, the vehicle automatically accelerates. Touch the left and

+ 8 - 0
3d/truck_town/car_select/car_select.gd

@@ -16,6 +16,14 @@ func _load_scene(car_scene: PackedScene) -> void:
 	var car: Node3D = car_scene.instantiate()
 	car.name = "car"
 	town = preload("res://town/town_scene.tscn").instantiate()
+	if $PanelContainer/MarginContainer/HBoxContainer/Sunrise.button_pressed:
+		town.mood = town.Mood.SUNRISE
+	elif $PanelContainer/MarginContainer/HBoxContainer/Day.button_pressed:
+		town.mood = town.Mood.DAY
+	elif $PanelContainer/MarginContainer/HBoxContainer/Sunset.button_pressed:
+		town.mood = town.Mood.SUNSET
+	elif $PanelContainer/MarginContainer/HBoxContainer/Night.button_pressed:
+		town.mood = town.Mood.NIGHT
 	town.get_node(^"InstancePos").add_child(car)
 	town.get_node(^"Spedometer").car_body = car.get_child(0)
 	town.get_node(^"Back").pressed.connect(_on_back_pressed)

+ 57 - 1
3d/truck_town/car_select/car_select.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=6 format=3 uid="uid://ckvqraq6j1okh"]
+[gd_scene load_steps=7 format=3 uid="uid://ckvqraq6j1okh"]
 
 [ext_resource type="Script" path="res://car_select/car_select.gd" id="1"]
 [ext_resource type="Texture2D" uid="uid://bh7b4n4lg1uqt" path="res://car_select/choose_van.png" id="2"]
@@ -11,6 +11,8 @@ variation_transform = Transform2D(1, 0.2, 0, 1, 0, 0)
 spacing_glyph = -1
 spacing_space = 4
 
+[sub_resource type="ButtonGroup" id="ButtonGroup_lcrm3"]
+
 [node name="CarSelect" type="Control"]
 layout_mode = 3
 anchors_preset = 8
@@ -75,6 +77,60 @@ theme_override_fonts/font = SubResource("FontVariation_hqcvw")
 theme_override_font_sizes/font_size = 64
 text = "Truck Town"
 
+[node name="PanelContainer" type="PanelContainer" parent="."]
+layout_mode = 1
+anchors_preset = 8
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+offset_left = -325.0
+offset_top = 164.0
+offset_right = 325.0
+offset_bottom = 205.0
+grow_horizontal = 2
+grow_vertical = 2
+
+[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
+layout_mode = 2
+theme_override_constants/margin_left = 20
+theme_override_constants/margin_top = 5
+theme_override_constants/margin_right = 20
+theme_override_constants/margin_bottom = 5
+
+[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer"]
+custom_minimum_size = Vector2(70, 0)
+layout_mode = 2
+text = "Mood"
+
+[node name="Sunrise" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+button_group = SubResource("ButtonGroup_lcrm3")
+text = "Sunrise"
+
+[node name="Day" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+button_pressed = true
+button_group = SubResource("ButtonGroup_lcrm3")
+text = "Day"
+
+[node name="Sunset" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+button_group = SubResource("ButtonGroup_lcrm3")
+text = "Sunset"
+
+[node name="Night" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+button_group = SubResource("ButtonGroup_lcrm3")
+text = "Night"
+
 [connection signal="pressed" from="HBoxContainer/MiniVan" to="." method="_on_mini_van_pressed"]
 [connection signal="pressed" from="HBoxContainer/TrailerTruck" to="." method="_on_trailer_truck_pressed"]
 [connection signal="pressed" from="HBoxContainer/TowTruck" to="." method="_on_tow_truck_pressed"]

+ 10 - 0
3d/truck_town/project.godot

@@ -148,6 +148,12 @@ cycle_camera={
 , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
 ]
 }
+cycle_mood={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":77,"physical_keycode":0,"key_label":0,"unicode":109,"location":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
+]
+}
 
 [physics]
 
@@ -159,11 +165,15 @@ textures/vram_compression/import_etc2_astc=true
 lights_and_shadows/directional_shadow/size=8192
 lights_and_shadows/directional_shadow/soft_shadow_filter_quality=3
 lights_and_shadows/directional_shadow/soft_shadow_filter_quality.mobile=1
+lights_and_shadows/positional_shadow/soft_shadow_filter_quality=3
+lights_and_shadows/positional_shadow/soft_shadow_filter_quality.mobile=1
 textures/default_filters/anisotropic_filtering_level=4
 textures/default_filters/texture_mipmap_bias=-0.5
 textures/decals/filter=1
 environment/defaults/default_clear_color=Color(0.133333, 0.133333, 0.133333, 1)
 anti_aliasing/quality/msaa_3d=2
 anti_aliasing/quality/use_debanding=true
+lights_and_shadows/positional_shadow/atlas_size=2048
+lights_and_shadows/positional_shadow/atlas_size.mobile=1024
 anti_aliasing/quality/msaa_3d.mobile=0
 scaling_3d/scale.mobile=0.67

+ 5 - 0
3d/truck_town/town/sky_day.tres

@@ -0,0 +1,5 @@
+[gd_resource type="ProceduralSkyMaterial" format=3 uid="uid://bpms6jemjgt36"]
+
+[resource]
+sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
+ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)

+ 6 - 0
3d/truck_town/town/sky_morning.tres

@@ -0,0 +1,6 @@
+[gd_resource type="ProceduralSkyMaterial" format=3 uid="uid://drtvj2ilm4c7h"]
+
+[resource]
+sky_top_color = Color(0.164732, 0.303048, 0.411552, 1)
+sky_horizon_color = Color(0.686775, 0.600323, 0.467043, 1)
+ground_horizon_color = Color(0.686275, 0.6, 0.466667, 1)

+ 6 - 0
3d/truck_town/town/sky_night.tres

@@ -0,0 +1,6 @@
+[gd_resource type="ProceduralSkyMaterial" format=3 uid="uid://c2w5t0j2rkiuu"]
+
+[resource]
+sky_top_color = Color(0.0964875, 0.114707, 0.155705, 1)
+sky_horizon_color = Color(0.201247, 0.148966, 0.125881, 1)
+ground_horizon_color = Color(0.2, 0.14902, 0.12549, 1)

+ 6 - 0
3d/truck_town/town/sky_sunset.tres

@@ -0,0 +1,6 @@
+[gd_resource type="ProceduralSkyMaterial" format=3 uid="uid://dbs05x6h8miq2"]
+
+[resource]
+sky_top_color = Color(0.252654, 0.288234, 0.368141, 1)
+sky_horizon_color = Color(0.77459, 0.550361, 0.50128, 1)
+ground_horizon_color = Color(0.776471, 0.54902, 0.501961, 1)

+ 50 - 0
3d/truck_town/town/town_scene.gd

@@ -0,0 +1,50 @@
+extends Node3D
+
+enum Mood {
+	SUNRISE,
+	DAY,
+	SUNSET,
+	NIGHT,
+	MAX,
+}
+
+var mood := Mood.DAY: set = set_mood
+
+
+func _input(event: InputEvent) -> void:
+	if event.is_action_pressed(&"cycle_mood"):
+		mood = wrapi(mood + 1, 0, Mood.MAX) as Mood
+
+
+func set_mood(p_mood: Mood) -> void:
+	mood = p_mood
+
+	match p_mood:
+		Mood.SUNRISE:
+			$DirectionalLight3D.rotation_degrees = Vector3(-20, -150, -137)
+			$DirectionalLight3D.light_color = Color(0.414, 0.377, 0.25)
+			$DirectionalLight3D.light_energy = 4.0
+			$WorldEnvironment.environment.fog_light_color = Color(0.686, 0.6, 0.467)
+			$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_morning.tres")
+			$ArtificialLights.visible = false
+		Mood.DAY:
+			$DirectionalLight3D.rotation_degrees = Vector3(-55, -120, -31)
+			$DirectionalLight3D.light_color = Color.WHITE
+			$DirectionalLight3D.light_energy = 1.45
+			$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_day.tres")
+			$WorldEnvironment.environment.fog_light_color = Color(0.62, 0.601, 0.601)
+			$ArtificialLights.visible = false
+		Mood.SUNSET:
+			$DirectionalLight3D.rotation_degrees = Vector3(-19, -31, 62)
+			$DirectionalLight3D.light_color = Color(0.488, 0.3, 0.1)
+			$DirectionalLight3D.light_energy = 4.0
+			$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_sunset.tres")
+			$WorldEnvironment.environment.fog_light_color = Color(0.776, 0.549, 0.502)
+			$ArtificialLights.visible = true
+		Mood.NIGHT:
+			$DirectionalLight3D.rotation_degrees = Vector3(-49, 116, -46)
+			$DirectionalLight3D.light_color = Color(0.232, 0.415, 0.413)
+			$DirectionalLight3D.light_energy = 0.7
+			$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_night.tres")
+			$WorldEnvironment.environment.fog_light_color = Color(0.2, 0.149, 0.125)
+			$ArtificialLights.visible = true

+ 140 - 8
3d/truck_town/town/town_scene.tscn

@@ -1,16 +1,14 @@
-[gd_scene load_steps=14 format=3 uid="uid://d0ygmqpylq0wy"]
+[gd_scene load_steps=15 format=3 uid="uid://d0ygmqpylq0wy"]
 
 [ext_resource type="PackedScene" uid="uid://csucj4oj3q3qt" path="res://town/model/town_model.gltf" id="1_amwer"]
-[ext_resource type="Script" path="res://spedometer.gd" id="2"]
+[ext_resource type="Script" path="res://town/town_scene.gd" id="1_gxe8p"]
+[ext_resource type="Script" uid="uid://ikqivupl66lr" path="res://spedometer.gd" id="2"]
+[ext_resource type="Material" uid="uid://bpms6jemjgt36" path="res://town/sky_day.tres" id="2_1df3w"]
 [ext_resource type="Material" uid="uid://c71ovlrgdfif5" path="res://town/materials/grass.tres" id="2_ubld8"]
 [ext_resource type="Material" uid="uid://bdjiubscxkdn6" path="res://town/materials/cement.tres" id="3_8s61a"]
 
-[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_2k12y"]
-sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
-ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
-
 [sub_resource type="Sky" id="Sky_1gf0c"]
-sky_material = SubResource("ProceduralSkyMaterial_2k12y")
+sky_material = ExtResource("2_1df3w")
 
 [sub_resource type="Environment" id="Environment_dauhq"]
 background_mode = 2
@@ -49,12 +47,13 @@ width = 128
 height = 128
 
 [node name="TownScene" type="Node3D"]
+script = ExtResource("1_gxe8p")
 
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 environment = SubResource("Environment_dauhq")
 
 [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
-transform = Transform3D(0.506501, -0.706305, -0.494561, -4.63342e-08, -0.573577, 0.819152, -0.862239, -0.414901, -0.290517, 11.0084, 12.3453, -31.3148)
+transform = Transform3D(-0.793955, 0.350561, -0.496732, -0.295414, 0.491651, 0.819152, 0.531381, 0.797111, -0.286788, 11.0084, 12.3453, -31.3148)
 light_energy = 1.45
 shadow_enabled = true
 shadow_bias = 0.015
@@ -62,6 +61,139 @@ shadow_blur = 1.5
 directional_shadow_mode = 0
 directional_shadow_max_distance = 80.0
 
+[node name="ArtificialLights" type="Node3D" parent="."]
+visible = false
+
+[node name="OmniLight3D" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, 38.1028, 10.5868, 14.8252)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D2" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, 13.1028, 11.5868, 20.8252)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D3" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, 14.1028, 11.5868, -6.1748)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D4" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, 36.1028, 13.5868, -7.1748)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D5" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, 45.1028, 13.5868, -17.1748)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D6" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -20.8972, 7.58679, 4.8252)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D7" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -15.8972, 7.58679, 20.8252)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D8" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -44.8972, 10.5868, 4.8252)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D9" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -43.8972, 10.5868, -15.1748)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
+[node name="OmniLight3D10" type="OmniLight3D" parent="ArtificialLights"]
+transform = Transform3D(0.747779, 0.367885, -0.552709, 0, 0.832459, 0.554087, 0.663947, -0.414335, 0.622495, -15.7972, 3.58679, -71.175)
+light_color = Color(1, 0.941176, 0.705882, 1)
+light_energy = 2.0
+shadow_enabled = true
+shadow_bias = 0.06
+shadow_blur = 2.0
+distance_fade_enabled = true
+distance_fade_begin = 100.0
+distance_fade_shadow = 35.0
+distance_fade_length = 15.0
+omni_range = 15.0
+
 [node name="InstancePos" type="Marker3D" parent="."]
 transform = Transform3D(3.57628e-07, 0, -1, 0, 1, 0, 1, 0, 3.57628e-07, 35.48, 8.72405, 14.335)
 

BIN
3d/truck_town/vehicles/meshes/minivan.res


BIN
3d/truck_town/vehicles/meshes/tow_truck.res


BIN
3d/truck_town/vehicles/meshes/truck_cab.res


BIN
3d/truck_town/vehicles/meshes/truck_trailer.res


BIN
3d/truck_town/vehicles/meshes/wheel.res