feat: spatial bounds

This commit is contained in:
Nova
2023-06-11 00:38:05 -04:00
parent e9089e83a9
commit c8206b14dd
6 changed files with 88 additions and 5 deletions

View File

@@ -14,7 +14,7 @@ use prisma::{Flatten, Lerp, Rgba};
use serde::Deserialize;
use stardust_xr::{schemas::flex::deserialize, values::Transform};
use std::{collections::VecDeque, sync::Arc};
use stereokit::{Color128, LinePoint as SkLinePoint, StereoKitDraw};
use stereokit::{bounds_grow_to_fit_pt, Bounds, Color128, LinePoint as SkLinePoint, StereoKitDraw};
use super::Drawable;
@@ -45,6 +45,16 @@ impl Lines {
"Internal: Node already has a drawable attached!"
);
let _ = node.spatial.get().unwrap().bounding_box_calc.set(|node| {
let mut bounds = Bounds::default();
let Some(Drawable::Lines(lines)) = node.drawable.get() else {return bounds};
for point in &lines.data.lock().points {
bounds = bounds_grow_to_fit_pt(bounds, point.point);
}
bounds
});
let lines = LINES_REGISTRY.add(Lines {
enabled: node.enabled.clone(),
space: node.get_aspect("Lines", "spatial", |n| &n.spatial)?.clone(),