fix: update reify implementation to use new color handling and streamline node creation
Some checks failed
CI / build-and-test (push) Has been cancelled
Rust Quality Checks / rust-checks (push) Has been cancelled

This commit is contained in:
MayaTheShy
2025-11-08 22:04:08 -05:00
parent 98a0240629
commit 4e3889afc6

View File

@@ -72,12 +72,12 @@ impl ClientState for BridgeState {
impl Reify for BridgeState { impl Reify for BridgeState {
fn reify(&self) -> impl ast::Element<Self> { fn reify(&self) -> impl ast::Element<Self> {
use stardust_xr_fusion::values::{rgba_linear, Vector3}; use stardust_xr_fusion::values::{color, Vector3};
use stardust_xr_fusion::drawable::{Line, LinePoint}; use stardust_xr_fusion::drawable::{Line, LinePoint};
eprintln!("[bridge/reify] Reifying {} nodes", self.nodes.len()); eprintln!("[bridge/reify] Reifying {} nodes", self.nodes.len());
fn create_wireframe_cube(color: stardust_xr_fusion::values::Color, thickness: f32) -> Vec<Line> { fn create_wireframe_cube(color_val: stardust_xr_fusion::values::Color, thickness: f32) -> Vec<Line> {
let h = 0.5; // half size let h = 0.5; // half size
let points = [ let points = [
[-h, -h, -h], [h, -h, -h], [h, h, -h], [-h, h, -h], // back face [-h, -h, -h], [h, -h, -h], [h, h, -h], [-h, h, -h], // back face
@@ -96,8 +96,8 @@ impl Reify for BridgeState {
let pb = points[*b]; let pb = points[*b];
Line { Line {
points: vec![ points: vec![
LinePoint { point: Vector3 { x: pa[0], y: pa[1], z: pa[2] }, thickness, color }, LinePoint { point: Vector3 { x: pa[0], y: pa[1], z: pa[2] }, thickness, color: color_val },
LinePoint { point: Vector3 { x: pb[0], y: pb[1], z: pb[2] }, thickness, color }, LinePoint { point: Vector3 { x: pb[0], y: pb[1], z: pb[2] }, thickness, color: color_val },
], ],
cyclic: false, cyclic: false,
} }
@@ -113,7 +113,7 @@ impl Reify for BridgeState {
let (scale, rot, trans) = node.transform.to_scale_rotation_translation(); let (scale, rot, trans) = node.transform.to_scale_rotation_translation();
let vis_scale = if dims.length() > 0.001 { dims } else { scale }; 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]); let node_color = color::rgba_linear!(node.color[0], node.color[1], node.color[2], node.color[3]);
let trans_array = [trans.x, trans.y, trans.z]; let trans_array = [trans.x, trans.y, trans.z];
let rot_array = [rot.x, rot.y, rot.z, rot.w]; let rot_array = [rot.x, rot.y, rot.z, rot.w];
@@ -121,28 +121,26 @@ impl Reify for BridgeState {
let transform = stardust_xr_fusion::spatial::Transform::from_translation_rotation_scale(trans_array, rot_array, scale_array); let transform = stardust_xr_fusion::spatial::Transform::from_translation_rotation_scale(trans_array, rot_array, scale_array);
// Create appropriate visual based on entity type // Create appropriate visual based on entity type
match node.entity_type { let element: ast::ElementWrapper<_, _, ()> = match node.entity_type {
1 => { 1 => {
// Box - use cube model with color // Box - use cube model with color
eprintln!("[bridge/reify] Creating box model for node {}", id); eprintln!("[bridge/reify] Creating box model for node {}", id);
let model = Model::namespaced("fusion", "tex_cube") Model::namespaced("fusion", "tex_cube")
.transform(transform) .transform(transform)
.part( .part(
ModelPart::new("Cube") ModelPart::new("Cube")
.mat_param("color", MaterialParameter::Color(node_color)) .mat_param("color", MaterialParameter::Color(node_color))
); ).build()
Some((*id, model.build()))
} }
2 => { 2 => {
// Sphere - use sphere model with color // Sphere - use sphere model with color
eprintln!("[bridge/reify] Creating sphere model for node {}", id); eprintln!("[bridge/reify] Creating sphere model for node {}", id);
let model = Model::namespaced("fusion", "tex_sphere") Model::namespaced("fusion", "tex_sphere")
.transform(transform) .transform(transform)
.part( .part(
ModelPart::new("Sphere") ModelPart::new("Sphere")
.mat_param("color", MaterialParameter::Color(node_color)) .mat_param("color", MaterialParameter::Color(node_color))
); ).build()
Some((*id, model.build()))
} }
3 => { 3 => {
// Model - use model URL if available, fallback to cube // Model - use model URL if available, fallback to cube
@@ -150,37 +148,34 @@ impl Reify for BridgeState {
eprintln!("[bridge/reify] Creating model from URL for node {}: {}", id, node.model_url); 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 // For now, use a fallback model since we can't load arbitrary URLs yet
// TODO: Implement model loading and caching // TODO: Implement model loading and caching
let model = Model::namespaced("fusion", "gyro") Model::namespaced("fusion", "gyro")
.transform(transform) .transform(transform)
.part( .part(
ModelPart::new("Gem") ModelPart::new("Gem")
.mat_param("color", MaterialParameter::Color(node_color)) .mat_param("color", MaterialParameter::Color(node_color))
); ).build()
Some((*id, model.build()))
} else { } else {
eprintln!("[bridge/reify] Creating fallback cube for node {} (no model URL)", id); eprintln!("[bridge/reify] Creating fallback cube for node {} (no model URL)", id);
let model = Model::namespaced("fusion", "tex_cube") Model::namespaced("fusion", "tex_cube")
.transform(transform) .transform(transform)
.part( .part(
ModelPart::new("Cube") ModelPart::new("Cube")
.mat_param("color", MaterialParameter::Color(node_color)) .mat_param("color", MaterialParameter::Color(node_color))
); ).build()
Some((*id, model.build()))
} }
} }
_ => { _ => {
// Unknown or unsupported type - render as wireframe // Unknown or unsupported type - render as wireframe
eprintln!("[bridge/reify] Creating wireframe for node {} type={}", id, node.entity_type); eprintln!("[bridge/reify] Creating wireframe for node {} type={}", id, node.entity_type);
let cube_lines = create_wireframe_cube(node_color, 0.003); let cube_lines = create_wireframe_cube(node_color, 0.003);
Some(( Spatial::default()
*id, .transform(transform)
Spatial::default() .build()
.transform(transform) .child(Lines::new(cube_lines).build())
.build()
.child(Lines::new(cube_lines).build())
))
} }
} };
Some((*id, element))
}); });
PlaySpace.build().stable_children(children) PlaySpace.build().stable_children(children)