1
1
mod conversions;
2
2
pub mod skinning;
3
+ use bevy_log:: warn;
3
4
pub use wgpu:: PrimitiveTopology ;
4
5
5
6
use crate :: {
@@ -323,17 +324,20 @@ impl Mesh {
323
324
324
325
/// Counts all vertices of the mesh.
325
326
///
326
- /// # Panics
327
- /// Panics if the attributes have different vertex counts.
327
+ /// If the attributes have different vertex counts, the smallest is returned.
328
328
pub fn count_vertices ( & self ) -> usize {
329
329
let mut vertex_count: Option < usize > = None ;
330
330
for ( attribute_id, attribute_data) in & self . attributes {
331
331
let attribute_len = attribute_data. values . len ( ) ;
332
332
if let Some ( previous_vertex_count) = vertex_count {
333
- assert_eq ! ( previous_vertex_count, attribute_len,
334
- "{attribute_id:?} has a different vertex count ({attribute_len}) than other attributes ({previous_vertex_count}) in this mesh." ) ;
333
+ if previous_vertex_count != attribute_len {
334
+ warn ! ( "{attribute_id:?} has a different vertex count ({attribute_len}) than other attributes ({previous_vertex_count}) in this mesh, \
335
+ all attributes will be truncated to match the smallest.") ;
336
+ vertex_count = Some ( std:: cmp:: min ( previous_vertex_count, attribute_len) ) ;
337
+ }
338
+ } else {
339
+ vertex_count = Some ( attribute_len) ;
335
340
}
336
- vertex_count = Some ( attribute_len) ;
337
341
}
338
342
339
343
vertex_count. unwrap_or ( 0 )
@@ -343,8 +347,8 @@ impl Mesh {
343
347
/// Therefore the attributes are located in the order of their [`MeshVertexAttribute::id`].
344
348
/// This is used to transform the vertex data into a GPU friendly format.
345
349
///
346
- /// # Panics
347
- /// Panics if the attributes have different vertex counts .
350
+ /// If the vertex attributes have different lengths, they are all truncated to
351
+ /// the length of the smallest .
348
352
pub fn get_vertex_buffer_data ( & self ) -> Vec < u8 > {
349
353
let mut vertex_size = 0 ;
350
354
for attribute_data in self . attributes . values ( ) {
@@ -356,7 +360,7 @@ impl Mesh {
356
360
let mut attributes_interleaved_buffer = vec ! [ 0 ; vertex_count * vertex_size] ;
357
361
// bundle into interleaved buffers
358
362
let mut attribute_offset = 0 ;
359
- for attribute_data in self . attributes . values ( ) {
363
+ for attribute_data in self . attributes . values ( ) . take ( vertex_count ) {
360
364
let attribute_size = attribute_data. attribute . format . get_size ( ) as usize ;
361
365
let attributes_bytes = attribute_data. values . get_bytes ( ) ;
362
366
for ( vertex_index, attribute_bytes) in
0 commit comments