77use ncollide:: procedural:: { TriMesh , TriMesh3 , IndexBuffer } ;
88use resource:: ShaderAttribute ;
99use resource:: gpu_vector:: { GPUVector , AllocationType , BufferType } ;
10+ use std:: iter;
1011
1112#[ path = "../error.rs" ]
1213mod error;
@@ -38,7 +39,7 @@ impl Mesh {
3839
3940 let uvs = match uvs {
4041 Some ( us) => us,
41- None => Vec :: from_elem ( coords . len ( ) , na:: orig ( ) )
42+ None => iter :: repeat ( na:: orig ( ) ) . take ( coords . len ( ) ) . collect ( )
4243 } ;
4344
4445 let location = if dynamic_draw { AllocationType :: DynamicDraw } else { AllocationType :: StaticDraw } ;
@@ -65,32 +66,32 @@ impl Mesh {
6566
6667 /// Creates a triangle mesh from this mesh.
6768 pub fn to_trimesh ( & self ) -> Option < TriMesh3 < GLfloat > > {
68- let unload_coords = !self . coords . read ( ) . is_on_ram ( ) ;
69- let unload_faces = !self . faces . read ( ) . is_on_ram ( ) ;
70- let unload_normals = !self . normals . read ( ) . is_on_ram ( ) ;
71- let unload_uvs = !self . uvs . read ( ) . is_on_ram ( ) ;
69+ let unload_coords = !self . coords . read ( ) . unwrap ( ) . is_on_ram ( ) ;
70+ let unload_faces = !self . faces . read ( ) . unwrap ( ) . is_on_ram ( ) ;
71+ let unload_normals = !self . normals . read ( ) . unwrap ( ) . is_on_ram ( ) ;
72+ let unload_uvs = !self . uvs . read ( ) . unwrap ( ) . is_on_ram ( ) ;
7273
73- self . coords . write ( ) . load_to_ram ( ) ;
74- self . faces . write ( ) . load_to_ram ( ) ;
75- self . normals . write ( ) . load_to_ram ( ) ;
76- self . uvs . write ( ) . load_to_ram ( ) ;
74+ self . coords . write ( ) . unwrap ( ) . load_to_ram ( ) ;
75+ self . faces . write ( ) . unwrap ( ) . load_to_ram ( ) ;
76+ self . normals . write ( ) . unwrap ( ) . load_to_ram ( ) ;
77+ self . uvs . write ( ) . unwrap ( ) . load_to_ram ( ) ;
7778
78- let coords = self . coords . read ( ) . to_owned ( ) ;
79- let faces = self . faces . read ( ) . to_owned ( ) ;
80- let normals = self . normals . read ( ) . to_owned ( ) ;
81- let uvs = self . uvs . read ( ) . to_owned ( ) ;
79+ let coords = self . coords . read ( ) . unwrap ( ) . to_owned ( ) ;
80+ let faces = self . faces . read ( ) . unwrap ( ) . to_owned ( ) ;
81+ let normals = self . normals . read ( ) . unwrap ( ) . to_owned ( ) ;
82+ let uvs = self . uvs . read ( ) . unwrap ( ) . to_owned ( ) ;
8283
8384 if unload_coords {
84- self . coords . write ( ) . unload_from_ram ( ) ;
85+ self . coords . write ( ) . unwrap ( ) . unload_from_ram ( ) ;
8586 }
8687 if unload_faces {
87- self . coords . write ( ) . unload_from_ram ( ) ;
88+ self . coords . write ( ) . unwrap ( ) . unload_from_ram ( ) ;
8889 }
8990 if unload_normals {
90- self . coords . write ( ) . unload_from_ram ( ) ;
91+ self . coords . write ( ) . unwrap ( ) . unload_from_ram ( ) ;
9192 }
9293 if unload_uvs {
93- self . coords . write ( ) . unload_from_ram ( ) ;
94+ self . coords . write ( ) . unwrap ( ) . unload_from_ram ( ) ;
9495 }
9596
9697 if coords. is_none ( ) || faces. is_none ( ) {
@@ -117,22 +118,22 @@ impl Mesh {
117118
118119 /// Binds this mesh vertex coordinates buffer to a vertex attribute.
119120 pub fn bind_coords ( & mut self , coords : & mut ShaderAttribute < Pnt3 < GLfloat > > ) {
120- coords. bind ( self . coords . write ( ) . deref_mut ( ) ) ;
121+ coords. bind ( self . coords . write ( ) . unwrap ( ) . deref_mut ( ) ) ;
121122 }
122123
123124 /// Binds this mesh vertex normals buffer to a vertex attribute.
124125 pub fn bind_normals ( & mut self , normals : & mut ShaderAttribute < Vec3 < GLfloat > > ) {
125- normals. bind ( self . normals . write ( ) . deref_mut ( ) ) ;
126+ normals. bind ( self . normals . write ( ) . unwrap ( ) . deref_mut ( ) ) ;
126127 }
127128
128129 /// Binds this mesh vertex uvs buffer to a vertex attribute.
129130 pub fn bind_uvs ( & mut self , uvs : & mut ShaderAttribute < Pnt2 < GLfloat > > ) {
130- uvs. bind ( self . uvs . write ( ) . deref_mut ( ) ) ;
131+ uvs. bind ( self . uvs . write ( ) . unwrap ( ) . deref_mut ( ) ) ;
131132 }
132133
133134 /// Binds this mesh vertex uvs buffer to a vertex attribute.
134135 pub fn bind_faces ( & mut self ) {
135- self . faces . write ( ) . bind ( ) ;
136+ self . faces . write ( ) . unwrap ( ) . bind ( ) ;
136137 }
137138
138139 /// Binds this mesh buffers to vertex attributes.
@@ -148,22 +149,22 @@ impl Mesh {
148149
149150 /// Unbind this mesh buffers to vertex attributes.
150151 pub fn unbind ( & self ) {
151- self . coords . write ( ) . unbind ( ) ;
152- self . normals . write ( ) . unbind ( ) ;
153- self . uvs . write ( ) . unbind ( ) ;
154- self . faces . write ( ) . unbind ( ) ;
152+ self . coords . write ( ) . unwrap ( ) . unbind ( ) ;
153+ self . normals . write ( ) . unwrap ( ) . unbind ( ) ;
154+ self . uvs . write ( ) . unwrap ( ) . unbind ( ) ;
155+ self . faces . write ( ) . unwrap ( ) . unbind ( ) ;
155156 }
156157
157158 /// Number of points needed to draw this mesh.
158159 pub fn num_pts ( & self ) -> uint {
159- self . faces . read ( ) . len ( ) * 3
160+ self . faces . read ( ) . unwrap ( ) . len ( ) * 3
160161 }
161162
162163 /// Recompute this mesh normals.
163164 pub fn recompute_normals ( & mut self ) {
164- Mesh :: compute_normals ( self . coords . read ( ) . data ( ) . as_ref ( ) . unwrap ( ) . as_slice ( ) ,
165- self . faces . read ( ) . data ( ) . as_ref ( ) . unwrap ( ) . as_slice ( ) ,
166- self . normals . write ( ) . data_mut ( ) . as_mut ( ) . unwrap ( ) ) ;
165+ Mesh :: compute_normals ( self . coords . read ( ) . unwrap ( ) . data ( ) . as_ref ( ) . unwrap ( ) . as_slice ( ) ,
166+ self . faces . read ( ) . unwrap ( ) . data ( ) . as_ref ( ) . unwrap ( ) . as_slice ( ) ,
167+ self . normals . write ( ) . unwrap ( ) . data_mut ( ) . as_mut ( ) . unwrap ( ) ) ;
167168 }
168169
169170 /// This mesh faces.
@@ -199,10 +200,10 @@ impl Mesh {
199200 pub fn compute_normals ( coordinates : & [ Pnt3 < GLfloat > ] ,
200201 faces : & [ Vec3 < GLuint > ] ,
201202 normals : & mut Vec < Vec3 < GLfloat > > ) {
202- let mut divisor = Vec :: from_elem ( coordinates. len ( ) , 0f32 ) ;
203+ let mut divisor: Vec < f32 > = iter :: repeat ( 0f32 ) . take ( coordinates. len ( ) ) . collect ( ) ;
203204
204205 normals. clear ( ) ;
205- normals. grow ( coordinates . len ( ) , na:: zero ( ) ) ;
206+ normals. extend ( iter :: repeat ( na:: zero ( ) ) . take ( coordinates . len ( ) ) ) ;
206207
207208 // Accumulate normals ...
208209 for f in faces. iter ( ) {
0 commit comments