cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
GDL
About building parametric objects with GDL.

Easy gdl mesh

rudl
Booster

Easy mesh:

! No more VERT EDGE PGON ! (because its a bit of a pain)

just a vertex array

and a face array with vert indices

Face direction should be automatic with the order of vertices, Edges are automatic

Needs more testing, may add some more features.

 

! ------------------------------------------------------------
! Geometry stored in vert and pgon arrays only Example: Pyramid
! ------------------------------------------------------------
! Important order of vertices in Pgon determine Normal / Face direction

! --- SETUP VARIABLES ---

dim points_s[][3]	!points start
dim edges_pi[][2]	!edges point index
dim faces_pi[][]	!faces point index
dim ppf[]			!points per face

! --- POPULATE ---

points_s[1][1] = -1 : points_s[1][2] = -1 : points_s[1][3] = 0	! base
points_s[2][1] =  1 : points_s[2][2] = -1 : points_s[2][3] = 0
points_s[3][1] =  1 : points_s[3][2] =  1 : points_s[3][3] = 0
points_s[4][1] = -1 : points_s[4][2] =  1 : points_s[4][3] = 0
points_s[5][1] =  0 : points_s[5][2] =  0 : points_s[5][3] = 2  	! apex

ppf[1] = 4 : faces_pi[1][1] = 1 : faces_pi[1][2] = 4 : faces_pi[1][3] = 3 : faces_pi[1][4] = 2 	! base (quad)
ppf[2] = 3 : faces_pi[2][1] = 1 : faces_pi[2][2] = 2 : faces_pi[2][3] = 5
ppf[3] = 3 : faces_pi[3][1] = 2 : faces_pi[3][2] = 3 : faces_pi[3][3] = 5
ppf[4] = 3 : faces_pi[4][1] = 3 : faces_pi[4][2] = 4 : faces_pi[4][3] = 5
ppf[5] = 3 : faces_pi[5][1] = 4 : faces_pi[5][2] = 1 : faces_pi[5][3] = 5

nPoints = 5 		! this should be known does not make sense to calc! optional with VARDIM1
nFaces = 5 		! this should be known does not make sense to calc! optional with VARDIM1

! ------------------------------------------------------------
! DO THE MAGIC THING:
! ------------------------------------------------------------

! --- Point index for edges --- edges_pi[][2] for use in EDGE

x=0	! the counter is important!
FOR i=1 TO nFaces
	FOR j=1 TO ppf[i]
		x = x+1
		IF j < ppf[i] THEN 
			edges_pi[x][1]=faces_pi[i][j]
			edges_pi[x][2]=faces_pi[i][j+1]
		ELSE 
			edges_pi[x][1]=faces_pi[i][j] !connect last point of face with first
			edges_pi[x][2]=faces_pi[i][1]		
		ENDIF
	NEXT j
NEXT i

lengthedge = VARDIM1 (edges_pi) ! total edges with duplicates should be nEDGE

! --- Create edge index --- edges[] for use in PGON
! There is some kind of "sorting" through to make the double edge indices negative
! could be optimised for larger meshes though

DIM edges[]
negcount = 0
FOR i = 1 TO lengthedge
	u = edges_pi[i][1]
	v = edges_pi[i][2] 
	edges[i]=i-negcount
		FOR j = 1 To i
			IF edges_pi[j][1]=v AND edges_pi[j][2] = u THEN
				edges[i]= edges[j]*(-1)
				negcount = negcount+1
			ENDIF
		NEXT J
NEXT i

! ------------------------------------------------------------
! BUILDING THE MESH:
! ------------------------------------------------------------

!PUT EVERYTHING TOGETHER

BASE
FOR i = 1 TO nPoints
	VERT points_s[i][1],points_s[i][2],points_s[i][3]
NEXT i

FOR i = 1 TO lengthedge
	IF edges[i]>=1 THEN
		EDGE edges_pi[i][1], edges_pi[i][2],-1,-1,0
	ENDIF
NEXT i

PUT edges
FOR i = 1 TO nFaces
	PGON ppf[i],0,0,GET(ppf[i])
NEXT i

BODY -1

! ------------------------------------------------------------
! DEBUG:
! ------------------------------------------------------------

!PRINT edges_pi
!PRINT edges

 

4 REPLIES 4
Barry Kelly
Moderator

Thanks for showing the method, but I am not sure I understand the purpose.

You did use VERT EDGE PGON, just in a loop.

And wouldn't it be easier to use the PYRAMID command?

 

Barry.

 

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

In the end of course i used Vert edge and pgons etc.

The pyramid is just a simple example  I'm thinking about much more complex things. Its more about how it is stored

Its way easier if you have indices than the order of creation 

especially if you want to create something parametric where the number of vertices edges pgons is not known

rudl
Booster

Not a pyramid:
In conjunction with a blender script (I did us chatgpt for that)

import bpy

# Output file path
output_file = "C:/Users/potato/mesh_data.txt"  # <-- change this

with open(output_file, 'w') as f:
    vertex_count = 1
    face_count = 1

    for obj in bpy.context.selected_objects:  # or bpy.data.objects for all
        if obj.type != 'MESH':
            continue
        
        mesh = obj.data
        #f.write(f"// Object: {obj.name}\n\n")

        # Write vertices
        for v in mesh.vertices:
            f.write(f"points_s[{vertex_count}][1] = {v.co.x}\n")
            f.write(f"points_s[{vertex_count}][2] = {v.co.y}\n")
            f.write(f"points_s[{vertex_count}][3] = {v.co.z}\n")
            vertex_count += 1

        f.write("\n")

        # Write faces
        for p in mesh.polygons:
            # Ensure we only handle triangles or quads (can expand if needed)
            verts = p.vertices
            for i in range(len(verts)):
                f.write(f"faces_pi[{face_count}][{i+1}] = {verts[i]+1}\n")  # +1 for 1-based indexing
            face_count += 1

        f.write("\n")

print(f"Mesh data exported to {output_file}")




Screenshot 2025-10-14 225243.png

 

 

rudl
Booster

Was a little slow but it should be much faster now.
Sorted the edges before checking for the "oposite edge" otherwise it loops through the whole array for every edge. ^^

! --- SETUP VARIABLES ---

dim po_s[][3]	!points start
dim edges_pi[][2]	!edges point index
dim f_pi[][]	!faces point index
dim ppf[]			!points per face

! --- POPULATE ---
po_s[1][1] = 0.03838 : po_s[1][2] = -0.02232 : po_s[1][3] = 0.08784
po_s[2][1] = -0.01273 : po_s[2][2] = 0.01263 : po_s[2][3] = 0.14178
po_s[3][1] = -0.07195 : po_s[3][2] = -0.01823 : po_s[3][3] = 0.08623
po_s[4][1] = 0.0298 : po_s[4][2] = -0.00251 : po_s[4][3] = 0.09868
...
po_s[243][1] = 0.0156 : po_s[243][2] = -0.03653 : po_s[243][3] = -0.0
po_s[244][1] = -0.04308 : po_s[244][2] = 0.03277 : po_s[244][3] = 0.1129
po_s[245][1] = -0.04553 : po_s[245][2] = 0.0671 : po_s[245][3] = 0.1219

f_pi[1][1]=5:f_pi[1][2]=141:f_pi[1][3]=28 : f_pi[2][1]=122:f_pi[2][2]=133:f_pi[2][3]=148 : f_pi[3][1]=147:f_pi[3][2]=11:f_pi[3][3]=111
f_pi[4][1]=134:f_pi[4][2]=52:f_pi[4][3]=124 : f_pi[5][1]=5:f_pi[5][2]=12:f_pi[5][3]=141 : f_pi[6][1]=28:f_pi[6][2]=141:f_pi[6][3]=31
f_pi[7][1]=21:f_pi[7][2]=155:f_pi[7][3]=163 : f_pi[8][1]=194:f_pi[8][2]=134:f_pi[8][3]=124 : f_pi[9][1]=52:f_pi[9][2]=134:f_pi[9][3]=40
...
f_pi[478][1]=230:f_pi[478][2]=229:f_pi[478][3]=238 : f_pi[479][1]=229:f_pi[479][2]=227:f_pi[479][3]=222 : f_pi[480][1]=222:f_pi[480][2]=224:f_pi[480][3]=229
f_pi[481][1]=223:f_pi[481][2]=226:f_pi[481][3]=225 : f_pi[482][1]=226:f_pi[482][2]=233:f_pi[482][3]=225 : f_pi[483][1]=243:f_pi[483][2]=238:f_pi[483][3]=240
f_pi[484][1]=240:f_pi[484][2]=232:f_pi[484][3]=243 : f_pi[485][1]=233:f_pi[485][2]=243:f_pi[485][3]=235 : f_pi[486][1]=232:f_pi[486][2]=235:f_pi[486][3]=243

nPoints = 245 		! this should be known does not make sense to calc! optional with VARDIM1
nFaces = 486 		! this should be known does not make sense to calc! optional with VARDIM1

FOR i=1 TO nFaces
	ppf[i]=3
NEXT i

! ------------------------------------------------------------
! DO THE MAGIC THING:
! ------------------------------------------------------------

! --- Point index for edges --- edges_pi[][2] for use in EDGE

DIM edges_so[][]

x=0	! the counter is important!
FOR i=1 TO nFaces
	FOR j=1 TO ppf[i]
		x = x+1
		IF j < ppf[i] THEN 
			edges_pi[x][1]=f_pi[i][j]
			edges_pi[x][2]=f_pi[i][j+1]
		ELSE 
			edges_pi[x][1]=f_pi[i][j] !connect last point of face with first
			edges_pi[x][2]=f_pi[i][1]		
		ENDIF
			 
		edges_so[edges_pi[x][1]][1] = edges_so[edges_pi[x][1]][1]+1 !self+1	
		edges_so[edges_pi[x][1]][edges_so[edges_pi[x][1]][1]+1] = x

	NEXT j
NEXT i

nEdges = VARDIM1 (edges_pi) ! total edges with duplicates

negcount = 0
DIM edges[]
FOR i = 1 TO nEdges
	!edges_pi[i][2]
	IF edges[i] < 0 THEN
	negcount = negcount +1
	ELSE
	tempi = i-negcount
	FOR j = 2 TO edges_so[edges_pi[i][2]][1]+1 
		IF edges_pi[i][1] = edges_pi[edges_so[edges_pi[i][2]][j]][2] THEN
			!"PRINT "gefunden"
			edges[i] = tempi
			edges[edges_so[edges_pi[i][2]][j]] = -tempi
		ENDIF
	NEXT j
	ENDIF
NEXT i

! ------------------------------------------------------------
! BUILDING THE MESH:
! ------------------------------------------------------------

BASE
FOR i = 1 TO nPoints
	VERT po_s[i][1],po_s[i][2],po_s[i][3]
NEXT i

FOR i = 1 TO nEdges
	IF edges[i]>=1 THEN
		EDGE edges_pi[i][1], edges_pi[i][2],-1,-1,0
	ENDIF
NEXT i

PUT edges
FOR i = 1 TO nFaces
	PGON ppf[i],0,0,GET(ppf[i])
NEXT i

BODY -1

Full res bunny example:
69664 Faces, 34834 Points

 

Screenshot 2025-10-25 232153.pngScreenshot 2025-10-25 234639.pngScreenshot 2025-10-25 234900.png