summaryrefslogtreecommitdiff
path: root/engine/src/file_format/wavefront/common.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-05-07 21:48:12 +0200
committerHampusM <hampus@hampusmat.com>2024-05-07 21:48:12 +0200
commit4d9ce83a8823e457f28f7d8d1377eca2db667d4c (patch)
tree52df772838281214ed652e73c9ea06a418c200df /engine/src/file_format/wavefront/common.rs
parentea0e2830db3b78b8d73ac103eede3a9fe1717851 (diff)
feat(engine): add support for Wavefront obj usemtl & mtllib
Diffstat (limited to 'engine/src/file_format/wavefront/common.rs')
-rw-r--r--engine/src/file_format/wavefront/common.rs40
1 files changed, 38 insertions, 2 deletions
diff --git a/engine/src/file_format/wavefront/common.rs b/engine/src/file_format/wavefront/common.rs
index 0c5ac33..2e27bcb 100644
--- a/engine/src/file_format/wavefront/common.rs
+++ b/engine/src/file_format/wavefront/common.rs
@@ -218,11 +218,19 @@ impl Value
})?));
}
- if value.contains('/') {
+ if value.contains('/')
+ && value
+ .chars()
+ .all(|character| character.is_ascii_digit() || character == '/')
+ {
return Ok(Self::Triplet(Triplet::parse::<KeywordT>(value, line_no)?));
}
- if value.contains(|character: char| character.is_ascii_digit()) {
+ if !value.is_empty()
+ && value
+ .chars()
+ .all(|character: char| character.is_ascii_digit())
+ {
return Ok(Self::Integer(value.parse().map_err(|err| {
ParsingError::InvalidIntegerValue {
err,
@@ -238,6 +246,18 @@ impl Value
Err(ParsingError::UnknownValueType(value.to_string()))
}
+
+ pub fn to_text(
+ &self,
+ argument_index: usize,
+ line_no: usize,
+ ) -> Result<&str, ParsingError>
+ {
+ match self {
+ Value::Text(value) => Ok(value),
+ _ => Err(ParsingError::UnexpectedArgumentType { argument_index, line_no }),
+ }
+ }
}
#[derive(Debug)]
@@ -265,6 +285,22 @@ impl<KeywordT: Keyword> Statement<KeywordT>
}
}
+ pub fn get_text_arg(&self, index: usize, line_no: usize)
+ -> Result<&str, ParsingError>
+ {
+ match self.arguments.get(index) {
+ Some(Value::Text(value)) => Ok(value),
+ Some(_) => Err(ParsingError::UnexpectedArgumentType {
+ argument_index: index,
+ line_no,
+ }),
+ None => Err(ParsingError::MissingArgument {
+ keyword: self.keyword.to_string(),
+ line_no,
+ }),
+ }
+ }
+
pub fn get_triplet_arg(
&self,
index: usize,