@@ -175,11 +175,7 @@ pub struct Colliders2DDemo {
175175}
176176
177177impl Colliders2DDemo {
178- fn push_vertex (
179- mesh_builder : & mut MeshBuilder ,
180- x : f32 ,
181- y : f32 ,
182- ) -> & mut MeshBuilder {
178+ fn push_vertex ( mesh_builder : MeshBuilder , x : f32 , y : f32 ) -> MeshBuilder {
183179 return mesh_builder. with_vertex (
184180 VertexBuilder :: new ( )
185181 . with_position ( [ x, y, 0.0 ] )
@@ -190,37 +186,38 @@ impl Colliders2DDemo {
190186 }
191187
192188 fn append_rectangle (
193- mesh_builder : & mut MeshBuilder ,
189+ mesh_builder : MeshBuilder ,
194190 vertex_count : & mut u32 ,
195191 half_width : f32 ,
196192 half_height : f32 ,
197- ) -> Range < u32 > {
193+ ) -> ( MeshBuilder , Range < u32 > ) {
198194 let start = * vertex_count;
199195
200196 let left = -half_width;
201197 let right = half_width;
202198 let bottom = -half_height;
203199 let top = half_height;
204200
205- Self :: push_vertex ( mesh_builder, left, bottom) ;
206- Self :: push_vertex ( mesh_builder, right, bottom) ;
207- Self :: push_vertex ( mesh_builder, right, top) ;
201+ let mesh_builder = Self :: push_vertex ( mesh_builder, left, bottom) ;
202+ let mesh_builder = Self :: push_vertex ( mesh_builder, right, bottom) ;
203+ let mesh_builder = Self :: push_vertex ( mesh_builder, right, top) ;
208204
209- Self :: push_vertex ( mesh_builder, left, bottom) ;
210- Self :: push_vertex ( mesh_builder, right, top) ;
211- Self :: push_vertex ( mesh_builder, left, top) ;
205+ let mesh_builder = Self :: push_vertex ( mesh_builder, left, bottom) ;
206+ let mesh_builder = Self :: push_vertex ( mesh_builder, right, top) ;
207+ let mesh_builder = Self :: push_vertex ( mesh_builder, left, top) ;
212208
213209 * vertex_count += 6 ;
214210 let end = * vertex_count;
215- return start..end;
211+ return ( mesh_builder , start..end) ;
216212 }
217213
218214 fn append_convex_polygon (
219- mesh_builder : & mut MeshBuilder ,
215+ mesh_builder : MeshBuilder ,
220216 vertex_count : & mut u32 ,
221217 vertices : & [ [ f32 ; 2 ] ] ,
222- ) -> Range < u32 > {
218+ ) -> ( MeshBuilder , Range < u32 > ) {
223219 let start = * vertex_count;
220+ let mut mesh_builder = mesh_builder;
224221
225222 let mut centroid = [ 0.0_f32 , 0.0_f32 ] ;
226223 for vertex in vertices. iter ( ) {
@@ -234,23 +231,24 @@ impl Colliders2DDemo {
234231 let a = vertices[ index] ;
235232 let b = vertices[ ( index + 1 ) % vertices. len ( ) ] ;
236233
237- Self :: push_vertex ( mesh_builder, centroid[ 0 ] , centroid[ 1 ] ) ;
238- Self :: push_vertex ( mesh_builder, a[ 0 ] , a[ 1 ] ) ;
239- Self :: push_vertex ( mesh_builder, b[ 0 ] , b[ 1 ] ) ;
234+ mesh_builder = Self :: push_vertex ( mesh_builder, centroid[ 0 ] , centroid[ 1 ] ) ;
235+ mesh_builder = Self :: push_vertex ( mesh_builder, a[ 0 ] , a[ 1 ] ) ;
236+ mesh_builder = Self :: push_vertex ( mesh_builder, b[ 0 ] , b[ 1 ] ) ;
240237 }
241238
242239 * vertex_count += 3 * vertices. len ( ) as u32 ;
243240 let end = * vertex_count;
244- return start..end;
241+ return ( mesh_builder , start..end) ;
245242 }
246243
247244 fn append_circle (
248- mesh_builder : & mut MeshBuilder ,
245+ mesh_builder : MeshBuilder ,
249246 vertex_count : & mut u32 ,
250247 radius : f32 ,
251248 segments : u32 ,
252- ) -> Range < u32 > {
249+ ) -> ( MeshBuilder , Range < u32 > ) {
253250 let start = * vertex_count;
251+ let mut mesh_builder = mesh_builder;
254252
255253 for index in 0 ..segments {
256254 let t0 = index as f32 / segments as f32 ;
@@ -264,23 +262,23 @@ impl Colliders2DDemo {
264262 let x1 = angle1. cos ( ) * radius;
265263 let y1 = angle1. sin ( ) * radius;
266264
267- Self :: push_vertex ( mesh_builder, 0.0 , 0.0 ) ;
268- Self :: push_vertex ( mesh_builder, x0, y0) ;
269- Self :: push_vertex ( mesh_builder, x1, y1) ;
265+ mesh_builder = Self :: push_vertex ( mesh_builder, 0.0 , 0.0 ) ;
266+ mesh_builder = Self :: push_vertex ( mesh_builder, x0, y0) ;
267+ mesh_builder = Self :: push_vertex ( mesh_builder, x1, y1) ;
270268 }
271269
272270 * vertex_count += 3 * segments;
273271 let end = * vertex_count;
274- return start..end;
272+ return ( mesh_builder , start..end) ;
275273 }
276274
277275 fn append_capsule (
278- mesh_builder : & mut MeshBuilder ,
276+ mesh_builder : MeshBuilder ,
279277 vertex_count : & mut u32 ,
280278 half_height : f32 ,
281279 radius : f32 ,
282280 segments : u32 ,
283- ) -> Range < u32 > {
281+ ) -> ( MeshBuilder , Range < u32 > ) {
284282 let mut vertices = Vec :: with_capacity ( ( segments as usize + 1 ) * 2 ) ;
285283
286284 for index in 0 ..=segments {
@@ -299,10 +297,10 @@ impl Colliders2DDemo {
299297 }
300298
301299 fn append_shape (
302- mesh_builder : & mut MeshBuilder ,
300+ mesh_builder : MeshBuilder ,
303301 vertex_count : & mut u32 ,
304302 shape : & ColliderShape2D ,
305- ) -> Range < u32 > {
303+ ) -> ( MeshBuilder , Range < u32 > ) {
306304 match shape {
307305 ColliderShape2D :: Circle { radius } => {
308306 return Self :: append_circle ( mesh_builder, vertex_count, * radius, 32 ) ;
@@ -394,15 +392,16 @@ impl Component<ComponentResult, String> for Colliders2DDemo {
394392 } ,
395393 ] ;
396394
397- let mut mesh_builder = MeshBuilder :: new ( ) ;
398- mesh_builder . with_attributes ( attributes. clone ( ) ) ;
395+ let mut mesh_builder =
396+ MeshBuilder :: new ( ) . with_attributes ( attributes. clone ( ) ) ;
399397 let mut vertex_count = 0_u32 ;
400398
401399 let mut colliders = Vec :: with_capacity ( self . collider_inits . len ( ) ) ;
402400
403401 for init in self . collider_inits . iter ( ) {
404- let vertices =
405- Self :: append_shape ( & mut mesh_builder, & mut vertex_count, & init. shape ) ;
402+ let ( updated_mesh_builder, vertices) =
403+ Self :: append_shape ( mesh_builder, & mut vertex_count, & init. shape ) ;
404+ mesh_builder = updated_mesh_builder;
406405
407406 let initial_uniform = ColliderGlobalsUniform {
408407 offset_rotation : [ 0.0 , 0.0 , 0.0 , 0.0 ] ,
0 commit comments