use crate::engine::ecs::ComponentId;
use crate::engine::ecs::component::Component;
#[derive(Debug, Clone)]
pub struct NormalVisualisationComponent {
pub thickness: f32,
pub spawned_roots: Vec<ComponentId>,
component: Option<ComponentId>,
}
impl NormalVisualisationComponent {
pub fn new() -> Self {
Self {
thickness: 0.02,
spawned_roots: Vec::new(),
component: None,
}
}
pub fn with_thickness(mut self, t: f32) -> Self {
self.thickness = t;
self
}
pub fn id(&self) -> Option<ComponentId> {
self.component
}
}
impl Default for NormalVisualisationComponent {
fn default() -> Self {
Self::new()
}
}
impl Component for NormalVisualisationComponent {
fn set_id(&mut self, component: ComponentId) {
self.component = Some(component);
}
fn name(&self) -> &'static str {
"normal_visualisation"
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
self
}
fn init(&mut self, emit: &mut dyn crate::engine::ecs::SignalEmitter, component: ComponentId) {
emit.push_intent_now(
component,
crate::engine::ecs::IntentValue::RegisterNormalVis {
component_id: component,
},
);
}
fn cleanup(
&mut self,
emit: &mut dyn crate::engine::ecs::SignalEmitter,
_component: ComponentId,
) {
for root in self.spawned_roots.drain(..) {
emit.push_intent_now(
root,
crate::engine::ecs::IntentValue::RemoveSubtree { component_id: root },
);
}
}
fn to_mms_ast(
&self,
_world: &crate::engine::ecs::World,
) -> crate::scripting::ast::ComponentExpression {
use crate::engine::ecs::component::ce_helpers::*;
ce_call("NormalVis", "thickness", vec![num(self.thickness as f64)])
}
}