Skip to content

Commit 51a7d38

Browse files
authored
Merge pull request #1138 from Calinou/truck-town-add-moods
Add moods (times of day) to Truck Town demo
2 parents 5f0e0ce + 15bcb94 commit 51a7d38

15 files changed

+289
-9
lines changed

3d/truck_town/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Controls:
1111
- <kbd>Right Arrow</kbd>, <kbd>Gamepad Left Stick</kbd>, <kbd>Gamepad D-Pad Right</kbd>: Steer right
1212
- <kbd>U</kbd>, <kbd>Gamepad Select</kbd>, left-click speedometer: Change speedometer unit (m/s, km/h, mph)
1313
- <kbd>C</kbd>, <kbd>Gamepad Y/Triangle</kbd>: Change camera (exterior, interior, top-down)
14+
- <kbd>M</kbd>, <kbd>Gamepad D-Pad Down</kbd>: Change mood (sunrise, day, sunset, night)
1415
- <kbd>Escape</kbd>, <kbd>Gamepad D-Pad Up</kbd>: Go back to menu (press again to exit)
1516

1617
On mobile platforms, the vehicle automatically accelerates. Touch the left and

3d/truck_town/car_select/car_select.gd

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ func _load_scene(car_scene: PackedScene) -> void:
1616
var car: Node3D = car_scene.instantiate()
1717
car.name = "car"
1818
town = preload("res://town/town_scene.tscn").instantiate()
19+
if $PanelContainer/MarginContainer/HBoxContainer/Sunrise.button_pressed:
20+
town.mood = town.Mood.SUNRISE
21+
elif $PanelContainer/MarginContainer/HBoxContainer/Day.button_pressed:
22+
town.mood = town.Mood.DAY
23+
elif $PanelContainer/MarginContainer/HBoxContainer/Sunset.button_pressed:
24+
town.mood = town.Mood.SUNSET
25+
elif $PanelContainer/MarginContainer/HBoxContainer/Night.button_pressed:
26+
town.mood = town.Mood.NIGHT
1927
town.get_node(^"InstancePos").add_child(car)
2028
town.get_node(^"Spedometer").car_body = car.get_child(0)
2129
town.get_node(^"Back").pressed.connect(_on_back_pressed)

3d/truck_town/car_select/car_select.tscn

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=6 format=3 uid="uid://ckvqraq6j1okh"]
1+
[gd_scene load_steps=7 format=3 uid="uid://ckvqraq6j1okh"]
22

33
[ext_resource type="Script" path="res://car_select/car_select.gd" id="1"]
44
[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)
1111
spacing_glyph = -1
1212
spacing_space = 4
1313

14+
[sub_resource type="ButtonGroup" id="ButtonGroup_lcrm3"]
15+
1416
[node name="CarSelect" type="Control"]
1517
layout_mode = 3
1618
anchors_preset = 8
@@ -75,6 +77,60 @@ theme_override_fonts/font = SubResource("FontVariation_hqcvw")
7577
theme_override_font_sizes/font_size = 64
7678
text = "Truck Town"
7779

80+
[node name="PanelContainer" type="PanelContainer" parent="."]
81+
layout_mode = 1
82+
anchors_preset = 8
83+
anchor_left = 0.5
84+
anchor_top = 0.5
85+
anchor_right = 0.5
86+
anchor_bottom = 0.5
87+
offset_left = -325.0
88+
offset_top = 164.0
89+
offset_right = 325.0
90+
offset_bottom = 205.0
91+
grow_horizontal = 2
92+
grow_vertical = 2
93+
94+
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
95+
layout_mode = 2
96+
theme_override_constants/margin_left = 20
97+
theme_override_constants/margin_top = 5
98+
theme_override_constants/margin_right = 20
99+
theme_override_constants/margin_bottom = 5
100+
101+
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer"]
102+
layout_mode = 2
103+
104+
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer"]
105+
custom_minimum_size = Vector2(70, 0)
106+
layout_mode = 2
107+
text = "Mood"
108+
109+
[node name="Sunrise" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
110+
layout_mode = 2
111+
size_flags_horizontal = 3
112+
button_group = SubResource("ButtonGroup_lcrm3")
113+
text = "Sunrise"
114+
115+
[node name="Day" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
116+
layout_mode = 2
117+
size_flags_horizontal = 3
118+
button_pressed = true
119+
button_group = SubResource("ButtonGroup_lcrm3")
120+
text = "Day"
121+
122+
[node name="Sunset" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
123+
layout_mode = 2
124+
size_flags_horizontal = 3
125+
button_group = SubResource("ButtonGroup_lcrm3")
126+
text = "Sunset"
127+
128+
[node name="Night" type="CheckBox" parent="PanelContainer/MarginContainer/HBoxContainer"]
129+
layout_mode = 2
130+
size_flags_horizontal = 3
131+
button_group = SubResource("ButtonGroup_lcrm3")
132+
text = "Night"
133+
78134
[connection signal="pressed" from="HBoxContainer/MiniVan" to="." method="_on_mini_van_pressed"]
79135
[connection signal="pressed" from="HBoxContainer/TrailerTruck" to="." method="_on_trailer_truck_pressed"]
80136
[connection signal="pressed" from="HBoxContainer/TowTruck" to="." method="_on_tow_truck_pressed"]

3d/truck_town/project.godot

+10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ cycle_camera={
148148
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
149149
]
150150
}
151+
cycle_mood={
152+
"deadzone": 0.5,
153+
"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)
154+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
155+
]
156+
}
151157

152158
[physics]
153159

@@ -159,11 +165,15 @@ textures/vram_compression/import_etc2_astc=true
159165
lights_and_shadows/directional_shadow/size=8192
160166
lights_and_shadows/directional_shadow/soft_shadow_filter_quality=3
161167
lights_and_shadows/directional_shadow/soft_shadow_filter_quality.mobile=1
168+
lights_and_shadows/positional_shadow/soft_shadow_filter_quality=3
169+
lights_and_shadows/positional_shadow/soft_shadow_filter_quality.mobile=1
162170
textures/default_filters/anisotropic_filtering_level=4
163171
textures/default_filters/texture_mipmap_bias=-0.5
164172
textures/decals/filter=1
165173
environment/defaults/default_clear_color=Color(0.133333, 0.133333, 0.133333, 1)
166174
anti_aliasing/quality/msaa_3d=2
167175
anti_aliasing/quality/use_debanding=true
176+
lights_and_shadows/positional_shadow/atlas_size=2048
177+
lights_and_shadows/positional_shadow/atlas_size.mobile=1024
168178
anti_aliasing/quality/msaa_3d.mobile=0
169179
scaling_3d/scale.mobile=0.67

3d/truck_town/town/sky_day.tres

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

3d/truck_town/town/sky_morning.tres

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

3d/truck_town/town/sky_night.tres

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

3d/truck_town/town/sky_sunset.tres

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

3d/truck_town/town/town_scene.gd

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
extends Node3D
2+
3+
enum Mood {
4+
SUNRISE,
5+
DAY,
6+
SUNSET,
7+
NIGHT,
8+
MAX,
9+
}
10+
11+
var mood := Mood.DAY: set = set_mood
12+
13+
14+
func _input(event: InputEvent) -> void:
15+
if event.is_action_pressed(&"cycle_mood"):
16+
mood = wrapi(mood + 1, 0, Mood.MAX) as Mood
17+
18+
19+
func set_mood(p_mood: Mood) -> void:
20+
mood = p_mood
21+
22+
match p_mood:
23+
Mood.SUNRISE:
24+
$DirectionalLight3D.rotation_degrees = Vector3(-20, -150, -137)
25+
$DirectionalLight3D.light_color = Color(0.414, 0.377, 0.25)
26+
$DirectionalLight3D.light_energy = 4.0
27+
$WorldEnvironment.environment.fog_light_color = Color(0.686, 0.6, 0.467)
28+
$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_morning.tres")
29+
$ArtificialLights.visible = false
30+
Mood.DAY:
31+
$DirectionalLight3D.rotation_degrees = Vector3(-55, -120, -31)
32+
$DirectionalLight3D.light_color = Color.WHITE
33+
$DirectionalLight3D.light_energy = 1.45
34+
$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_day.tres")
35+
$WorldEnvironment.environment.fog_light_color = Color(0.62, 0.601, 0.601)
36+
$ArtificialLights.visible = false
37+
Mood.SUNSET:
38+
$DirectionalLight3D.rotation_degrees = Vector3(-19, -31, 62)
39+
$DirectionalLight3D.light_color = Color(0.488, 0.3, 0.1)
40+
$DirectionalLight3D.light_energy = 4.0
41+
$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_sunset.tres")
42+
$WorldEnvironment.environment.fog_light_color = Color(0.776, 0.549, 0.502)
43+
$ArtificialLights.visible = true
44+
Mood.NIGHT:
45+
$DirectionalLight3D.rotation_degrees = Vector3(-49, 116, -46)
46+
$DirectionalLight3D.light_color = Color(0.232, 0.415, 0.413)
47+
$DirectionalLight3D.light_energy = 0.7
48+
$WorldEnvironment.environment.sky.sky_material = preload("res://town/sky_night.tres")
49+
$WorldEnvironment.environment.fog_light_color = Color(0.2, 0.149, 0.125)
50+
$ArtificialLights.visible = true

3d/truck_town/town/town_scene.tscn

+140-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
[gd_scene load_steps=14 format=3 uid="uid://d0ygmqpylq0wy"]
1+
[gd_scene load_steps=15 format=3 uid="uid://d0ygmqpylq0wy"]
22

33
[ext_resource type="PackedScene" uid="uid://csucj4oj3q3qt" path="res://town/model/town_model.gltf" id="1_amwer"]
4-
[ext_resource type="Script" path="res://spedometer.gd" id="2"]
4+
[ext_resource type="Script" path="res://town/town_scene.gd" id="1_gxe8p"]
5+
[ext_resource type="Script" uid="uid://ikqivupl66lr" path="res://spedometer.gd" id="2"]
6+
[ext_resource type="Material" uid="uid://bpms6jemjgt36" path="res://town/sky_day.tres" id="2_1df3w"]
57
[ext_resource type="Material" uid="uid://c71ovlrgdfif5" path="res://town/materials/grass.tres" id="2_ubld8"]
68
[ext_resource type="Material" uid="uid://bdjiubscxkdn6" path="res://town/materials/cement.tres" id="3_8s61a"]
79

8-
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_2k12y"]
9-
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
10-
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
11-
1210
[sub_resource type="Sky" id="Sky_1gf0c"]
13-
sky_material = SubResource("ProceduralSkyMaterial_2k12y")
11+
sky_material = ExtResource("2_1df3w")
1412

1513
[sub_resource type="Environment" id="Environment_dauhq"]
1614
background_mode = 2
@@ -49,19 +47,153 @@ width = 128
4947
height = 128
5048

5149
[node name="TownScene" type="Node3D"]
50+
script = ExtResource("1_gxe8p")
5251

5352
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
5453
environment = SubResource("Environment_dauhq")
5554

5655
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
57-
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)
56+
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)
5857
light_energy = 1.45
5958
shadow_enabled = true
6059
shadow_bias = 0.015
6160
shadow_blur = 1.5
6261
directional_shadow_mode = 0
6362
directional_shadow_max_distance = 80.0
6463

64+
[node name="ArtificialLights" type="Node3D" parent="."]
65+
visible = false
66+
67+
[node name="OmniLight3D" type="OmniLight3D" parent="ArtificialLights"]
68+
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)
69+
light_color = Color(1, 0.941176, 0.705882, 1)
70+
light_energy = 2.0
71+
shadow_enabled = true
72+
shadow_bias = 0.06
73+
shadow_blur = 2.0
74+
distance_fade_enabled = true
75+
distance_fade_begin = 100.0
76+
distance_fade_shadow = 35.0
77+
distance_fade_length = 15.0
78+
omni_range = 15.0
79+
80+
[node name="OmniLight3D2" type="OmniLight3D" parent="ArtificialLights"]
81+
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)
82+
light_color = Color(1, 0.941176, 0.705882, 1)
83+
light_energy = 2.0
84+
shadow_enabled = true
85+
shadow_bias = 0.06
86+
shadow_blur = 2.0
87+
distance_fade_enabled = true
88+
distance_fade_begin = 100.0
89+
distance_fade_shadow = 35.0
90+
distance_fade_length = 15.0
91+
omni_range = 15.0
92+
93+
[node name="OmniLight3D3" type="OmniLight3D" parent="ArtificialLights"]
94+
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)
95+
light_color = Color(1, 0.941176, 0.705882, 1)
96+
light_energy = 2.0
97+
shadow_enabled = true
98+
shadow_bias = 0.06
99+
shadow_blur = 2.0
100+
distance_fade_enabled = true
101+
distance_fade_begin = 100.0
102+
distance_fade_shadow = 35.0
103+
distance_fade_length = 15.0
104+
omni_range = 15.0
105+
106+
[node name="OmniLight3D4" type="OmniLight3D" parent="ArtificialLights"]
107+
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)
108+
light_color = Color(1, 0.941176, 0.705882, 1)
109+
light_energy = 2.0
110+
shadow_enabled = true
111+
shadow_bias = 0.06
112+
shadow_blur = 2.0
113+
distance_fade_enabled = true
114+
distance_fade_begin = 100.0
115+
distance_fade_shadow = 35.0
116+
distance_fade_length = 15.0
117+
omni_range = 15.0
118+
119+
[node name="OmniLight3D5" type="OmniLight3D" parent="ArtificialLights"]
120+
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)
121+
light_color = Color(1, 0.941176, 0.705882, 1)
122+
light_energy = 2.0
123+
shadow_enabled = true
124+
shadow_bias = 0.06
125+
shadow_blur = 2.0
126+
distance_fade_enabled = true
127+
distance_fade_begin = 100.0
128+
distance_fade_shadow = 35.0
129+
distance_fade_length = 15.0
130+
omni_range = 15.0
131+
132+
[node name="OmniLight3D6" type="OmniLight3D" parent="ArtificialLights"]
133+
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)
134+
light_color = Color(1, 0.941176, 0.705882, 1)
135+
light_energy = 2.0
136+
shadow_enabled = true
137+
shadow_bias = 0.06
138+
shadow_blur = 2.0
139+
distance_fade_enabled = true
140+
distance_fade_begin = 100.0
141+
distance_fade_shadow = 35.0
142+
distance_fade_length = 15.0
143+
omni_range = 15.0
144+
145+
[node name="OmniLight3D7" type="OmniLight3D" parent="ArtificialLights"]
146+
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)
147+
light_color = Color(1, 0.941176, 0.705882, 1)
148+
light_energy = 2.0
149+
shadow_enabled = true
150+
shadow_bias = 0.06
151+
shadow_blur = 2.0
152+
distance_fade_enabled = true
153+
distance_fade_begin = 100.0
154+
distance_fade_shadow = 35.0
155+
distance_fade_length = 15.0
156+
omni_range = 15.0
157+
158+
[node name="OmniLight3D8" type="OmniLight3D" parent="ArtificialLights"]
159+
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)
160+
light_color = Color(1, 0.941176, 0.705882, 1)
161+
light_energy = 2.0
162+
shadow_enabled = true
163+
shadow_bias = 0.06
164+
shadow_blur = 2.0
165+
distance_fade_enabled = true
166+
distance_fade_begin = 100.0
167+
distance_fade_shadow = 35.0
168+
distance_fade_length = 15.0
169+
omni_range = 15.0
170+
171+
[node name="OmniLight3D9" type="OmniLight3D" parent="ArtificialLights"]
172+
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)
173+
light_color = Color(1, 0.941176, 0.705882, 1)
174+
light_energy = 2.0
175+
shadow_enabled = true
176+
shadow_bias = 0.06
177+
shadow_blur = 2.0
178+
distance_fade_enabled = true
179+
distance_fade_begin = 100.0
180+
distance_fade_shadow = 35.0
181+
distance_fade_length = 15.0
182+
omni_range = 15.0
183+
184+
[node name="OmniLight3D10" type="OmniLight3D" parent="ArtificialLights"]
185+
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)
186+
light_color = Color(1, 0.941176, 0.705882, 1)
187+
light_energy = 2.0
188+
shadow_enabled = true
189+
shadow_bias = 0.06
190+
shadow_blur = 2.0
191+
distance_fade_enabled = true
192+
distance_fade_begin = 100.0
193+
distance_fade_shadow = 35.0
194+
distance_fade_length = 15.0
195+
omni_range = 15.0
196+
65197
[node name="InstancePos" type="Marker3D" parent="."]
66198
transform = Transform3D(3.57628e-07, 0, -1, 0, 1, 0, 1, 0, 3.57628e-07, 35.48, 8.72405, 14.335)
67199

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)