Add generalized bvh for pbrt
This commit is contained in:
parent
807168f787
commit
6403aabc11
5 changed files with 360 additions and 43 deletions
|
|
@ -1,7 +1,8 @@
|
|||
use crate::{
|
||||
bvh::Bvh,
|
||||
either::Either,
|
||||
scene::PbrtScene,
|
||||
shape::{Shape, ShapeAlpha, ShapeType},
|
||||
shape::{Shape, ShapeAlpha, ShapeType, TriangleMesh},
|
||||
tokenizer::{Token, Tokenizer},
|
||||
};
|
||||
use material::PbrtMaterial;
|
||||
|
|
@ -23,6 +24,7 @@ use texture::PbrtTexture;
|
|||
#[macro_use]
|
||||
mod tokenizer;
|
||||
|
||||
mod bvh;
|
||||
mod either;
|
||||
mod error;
|
||||
mod material;
|
||||
|
|
@ -151,14 +153,14 @@ fn parse_shape<R>(iter: &mut Tokenizer) -> Result<Statement<R>> {
|
|||
n, Vec<Dir3>, Vec::new();
|
||||
s, Vec<Dir3>, Vec::new();
|
||||
uv, Vec<[Float; 2]>, Vec::new();
|
||||
indices, Vec<usize>, Vec::new();
|
||||
indices, Vec<[usize;3]>, Vec::new();
|
||||
alpha, ShapeAlpha, ShapeAlpha::None
|
||||
=>
|
||||
p, "point3 P", iter.parse_list_3(Pos3::new)?;
|
||||
n, "normal N", iter.parse_list_3(Dir3::new)?;
|
||||
s, "normal S", iter.parse_list_3(Dir3::new)?;
|
||||
uv, "point2 uv", iter.parse_list_2(|u, v| [u, v])?;
|
||||
indices, "integer indices", iter.parse_list()?;
|
||||
indices, "integer indices", iter.parse_list_3(|a, b, c|[a, b, c])?;
|
||||
alpha, "float alpha", ShapeAlpha::Value(iter.parse_parameter()?);
|
||||
alpha, "texture alpha", ShapeAlpha::Texture(iter.parse_parameter()?)
|
||||
);
|
||||
|
|
@ -170,13 +172,6 @@ fn parse_shape<R>(iter: &mut Tokenizer) -> Result<Statement<R>> {
|
|||
bail!("Indices required for trianglemesh with more than 3 points.")
|
||||
}
|
||||
|
||||
if t.indices.len() % 3 != 0 {
|
||||
bail!(
|
||||
"number of indices must be divisible by 3. num indices: {}",
|
||||
t.indices.len()
|
||||
)
|
||||
}
|
||||
|
||||
if !t.n.is_empty() && t.n.len() != t.p.len() {
|
||||
bail!("Number of normals not equal to number of positions.")
|
||||
}
|
||||
|
|
@ -189,13 +184,16 @@ fn parse_shape<R>(iter: &mut Tokenizer) -> Result<Statement<R>> {
|
|||
}
|
||||
|
||||
Ok(Statement::Shape(
|
||||
ShapeType::TriangleMesh {
|
||||
indices: t.indices,
|
||||
p: t.p,
|
||||
n: t.n,
|
||||
s: t.s,
|
||||
uv: t.uv,
|
||||
},
|
||||
ShapeType::TriangleMesh(Bvh::new(
|
||||
TriangleMesh {
|
||||
indices: t.indices,
|
||||
p: t.p,
|
||||
n: t.n,
|
||||
s: t.s,
|
||||
uv: t.uv,
|
||||
},
|
||||
8,
|
||||
)),
|
||||
t.alpha,
|
||||
))
|
||||
}
|
||||
|
|
@ -863,7 +861,7 @@ fn inner_parse_pbrt<R: Rng + std::fmt::Debug>(
|
|||
|
||||
// dbg!(context);
|
||||
|
||||
Ok(dbg!(pbrt))
|
||||
Ok(pbrt)
|
||||
}
|
||||
|
||||
pub fn parse_pbrt_v4<R: Rng + std::fmt::Debug>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue