Fix all warnings

This commit is contained in:
hal8174 2025-08-23 13:36:07 +02:00
parent 2bc5ec93fe
commit ae4dc2c21a
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw
26 changed files with 249 additions and 185 deletions

View file

@ -10,7 +10,7 @@ struct Args {
fn main() -> Result<(), miette::Error> {
let args = Args::parse();
let t = parse_pbrt_v4(args.filename)?;
let _t = parse_pbrt_v4(args.filename)?;
// dbg!(t);

View file

@ -5,12 +5,12 @@ pub enum Either<A, B> {
}
impl<A, B> Either<A, B> {
pub fn map_a<C>(self, f: impl FnOnce(A) -> C) -> Either<C, B> {
match self {
Either::A(a) => Either::A(f(a)),
Either::B(b) => Either::B(b),
}
}
// pub fn map_a<C>(self, f: impl FnOnce(A) -> C) -> Either<C, B> {
// match self {
// Either::A(a) => Either::A(f(a)),
// Either::B(b) => Either::B(b),
// }
// }
pub fn map_b<C>(self, f: impl FnOnce(B) -> C) -> Either<A, C> {
match self {
Either::A(a) => Either::A(a),

View file

@ -1,12 +1,10 @@
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};
use miette::{IntoDiagnostic, Result, bail, miette};
use ray_tracing_core::{
affine_transform::AffineTransform,
math::{Dir3, Pos3},
@ -18,7 +16,6 @@ use std::{
sync::Arc,
};
use texture::PbrtTexture;
use thiserror::Error;
#[macro_use]
mod tokenizer;
@ -43,6 +40,7 @@ impl Lexer {
}
#[derive(Debug)]
#[allow(dead_code)]
enum CameraType {
Orthographic {
frame_aspect_ratio: Option<Float>,
@ -60,6 +58,7 @@ enum CameraType {
}
#[derive(Debug)]
#[allow(dead_code)]
struct PbrtCamera {
camera_type: CameraType,
shutter_open: Float,
@ -465,8 +464,8 @@ fn parse_transform(input: &mut Tokenizer) -> Result<AffineTransform> {
let mut v = [0.0; 16];
for i in 0..16 {
v[i] = input
for i in &mut v {
*i = input
.next()
.ok_or(miette!("value expected"))??
.parse::<Float>()
@ -618,7 +617,8 @@ impl Pbrt {
}
#[derive(Debug)]
struct PbrtWorldSettings {
#[allow(dead_code)]
pub struct PbrtWorldSettings {
camera: PbrtCamera,
camera_ctm: AffineTransform,
}
@ -747,7 +747,7 @@ fn inner_parse_pbrt(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Pbrt> {
match p {
Statement::AttributeBegin => context.push(),
Statement::AttributeEnd => {
context.pop();
context.pop()?;
}
Statement::Include(_) => unreachable!(),
Statement::ConcatTransform(affine_transform) => {

View file

@ -2,7 +2,7 @@ use ray_tracing_core::color::Color;
use crate::{
either::Either,
texture::{Pbrt_2d_float_texture, Pbrt_2d_spectrum_texture, parse_rgb},
texture::{Pbrt2dFloatTexture, Pbrt2dSpectrumTexture, parse_rgb},
};
use super::*;
@ -24,40 +24,45 @@ pub fn parse_make_named_material(
}
#[derive(Debug)]
#[allow(dead_code)]
struct PbrtCoatedDiffuseMaterial {
albedo: Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
g: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
albedo: Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
g: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
maxdepth: usize,
nsamples: usize,
thickness: Float,
roughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
uroughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
vroughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
reflectance: Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
roughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
uroughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
vroughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
reflectance: Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
#[allow(clippy::type_complexity)]
eta: Either<
Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
>,
}
impl PbrtMaterial for PbrtCoatedDiffuseMaterial {}
#[derive(Debug)]
#[allow(dead_code)]
struct PbrtDielectricMaterial {
#[allow(clippy::type_complexity)]
eta: Either<
Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
>,
roughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
uroughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
vroughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
roughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
uroughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
vroughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
}
impl PbrtMaterial for PbrtDielectricMaterial {}
#[derive(Debug)]
#[allow(dead_code)]
struct PbrtDiffuseMaterial {
reflectance: Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
reflectance: Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
}
impl PbrtMaterial for PbrtDiffuseMaterial {}
@ -65,7 +70,7 @@ impl PbrtMaterial for PbrtDiffuseMaterial {}
fn parse_2d_float_texture(
input: &mut Tokenizer,
context: &PbrtContext,
) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
let n = input.parse_parameter()?;
context
@ -77,7 +82,7 @@ fn parse_2d_float_texture(
fn parse_2d_spectrum_texture(
input: &mut Tokenizer,
context: &PbrtContext,
) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
let n = input.parse_parameter()?;
context

View file

@ -17,11 +17,11 @@ impl<R: Rng> Scene<R> for PbrtScene {
R: 'a;
fn intersect(
&self,
&'_ self,
ray: ray_tracing_core::prelude::Ray,
min: ray_tracing_core::prelude::Float,
max: ray_tracing_core::prelude::Float,
) -> Option<ray_tracing_core::scene::Intersection<R, Self::Mat<'_>>> {
) -> Option<ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'_>>> {
let mut i = None;
for s in &self.shapes {
if let Some(new_i) = s.intersect::<R>(ray, min, max)
@ -40,9 +40,9 @@ impl<R: Rng> Scene<R> for PbrtScene {
fn sample_light<'b>(
&self,
w_in: ray_tracing_core::prelude::Dir3,
intersection: &ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'b>>,
rng: &mut R,
_w_in: ray_tracing_core::prelude::Dir3,
_intersection: &ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'b>>,
_rng: &mut R,
) -> Option<ray_tracing_core::scene::LightSample<'_, R>>
where
Self: 'b,

View file

@ -5,6 +5,7 @@ use ray_tracing_core::{affine_transform::AffineTransform, prelude::*, scene::Int
use crate::material::PbrtMaterial;
#[derive(Debug)]
#[allow(dead_code)]
pub(crate) struct Shape {
pub(crate) ctm: AffineTransform,
pub(crate) material: Arc<dyn PbrtMaterial>,
@ -13,6 +14,7 @@ pub(crate) struct Shape {
}
#[derive(Debug)]
#[allow(dead_code)]
pub(crate) enum ShapeAlpha {
None,
Value(Float),
@ -20,6 +22,7 @@ pub(crate) enum ShapeAlpha {
}
#[derive(Debug)]
#[allow(dead_code)]
pub(crate) enum ShapeType {
Sphere {
radius: Float,
@ -115,7 +118,7 @@ fn bilinear_intersection(
.into_iter()
.flatten()
.filter(|&u| {
if 0.0 <= u && u <= 1.0 {
if (0.0..=1.0).contains(&u) {
return true;
}
false
@ -146,7 +149,7 @@ fn bilinear_intersection(
- ud.x() * deltao.y() * perp.z()
- perp.x() * ud.y() * deltao.z();
if t1 > 0.0 && 0.0 < v1 && v1 <= p2 {
if t1 >= min && t1 <= max && 0.0 < v1 && v1 <= p2 {
Some((t1 / p2, u, v1 / p2))
} else {
None
@ -157,11 +160,11 @@ fn bilinear_intersection(
impl Shape {
pub(crate) fn intersect<R: Rng>(
&self,
&'_ self,
ray: Ray,
min: Float,
max: Float,
) -> Option<Intersection<R, &'_ dyn Material<R>>> {
) -> Option<Intersection<'_, R, &'_ dyn Material<R>>> {
let ray = self.ctm.transform_ray(ray);
match &self.obj {
@ -220,14 +223,13 @@ impl Shape {
}
}
}
ShapeType::TriangleMesh {
ShapeType::TriangleMesh { .. } => (),
ShapeType::BilinearMesh {
indices,
p,
n,
s,
uv,
} => (),
ShapeType::BilinearMesh { indices, p, n, uv } => {
n: _,
uv: _,
} => {
if indices.is_empty()
&& let Some((t, _u, _v)) =
bilinear_intersection(ray, min, max, [p[0], p[1], p[2], p[3]])
@ -235,18 +237,9 @@ impl Shape {
return Some(Intersection::new(t, Dir3::up(), None, None, 0.0));
}
}
ShapeType::LoopSubDiv { levels, indices, p } => todo!(),
ShapeType::Disk {
height,
radius,
innerradius,
phimax,
} => (),
ShapeType::PlyMesh {
filename,
displacement,
edgelength,
} => (),
ShapeType::LoopSubDiv { .. } => todo!(),
ShapeType::Disk { .. } => (),
ShapeType::PlyMesh { .. } => (),
}
None

View file

@ -1,10 +1,9 @@
use crate::{PbrtContext, either::Either, tokenizer::Tokenizer};
use imagemap::{ImageMapEncoding, ImageMapWrap, SpectrumImageMapTexture};
use miette::{Result, miette};
use ray_tracing_core::{affine_transform::AffineTransform, color::Color, prelude::Float};
use ray_tracing_core::{color::Color, prelude::Float};
use scale::SpectrumScaleTexture2d;
use std::{collections::HashMap, ops::Deref, sync::Arc};
use crate::{PbrtContext, either::Either, tokenizer::Tokenizer};
use std::sync::Arc;
mod checkerboard;
mod imagemap;
@ -12,20 +11,20 @@ mod scale;
pub trait PbrtTexture: std::fmt::Debug + Send + Sync {
fn get_dimension(&self) -> TextureDimension;
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>>;
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>>;
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>>;
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>>;
}
pub trait Pbrt_2d_float_texture: std::fmt::Debug + Sync + Send {
pub trait Pbrt2dFloatTexture: std::fmt::Debug + Sync + Send {
fn get(&self, u: Float, v: Float) -> Float;
}
pub trait Pbrt_2d_spectrum_texture: std::fmt::Debug + Sync + Send {
pub trait Pbrt2dSpectrumTexture: std::fmt::Debug + Sync + Send {
fn get(&self, u: Float, v: Float) -> Color;
}
#[derive(Debug)]
enum TextureDimension {
pub enum TextureDimension {
D2,
D3,
}
@ -57,6 +56,7 @@ impl TextureMapping {
}
pub fn parse_spectrum(input: &mut Tokenizer) -> Result<Color> {
let _ = input;
todo!()
}
@ -71,8 +71,67 @@ fn parse_float_texture(
) -> Result<Arc<dyn PbrtTexture>> {
let texture_class: String = input.parse_next()?;
dbg!(texture_class);
todo!()
match texture_class.as_str() {
"\"checkerboard\"" => {
let t = parse_dict!(input =>
mapping, TextureMapping, TextureMapping::UV;
uscale, Float, 1.0;
vscale, Float, 1.0;
udelta, Float, 0.0;
vdelta, Float, 0.0;
dimension, TextureDimension, TextureDimension::D2;
tex1, Either<Float, String>, Either::A(1.0);
tex2, Either<Float, String>, Either::A(0.0)
=>
mapping, "\"string mapping\"", TextureMapping::new(input.parse_parameter()?)?;
uscale, "\"float uscale\"", input.parse_parameter()?;
vscale, "\"float vscale\"", input.parse_parameter()?;
udelta, "\"float udelta\"", input.parse_parameter()?;
vdelta, "\"float vdelta\"", input.parse_parameter()?;
dimension, "\"integer dimension\"", TextureDimension::new(input.parse_parameter()?)?;
tex1, "\"float tex1\"", Either::A(input.parse_parameter()?);
tex1, "\"texture tex1\"", Either::B(input.parse_parameter()?);
tex2, "\"float tex2\"", Either::A(input.parse_parameter()?);
tex2, "\"texture tex2\"", Either::B(input.parse_parameter()?)
);
let mapping = UVMapping::new(t.mapping, t.uscale, t.vscale, t.udelta, t.vdelta);
match t.dimension {
TextureDimension::D2 => Ok(Arc::new(checkerboard::FloatCheckerboardTexture2d {
mapping,
tex: [
t.tex1
.map_b(|name| {
Arc::clone(
context
.get_texture(&name)
.ok_or_else(|| miette!("unable to find texture"))?,
)
.get_2d_float_texture()
})
.transpose_b()?,
t.tex2
.map_b(|name| {
Arc::clone(
context
.get_texture(&name)
.ok_or_else(|| miette!("unable to find texture"))?,
)
.get_2d_float_texture()
})
.transpose_b()?,
],
})),
TextureDimension::D3 => {
todo!()
}
}
}
_ => Err(miette!("unknown error {texture_class}")),
}
}
fn parse_spectrum_texture(

View file

@ -3,10 +3,10 @@ use super::*;
#[derive(Debug)]
pub(super) struct FloatCheckerboardTexture2d {
pub(super) mapping: UVMapping,
pub(super) tex: [Either<Float, Arc<dyn Pbrt_2d_float_texture>>; 2],
pub(super) tex: [Either<Float, Arc<dyn Pbrt2dFloatTexture>>; 2],
}
impl Pbrt_2d_float_texture for FloatCheckerboardTexture2d {
impl Pbrt2dFloatTexture for FloatCheckerboardTexture2d {
fn get(&self, u: Float, v: Float) -> Float {
let (u, v) = self.mapping.map(u, v);
@ -28,11 +28,11 @@ impl Pbrt_2d_float_texture for FloatCheckerboardTexture2d {
}
impl PbrtTexture for FloatCheckerboardTexture2d {
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
Ok(self)
}
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
Err(miette!("Unable to use this texture as a spectrum texture"))
}
@ -43,10 +43,10 @@ impl PbrtTexture for FloatCheckerboardTexture2d {
#[derive(Debug)]
pub(super) struct SpectrumCheckerboardTexture2d {
pub(super) mapping: UVMapping,
pub(super) tex: [Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>; 2],
pub(super) tex: [Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>; 2],
}
impl Pbrt_2d_spectrum_texture for SpectrumCheckerboardTexture2d {
impl Pbrt2dSpectrumTexture for SpectrumCheckerboardTexture2d {
fn get(&self, u: Float, v: Float) -> Color {
let (u, v) = self.mapping.map(u, v);
@ -68,11 +68,11 @@ impl Pbrt_2d_spectrum_texture for SpectrumCheckerboardTexture2d {
}
impl PbrtTexture for SpectrumCheckerboardTexture2d {
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
Err(miette!("Unable to use this texture as a float texture"))
}
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
Ok(self)
}

View file

@ -24,6 +24,7 @@ impl ImageMapWrap {
#[derive(Debug)]
pub(super) enum ImageMapEncoding {
#[allow(clippy::upper_case_acronyms)]
SRGB,
Linear,
Gamma(Float),
@ -118,22 +119,23 @@ impl SpectrumImageMapTexture {
}
}
impl Pbrt_2d_spectrum_texture for SpectrumImageMapTexture {
impl Pbrt2dSpectrumTexture for SpectrumImageMapTexture {
fn get(&self, u: Float, v: Float) -> Color {
let (u, v) = self.mapping.map(u, v);
let (w, h) = self.image.dimensions();
dbg!(u, v, w, h);
todo!()
}
}
impl PbrtTexture for SpectrumImageMapTexture {
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
Err(miette!("Unable to use this texture as a float texture"))
}
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
Ok(self)
}

View file

@ -2,8 +2,8 @@ use super::*;
#[derive(Debug)]
pub(super) struct SpectrumScaleTexture2d {
pub(super) tex: Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
pub(super) scale: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
pub(super) tex: Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
pub(super) scale: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
}
impl PbrtTexture for SpectrumScaleTexture2d {
@ -11,16 +11,16 @@ impl PbrtTexture for SpectrumScaleTexture2d {
TextureDimension::D2
}
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
Err(miette!("Unable to convert to float texture"))
}
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
Ok(self)
}
}
impl Pbrt_2d_spectrum_texture for SpectrumScaleTexture2d {
impl Pbrt2dSpectrumTexture for SpectrumScaleTexture2d {
fn get(&self, u: Float, v: Float) -> Color {
let x = match &self.tex {
Either::A(x) => *x,

View file

@ -1,15 +1,10 @@
use crate::{
BytesToChar, PbrtContext, either::Either, error::SourceFile, texture::Pbrt_2d_float_texture,
};
use const_format::concatcp;
use miette::{Diagnostic, Error, IntoDiagnostic, Report, Result, SourceSpan};
use ray_tracing_core::prelude::Float;
use crate::{BytesToChar, error::SourceFile};
use miette::{Diagnostic, IntoDiagnostic, Report, Result, SourceSpan};
use std::{
fs::File,
io::{BufReader, Bytes, Read},
iter::Peekable,
path::{Path, PathBuf},
sync::Arc,
};
use thiserror::Error;
@ -32,10 +27,6 @@ impl Tokenizer {
})
}
pub fn get_path(&self) -> &Path {
&self.path
}
pub fn get_base_path(&self) -> &Path {
&self.base_path
}