use crate::engine::ecs::ComponentId;
use crate::engine::ecs::component::Component;
#[derive(Debug, Clone)]
pub struct GLTFComponent {
pub uri: String,
pub with_visualized_transforms: bool,
pub spawned: bool,
pub armature_visible: bool,
pub bounds_visible: bool,
pub spawned_node_transforms: Vec<ComponentId>,
pub armature_joint_transforms: Vec<ComponentId>,
component: Option<ComponentId>,
}
impl GLTFComponent {
pub fn new(uri: impl Into<String>) -> Self {
Self {
uri: uri.into(),
with_visualized_transforms: false,
spawned: false,
armature_visible: false,
bounds_visible: false,
spawned_node_transforms: Vec::new(),
armature_joint_transforms: Vec::new(),
component: None,
}
}
pub fn with_visualized_transforms(mut self, with_visualized_transforms: bool) -> Self {
self.with_visualized_transforms = with_visualized_transforms;
self
}
}
impl Component for GLTFComponent {
fn name(&self) -> &'static str {
"gltf"
}
fn set_id(&mut self, component: ComponentId) {
self.component = Some(component);
let _ = self.component;
}
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::RegisterGLTF {
component_id: component,
},
);
}
fn to_mms_ast(
&self,
_world: &crate::engine::ecs::World,
) -> crate::scripting::ast::ComponentExpression {
use crate::engine::ecs::component::ce_helpers::*;
let mut ce = ce_call("GLTF", "new", vec![s(&self.uri)]);
if self.with_visualized_transforms {
ce = ce.with_call("with_visualized_transforms", vec![b(true)]);
}
ce
}
}