Skip to content

Commit 175af9e

Browse files
committed
initial high level lights api on railvehicle3d
1 parent 9201da5 commit 175af9e

5 files changed

Lines changed: 44 additions & 8 deletions

File tree

addons/libmaszyna/e3d/e3d_model_instance.gd

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var _current_editable: bool = false
3232
@export var lights_state: Dictionary[String, bool] = {}:
3333
set(x):
3434
lights_state = x
35-
if is_inside_tree():
35+
if is_inside_tree() and e3d_loaded:
3636
_current_instancer.sync_lights(self)
3737

3838

@@ -139,9 +139,7 @@ func _ready() -> void:
139139

140140

141141
func _enter_tree() -> void:
142-
if _model and _current_instancer:
143-
_current_instancer.instantiate(self, _model, _current_editable)
144-
142+
pass
145143

146144
func _exit_tree() -> void:
147145
if _current_instancer:

addons/libmaszyna/e3d/e3d_nodes_instancer.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func _create_submodel_instance(target_node: E3DModelInstance, submodel: E3DSubMo
151151
obj.light_color = submodel.diffuse_color
152152
obj.light_color.a = 1.0
153153
#obj.light_energy = submodel.visibility_light # ????
154-
obj.light_energy = 10.0 # FIXME: guessing
154+
obj.light_energy = 1.0 # FIXME: guessing
155155
obj.light_volumetric_fog_energy = 4.0 # FIXME: guessing
156156
obj.shadow_enabled = true
157157
obj.distance_fade_enabled = true

addons/libmaszyna/rail_vehicle_3d.gd

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@
22
extends Node3D
33
class_name RailVehicle3D
44

5+
const EMPTY_LIGHTS:Dictionary[String, bool] = {}
6+
57
# FIXME: Head Display implementation is experimental and only for demo purposes
8+
@export_node_path("E3DModelInstance") var model_instance_path:NodePath = NodePath(""):
9+
set(x):
10+
if not x == model_instance_path:
11+
model_instance_path = x
12+
lights = {}
13+
if is_inside_tree() and model_instance_path:
14+
_model_node = get_node_or_null(model_instance_path)
15+
lights = _model_node.lights_state if _model_node else EMPTY_LIGHTS
16+
_dirty = true
17+
18+
@export var lights:Dictionary[String, bool] = EMPTY_LIGHTS:
19+
set(x):
20+
if not x == lights:
21+
lights = x
22+
if is_inside_tree() and _model_node:
23+
_model_node.lights_state = lights
624

725
@export_node_path("TrainController") var controller_path:NodePath = NodePath(""):
826
set(x):
@@ -40,6 +58,7 @@ var _head_display_e3d:E3DModelInstance
4058
var _cabin:Cabin3D
4159
var _camera:FreeCamera3D
4260
var _controller:TrainController
61+
var _model_node:E3DModelInstance
4362
var _t:float = 0.0
4463

4564

@@ -163,8 +182,11 @@ func _process(delta):
163182
if _head_display_e3d:
164183
_head_display_e3d.e3d_loaded.connect(func(): _needs_head_display_update = true)
165184

166-
if controller_path and is_inside_tree():
167-
_controller = get_node(controller_path)
185+
if is_inside_tree():
186+
if controller_path:
187+
_controller = get_node_or_null(controller_path)
188+
if model_instance_path:
189+
_model_node = get_node_or_null(model_instance_path)
168190

169191
_t += delta
170192
if _t > 0.25 and _needs_head_display_update:
@@ -184,3 +206,7 @@ func _ready() -> void:
184206

185207
for instance:E3DModelInstance in find_children("", "E3DModelInstance", true, false):
186208
instance.e3d_loaded.connect(_schedule_head_display_update)
209+
210+
var model_node = get_node_or_null(model_instance_path)
211+
if model_node:
212+
model_node.lights_state = lights

demo/demo_3d.tscn

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ script = ExtResource("1_ut343")
102102
[node name="DebugMenuFPS" parent="." unique_id=28357571 instance=ExtResource("2_qg2pq")]
103103

104104
[node name="TopBar" type="Container" parent="." unique_id=1102380660]
105-
top_level = true
106105
clip_contents = true
107106
anchors_preset = 10
108107
anchor_right = 1.0
@@ -264,6 +263,18 @@ environment = SubResource("Environment_jrns0")
264263

265264
[node name="SM42-099" parent="." unique_id=1125812614 instance=ExtResource("11_8gidn")]
266265
transform = Transform3D(-0.9996828, 0, 0.02518662, 0, 1, 0, -0.02518662, 0, -0.9996828, -25.735577, 0.16, 180.73814)
266+
lights = Dictionary[String, bool]({
267+
"endsignal12": false,
268+
"endsignal13": false,
269+
"endsignal22": true,
270+
"endsignal23": true,
271+
"headlamp11": true,
272+
"headlamp12": true,
273+
"headlamp13": true,
274+
"headlamp21": false,
275+
"headlamp22": false,
276+
"headlamp23": false
277+
})
267278

268279
[node name="Impuls" parent="." unique_id=2111644575 instance=ExtResource("12_hsov8")]
269280
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.021647027, -0.019251347, -4.3020163)

demo/vehicles/sm42/sm_42.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ size = Vector3(4.5332, 4.72223, 17.0549)
1111
[node name="SM42-099" type="Node3D" unique_id=1967816975]
1212
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
1313
script = ExtResource("1_iiqbf")
14+
model_instance_path = NodePath("SM42-099")
1415
controller_path = NodePath("SM42v1")
1516
cabin_scene = ExtResource("2_htu7b")
1617
low_poly_cabin_path = NodePath("SM42-099-LowPolyCab")

0 commit comments

Comments
 (0)