feat: added Model struct and some utils
This commit is contained in:
parent
2c11839d21
commit
76b30d6b0f
|
@ -264,10 +264,23 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"image",
|
||||
"lithium-loader",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lithium-loader"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lithium-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lithium-utils"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.11"
|
||||
|
@ -436,6 +449,15 @@ version = "0.3.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.11.2"
|
||||
|
|
|
@ -8,7 +8,10 @@ authors = ["antifallobst"]
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
lithium-loader = { path = "lithium-loader" }
|
||||
|
||||
anyhow = "1.0.75"
|
||||
thiserror = "1.0.50"
|
||||
tokio = { version = "1.34.0", features = ["rt-multi-thread", "sync", "macros"] }
|
||||
image = "0.24.7"
|
||||
slab = "0.4.9"
|
||||
|
|
|
@ -5,3 +5,10 @@ version = 3
|
|||
[[package]]
|
||||
name = "lithium-loader"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lithium-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lithium-utils"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
name = "lithium-loader"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = ["antifallobst"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
lithium-utils = { path = "../lithium-utils" }
|
|
@ -1,14 +1,40 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
use lithium_utils::{Vector2, Vector3, Vertex};
|
||||
|
||||
pub struct Model {
|
||||
name: String,
|
||||
|
||||
sub_models: Vec<Model>,
|
||||
vertices: Vec<Vertex>,
|
||||
faces: Vec<(u32, u32, u32)>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
impl Model {
|
||||
pub fn test() -> Self {
|
||||
let vertices = vec![
|
||||
Vertex::new(
|
||||
Vector3::new(0_f32, 0_f32, 0_f32),
|
||||
Vector2::default(),
|
||||
Vector3::default(),
|
||||
),
|
||||
Vertex::new(
|
||||
Vector3::new(0.5_f32, 1_f32, 0_f32),
|
||||
Vector2::default(),
|
||||
Vector3::default(),
|
||||
),
|
||||
Vertex::new(
|
||||
Vector3::new(1_f32, 0_f32, 0_f32),
|
||||
Vector2::default(),
|
||||
Vector3::default(),
|
||||
),
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
let faces = vec![(0, 1, 2)];
|
||||
|
||||
Self {
|
||||
name: "Test".to_string(),
|
||||
sub_models: Vec::new(),
|
||||
vertices,
|
||||
faces,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/target
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "lithium-utils"
|
||||
version = "0.1.0"
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "lithium-utils"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = ["antifallobst"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -0,0 +1,54 @@
|
|||
pub struct Vector2 {
|
||||
x: f32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
impl Default for Vector3 {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
x: 0_f32,
|
||||
y: 0_f32,
|
||||
z: 0_f32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Vector2 {
|
||||
pub fn new(x: f32, y: f32) -> Self {
|
||||
Self { x, y }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Vector3 {
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
}
|
||||
|
||||
impl Default for Vector2 {
|
||||
fn default() -> Self {
|
||||
Self { x: 0_f32, y: 0_f32 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Vector3 {
|
||||
pub fn new(x: f32, y: f32, z: f32) -> Self {
|
||||
Self { x, y, z }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Vertex {
|
||||
position: Vector3,
|
||||
uv: Vector2,
|
||||
normal: Vector3,
|
||||
}
|
||||
|
||||
impl Vertex {
|
||||
pub fn new(position: Vector3, uv: Vector2, normal: Vector3) -> Self {
|
||||
Self {
|
||||
position,
|
||||
uv,
|
||||
normal,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
pub struct Coords3d {
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
}
|
||||
|
||||
impl Coords3d {
|
||||
pub fn new(x: f32, y: f32, z: f32) -> Self {
|
||||
Self { x, y, z }
|
||||
}
|
||||
}
|
|
@ -1,38 +1,25 @@
|
|||
pub mod camera;
|
||||
pub mod coords;
|
||||
mod vertex;
|
||||
|
||||
use crate::output::Output;
|
||||
use crate::render::camera::Camera;
|
||||
use crate::render::coords::Coords3d;
|
||||
use crate::render::vertex::Vertex;
|
||||
|
||||
use lithium_loader::Model;
|
||||
use slab::Slab;
|
||||
|
||||
pub struct Renderer {
|
||||
cameras: Vec<Camera>,
|
||||
vertices: Vec<Vertex>,
|
||||
|
||||
vertex_id: u32,
|
||||
cameras: Slab<Camera>,
|
||||
models: Slab<Model>,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
cameras: Vec::new(),
|
||||
vertices: Vec::new(),
|
||||
vertex_id: 0,
|
||||
cameras: Slab::new(),
|
||||
models: Slab::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_vertex(&mut self, position: Coords3d) -> u32 {
|
||||
let id = self.vertex_id;
|
||||
self.vertex_id = self.vertex_id + 1;
|
||||
|
||||
self.vertices.push(Vertex::new(id, position));
|
||||
id
|
||||
}
|
||||
|
||||
pub fn add_camera(&mut self, output: impl Output + 'static) {
|
||||
self.cameras.push(Camera::new(output))
|
||||
pub fn add_camera(&mut self, output: impl Output + 'static) -> usize {
|
||||
self.cameras.insert(Camera::new(output))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
use crate::render::coords::Coords3d;
|
||||
|
||||
pub struct Vertex {
|
||||
id: u32,
|
||||
position: Coords3d,
|
||||
}
|
||||
|
||||
impl Vertex {
|
||||
pub fn new(id: u32, position: Coords3d) -> Self {
|
||||
Self { id, position }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue