@@ -65,7 +65,7 @@ pub trait ToSimpleMesh {
65
65
}
66
66
67
67
pub trait ToSimpleMeshWithMaterial {
68
- fn to_simple_mesh_with_materials ( & self , materials : & Vec < Material > ) -> SimpleMesh ;
68
+ fn to_simple_mesh_with_materials ( & self , materials : & [ Material ] ) -> SimpleMesh ;
69
69
}
70
70
71
71
pub struct SimpleMesh {
@@ -74,7 +74,7 @@ pub struct SimpleMesh {
74
74
}
75
75
76
76
impl ToSimpleMeshWithMaterial for Mesh {
77
- fn to_simple_mesh_with_materials ( & self , materials : & Vec < Material > ) -> SimpleMesh {
77
+ fn to_simple_mesh_with_materials ( & self , materials : & [ Material ] ) -> SimpleMesh {
78
78
let mut bounding_box = AABB {
79
79
// This is the general bounding box for the mesh
80
80
min : Vector4 :: new ( 0.0 , 0.0 , 0.0 , 1.0 ) ,
@@ -101,8 +101,8 @@ impl ToSimpleMeshWithMaterial for Mesh {
101
101
tri. v3 . y = self . positions [ ( self . indices [ x * 3 + 2 ] * 3 + 1 ) as usize ] ;
102
102
tri. v3 . z = self . positions [ ( self . indices [ x * 3 + 2 ] * 3 + 2 ) as usize ] ;
103
103
104
- if materials. len ( ) > 0 {
105
- let material = & materials[ * & self . material_id . unwrap ( ) ] ;
104
+ if materials. is_empty ( ) {
105
+ let material = & materials[ self . material_id . unwrap ( ) ] ;
106
106
tri. color = (
107
107
( material. diffuse [ 0 ] * 255.0 ) as u8 ,
108
108
( material. diffuse [ 1 ] * 255.0 ) as u8 ,
@@ -127,7 +127,7 @@ impl ToSimpleMeshWithMaterial for Mesh {
127
127
128
128
impl ToSimpleMesh for Mesh {
129
129
fn to_simple_mesh ( & self ) -> SimpleMesh {
130
- self . to_simple_mesh_with_materials ( & vec ! [ ] )
130
+ self . to_simple_mesh_with_materials ( & [ ] )
131
131
}
132
132
}
133
133
@@ -151,11 +151,12 @@ impl ToSimpleMesh for stl_io::IndexedMesh {
151
151
} ;
152
152
self . faces. len( )
153
153
] ;
154
- for i in 0 ..self . faces . len ( ) {
155
- triangles[ i] . v1 = stlv2v4 ( self . vertices [ self . faces [ i] . vertices [ 0 ] ] ) ;
156
- triangles[ i] . v2 = stlv2v4 ( self . vertices [ self . faces [ i] . vertices [ 1 ] ] ) ;
157
- triangles[ i] . v3 = stlv2v4 ( self . vertices [ self . faces [ i] . vertices [ 2 ] ] ) ;
158
- let aabb = triangles[ i] . to_aabb ( ) ;
154
+ #[ allow( clippy:: needless_range_loop) ] // We need an index number, to get the triangle's index too
155
+ for t_index in 0 ..self . faces . len ( ) {
156
+ triangles[ t_index] . v1 = stlv2v4 ( self . vertices [ self . faces [ t_index] . vertices [ 0 ] ] ) ;
157
+ triangles[ t_index] . v2 = stlv2v4 ( self . vertices [ self . faces [ t_index] . vertices [ 1 ] ] ) ;
158
+ triangles[ t_index] . v3 = stlv2v4 ( self . vertices [ self . faces [ t_index] . vertices [ 2 ] ] ) ;
159
+ let aabb = triangles[ t_index] . to_aabb ( ) ;
159
160
bounding_box. min . x = aabb. min . x . min ( bounding_box. min . x ) ;
160
161
bounding_box. min . y = aabb. min . y . min ( bounding_box. min . y ) ;
161
162
bounding_box. min . z = aabb. min . z . min ( bounding_box. min . z ) ;
0 commit comments