From d28ad338128b114230c5d48d0d54cd01006aa1d7 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sat, 8 Nov 2025 22:02:12 -0500 Subject: [PATCH] fix: enhance node rendering in reify by adding model support for different entity types --- bridge/src/lib.rs | 76 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/bridge/src/lib.rs b/bridge/src/lib.rs index 92290af..01ee118 100644 --- a/bridge/src/lib.rs +++ b/bridge/src/lib.rs @@ -72,13 +72,11 @@ impl ClientState for BridgeState { impl Reify for BridgeState { fn reify(&self) -> impl ast::Element { - use stardust_xr_fusion::values::color::rgba_linear; + use stardust_xr_fusion::values::{rgba_linear, Vector3}; use stardust_xr_fusion::drawable::{Line, LinePoint}; - use stardust_xr_fusion::values::Vector3; eprintln!("[bridge/reify] Reifying {} nodes", self.nodes.len()); - // Create simple wireframe cubes (12 edges) fn create_wireframe_cube(color: stardust_xr_fusion::values::Color, thickness: f32) -> Vec { let h = 0.5; // half size let points = [ @@ -113,8 +111,6 @@ impl Reify for BridgeState { return None; } - eprintln!("[bridge/reify] Creating wireframe for node {} type={}", id, node.entity_type); - let (scale, rot, trans) = node.transform.to_scale_rotation_translation(); let vis_scale = if dims.length() > 0.001 { dims } else { scale }; let node_color = rgba_linear!(node.color[0], node.color[1], node.color[2], node.color[3]); @@ -124,15 +120,67 @@ impl Reify for BridgeState { let scale_array = [vis_scale.x, vis_scale.y, vis_scale.z]; let transform = stardust_xr_fusion::spatial::Transform::from_translation_rotation_scale(trans_array, rot_array, scale_array); - let cube_lines = create_wireframe_cube(node_color, 0.003); - - Some(( - *id, - Spatial::default() - .transform(transform) - .build() - .child(Lines::new(cube_lines).build()) - )) + // Create appropriate visual based on entity type + match node.entity_type { + 1 => { + // Box - use cube model with color + eprintln!("[bridge/reify] Creating box model for node {}", id); + let model = Model::namespaced("fusion", "tex_cube") + .transform(transform) + .part( + ModelPart::new("Cube") + .mat_param("color", MaterialParameter::Color(node_color)) + ); + Some((*id, model.build())) + } + 2 => { + // Sphere - use sphere model with color + eprintln!("[bridge/reify] Creating sphere model for node {}", id); + let model = Model::namespaced("fusion", "tex_sphere") + .transform(transform) + .part( + ModelPart::new("Sphere") + .mat_param("color", MaterialParameter::Color(node_color)) + ); + Some((*id, model.build())) + } + 3 => { + // Model - use model URL if available, fallback to cube + if !node.model_url.is_empty() { + eprintln!("[bridge/reify] Creating model from URL for node {}: {}", id, node.model_url); + // For now, use a fallback model since we can't load arbitrary URLs yet + // TODO: Implement model loading and caching + let model = Model::namespaced("fusion", "gyro") + .transform(transform) + .part( + ModelPart::new("Gem") + .mat_param("color", MaterialParameter::Color(node_color)) + ); + Some((*id, model.build())) + } else { + eprintln!("[bridge/reify] Creating fallback cube for node {} (no model URL)", id); + let model = Model::namespaced("fusion", "tex_cube") + .transform(transform) + .part( + ModelPart::new("Cube") + .mat_param("color", MaterialParameter::Color(node_color)) + ); + Some((*id, model.build())) + } + } + _ => { + // Unknown or unsupported type - render as wireframe + eprintln!("[bridge/reify] Creating wireframe for node {} type={}", id, node.entity_type); + let cube_lines = create_wireframe_cube(node_color, 0.003); + Some(( + *id, + Spatial::default() + .transform(transform) + .build() + .child(Lines::new(cube_lines).build()) + )) + } + } }); PlaySpace.build().stable_children(children)