Mesh::face_arities becomes Option<Vec<u32>> - #80
Open
virtualritz wants to merge 2 commits into
Open
Conversation
LoadOptions gains progress_callback: Option<LoadProgressCallback> (Arc<dyn Fn(&LoadProgress) -> ControlFlow<()> + Send + Sync>, an options field rather than a second _with_progress function), invoked every 1000 lines during load_obj_buf's parse loop. Returning ControlFlow::Break stops the load and returns the new LoadError::Cancelled. No behavior change when progress_callback is None (the default): verified by a test comparing output with and without a no-op callback. load_obj_buf_async is untouched.
None now means "all faces are triangles" instead of an empty Vec, saving
the allocation for triangle-only meshes -- the common case. New
Mesh::{face_count, face_arity, is_triangulated, face_indices} helpers
replace manual index-arithmetic over face_arities at call sites (see
print_mesh.rs and the module doc example). Also tidies two loops
(parse_face, TmpMaterials::extend) into iterator chains while in the area.
BREAKING CHANGE: any caller reading Mesh::face_arities directly (as a Vec)
needs to match on the Option, or switch to the new helper methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacks on #79 (progress-callback) — this diff includes both commits until #79 merges; the second commit is the one this PR is actually about.
Mesh::face_aritieschanges fromVec<u32>toOption<Vec<u32>>.Nonenow means "all faces are triangles" instead of an emptyVec, which skips the allocation for triangle-only meshes — the common case, especially withtriangulate: true.Mesh::{face_count, face_arity, is_triangulated, face_indices}helper methods replace manual index-arithmetic overface_aritiesat call sites (see the updatedexamples/print_mesh.rsand the crate's module-doc example) — the offset math for finding a given face's indices was previously left to every caller to get right.parse_face,TmpMaterials::extend) into iterator chains while in the area — no behavior change there.BREAKING CHANGE: any caller reading
Mesh::face_aritiesdirectly as aVecneeds to match on theOption, or switch to the new helper methods. Happy to gate this behind a semver-major bump on your end, or split differently if you'd rather land it separately from #79 for that reason.Test plan
cargo test --all-features: 21 lib tests + 5 doctests pass, including updatednon_triangulated_quadcoverage for theNone/Somecasescargo build --example print_mesh --all-featurescargo fmt --all -- --check: cleancargo clippy --all-targets --all-features -- -D warnings: clean (exit 0)