Procedural circle mesh with uniform faces












4















I'm trying to create a 2d circle procedurally with uniform faces like so.



enter image description here



Normally, I would create it with a triangle fan structure, but I need faces to be roughly identical. I looked for examples, but I could only find "cube to sphere" examples. A compromise could be something similar to this :



enter image description here



Could you help me finding a way to draw this structure? I'd like to do it in C# but js or even pseudo code would do!



Thanks a lot










share|improve this question

























  • Maybe create it with any solution, then perform some uniform remeshing on it

    – Basile Perrenoud
    Nov 21 '18 at 8:41











  • Maybe this post can help stackoverflow.com/questions/33510979/…

    – Kiwad
    Nov 21 '18 at 19:41
















4















I'm trying to create a 2d circle procedurally with uniform faces like so.



enter image description here



Normally, I would create it with a triangle fan structure, but I need faces to be roughly identical. I looked for examples, but I could only find "cube to sphere" examples. A compromise could be something similar to this :



enter image description here



Could you help me finding a way to draw this structure? I'd like to do it in C# but js or even pseudo code would do!



Thanks a lot










share|improve this question

























  • Maybe create it with any solution, then perform some uniform remeshing on it

    – Basile Perrenoud
    Nov 21 '18 at 8:41











  • Maybe this post can help stackoverflow.com/questions/33510979/…

    – Kiwad
    Nov 21 '18 at 19:41














4












4








4


3






I'm trying to create a 2d circle procedurally with uniform faces like so.



enter image description here



Normally, I would create it with a triangle fan structure, but I need faces to be roughly identical. I looked for examples, but I could only find "cube to sphere" examples. A compromise could be something similar to this :



enter image description here



Could you help me finding a way to draw this structure? I'd like to do it in C# but js or even pseudo code would do!



Thanks a lot










share|improve this question
















I'm trying to create a 2d circle procedurally with uniform faces like so.



enter image description here



Normally, I would create it with a triangle fan structure, but I need faces to be roughly identical. I looked for examples, but I could only find "cube to sphere" examples. A compromise could be something similar to this :



enter image description here



Could you help me finding a way to draw this structure? I'd like to do it in C# but js or even pseudo code would do!



Thanks a lot







javascript c# unity3d mesh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 7:31







Kiwad

















asked Nov 21 '18 at 6:42









KiwadKiwad

380516




380516













  • Maybe create it with any solution, then perform some uniform remeshing on it

    – Basile Perrenoud
    Nov 21 '18 at 8:41











  • Maybe this post can help stackoverflow.com/questions/33510979/…

    – Kiwad
    Nov 21 '18 at 19:41



















  • Maybe create it with any solution, then perform some uniform remeshing on it

    – Basile Perrenoud
    Nov 21 '18 at 8:41











  • Maybe this post can help stackoverflow.com/questions/33510979/…

    – Kiwad
    Nov 21 '18 at 19:41

















Maybe create it with any solution, then perform some uniform remeshing on it

– Basile Perrenoud
Nov 21 '18 at 8:41





Maybe create it with any solution, then perform some uniform remeshing on it

– Basile Perrenoud
Nov 21 '18 at 8:41













Maybe this post can help stackoverflow.com/questions/33510979/…

– Kiwad
Nov 21 '18 at 19:41





Maybe this post can help stackoverflow.com/questions/33510979/…

– Kiwad
Nov 21 '18 at 19:41












1 Answer
1






active

oldest

votes


















4














You got me interested with your question, and I think I've got the solution you were looking for. Here is how we can create a topology that you desired:



1) We start with a hexagon. Why hexagon and not other shape? Because hexagon is the only magic shape with its radius equal too the length of its side. We will call this radius R. We will now try to create a shape that resembles circle and is made of triangles with side length approximately R.



2) Now imagine some concentric circles, with radius R, 2R, 3R and so on - the more, the higher is the resolution.



3) Circle number 1 has radius R. We will now replace that circle with a hexagon with radius R.



Example 1



4) We will now add more nodes on second circle to expand our hexagon. What is the circumference of circle number N? It is 2PiRN. Now we want to divide it into X edges of length approximately R. Hence X=2PiN, which is approximately 6N. So we will divide first circle into 6 edges (hexagon), second one into 12, then 18, 24 and so on.



5) Now we have lots of circles divided into edges. We now need to connect edges into triangles. How do we build triangles between circle N (outer) and N-1 (inner)? Outer circle has 6 more edges than the inner one. If they had identical number of vertices, we could connect them with quads. But they don't. So, we will still try to build quads, but for each N quads we build, we will need to add 1 triangle. Each quad uses 2 vertices from inner and 2 vertices from outer circle. Each triangle uses 2 vertices from the outer circle and only 1 from inner, thus compensating the excess of vertices.



Example 2



6) And now at last, there is some tested sample code that does what you need. It will generate a circle with uniform topology, with center point at origin and radius of 1, divided into *resolution sub circles. It could use some minor performance optimization (that's out of scope for now), but all in all it should do the job.



using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(MeshFilter))]
public class UniformCirclePlane : MonoBehaviour {

public int resolution = 4;

// Use this for initialization
void Start() {
GetComponent<MeshFilter>().mesh = GenerateCircle(resolution);
}

// Update is called once per frame
void Update() {

}

// Get the index of point number 'x' in circle number 'c'
static int GetPointIndex(int c, int x) {
if (c < 0) return 0; // In case of center point
x = x % ((c + 1) * 6); // Make the point index circular
// Explanation: index = number of points in previous circles + central point + x
// hence: (0+1+2+...+c)*6+x+1 = ((c/2)*(c+1))*6+x+1 = 3*c*(c+1)+x+1

return (3 * c * (c + 1) + x + 1);
}

public static Mesh GenerateCircle(int res) {

float d = 1f / res;

var vtc = new List<Vector3>();
vtc.Add(Vector3.zero); // Start with only center point
var tris = new List<int>();

// First pass => build vertices
for (int circ = 0; circ < res; ++circ) {
float angleStep = (Mathf.PI * 2f) / ((circ + 1) * 6);
for (int point = 0; point < (circ + 1) * 6; ++point) {
vtc.Add(new Vector2(
Mathf.Cos(angleStep * point),
Mathf.Sin(angleStep * point)) * d * (circ + 1));
}
}

// Second pass => connect vertices into triangles
for (int circ = 0; circ < res; ++circ) {
for (int point = 0, other = 0; point < (circ + 1) * 6; ++point) {
if (point % (circ + 1) != 0) {
// Create 2 triangles
tris.Add(GetPointIndex(circ - 1, other + 1));
tris.Add(GetPointIndex(circ - 1, other));
tris.Add(GetPointIndex(circ, point));
tris.Add(GetPointIndex(circ, point));
tris.Add(GetPointIndex(circ, point + 1));
tris.Add(GetPointIndex(circ - 1, other + 1));
++other;
} else {
// Create 1 inverse triange
tris.Add(GetPointIndex(circ, point));
tris.Add(GetPointIndex(circ, point + 1));
tris.Add(GetPointIndex(circ - 1, other));
// Do not move to the next point in the smaller circle
}
}
}

// Create the mesh
var m = new Mesh();
m.SetVertices(vtc);
m.SetTriangles(tris, 0);
m.RecalculateNormals();
m.UploadMeshData(true);

return m;

}
}


Final Result:



enter image description here






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406534%2fprocedural-circle-mesh-with-uniform-faces%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    You got me interested with your question, and I think I've got the solution you were looking for. Here is how we can create a topology that you desired:



    1) We start with a hexagon. Why hexagon and not other shape? Because hexagon is the only magic shape with its radius equal too the length of its side. We will call this radius R. We will now try to create a shape that resembles circle and is made of triangles with side length approximately R.



    2) Now imagine some concentric circles, with radius R, 2R, 3R and so on - the more, the higher is the resolution.



    3) Circle number 1 has radius R. We will now replace that circle with a hexagon with radius R.



    Example 1



    4) We will now add more nodes on second circle to expand our hexagon. What is the circumference of circle number N? It is 2PiRN. Now we want to divide it into X edges of length approximately R. Hence X=2PiN, which is approximately 6N. So we will divide first circle into 6 edges (hexagon), second one into 12, then 18, 24 and so on.



    5) Now we have lots of circles divided into edges. We now need to connect edges into triangles. How do we build triangles between circle N (outer) and N-1 (inner)? Outer circle has 6 more edges than the inner one. If they had identical number of vertices, we could connect them with quads. But they don't. So, we will still try to build quads, but for each N quads we build, we will need to add 1 triangle. Each quad uses 2 vertices from inner and 2 vertices from outer circle. Each triangle uses 2 vertices from the outer circle and only 1 from inner, thus compensating the excess of vertices.



    Example 2



    6) And now at last, there is some tested sample code that does what you need. It will generate a circle with uniform topology, with center point at origin and radius of 1, divided into *resolution sub circles. It could use some minor performance optimization (that's out of scope for now), but all in all it should do the job.



    using System.Collections.Generic;
    using UnityEngine;

    [RequireComponent(typeof(MeshFilter))]
    public class UniformCirclePlane : MonoBehaviour {

    public int resolution = 4;

    // Use this for initialization
    void Start() {
    GetComponent<MeshFilter>().mesh = GenerateCircle(resolution);
    }

    // Update is called once per frame
    void Update() {

    }

    // Get the index of point number 'x' in circle number 'c'
    static int GetPointIndex(int c, int x) {
    if (c < 0) return 0; // In case of center point
    x = x % ((c + 1) * 6); // Make the point index circular
    // Explanation: index = number of points in previous circles + central point + x
    // hence: (0+1+2+...+c)*6+x+1 = ((c/2)*(c+1))*6+x+1 = 3*c*(c+1)+x+1

    return (3 * c * (c + 1) + x + 1);
    }

    public static Mesh GenerateCircle(int res) {

    float d = 1f / res;

    var vtc = new List<Vector3>();
    vtc.Add(Vector3.zero); // Start with only center point
    var tris = new List<int>();

    // First pass => build vertices
    for (int circ = 0; circ < res; ++circ) {
    float angleStep = (Mathf.PI * 2f) / ((circ + 1) * 6);
    for (int point = 0; point < (circ + 1) * 6; ++point) {
    vtc.Add(new Vector2(
    Mathf.Cos(angleStep * point),
    Mathf.Sin(angleStep * point)) * d * (circ + 1));
    }
    }

    // Second pass => connect vertices into triangles
    for (int circ = 0; circ < res; ++circ) {
    for (int point = 0, other = 0; point < (circ + 1) * 6; ++point) {
    if (point % (circ + 1) != 0) {
    // Create 2 triangles
    tris.Add(GetPointIndex(circ - 1, other + 1));
    tris.Add(GetPointIndex(circ - 1, other));
    tris.Add(GetPointIndex(circ, point));
    tris.Add(GetPointIndex(circ, point));
    tris.Add(GetPointIndex(circ, point + 1));
    tris.Add(GetPointIndex(circ - 1, other + 1));
    ++other;
    } else {
    // Create 1 inverse triange
    tris.Add(GetPointIndex(circ, point));
    tris.Add(GetPointIndex(circ, point + 1));
    tris.Add(GetPointIndex(circ - 1, other));
    // Do not move to the next point in the smaller circle
    }
    }
    }

    // Create the mesh
    var m = new Mesh();
    m.SetVertices(vtc);
    m.SetTriangles(tris, 0);
    m.RecalculateNormals();
    m.UploadMeshData(true);

    return m;

    }
    }


    Final Result:



    enter image description here






    share|improve this answer




























      4














      You got me interested with your question, and I think I've got the solution you were looking for. Here is how we can create a topology that you desired:



      1) We start with a hexagon. Why hexagon and not other shape? Because hexagon is the only magic shape with its radius equal too the length of its side. We will call this radius R. We will now try to create a shape that resembles circle and is made of triangles with side length approximately R.



      2) Now imagine some concentric circles, with radius R, 2R, 3R and so on - the more, the higher is the resolution.



      3) Circle number 1 has radius R. We will now replace that circle with a hexagon with radius R.



      Example 1



      4) We will now add more nodes on second circle to expand our hexagon. What is the circumference of circle number N? It is 2PiRN. Now we want to divide it into X edges of length approximately R. Hence X=2PiN, which is approximately 6N. So we will divide first circle into 6 edges (hexagon), second one into 12, then 18, 24 and so on.



      5) Now we have lots of circles divided into edges. We now need to connect edges into triangles. How do we build triangles between circle N (outer) and N-1 (inner)? Outer circle has 6 more edges than the inner one. If they had identical number of vertices, we could connect them with quads. But they don't. So, we will still try to build quads, but for each N quads we build, we will need to add 1 triangle. Each quad uses 2 vertices from inner and 2 vertices from outer circle. Each triangle uses 2 vertices from the outer circle and only 1 from inner, thus compensating the excess of vertices.



      Example 2



      6) And now at last, there is some tested sample code that does what you need. It will generate a circle with uniform topology, with center point at origin and radius of 1, divided into *resolution sub circles. It could use some minor performance optimization (that's out of scope for now), but all in all it should do the job.



      using System.Collections.Generic;
      using UnityEngine;

      [RequireComponent(typeof(MeshFilter))]
      public class UniformCirclePlane : MonoBehaviour {

      public int resolution = 4;

      // Use this for initialization
      void Start() {
      GetComponent<MeshFilter>().mesh = GenerateCircle(resolution);
      }

      // Update is called once per frame
      void Update() {

      }

      // Get the index of point number 'x' in circle number 'c'
      static int GetPointIndex(int c, int x) {
      if (c < 0) return 0; // In case of center point
      x = x % ((c + 1) * 6); // Make the point index circular
      // Explanation: index = number of points in previous circles + central point + x
      // hence: (0+1+2+...+c)*6+x+1 = ((c/2)*(c+1))*6+x+1 = 3*c*(c+1)+x+1

      return (3 * c * (c + 1) + x + 1);
      }

      public static Mesh GenerateCircle(int res) {

      float d = 1f / res;

      var vtc = new List<Vector3>();
      vtc.Add(Vector3.zero); // Start with only center point
      var tris = new List<int>();

      // First pass => build vertices
      for (int circ = 0; circ < res; ++circ) {
      float angleStep = (Mathf.PI * 2f) / ((circ + 1) * 6);
      for (int point = 0; point < (circ + 1) * 6; ++point) {
      vtc.Add(new Vector2(
      Mathf.Cos(angleStep * point),
      Mathf.Sin(angleStep * point)) * d * (circ + 1));
      }
      }

      // Second pass => connect vertices into triangles
      for (int circ = 0; circ < res; ++circ) {
      for (int point = 0, other = 0; point < (circ + 1) * 6; ++point) {
      if (point % (circ + 1) != 0) {
      // Create 2 triangles
      tris.Add(GetPointIndex(circ - 1, other + 1));
      tris.Add(GetPointIndex(circ - 1, other));
      tris.Add(GetPointIndex(circ, point));
      tris.Add(GetPointIndex(circ, point));
      tris.Add(GetPointIndex(circ, point + 1));
      tris.Add(GetPointIndex(circ - 1, other + 1));
      ++other;
      } else {
      // Create 1 inverse triange
      tris.Add(GetPointIndex(circ, point));
      tris.Add(GetPointIndex(circ, point + 1));
      tris.Add(GetPointIndex(circ - 1, other));
      // Do not move to the next point in the smaller circle
      }
      }
      }

      // Create the mesh
      var m = new Mesh();
      m.SetVertices(vtc);
      m.SetTriangles(tris, 0);
      m.RecalculateNormals();
      m.UploadMeshData(true);

      return m;

      }
      }


      Final Result:



      enter image description here






      share|improve this answer


























        4












        4








        4







        You got me interested with your question, and I think I've got the solution you were looking for. Here is how we can create a topology that you desired:



        1) We start with a hexagon. Why hexagon and not other shape? Because hexagon is the only magic shape with its radius equal too the length of its side. We will call this radius R. We will now try to create a shape that resembles circle and is made of triangles with side length approximately R.



        2) Now imagine some concentric circles, with radius R, 2R, 3R and so on - the more, the higher is the resolution.



        3) Circle number 1 has radius R. We will now replace that circle with a hexagon with radius R.



        Example 1



        4) We will now add more nodes on second circle to expand our hexagon. What is the circumference of circle number N? It is 2PiRN. Now we want to divide it into X edges of length approximately R. Hence X=2PiN, which is approximately 6N. So we will divide first circle into 6 edges (hexagon), second one into 12, then 18, 24 and so on.



        5) Now we have lots of circles divided into edges. We now need to connect edges into triangles. How do we build triangles between circle N (outer) and N-1 (inner)? Outer circle has 6 more edges than the inner one. If they had identical number of vertices, we could connect them with quads. But they don't. So, we will still try to build quads, but for each N quads we build, we will need to add 1 triangle. Each quad uses 2 vertices from inner and 2 vertices from outer circle. Each triangle uses 2 vertices from the outer circle and only 1 from inner, thus compensating the excess of vertices.



        Example 2



        6) And now at last, there is some tested sample code that does what you need. It will generate a circle with uniform topology, with center point at origin and radius of 1, divided into *resolution sub circles. It could use some minor performance optimization (that's out of scope for now), but all in all it should do the job.



        using System.Collections.Generic;
        using UnityEngine;

        [RequireComponent(typeof(MeshFilter))]
        public class UniformCirclePlane : MonoBehaviour {

        public int resolution = 4;

        // Use this for initialization
        void Start() {
        GetComponent<MeshFilter>().mesh = GenerateCircle(resolution);
        }

        // Update is called once per frame
        void Update() {

        }

        // Get the index of point number 'x' in circle number 'c'
        static int GetPointIndex(int c, int x) {
        if (c < 0) return 0; // In case of center point
        x = x % ((c + 1) * 6); // Make the point index circular
        // Explanation: index = number of points in previous circles + central point + x
        // hence: (0+1+2+...+c)*6+x+1 = ((c/2)*(c+1))*6+x+1 = 3*c*(c+1)+x+1

        return (3 * c * (c + 1) + x + 1);
        }

        public static Mesh GenerateCircle(int res) {

        float d = 1f / res;

        var vtc = new List<Vector3>();
        vtc.Add(Vector3.zero); // Start with only center point
        var tris = new List<int>();

        // First pass => build vertices
        for (int circ = 0; circ < res; ++circ) {
        float angleStep = (Mathf.PI * 2f) / ((circ + 1) * 6);
        for (int point = 0; point < (circ + 1) * 6; ++point) {
        vtc.Add(new Vector2(
        Mathf.Cos(angleStep * point),
        Mathf.Sin(angleStep * point)) * d * (circ + 1));
        }
        }

        // Second pass => connect vertices into triangles
        for (int circ = 0; circ < res; ++circ) {
        for (int point = 0, other = 0; point < (circ + 1) * 6; ++point) {
        if (point % (circ + 1) != 0) {
        // Create 2 triangles
        tris.Add(GetPointIndex(circ - 1, other + 1));
        tris.Add(GetPointIndex(circ - 1, other));
        tris.Add(GetPointIndex(circ, point));
        tris.Add(GetPointIndex(circ, point));
        tris.Add(GetPointIndex(circ, point + 1));
        tris.Add(GetPointIndex(circ - 1, other + 1));
        ++other;
        } else {
        // Create 1 inverse triange
        tris.Add(GetPointIndex(circ, point));
        tris.Add(GetPointIndex(circ, point + 1));
        tris.Add(GetPointIndex(circ - 1, other));
        // Do not move to the next point in the smaller circle
        }
        }
        }

        // Create the mesh
        var m = new Mesh();
        m.SetVertices(vtc);
        m.SetTriangles(tris, 0);
        m.RecalculateNormals();
        m.UploadMeshData(true);

        return m;

        }
        }


        Final Result:



        enter image description here






        share|improve this answer













        You got me interested with your question, and I think I've got the solution you were looking for. Here is how we can create a topology that you desired:



        1) We start with a hexagon. Why hexagon and not other shape? Because hexagon is the only magic shape with its radius equal too the length of its side. We will call this radius R. We will now try to create a shape that resembles circle and is made of triangles with side length approximately R.



        2) Now imagine some concentric circles, with radius R, 2R, 3R and so on - the more, the higher is the resolution.



        3) Circle number 1 has radius R. We will now replace that circle with a hexagon with radius R.



        Example 1



        4) We will now add more nodes on second circle to expand our hexagon. What is the circumference of circle number N? It is 2PiRN. Now we want to divide it into X edges of length approximately R. Hence X=2PiN, which is approximately 6N. So we will divide first circle into 6 edges (hexagon), second one into 12, then 18, 24 and so on.



        5) Now we have lots of circles divided into edges. We now need to connect edges into triangles. How do we build triangles between circle N (outer) and N-1 (inner)? Outer circle has 6 more edges than the inner one. If they had identical number of vertices, we could connect them with quads. But they don't. So, we will still try to build quads, but for each N quads we build, we will need to add 1 triangle. Each quad uses 2 vertices from inner and 2 vertices from outer circle. Each triangle uses 2 vertices from the outer circle and only 1 from inner, thus compensating the excess of vertices.



        Example 2



        6) And now at last, there is some tested sample code that does what you need. It will generate a circle with uniform topology, with center point at origin and radius of 1, divided into *resolution sub circles. It could use some minor performance optimization (that's out of scope for now), but all in all it should do the job.



        using System.Collections.Generic;
        using UnityEngine;

        [RequireComponent(typeof(MeshFilter))]
        public class UniformCirclePlane : MonoBehaviour {

        public int resolution = 4;

        // Use this for initialization
        void Start() {
        GetComponent<MeshFilter>().mesh = GenerateCircle(resolution);
        }

        // Update is called once per frame
        void Update() {

        }

        // Get the index of point number 'x' in circle number 'c'
        static int GetPointIndex(int c, int x) {
        if (c < 0) return 0; // In case of center point
        x = x % ((c + 1) * 6); // Make the point index circular
        // Explanation: index = number of points in previous circles + central point + x
        // hence: (0+1+2+...+c)*6+x+1 = ((c/2)*(c+1))*6+x+1 = 3*c*(c+1)+x+1

        return (3 * c * (c + 1) + x + 1);
        }

        public static Mesh GenerateCircle(int res) {

        float d = 1f / res;

        var vtc = new List<Vector3>();
        vtc.Add(Vector3.zero); // Start with only center point
        var tris = new List<int>();

        // First pass => build vertices
        for (int circ = 0; circ < res; ++circ) {
        float angleStep = (Mathf.PI * 2f) / ((circ + 1) * 6);
        for (int point = 0; point < (circ + 1) * 6; ++point) {
        vtc.Add(new Vector2(
        Mathf.Cos(angleStep * point),
        Mathf.Sin(angleStep * point)) * d * (circ + 1));
        }
        }

        // Second pass => connect vertices into triangles
        for (int circ = 0; circ < res; ++circ) {
        for (int point = 0, other = 0; point < (circ + 1) * 6; ++point) {
        if (point % (circ + 1) != 0) {
        // Create 2 triangles
        tris.Add(GetPointIndex(circ - 1, other + 1));
        tris.Add(GetPointIndex(circ - 1, other));
        tris.Add(GetPointIndex(circ, point));
        tris.Add(GetPointIndex(circ, point));
        tris.Add(GetPointIndex(circ, point + 1));
        tris.Add(GetPointIndex(circ - 1, other + 1));
        ++other;
        } else {
        // Create 1 inverse triange
        tris.Add(GetPointIndex(circ, point));
        tris.Add(GetPointIndex(circ, point + 1));
        tris.Add(GetPointIndex(circ - 1, other));
        // Do not move to the next point in the smaller circle
        }
        }
        }

        // Create the mesh
        var m = new Mesh();
        m.SetVertices(vtc);
        m.SetTriangles(tris, 0);
        m.RecalculateNormals();
        m.UploadMeshData(true);

        return m;

        }
        }


        Final Result:



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 23:47









        Yuri NudelmanYuri Nudelman

        1,4031613




        1,4031613
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406534%2fprocedural-circle-mesh-with-uniform-faces%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?