Skip to content

Conversation

@beicause
Copy link
Contributor

@beicause beicause commented Nov 24, 2025

Objective

Indices::U32 uses more memory and it's unnecessary if vertex count <= 65536 (most case). But all mesh primitives use Indices::U32

Solution

Use Indices::U16 if possible in mesh primitives.
I added Indices::with_capacity(), resize() and set() as helpers to create indices. Also added glam_bytemuck and used it in Capsule3dMeshBuilder.

Testing

Tested with the 2d_shapes and 3d_shapes examples.

@atlv24
Copy link
Contributor

atlv24 commented Nov 24, 2025

i believe the mesh merge op does not work on meshes of distinct index types. just something to keep in mind, this might break some use cases.

@beicause
Copy link
Contributor Author

beicause commented Nov 24, 2025

// Extend indices of `self` with indices of `other`.
if let (Some(indices), Some(other_indices)) = (self.indices_mut(), other.indices()) {
indices.extend(other_indices.iter().map(|i| (i + index_offset) as u32));
}

fn extend<T: IntoIterator<Item = u32>>(&mut self, iter: T) {

If I understand correctly, merge op can extend u16 to u32 if it will overflow so this doesn't break.

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