feat(core): added the Object type

This commit is contained in:
antifallobst 2023-11-30 19:10:36 +01:00
parent eddb0693e4
commit 6815077035
Signed by: antifallobst
GPG Key ID: 2B4F402172791BAF
5 changed files with 38 additions and 8 deletions

1
Cargo.lock generated
View File

@ -265,6 +265,7 @@ dependencies = [
"anyhow",
"image",
"lithium-loader",
"lithium-utils",
"slab",
"thiserror",
"tokio",

View File

@ -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"

View File

@ -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(())
}

View File

@ -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<Camera>,
models: Slab<Model>,
objects: Slab<Object>,
}
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<image::RgbImage, LithiumError> {
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<RgbImage, LithiumError> {
let camera = self
.cameras
.get(camera)

13
src/render/object.rs Normal file
View File

@ -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 }
}
}