From dbc12e431d48a070856347fb0a0ca3bffdb5e93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sat, 16 Mar 2024 10:09:39 +0000 Subject: [PATCH] add get source transform node and cache transform in decompose obs transform node (#118) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #117 Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/118 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- .../deck/nodes/obs/obs_decompose_transform.gd | 10 +++- .../nodes/obs/obs_get_source_transform.gd | 60 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 classes/deck/nodes/obs/obs_get_source_transform.gd diff --git a/classes/deck/nodes/obs/obs_decompose_transform.gd b/classes/deck/nodes/obs/obs_decompose_transform.gd index 70c4260..f8b6b26 100644 --- a/classes/deck/nodes/obs/obs_decompose_transform.gd +++ b/classes/deck/nodes/obs/obs_decompose_transform.gd @@ -3,6 +3,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) extends DeckNode +var _cached: Dictionary func _init() -> void: name = "Decompose OBS Transform" @@ -30,7 +31,12 @@ func _init() -> void: func _value_request(on_port: int) -> Variant: - var t = await request_value_async(0) + var t + if not _cached.is_empty(): + t = _cached + else: + t = await resolve_input_port_value_async(0) + if t == null: return null @@ -49,7 +55,9 @@ func _receive(_on_input_port: int, data: Variant) -> void: if not data is Dictionary: return + _cached = data var id := UUID.v4() send(0, data.get("rotation"), id) send(1, data.get("position_x"), id) send(2, data.get("position_y"), id) + _cached = {} diff --git a/classes/deck/nodes/obs/obs_get_source_transform.gd b/classes/deck/nodes/obs/obs_get_source_transform.gd new file mode 100644 index 0000000..0669b37 --- /dev/null +++ b/classes/deck/nodes/obs/obs_get_source_transform.gd @@ -0,0 +1,60 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + +var noobs: NoOBSWS + + +func _init() -> void: + name = "Get Source Transform" + node_type = "obs_get_source_transform" + description = "Gets an OBS source's transform, which includes position and rotation, among other things." + + add_input_port( + DeckType.Types.STRING, + "Scene name", + "field" + ) + + add_input_port( + DeckType.Types.NUMERIC, + "Source ID", + "field" + ) + + add_output_port( + DeckType.Types.DICTIONARY, + "Transform", + "", + ) + + +func get_xform(scene: String, source_id: float) -> Dictionary: + if noobs == null: + noobs = Connections.obs_websocket + + var req := noobs.make_generic_request( + "GetSceneItemTransform", + { + "scene_name": scene, + "scene_item_id": source_id, + } + ) + await req.response_received + return req.message.response_data.scene_item_transform + + +func _receive(to_input_port: int, data: Variant) -> void: + if to_input_port == 0: + var source_id: float = await resolve_input_port_value_async(1) + send(0, await get_xform(data, source_id)) + else: + var scene: String = await resolve_input_port_value_async(0) + send(0, await get_xform(scene, data)) + + +func _value_request(on_input_port: int) -> Variant: + var scene: String = await resolve_input_port_value_async(0) + var source_id: float = await resolve_input_port_value_async(1) + return await get_xform(scene, source_id)