From 4ba5e2d302ebc3a47aa594b64a7481f61be58d7d Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sat, 8 Nov 2025 14:41:09 -0500 Subject: [PATCH] feat: enhance BridgeState to manage nodes; update reify method to utilize local node registry for Axes elements --- bridge/src/lib.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bridge/src/lib.rs b/bridge/src/lib.rs index 4ea3d07..998fa2d 100644 --- a/bridge/src/lib.rs +++ b/bridge/src/lib.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use std::ffi::CStr; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Mutex; +use std::sync::{Arc, Mutex}; use std::thread::JoinHandle; use glam::Mat4; @@ -16,8 +16,16 @@ use stardust_xr_asteroids::{ use stardust_xr_asteroids::CustomElement; use tokio::runtime::Runtime; -#[derive(Default, serde::Serialize, serde::Deserialize)] -struct BridgeState {} +#[derive(Clone, serde::Serialize, serde::Deserialize)] +struct BridgeState { + nodes: HashMap, +} + +impl Default for BridgeState { + fn default() -> Self { + Self { nodes: HashMap::new() } + } +} enum Command { Create { c_id: u64, name: String, transform: Mat4 }, @@ -35,18 +43,13 @@ impl ClientState for BridgeState { impl Reify for BridgeState { fn reify(&self) -> impl ast::Element { // Root playspace. Attach a visible Axes element per tracked node id. - // We read from the global CTRL so the element tree reflects the latest node registry. - let nodes = CTRL.lock().ok() - .map(|c| c.nodes.clone()) - .unwrap_or_default(); - - let children = nodes.into_iter().map(|(id, node)| { + let children = self.nodes.iter().map(|(id, node)| { // Decompose transform into TRS let (scale, rot, trans) = node.transform.to_scale_rotation_translation(); - // Axes are small; apply a uniform visual scale multiplier based on TRS scale.x - let vis_scale = glam::Vec3::new(scale.x, scale.y, scale.z) * 0.2; + // Make axes much larger and visible: default is 1cm, scale up to 20cm + let vis_scale = glam::Vec3::splat(20.0) * scale.x; ( - id, + *id, Axes::default() .pos(trans) .rot(rot)