@@ -145,21 +145,21 @@ public static VoxelMeshData CreateMeshData(float[] heightMap, int width, int hei
145145
146146 public class VoxelMeshData
147147 {
148- private List < Vector3 > vertices = new List < Vector3 > ( ) ;
149- private List < Vector2 > uv = new List < Vector2 > ( ) ;
150- private List < int > triangles = new List < int > ( ) ;
148+ private readonly List < Vector3 > _vertices = new List < Vector3 > ( ) ;
149+ private readonly List < Vector2 > _uv = new List < Vector2 > ( ) ;
150+ private readonly List < int > _triangles = new List < int > ( ) ;
151151
152- private int width ;
153- private int height ;
154- private int quadCount ;
155- private Vector2Int offset ;
152+ private readonly int _width ;
153+ private readonly int _height ;
154+ private int _quadCount ;
155+ private readonly Vector2Int _offset ;
156156
157157 public VoxelMeshData ( int width , int height , Vector2Int offset )
158158 {
159- this . width = width ;
160- this . height = height ;
161- this . offset = offset ;
162- quadCount = 0 ;
159+ _width = width ;
160+ _height = height ;
161+ _offset = offset ;
162+ _quadCount = 0 ;
163163 }
164164
165165 /// <summary>
@@ -177,10 +177,10 @@ public void AddUpQuad(int x, int y, float elevation)
177177 var topRight = new Vector3 ( x + 1 , elevation , y + 1 ) ;
178178 var bottomRight = new Vector3 ( x + 1 , elevation , y ) ;
179179
180- vertices . Add ( bottomLeft ) ;
181- vertices . Add ( topLeft ) ;
182- vertices . Add ( topRight ) ;
183- vertices . Add ( bottomRight ) ;
180+ _vertices . Add ( bottomLeft ) ;
181+ _vertices . Add ( topLeft ) ;
182+ _vertices . Add ( topRight ) ;
183+ _vertices . Add ( bottomRight ) ;
184184
185185 AddUV ( x , y ) ;
186186 AddTriangles ( ) ;
@@ -201,10 +201,10 @@ public void AddLeftQuad(int x, int y, float elevation, float depth)
201201 var topRight = new Vector3 ( x , elevation , y ) ;
202202 var bottomRight = new Vector3 ( x , elevation - depth , y ) ;
203203
204- vertices . Add ( bottomLeft ) ;
205- vertices . Add ( topLeft ) ;
206- vertices . Add ( topRight ) ;
207- vertices . Add ( bottomRight ) ;
204+ _vertices . Add ( bottomLeft ) ;
205+ _vertices . Add ( topLeft ) ;
206+ _vertices . Add ( topRight ) ;
207+ _vertices . Add ( bottomRight ) ;
208208
209209 AddUV ( x , y ) ;
210210 AddTriangles ( ) ;
@@ -225,10 +225,10 @@ public void AddRightQuad(int x, int y, float elevation, float depth)
225225 var topRight = new Vector3 ( x + 1 , elevation , y + 1 ) ;
226226 var bottomRight = new Vector3 ( x + 1 , elevation - depth , y + 1 ) ;
227227
228- vertices . Add ( bottomLeft ) ;
229- vertices . Add ( topLeft ) ;
230- vertices . Add ( topRight ) ;
231- vertices . Add ( bottomRight ) ;
228+ _vertices . Add ( bottomLeft ) ;
229+ _vertices . Add ( topLeft ) ;
230+ _vertices . Add ( topRight ) ;
231+ _vertices . Add ( bottomRight ) ;
232232
233233 AddUV ( x , y ) ;
234234 AddTriangles ( ) ;
@@ -249,10 +249,10 @@ public void AddBackQuad(int x, int y, float elevation, float depth)
249249 var topRight = new Vector3 ( x + 1 , elevation , y ) ;
250250 var bottomRight = new Vector3 ( x + 1 , elevation - depth , y ) ;
251251
252- vertices . Add ( bottomLeft ) ;
253- vertices . Add ( topLeft ) ;
254- vertices . Add ( topRight ) ;
255- vertices . Add ( bottomRight ) ;
252+ _vertices . Add ( bottomLeft ) ;
253+ _vertices . Add ( topLeft ) ;
254+ _vertices . Add ( topRight ) ;
255+ _vertices . Add ( bottomRight ) ;
256256
257257 AddUV ( x , y ) ;
258258 AddTriangles ( ) ;
@@ -273,10 +273,10 @@ public void AddFrontQuad(int x, int y, float elevation, float depth)
273273 var topRight = new Vector3 ( x , elevation , y + 1 ) ;
274274 var bottomRight = new Vector3 ( x , elevation - depth , y + 1 ) ;
275275
276- vertices . Add ( bottomLeft ) ;
277- vertices . Add ( topLeft ) ;
278- vertices . Add ( topRight ) ;
279- vertices . Add ( bottomRight ) ;
276+ _vertices . Add ( bottomLeft ) ;
277+ _vertices . Add ( topLeft ) ;
278+ _vertices . Add ( topRight ) ;
279+ _vertices . Add ( bottomRight ) ;
280280
281281 AddUV ( x , y ) ;
282282 AddTriangles ( ) ;
@@ -291,43 +291,43 @@ public void AddFrontQuad(int x, int y, float elevation, float depth)
291291 private void AddUV ( int x , int y , float padding = 0.1f )
292292 {
293293 //We need to add the offset so UVs are shifted to correct texture chunk
294- var uvBottomLeft = new Vector2 ( ( x + offset . x + padding ) / width , ( y + offset . y + padding ) / height ) ;
295- var uvTopLeft = new Vector2 ( ( x + offset . x + padding ) / width , ( y + offset . y + 1 - padding ) / height ) ;
296- var uvTopRight = new Vector2 ( ( x + offset . x + 1 - padding ) / width , ( y + offset . y + 1 - padding ) / height ) ;
297- var uvBottomRight = new Vector2 ( ( x + offset . x + 1 - padding ) / width , ( y + offset . y + padding ) / height ) ;
298-
299- uv . Add ( uvBottomLeft ) ;
300- uv . Add ( uvTopLeft ) ;
301- uv . Add ( uvTopRight ) ;
302- uv . Add ( uvBottomRight ) ;
294+ var uvBottomLeft = new Vector2 ( ( x + _offset . x + padding ) / _width , ( y + _offset . y + padding ) / _height ) ;
295+ var uvTopLeft = new Vector2 ( ( x + _offset . x + padding ) / _width , ( y + _offset . y + 1 - padding ) / _height ) ;
296+ var uvTopRight = new Vector2 ( ( x + _offset . x + 1 - padding ) / _width , ( y + _offset . y + 1 - padding ) / _height ) ;
297+ var uvBottomRight = new Vector2 ( ( x + _offset . x + 1 - padding ) / _width , ( y + _offset . y + padding ) / _height ) ;
298+
299+ _uv . Add ( uvBottomLeft ) ;
300+ _uv . Add ( uvTopLeft ) ;
301+ _uv . Add ( uvTopRight ) ;
302+ _uv . Add ( uvBottomRight ) ;
303303 }
304304
305305 /// <summary>
306306 /// Add triangles for current quad
307307 /// </summary>
308308 private void AddTriangles ( )
309309 {
310- int triangleIndex = quadCount * 4 ;
310+ int triangleIndex = _quadCount * 4 ;
311311
312- triangles . Add ( triangleIndex + 0 ) ;
313- triangles . Add ( triangleIndex + 1 ) ;
314- triangles . Add ( triangleIndex + 2 ) ;
312+ _triangles . Add ( triangleIndex + 0 ) ;
313+ _triangles . Add ( triangleIndex + 1 ) ;
314+ _triangles . Add ( triangleIndex + 2 ) ;
315315
316- triangles . Add ( triangleIndex + 0 ) ;
317- triangles . Add ( triangleIndex + 2 ) ;
318- triangles . Add ( triangleIndex + 3 ) ;
316+ _triangles . Add ( triangleIndex + 0 ) ;
317+ _triangles . Add ( triangleIndex + 2 ) ;
318+ _triangles . Add ( triangleIndex + 3 ) ;
319319
320- quadCount ++ ;
320+ _quadCount ++ ;
321321 }
322322
323323
324324 public Mesh CreateMesh ( )
325325 {
326326 var mesh = new Mesh
327327 {
328- vertices = vertices . ToArray ( ) ,
329- triangles = triangles . ToArray ( ) ,
330- uv = uv . ToArray ( )
328+ vertices = _vertices . ToArray ( ) ,
329+ triangles = _triangles . ToArray ( ) ,
330+ uv = _uv . ToArray ( )
331331 } ;
332332 mesh . RecalculateNormals ( ) ;
333333 return mesh ;
0 commit comments