# HG changeset patch # User Sam # Date 1675701190 -25200 # Node ID a7f950307d2d0a8601a83bb4cab813b59db1afc3 # Parent 779607656b124eee71a6493ca64f158e2ad20ce9 add: circle mesh diff -r 779607656b12 -r a7f950307d2d src/semicongine/mesh.nim --- a/src/semicongine/mesh.nim Mon Feb 06 23:32:59 2023 +0700 +++ b/src/semicongine/mesh.nim Mon Feb 06 23:33:10 2023 +0700 @@ -1,3 +1,4 @@ +import std/math import std/options import std/typetraits @@ -123,3 +124,19 @@ VecType([T(-0.5), T(+0.5), T(0)]), ] value.useOnDeviceMemory = true + +func circle*[VertexType, VecType, T](n = 16): Mesh[VertexType, uint16] = + result = new Mesh[VertexType, uint16] + result.indexed = true + let angleStep = (2'f * PI) / float32(n) + var data = @[VecType([T(0), T(0), T(0)])] + for i in 1 .. n: + data.add VecType([T(cos(float32(i) * angleStep)), T(sin(float32(i) * + angleStep)), T(0)]) + result.indices.add [0'u16, uint16(i), uint16(i mod (n) + 1)] + + result.vertexData = VertexType() + for attrname, value in result.vertexData.fieldPairs: + when typeof(value) is PositionAttribute: + value.data = data + value.useOnDeviceMemory = true