feat(core): added the Object type
This commit is contained in:
parent
eddb0693e4
commit
6815077035
|
@ -265,6 +265,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"image",
|
||||
"lithium-loader",
|
||||
"lithium-utils",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue