Skip to content

Vertices Orden #2

@ThinkingInXyZ

Description

@ThinkingInXyZ

Hello,

First of all, Great work! I think you have done very hard work with your CSG library.

Now, I am trying to create a Viewer on SharpGL to visualize the SOLIDS. So I am trying to convert your polygons to be drawn by SharopGL however I dont get any good results at all. I tried two main methods, but non of them worked well. And basically it is because, I dont know exactly the order of the vertices.

To illustrate my situation, I created the following simple case:

float radius_gear  = 10;
float radius_teeth = 1;
Solid gear   = Solids.Cylinder(radius_gear, 0.6, true);
Solid tooth = Solids.Cylinder(radius_teeth, 1.2, true).Translate(radius_gear, 0, 0);
Solid final   = Solids.Difference(gear, tooth);

Approach 1 Simple Straight forward approach

// Get the Vertices from the Solid
var verts = csg.
                  Polygons.
                   SelectMany(x => x.Vertices).
                    Select(ToSCNVector3).
                    ToArray();
.
.
.
// Draw the Mesh based on the grabbed vertices
gl.Begin(OpenGL.GL_TRIANGLE_STRIP);  // I tried different methods here

for (int i = 0; i < verts .Length; i += 3)
    gl.Vertex((float)verts [i].X, (float)verts [i].Y, (float)verts [i].Z);  
            
gl.End();

image

Approach 2 Converting Polygon to Polygon in Quads

        private void DrawSolid(OpenGL gl, Solid pSolid)
        {
            foreach (var poly in pSolid.Polygons)
            {
                gl.Begin(OpenGL.GL_QUADS);
                for(int i=0; i < poly.Vertices.Count; i++)
                    gl.Vertex((float)poly.Vertices[i].Pos.X, (float)poly.Vertices[i].Pos.Y, (float)poly.Vertices[i].Pos.Z);  
                gl.End();    
            }
        }

image

Please, could you tell me how the vertices are organized? Or can you point me what i am doing wrong?

Thank you very much in advance!!

Kind Regards,
Ting

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions