Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to return a slice intead of an iterator ? #397

Open
ThomasCartier opened this issue Nov 29, 2023 · 1 comment
Open

Possible to return a slice intead of an iterator ? #397

ThomasCartier opened this issue Nov 29, 2023 · 1 comment

Comments

@ThomasCartier
Copy link

Hi,

Not very experienced in Rust,

for skin in import.doc.skins() {
    let name = skin.name().map(|name| name.into());
    let joint_node_indices: Vec<usize> = skin.joints().map(|j| j.index()).collect();
    for node_index in joint_node_indices.iter().cloned() {
        nodes[node_index].is_joint = true;
    }
    let reader = skin.reader(|buffer| Some(&import.buffers[buffer.index()]));
    let inverse_bind_matrices = if let Some(inverse_bind_matrices) = reader.read_inverse_bind_matrices() {
        inverse_bind_matrices.collect()
    } else {
        let identity = *mat4(&cgmath::Matrix4::identity());
        vec![identity; joint_node_indices.len()]
    };

   ...
}

read_inverse_bind_matrices returns an iterator, which force to collect() afterwards.

Is it possible to return a slice over the buffer instead, avoiding to collect?

Maybe through a read_slice_inverse_bind_matrices ?

Thanks!

@ThomasCartier
Copy link
Author

The context is random access of accessors, because iterators consume their view. A slice doesn't suffer from this and is more efficient in that case, instead of rebuilding a reader everytime.
What do you think ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant