cyborg/editor/src/model.rs

52 lines
1.1 KiB
Rust

pub struct Model {
pub name: Option<String>,
pub objects: Vec<Object>,
}
pub struct Object {
pub name: Option<String>,
pub transform: Transform,
pub meshes: Vec<Mesh>,
pub children: Vec<Object>,
}
pub struct Mesh {
pub vertices: Vec<BasicVertex>,
pub indices: Vec<u32>,
}
pub struct BasicVertex {
pub position: glam::Vec3,
}
#[derive(Copy, Clone, Debug)]
pub struct Transform {
pub position: glam::Vec3,
pub rotation: glam::Vec3, // TODO support glam::Quat too
pub scale: f32,
}
impl Transform {
pub fn to_mat4(&self) -> glam::Mat4 {
let translation = self.position;
let rotation = glam::Quat::from_euler(
glam::EulerRot::XYZ,
self.rotation[0],
self.rotation[1],
self.rotation[2],
);
let scale = glam::Vec3::splat(self.scale);
glam::Mat4::from_scale_rotation_translation(scale, rotation, translation)
}
}
impl Default for Transform {
fn default() -> Self {
Self {
position: glam::Vec3::ZERO,
rotation: glam::Vec3::ZERO,
scale: 1.0,
}
}
}