2025-10-14 10:03 AM
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
3 weeks ago
That is definitely on my todo list.
Main focus is still making it easier to script meshes within gdl.
3 weeks ago
Parametric torus and bended beams.
Torus example:
theta = 360/u
FOR i = 2 TO u
vec_temp[1]=po_s[i-1]
GOSUB "V_ArotX":
po_s[i] = vec_temp[3]
NEXT i
FOR i =1 TO u
po_s[i][2]= po_s[i][2]+rv
NEXT i
theta = 360/v
FOR i = 1 TO v-1
FOR j = 1 TO u
vec_temp[1]=po_s[(i-1)*u+j]
GOSUB "V_ArotZ":
po_s[i*u+j] = vec_temp[3]
NEXT j
NEXT i
c =0
FOR i = 1 TO v
FOR j = 1 TO u
IF i = v THEN
IF j = u THEN
c = c +1
f_pi[c][1]=(i-1)*u+j
f_pi[c][2]= j
f_pi[c][3]=(i-2)*u+j+1
c = c +1
f_pi[c][1]= j
f_pi[c][2]= 1
f_pi[c][3]=(i-2)*u+j+1
ELSE
c = c +1
f_pi[c][1]=(i-1)*u+j
f_pi[c][2]= j
f_pi[c][3]=(i-1)*u+j+1
c = c +1
f_pi[c][1]= j
f_pi[c][2]= j+1
f_pi[c][3]= (i-1)*u+j+1
ENDIF
ELSE
IF j = u THEN
c = c +1
f_pi[c][1]=(i-1)*u+j
f_pi[c][2]=(i)*u+j
f_pi[c][3]=(i-2)*u+j+1
c = c +1
f_pi[c][1]=(i)*u+j
f_pi[c][2]=(i-1)*u+j+1
f_pi[c][3]=(i-2)*u+j+1
ELSE
c = c +1
f_pi[c][1]=(i-1)*u+j
f_pi[c][2]=(i)*u+j
f_pi[c][3]=(i-1)*u+j+1
c = c +1
f_pi[c][1]= (i)*u+j
f_pi[c][2]= (i)*u+j+1
f_pi[c][3]= (i-1)*u+j+1
ENDIF
ENDIF
NEXT j
NEXT iyesterday
*) Monkey read from text-file
*) Arbitary rotation around an axis rodriques transformation
*) Display Helper Axes