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

Add the ability to pass Vec<VecX> directly to mesh.set_attribute + simple example #2719

Closed
wants to merge 4 commits into from

Conversation

sarkahn
Copy link
Contributor

@sarkahn sarkahn commented Aug 24, 2021

Objective

With this pr we can pass Vec<VecX> directly to mesh.set_attribute. When working with custom meshes, particularly with procedural generation, I find it extremely helpful to work directly with Vec<VecX> to represent my mesh points/uvs/colors/etc.

Solution

Using bytemuck we can perform a conversion from Vec<VecX> to Vec<[f32;X]> when it gets passed to the mesh. Then we can use Vec<Vec3> directly to represent mesh points for example:

    let origin = Vec3::new(0.0, 0.0, 0.0);
    let right = Vec3::new(1.0, 0.0, 0.0);
    let up = Vec3::new(0.0, 1.0, 0.0);

    let positions = vec![
        origin + up,
        origin + up + right,
        origin,
        origin + right,
    ];

    let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
    mesh.set_attribute(Mesh::ATTRIBUTE_POSITION, positions);

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Aug 24, 2021
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible and removed S-Needs-Triage This issue needs to be labelled labels Aug 24, 2021
@alice-i-cecile
Copy link
Member

Could you retarget this to pipelined-rendering? That branch contains our rendering rework, and it would be much better to put the effort into improving the codebase there.

I suspect the basic idea should still hold, but you may have to do some reorganization and cleanup to match the new APIs.

@sarkahn sarkahn changed the base branch from main to pipelined-rendering August 24, 2021 19:40
@sarkahn
Copy link
Contributor Author

sarkahn commented Aug 24, 2021

Could you retarget this to pipelined-rendering? That branch contains our rendering rework, and it would be much better to put the effort into improving the codebase there.

I suspect the basic idea should still hold, but you may have to do some reorganization and cleanup to match the new APIs.

Done, looks like there were no issues.

bors bot pushed a commit that referenced this pull request Nov 4, 2022
Allow passing `Vec`s of glam vector types as vertex attributes.
Alternative to #4548 and #2719

Also used some macros to cut down on all the repetition.

# Migration Guide
Implementations of `From<Vec<[u16; 4]>>` and `From<Vec<[u8; 4]>>` for `VertexAttributeValues` have been removed.
I you're passing either `Vec<[u16; 4]>` or `Vec<[u8; 4]>` into `Mesh::insert_attribute` it will now require wrapping it with right the `VertexAttributeValues` enum variant. 

Co-authored-by: devil-ira <justthecooldude@gmail.com>
@tim-blackbird
Copy link
Contributor

This was superseded by #6442.

ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
Allow passing `Vec`s of glam vector types as vertex attributes.
Alternative to bevyengine#4548 and bevyengine#2719

Also used some macros to cut down on all the repetition.

# Migration Guide
Implementations of `From<Vec<[u16; 4]>>` and `From<Vec<[u8; 4]>>` for `VertexAttributeValues` have been removed.
I you're passing either `Vec<[u16; 4]>` or `Vec<[u8; 4]>` into `Mesh::insert_attribute` it will now require wrapping it with right the `VertexAttributeValues` enum variant. 

Co-authored-by: devil-ira <justthecooldude@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants