mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:42:27 +00:00
Preserve repeated OBJ group declarations
This commit is contained in:
1 parent
284b0d815b
commit
2ee29d87b5
2 files changed
+16
-1
No files matched your search
@@ -176,6 +176,8 @@ pub struct ReadOptions {
|
||||
pub preserve_runs: bool,
|
||||
/// Do not resolve or report material libraries; `usemtl` names remain available.
|
||||
pub ignore_material_libraries: bool,
|
||||
/// Treat each group declaration as an object boundary, retaining repeated names.
|
||||
pub groups_as_objects: bool,
|
||||
}
|
||||
|
||||
struct Reader<'a> {
|
||||
@@ -407,6 +409,10 @@ impl Reader<'_> {
|
||||
};
|
||||
}
|
||||
"o" => self.start_object(after.to_string())?,
|
||||
"g" if self.options.groups_as_objects => {
|
||||
self.group.clear();
|
||||
self.start_object(after.to_string())?;
|
||||
}
|
||||
"g" => {
|
||||
self.slot = None;
|
||||
self.group = after.to_string();
|
||||
|
||||
@@ -356,7 +356,7 @@ fn face_tokens_and_continued_lines_are_bounded_before_collection() {
|
||||
#[test]
|
||||
fn compatibility_options_keep_runs_and_skip_material_libraries() {
|
||||
let input = b"\xef\xbb\xbf v 0 0 0\nv 1 0 0\nv 0 1 0\nmtllib missing.mtl\nusemtl Red\nf 1 2 3\nusemtl Blue\nf 1 2 3\nusemtl Red\nf 1 2 3\n";
|
||||
let options = crate::obj::ReadOptions { strict: true, preserve_runs: true, ignore_material_libraries: true };
|
||||
let options = crate::obj::ReadOptions { strict: true, preserve_runs: true, ignore_material_libraries: true, ..Default::default() };
|
||||
let scene = crate::obj::read_with_options(input, &Limits::default(), &mut no_external, &options).unwrap();
|
||||
let parts = &scene.meshes[0].parts;
|
||||
assert_eq!(parts.len(), 3);
|
||||
@@ -364,3 +364,12 @@ fn compatibility_options_keep_runs_and_skip_material_libraries() {
|
||||
assert!(scene.warnings.is_empty());
|
||||
assert!(crate::obj::read_with_options(b"v NaN 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n", &Limits::default(), &mut no_external, &options).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_boundaries_keep_repeated_names_separate() {
|
||||
let input = b"v 0 0 0\nv 1 0 0\nv 0 1 0\ng Same\nusemtl M\nf 1 2 3\ng Same\nf 1 3 2\n";
|
||||
let options = crate::obj::ReadOptions { groups_as_objects: true, ..Default::default() };
|
||||
let scene = crate::obj::read_with_options(input, &Limits::default(), &mut no_external, &options).unwrap();
|
||||
assert_eq!(scene.meshes.len(), 2);
|
||||
assert!(scene.meshes.iter().all(|m| m.name == "Same"));
|
||||
}
|
||||
Reference in new issue
Block a user