Rendering something parsed from a pbrt file

This commit is contained in:
hal8174 2025-08-20 23:20:41 +02:00
parent c8ff77a0a9
commit 6d363aecd0
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw
7 changed files with 316 additions and 127 deletions

View file

@ -1,4 +1,9 @@
use crate::{texture::Pbrt_2d_float_texture, tokenizer::Tokenizer};
use crate::{
scene::PbrtScene,
shape::{Shape, ShapeAlpha, ShapeType},
texture::Pbrt_2d_float_texture,
tokenizer::Tokenizer,
};
use error::SourceFile;
use material::PbrtMaterial;
use miette::{Diagnostic, IntoDiagnostic, Result, SourceSpan, bail, miette};
@ -21,6 +26,8 @@ mod tokenizer;
mod either;
mod error;
mod material;
pub mod scene;
mod shape;
mod texture;
struct Lexer {
@ -595,64 +602,10 @@ impl Parser {
}
}
#[derive(Debug)]
enum ShapeType {
Sphere {
radius: Float,
zmin: Float,
zmax: Float,
phimax: Float,
},
TriangleMesh {
indices: Vec<usize>,
p: Vec<Pos3>,
n: Vec<Dir3>,
s: Vec<Dir3>,
uv: Vec<[Float; 2]>,
},
BilinearMesh {
indices: Vec<usize>,
p: Vec<Pos3>,
n: Vec<Dir3>,
uv: Vec<[Float; 2]>,
},
LoopSubDiv {
levels: u32,
indices: Vec<usize>,
p: Vec<Pos3>,
},
Disk {
height: Float,
radius: Float,
innerradius: Float,
phimax: Float,
},
PlyMesh {
filename: String,
displacement: Option<String>,
edgelength: Float,
},
}
#[derive(Debug)]
enum ShapeAlpha {
None,
Value(Float),
Texture(String),
}
#[derive(Debug)]
struct Shape {
ctm: AffineTransform,
material: Arc<dyn PbrtMaterial>,
obj: ShapeType,
alpha: ShapeAlpha,
}
#[derive(Debug)]
pub struct Pbrt {
settings: PbrtWorldSettings,
scene: PbrtScene,
pub settings: PbrtWorldSettings,
pub scene: PbrtScene,
}
impl Pbrt {
@ -670,11 +623,6 @@ struct PbrtWorldSettings {
camera_ctm: AffineTransform,
}
#[derive(Debug)]
struct PbrtScene {
shapes: Vec<Shape>,
}
#[derive(Debug)]
pub struct PbrtContext {
ctm: Vec<AffineTransform>,
@ -861,7 +809,7 @@ fn inner_parse_pbrt(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Pbrt> {
}
}
dbg!(context);
// dbg!(context);
Ok(pbrt)
}