refactor: alias_id

This commit is contained in:
Nova
2024-09-11 13:55:15 -04:00
parent 79935befb7
commit 4730f0732b
26 changed files with 467 additions and 356 deletions

View File

@@ -1,7 +1,7 @@
use super::{Line, LinesAspect};
use crate::{
core::{client::Client, registry::Registry},
nodes::{spatial::Spatial, Aspect, Node},
nodes::{spatial::Spatial, Node},
};
use color_eyre::eyre::Result;
use glam::Vec3;
@@ -40,7 +40,6 @@ impl Lines {
space: node.get_aspect::<Spatial>()?.clone(),
data: Mutex::new(lines),
});
<Lines as LinesAspect>::add_node_members(node);
node.add_aspect_raw(lines.clone());
Ok(lines)
@@ -83,9 +82,6 @@ impl Lines {
}
}
}
impl Aspect for Lines {
const NAME: &'static str = "Lines";
}
impl LinesAspect for Lines {
fn set_lines(node: Arc<Node>, _calling_client: Arc<Client>, lines: Vec<Line>) -> Result<()> {
let lines_aspect = node.get_aspect::<Lines>()?;

View File

@@ -8,14 +8,12 @@ pub mod text;
use self::{lines::Lines, model::Model, text::Text};
use super::{
spatial::{Spatial, Transform},
Node,
Aspect, Node,
};
use crate::core::{client::Client, resource::get_resource_file};
use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO;
use crate::{
core::{client::Client, resource::get_resource_file},
create_interface,
};
use color_eyre::eyre::{self, Result};
use model::ModelPart;
use parking_lot::Mutex;
use stardust_xr::values::ResourceID;
use std::{ffi::OsStr, path::PathBuf, sync::Arc};
@@ -43,10 +41,20 @@ static QUEUED_SKYLIGHT: Mutex<Option<PathBuf>> = Mutex::new(None);
static QUEUED_SKYTEX: Mutex<Option<PathBuf>> = Mutex::new(None);
stardust_xr_server_codegen::codegen_drawable_protocol!();
create_interface!(DrawableInterface);
impl Aspect for Lines {
impl_aspect_for_lines_aspect! {}
}
impl Aspect for Model {
impl_aspect_for_model_aspect! {}
}
impl Aspect for ModelPart {
impl_aspect_for_model_part_aspect! {}
}
impl Aspect for Text {
impl_aspect_for_text_aspect! {}
}
pub struct DrawableInterface;
impl InterfaceAspect for DrawableInterface {
impl InterfaceAspect for Interface {
fn set_sky_tex(_node: Arc<Node>, calling_client: Arc<Client>, tex: ResourceID) -> Result<()> {
let resource_path = get_resource_file(&tex, &calling_client, &[OsStr::new("hdr")])
.ok_or(eyre::eyre!("Could not find resource"))?;

View File

@@ -4,7 +4,7 @@ use crate::core::registry::Registry;
use crate::core::resource::get_resource_file;
use crate::nodes::alias::{Alias, AliasList};
use crate::nodes::spatial::Spatial;
use crate::nodes::{Aspect, Node};
use crate::nodes::Node;
use color_eyre::eyre::{bail, eyre, Result};
use glam::{Mat4, Vec2, Vec3};
use once_cell::sync::{Lazy, OnceCell};
@@ -204,7 +204,6 @@ impl ModelPart {
pending_material_replacement: Mutex::new(None),
aliases: AliasList::default(),
});
<ModelPart as ModelPartAspect>::add_node_members(&node);
node.add_aspect_raw(model_part.clone());
parts.push(model_part.clone());
Some(model_part)
@@ -278,9 +277,6 @@ impl ModelPart {
}
}
}
impl Aspect for ModelPart {
const NAME: &'static str = "ModelPart";
}
impl ModelPartAspect for ModelPart {
#[doc = "Set this model part's material to one that cuts a hole in the world. Often used for overlays/passthrough where you want to show the background through an object."]
fn apply_holdout_material(node: Arc<Node>, _calling_client: Arc<Client>) -> Result<()> {
@@ -327,7 +323,6 @@ impl Model {
sk_model: OnceCell::new(),
parts: Mutex::new(Vec::default()),
});
<Model as ModelAspect>::add_node_members(node);
MODEL_REGISTRY.add_raw(&model);
// technically doing this in anything but the main thread isn't a good idea but dangit we need those model nodes ASAP
@@ -361,9 +356,6 @@ impl Model {
// TODO: proper hread safety in stereokit_rust (probably just bind stereokit directly)
unsafe impl Send for Model {}
unsafe impl Sync for Model {}
impl Aspect for Model {
const NAME: &'static str = "Model";
}
impl ModelAspect for Model {
#[doc = "Bind a model part to the node with the ID input."]
fn bind_model_part(

View File

@@ -1,6 +1,6 @@
use crate::{
core::{client::Client, destroy_queue, registry::Registry, resource::get_resource_file},
nodes::{spatial::Spatial, Aspect, Node},
nodes::{spatial::Spatial, Node},
};
use color_eyre::eyre::{eyre, Result};
use glam::{vec3, Mat4, Vec2};
@@ -53,7 +53,6 @@ impl Text {
text: Mutex::new(text),
data: Mutex::new(style),
});
<Text as TextAspect>::add_node_members(node);
node.add_aspect_raw(text.clone());
Ok(text)
@@ -132,9 +131,6 @@ impl Text {
}
}
}
impl Aspect for Text {
const NAME: &'static str = "Text";
}
impl TextAspect for Text {
fn set_character_height(
node: Arc<Node>,