22extends Node3D
33class_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
4058var _cabin :Cabin3D
4159var _camera :FreeCamera3D
4260var _controller :TrainController
61+ var _model_node :E3DModelInstance
4362var _t :float = 0.0
4463
4564
@@ -163,8 +182,11 @@ func _process(delta):
163182 if _head_display_e3d :
164183 _head_display_e3d .e3 d_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 .e3 d_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
0 commit comments