From d4f7fa604aed21e685d8c7aab07795f5160ee9ae Mon Sep 17 00:00:00 2001 From: copygirl Date: Tue, 10 Dec 2024 14:13:35 +0100 Subject: [PATCH] Use scene_init to detect model change --- copyMultiplayer.gd | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/copyMultiplayer.gd b/copyMultiplayer.gd index ad4302f..25e235d 100644 --- a/copyMultiplayer.gd +++ b/copyMultiplayer.gd @@ -27,6 +27,9 @@ var accumulative_offset := Vector3( 0.35, 0.0, 0.0) # I don't believe this should be a source of issues. func _ready() -> void: + # FIXME: Hardcoded way to get the main model controller. + main_controller = $"/root/SnekStudio_Main/ModelController" + # FIXME: This is just thrown together. Dunno if this is an accurate list. # TODO: Allow specifying additional bones, with the help of a hierachical list of existing bones in the model. tracked_bones = [ "Hips", "Spine", "Chest", "UpperChest", "Neck", "Head" ] @@ -46,11 +49,6 @@ func _ready() -> void: for phalange in [ "Proximal", "Intermediate", "Distal" ]: tracked_bones.append("%s%s%s" % [ side, finger, phalange ]) - # FIXME: Hardcoded way to get the main model controller. - main_controller = $"/root/SnekStudio_Main/ModelController" - main_controller.child_entered_tree.connect(on_model_changed) - on_model_changed(main_controller.get_node_or_null("Model")) - setup_setting_widget("cache" , "Cache/LineEdit", true ) setup_setting_widget("nickname", "Name/LineEdit" , false) setup_setting_widget("address" , "Host/Address" , true ) @@ -222,13 +220,12 @@ func clear_player_models() -> void: func _process(_delta: float) -> void: SyncController.send_model_animation(self) -# Will be called once when the module is initialized, and also when a child is -# added to the main ModelController, which happens when the model is changed. -func on_model_changed(model: Node) -> void: - if (model == null) or (model.name != "Model"): return - - var skeleton: Skeleton3D = main_controller._get_model_skeleton() - if not skeleton: return # Do nothing, I guess? Unsure if potential bug. +# Called when module is initialized or load_vrm is called. +func scene_init() -> void: + var model := get_model() + var skeleton := get_skeleton() + # Do nothing, I guess? Unsure if source of potential bugs. + if (not model) or (not skeleton): return # This "version" is used to ensure that sync updates # are not applied to the incorrect lookup tables. @@ -250,11 +247,8 @@ func on_model_changed(model: Node) -> void: blendshape_lookup.append(anim.track_get_path(track_index)) continue - # Wait for one frame, then "_last_loaded_vrm" is updated. - await get_tree().process_frame - var filename = main_controller._last_loaded_vrm.get_file() - if multiplayer.get_peers().size() > 1: + var filename = main_controller._last_loaded_vrm.get_file() change_model.rpc(version, bone_lookup, blendshape_lookup, filename)