@@ -64,7 +64,7 @@ impl MeshBuilder {
6464
6565 /// Allocates memory for the given number of vertices and fills
6666 /// the mesh with empty vertices.
67- pub fn with_capacity ( & mut self , size : usize ) -> & mut Self {
67+ pub fn with_capacity ( mut self , size : usize ) -> Self {
6868 self . vertices . resize (
6969 size,
7070 Vertex {
@@ -77,34 +77,32 @@ impl MeshBuilder {
7777 }
7878
7979 /// Adds a vertex to the mesh.
80- pub fn with_vertex ( & mut self , vertex : Vertex ) -> & mut Self {
80+ pub fn with_vertex ( mut self , vertex : Vertex ) -> Self {
8181 self . vertices . push ( vertex) ;
8282 return self ;
8383 }
8484
8585 /// Specify the attributes of the mesh. This is used to map the vertex data to
8686 /// the input of the vertex shader.
87- pub fn with_attributes (
88- & mut self ,
89- attributes : Vec < VertexAttribute > ,
90- ) -> & mut Self {
87+ pub fn with_attributes ( mut self , attributes : Vec < VertexAttribute > ) -> Self {
9188 self . attributes = attributes;
9289 return self ;
9390 }
9491
9592 /// Builds a mesh from the vertices and indices that have been added to the
9693 /// builder and allocates the memory for the mesh on the GPU.
97- pub fn build ( & self ) -> Mesh {
94+ pub fn build ( self ) -> Mesh {
9895 return Mesh {
99- vertices : self . vertices . clone ( ) ,
100- attributes : self . attributes . clone ( ) ,
96+ vertices : self . vertices ,
97+ attributes : self . attributes ,
10198 } ;
10299 }
103100
104101 /// Builds a mesh from the vertices of an OBJ file. The mesh will have the same
105102 /// attributes as the OBJ file and can be allocated on to the GPU with
106103 /// `BufferBuilder::build_from_mesh`.
107- pub fn build_from_obj ( & self , file_path : & str ) -> Mesh {
104+ pub fn build_from_obj ( self , file_path : & str ) -> Mesh {
105+ let _ = self ;
108106 let obj = load_textured_obj_from_file ( file_path) ;
109107
110108 let vertices = obj
@@ -170,17 +168,16 @@ mod tests {
170168 /// the built mesh.
171169 #[ test]
172170 fn mesh_builder_capacity_and_attributes_are_applied ( ) {
173- let mut builder = MeshBuilder :: new ( ) ;
174- builder. with_capacity ( 2 ) ;
171+ let builder = MeshBuilder :: new ( ) . with_capacity ( 2 ) ;
175172 assert_eq ! ( builder. vertices. len( ) , 2 ) ;
176173
177- builder . with_vertex ( Vertex {
178- position : [ 1.0 , 2.0 , 3.0 ] ,
179- normal : [ 0 .0, 1 .0, 0 .0] ,
180- color : [ 0.5 , 0.5 , 0.5 ] ,
181- } ) ;
182-
183- let mesh = builder . build ( ) ;
174+ let mesh = builder
175+ . with_vertex ( Vertex {
176+ position : [ 1 .0, 2 .0, 3 .0] ,
177+ normal : [ 0.0 , 1.0 , 0.0 ] ,
178+ color : [ 0.5 , 0.5 , 0.5 ] ,
179+ } )
180+ . build ( ) ;
184181 assert_eq ! ( mesh. vertices( ) . len( ) , 3 ) ;
185182 }
186183
0 commit comments