From 681507703570ef62c754fb85eaedb548b1819c4e Mon Sep 17 00:00:00 2001 From: antifallobst Date: Thu, 30 Nov 2023 19:10:36 +0100 Subject: [PATCH] feat(core): added the Object type --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 9 ++++++--- src/render/mod.rs | 22 +++++++++++++++++----- src/render/object.rs | 13 +++++++++++++ 5 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/render/object.rs diff --git a/Cargo.lock b/Cargo.lock index ae15851..87d2f51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,6 +265,7 @@ dependencies = [ "anyhow", "image", "lithium-loader", + "lithium-utils", "slab", "thiserror", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 9438b0d..826a4ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ authors = ["antifallobst"] [dependencies] lithium-loader = { path = "lithium-loader" } +lithium-utils = { path = "lithium-utils" } anyhow = "1.0.75" thiserror = "1.0.50" diff --git a/src/main.rs b/src/main.rs index 23c45db..d7f30a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,19 @@ -pub mod render; pub mod error; +pub mod render; use crate::render::Renderer; use anyhow::Result; +use lithium_loader::Model; +use lithium_utils::Vector3; #[tokio::main] async fn main() -> Result<()> { let mut renderer = Renderer::new(); let camera = renderer.add_camera(512, 512); - + let test = renderer.add_object(Model::test(), Vector3::default()); + let image = renderer.render(camera).await?; image.save("image.png")?; - + Ok(()) } diff --git a/src/render/mod.rs b/src/render/mod.rs index 067a172..a1d9a77 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1,29 +1,41 @@ pub mod camera; +pub mod object; -use crate::{error::LithiumError, render::camera::Camera}; +use crate::{ + error::LithiumError, + render::{camera::Camera, object::Object}, +}; use anyhow::Result; use image::RgbImage; use lithium_loader::Model; +use lithium_utils::Vector3; use slab::Slab; +pub type CameraHandle = usize; +pub type ObjectHandle = usize; + pub struct Renderer { cameras: Slab, - models: Slab, + objects: Slab, } impl Renderer { pub fn new() -> Self { Self { cameras: Slab::new(), - models: Slab::new(), + objects: Slab::new(), } } - pub fn add_camera(&mut self, width: u32, height: u32) -> usize { + pub fn add_camera(&mut self, width: u32, height: u32) -> CameraHandle { self.cameras.insert(Camera::new(width, height)) } - pub async fn render(&self, camera: usize) -> Result { + pub fn add_object(&mut self, model: Model, position: Vector3) -> ObjectHandle { + self.objects.insert(Object::new(model, position)) + } + + pub async fn render(&self, camera: CameraHandle) -> Result { let camera = self .cameras .get(camera) diff --git a/src/render/object.rs b/src/render/object.rs new file mode 100644 index 0000000..2a1bdab --- /dev/null +++ b/src/render/object.rs @@ -0,0 +1,13 @@ +use lithium_loader::Model; +use lithium_utils::Vector3; + +pub struct Object { + model: Model, + position: Vector3, +} + +impl Object { + pub fn new(model: Model, position: Vector3) -> Self { + Self { model, position } + } +}