# HG changeset patch # User sam # Date 1717320112 -25200 # Node ID a52e924e5666ebffe22953744f4d06c5c9886398 # Parent 7f2c477ae1f4de5c6d3cdbc03323478b873d2fcf add: function to generate circle-mesh data (not mesh object) diff -r 7f2c477ae1f4 -r a52e924e5666 semicongine/mesh.nim --- a/semicongine/mesh.nim Thu May 23 02:26:37 2024 +0700 +++ b/semicongine/mesh.nim Sun Jun 02 16:21:52 2024 +0700 @@ -489,6 +489,16 @@ result[].initVertexAttribute("color", @[colorVec, colorVec, colorVec]) `material=`(result[], material) +proc CircleMesh*(nSegments: int): (seq[Vec3f], seq[array[3, uint16]]) = + let + rX = 0.5 + rY = 0.5 + step = (2'f32 * PI) / float32(nSegments) + result[0] = @[newVec3f(0, 0), newVec3f(rX, 0)] + for i in 1 .. nSegments: + result[0].add newVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) + result[1].add [uint16(0), uint16(i), uint16(i + 1)] + proc circle*(width = 1'f32, height = 1'f32, nSegments = 12, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = assert nSegments >= 3 result = Mesh(