# HG changeset patch # User Sam # Date 1675701190 -25200 # Node ID 410ebd46c539ff26dfca48df5982d13afc4fc8a8 # Parent 21c276c0a968e101a25433ba07ea29f907e1ac7c add: circle mesh diff -r 21c276c0a968 -r 410ebd46c539 src/semicongine/mesh.nim --- a/src/semicongine/mesh.nim Mon Feb 06 23:32:45 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