56 lines
1.2 KiB
Rust
56 lines
1.2 KiB
Rust
pub struct Model {
|
|
pub name: Option<String>,
|
|
pub objects: Vec<Object>,
|
|
}
|
|
|
|
pub struct Object {
|
|
pub name: Option<String>,
|
|
pub mesh: Mesh,
|
|
pub children: Vec<Object>,
|
|
}
|
|
|
|
pub struct Mesh {
|
|
pub transform: Transform,
|
|
pub data: MeshData,
|
|
}
|
|
|
|
pub struct MeshData {
|
|
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,
|
|
}
|
|
}
|
|
}
|