Textures working a little bit
This commit is contained in:
parent
1196cb7758
commit
2476d2d49a
7 changed files with 407 additions and 84 deletions
|
|
@ -25,9 +25,9 @@ struct Lexer {
|
|||
}
|
||||
|
||||
impl Lexer {
|
||||
fn new(path: impl AsRef<Path>) -> Result<Self> {
|
||||
fn new(path: PathBuf, base_path: PathBuf) -> Result<Self> {
|
||||
Ok(Self {
|
||||
input: Tokenizer::new(path)?,
|
||||
input: Tokenizer::new(path, base_path)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -396,7 +396,7 @@ impl Lexer {
|
|||
"Rotate" => Some(parse_rotate(&mut self.input)),
|
||||
"Transform" => Some(parse_transform(&mut self.input).map(Statement::Transform)),
|
||||
"Texture" => Some(
|
||||
texture::parse_texture(&mut self.input)
|
||||
texture::parse_texture(&mut self.input, textures)
|
||||
.map(|(name, texture)| Statement::Texture(name, texture)),
|
||||
),
|
||||
"ConcatTransform" => {
|
||||
|
|
@ -545,23 +545,25 @@ impl<I: Iterator<Item = Result<u8, std::io::Error>>> Iterator for BytesToChar<I>
|
|||
}
|
||||
}
|
||||
|
||||
struct Parser<P> {
|
||||
path: P,
|
||||
inner: Option<Box<Parser<PathBuf>>>,
|
||||
struct Parser {
|
||||
path: PathBuf,
|
||||
base_path: PathBuf,
|
||||
inner: Option<Box<Parser>>,
|
||||
iter: Lexer,
|
||||
}
|
||||
|
||||
impl<P: AsRef<Path> + std::fmt::Debug> Parser<P> {
|
||||
fn new(path: P) -> Result<Self> {
|
||||
impl Parser {
|
||||
fn new(path: PathBuf, base_path: PathBuf) -> Result<Self> {
|
||||
Ok(Self {
|
||||
iter: Lexer::new(path.as_ref())?,
|
||||
iter: Lexer::new(path.clone(), base_path.clone())?,
|
||||
base_path,
|
||||
path,
|
||||
inner: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: AsRef<Path>> Parser<P> {
|
||||
impl Parser {
|
||||
fn next(
|
||||
&mut self,
|
||||
textures: &HashMap<String, Arc<dyn PbrtTexture>>,
|
||||
|
|
@ -575,8 +577,8 @@ impl<P: AsRef<Path>> Parser<P> {
|
|||
|
||||
match self.iter.next(textures) {
|
||||
Some(Ok(Statement::Include(s))) => {
|
||||
let path = self.path.as_ref().parent().unwrap().join(s);
|
||||
self.inner = Some(Box::new(Parser::new(path).unwrap()));
|
||||
let path = self.path.parent().unwrap().join(s);
|
||||
self.inner = Some(Box::new(Parser::new(path, self.base_path.clone()).unwrap()));
|
||||
|
||||
self.next(textures)
|
||||
}
|
||||
|
|
@ -670,7 +672,13 @@ fn inner_parse_pbrt(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Pbrt> {
|
|||
// unwrap on context.last() ok because context is never empty
|
||||
let mut context_ctm = vec![AffineTransform::identity()];
|
||||
|
||||
let mut parser = Parser::new(path)?;
|
||||
let mut parser = Parser::new(
|
||||
path.as_ref().to_path_buf(),
|
||||
path.as_ref()
|
||||
.parent()
|
||||
.ok_or_else(|| miette!("parent from file not found"))?
|
||||
.to_path_buf(),
|
||||
)?;
|
||||
|
||||
// parse global settings
|
||||
|
||||
|
|
@ -761,10 +769,15 @@ fn inner_parse_pbrt(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Pbrt> {
|
|||
Statement::Unknown(s, _items) => {
|
||||
eprintln!("Unknown statement: {s}")
|
||||
}
|
||||
Statement::Texture(name, texture) => {
|
||||
textures.insert(name, texture);
|
||||
}
|
||||
s => bail!("unexpected statemnet in world settings: {s:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
dbg!(textures);
|
||||
|
||||
Ok(pbrt)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue