ft: added cube

This commit is contained in:
2026-05-02 12:57:45 +02:00
parent e7018a84ed
commit c3d37f4758
6 changed files with 99 additions and 25 deletions

View File

@@ -1,13 +1,13 @@
use std::fmt::Debug;
use std::sync::Arc;
use serde_json::error::Error;
use log::warn;
use serde::Deserialize;
use crate::{
camera::Camera,
objects::{
cube::Cube,
materials::{
dielectric::Dielectric,
lambertian::{Lambertian, Metal},
@@ -113,8 +113,6 @@ impl RawMaterial {
}
}
#[derive(Deserialize)]
struct RawSphere {
pub center: Vec3,
@@ -139,12 +137,26 @@ struct RawQuad {
pub material: RawMaterial,
}
#[derive(Deserialize)]
struct RawCube {
pub p1: Vec3,
pub p2: Vec3,
pub p3: Vec3,
pub p4: Vec3,
pub p5: Vec3,
pub p6: Vec3,
pub p7: Vec3,
pub p8: Vec3,
pub material: RawMaterial,
}
#[derive(Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
enum HittableDef {
Sphere(RawSphere),
Triangle(RawTriangle),
Quad(RawQuad),
Cube(RawCube),
}
impl HittableDef {
@@ -175,6 +187,16 @@ impl HittableDef {
None
}
}
HittableDef::Cube(c) => {
let material = c.material.into_arc(materials);
if let Some(m) = material {
Some(Arc::new(Cube::new(
c.p1, c.p2, c.p3, c.p4, c.p5, c.p6, c.p7, c.p8, m,
)))
} else {
None
}
}
}
}
}