First materials succesfully parsed

This commit is contained in:
hal8174 2025-08-19 20:38:03 +02:00
parent 9a95ca8fd7
commit c8ff77a0a9
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw
5 changed files with 197 additions and 172 deletions

View file

@ -1,6 +1,7 @@
use crate::tokenizer::Tokenizer;
use crate::{texture::Pbrt_2d_float_texture, tokenizer::Tokenizer};
use error::SourceFile;
use material::PbrtMaterial;
use miette::{IntoDiagnostic, Result, bail, miette};
use miette::{Diagnostic, IntoDiagnostic, Result, SourceSpan, bail, miette};
use ray_tracing_core::{
affine_transform::AffineTransform,
math::{Dir3, Pos3},
@ -12,6 +13,7 @@ use std::{
sync::Arc,
};
use texture::PbrtTexture;
use thiserror::Error;
#[macro_use]
mod tokenizer;
@ -642,7 +644,7 @@ enum ShapeAlpha {
#[derive(Debug)]
struct Shape {
ctm: AffineTransform,
material: usize,
material: Arc<dyn PbrtMaterial>,
obj: ShapeType,
alpha: ShapeAlpha,
}
@ -809,7 +811,12 @@ fn inner_parse_pbrt(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Pbrt> {
Statement::Shape(shape_type, shape_alpha) => {
pbrt.scene.shapes.push(Shape {
ctm: context.get_ctm(),
material: 0,
material: Arc::clone(
context
.material
.last()
.ok_or_else(|| miette!("No material specified"))?,
),
obj: shape_type,
alpha: shape_alpha,
});