add get source transform node and cache transform in decompose obs transform node (#118)

closes #117

Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/118
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2024-03-16 10:09:39 +00:00 committed by yagich
parent a29e80bb9b
commit dbc12e431d
2 changed files with 69 additions and 1 deletions

View file

@ -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 = {}

View file

@ -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)