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

Mutable mesh accessors: indices_mut and attribute_mut #1164

Merged
merged 2 commits into from
Dec 30, 2020
Merged

Mutable mesh accessors: indices_mut and attribute_mut #1164

merged 2 commits into from
Dec 30, 2020

Conversation

msklywenn
Copy link
Contributor

@msklywenn msklywenn commented Dec 29, 2020

Hello,

In current bevy render, the only way to set attributes on a mesh is to set all values which involves a lot of cloning. For faster updating of dynamic meshes, I propose in this pull request to add two new accessors to Mesh so that it is possible to edit its values directly.

In this example, the iterator is copied directly to the mesh

let pos = sub.attribute_mut(Mesh::ATTRIBUTE_POSITION).unwrap();
if let VertexAttributeValues::Float3(ref mut pos) = pos {
    pos.clear();
    pos.extend(triangles.vertices.iter().map(|v| [v.pos.x, v.pos.y, 0.0f32]));
}

avoiding a collect() needed by the current approach

sub.set_attribute(Mesh::ATTRIBUTE_POSITION, VertexAttributeValues::Float3(triangles.vertices.iter().map(|v| [v.pos.x, v.pos.y, 0.0f32]).collect()));

@msklywenn msklywenn marked this pull request as ready for review December 29, 2020 21:58
@cart
Copy link
Member

cart commented Dec 30, 2020

Looks good to me. Thanks!

@cart cart merged commit 2754a9d into bevyengine:master Dec 30, 2020
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

Successfully merging this pull request may close these issues.

2 participants