# HG changeset patch # User Sam # Date 1703870224 -25200 # Node ID 6406a5af430d04dd5a3e3651004ee0a23598f266 # Parent 6001079399a6cb449a18f2b24f326801fa023598 add: correct grid-mesh indices diff -r 6001079399a6 -r 6406a5af430d semicongine/mesh.nim --- a/semicongine/mesh.nim Thu Dec 28 22:33:12 2023 +0700 +++ b/semicongine/mesh.nim Sat Dec 30 00:17:04 2023 +0700 @@ -502,7 +502,7 @@ result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) result[].initVertexAttribute("color", col) -proc grid*(columns, rows: int, cellSize=1.0'f32, color="ffffffff", material=EMPTY_MATERIAL.initMaterialData()): Mesh = +proc grid*(columns, rows: uint16, cellSize=1.0'f32, color="ffffffff", material=EMPTY_MATERIAL.initMaterialData()): Mesh = result = Mesh( vertexCount: int((rows + 1) * (columns + 1)), @@ -520,12 +520,15 @@ var pos = @[newVec3f(center_offset_x, center_offset_y)] col = @[color, color] - for h in 0 .. rows: - for w in 0 .. columns: + i = 0'u16 + for h in 0'u16 .. rows: + for w in 0'u16 .. columns: pos.add newVec3f(center_offset_x + float32(w) * cellSize, center_offset_y + float32(h) * cellSize) col.add color if w > 0 and h > 0: - result[].smallIndices.add [uint16(0), uint16(1), uint16(2)] + result[].smallIndices.add [i, i - 1, i - w - 1] + result[].smallIndices.add [i, i - w - 1, i - w] + i.inc result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) result[].initVertexAttribute("color", col)