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 = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"image",
|
"image",
|
||||||
|
"lithium-loader",
|
||||||
|
"slab",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lithium-loader"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"lithium-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lithium-utils"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.11"
|
version = "0.4.11"
|
||||||
|
@ -436,6 +449,15 @@ version = "0.3.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "slab"
|
||||||
|
version = "0.4.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.11.2"
|
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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
lithium-loader = { path = "lithium-loader" }
|
||||||
|
|
||||||
anyhow = "1.0.75"
|
anyhow = "1.0.75"
|
||||||
thiserror = "1.0.50"
|
thiserror = "1.0.50"
|
||||||
tokio = { version = "1.34.0", features = ["rt-multi-thread", "sync", "macros"] }
|
tokio = { version = "1.34.0", features = ["rt-multi-thread", "sync", "macros"] }
|
||||||
image = "0.24.7"
|
image = "0.24.7"
|
||||||
|
slab = "0.4.9"
|
||||||
|
|
|
@ -5,3 +5,10 @@ version = 3
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lithium-loader"
|
name = "lithium-loader"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"lithium-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lithium-utils"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
name = "lithium-loader"
|
name = "lithium-loader"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
license = "MIT"
|
||||||
|
authors = ["antifallobst"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
lithium-utils = { path = "../lithium-utils" }
|
|
@ -1,14 +1,40 @@
|
||||||
pub fn add(left: usize, right: usize) -> usize {
|
use lithium_utils::{Vector2, Vector3, Vertex};
|
||||||
left + right
|
|
||||||
|
pub struct Model {
|
||||||
|
name: String,
|
||||||
|
|
||||||
|
sub_models: Vec<Model>,
|
||||||
|
vertices: Vec<Vertex>,
|
||||||
|
faces: Vec<(u32, u32, u32)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
impl Model {
|
||||||
mod tests {
|
pub fn test() -> Self {
|
||||||
use super::*;
|
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]
|
let faces = vec![(0, 1, 2)];
|
||||||
fn it_works() {
|
|
||||||
let result = add(2, 2);
|
Self {
|
||||||
assert_eq!(result, 4);
|
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 camera;
|
||||||
pub mod coords;
|
|
||||||
mod vertex;
|
|
||||||
|
|
||||||
use crate::output::Output;
|
use crate::output::Output;
|
||||||
use crate::render::camera::Camera;
|
use crate::render::camera::Camera;
|
||||||
use crate::render::coords::Coords3d;
|
|
||||||
use crate::render::vertex::Vertex;
|
use lithium_loader::Model;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
|
|
||||||
pub struct Renderer {
|
pub struct Renderer {
|
||||||
cameras: Vec<Camera>,
|
cameras: Slab<Camera>,
|
||||||
vertices: Vec<Vertex>,
|
models: Slab<Model>,
|
||||||
|
|
||||||
vertex_id: u32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
cameras: Vec::new(),
|
cameras: Slab::new(),
|
||||||
vertices: Vec::new(),
|
models: Slab::new(),
|
||||||
vertex_id: 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_vertex(&mut self, position: Coords3d) -> u32 {
|
pub fn add_camera(&mut self, output: impl Output + 'static) -> usize {
|
||||||
let id = self.vertex_id;
|
self.cameras.insert(Camera::new(output))
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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