Guest User

Tunnel 3D

a guest
Jul 27th, 2026
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.23 KB | Science | 0 0
  1. #!/usr/bin/env gmic
  2. # File : tunnel3d.gmic
  3. # Author : David Tschumperle
  4.  
  5. # Entrypoint when run from CLI:
  6. go =>[^] "Tunnel 3D" e[] "" animate 30
  7.  
  8. # Main function
  9. go :
  10.   v 0
  11.  
  12.   # Generate template mesh for the 3D tunnel.
  13.   curve3d 0,0,t,1,64,0,63,16,0 rv3d # Generate a straight bar along z-axis
  14.   s3d eval "i[#1,1]-=32" rows... 0,{-3,h-4*32-1} rows.. 0,{-2,h-3*32-1} rows. 0,{h-32-1} a y # Remove closed extremities
  15.   2,1024,1,3,"x?[255,200,128]:[255,0,0]"
  16.   (0^0^0;0.25^0.25^1;1^1^1;0^0^0)
  17.   2,{-2,h},1,3,"Y = lerp(0,h#-1,(y/h)^0.5); cut(I(#-1,0,Y,0,2),0,1)" rm.. *[-2,-1] # Colors for depth shading
  18.  
  19.   t3d.. . rm. . => template3d,mesh3d
  20.   +l. { s3d off_p:=8+{2,h} k... r 13,{h/13},1,1,-1 permute zycx } => primitives # Keep editable version of primitives
  21.  
  22.   # Generate sequence of 3D tunnel centers.
  23.   1,48,1,2,g b. y,4,2 n. -1.5,2 a. .,y => coords
  24.   +g. y b. 1,2 channels. 0,2 sh. 100% f. 1 rm. orientation. => orientations # Desired camera orientations
  25.  
  26.   # Display animation
  27.   nbf=256 mzi2=-inf
  28.   repeat $nbf { f=$>
  29.     e[] "\r  > Frame "{$f+1}"/"$nbf
  30.  
  31.     z:=16+lerp(0,h#$coords/2,$>/$nbf)
  32.     zi2:=2*int($z/2)
  33.     if $zi2!=$mzi2 # Generate 3D mesh for current tunnel view.
  34.       +z[template3d] 0,8,0,{template3d,8+3*i[6]-1} r. 3,{h/3},1,1,-1 permute. zycx # Extract 3D coordinates
  35.       f. "C = I[#$coords,$zi2 + i2,2]; [ i0 + C[0],i1 + C[1],i2 ]"
  36.       permute. cyzx y. +j[template3d] .,0,8,0,0 rm..
  37.       mzi2:=$zi2
  38.       j[mesh3d] . rm.
  39.     fi
  40.  
  41.     cx,cy:="I(#$coords,0,$z,0,2,2)"
  42.     u,v,w:="unitnorm(I(#$orientations,0,$z,0,2,2))"
  43.     M:="W = unitnorm(I(#$orientations,0,$z,0,2,2)); V = cross(W,[1,0,0]); U = cross(V,W); 1.5*[ U,V,W ]" # Camera matrix
  44.  
  45.     +-3d[mesh3d] $cx,$cy,{$z%2}
  46.     apply_matrix3d. $M
  47.     r3d. 0,0,1,{180*cos(2*pi*$>/$nbf)}
  48.  
  49.     # Add depth effect.
  50.     f[primitives] "
  51.      P = I;
  52.      z = int(y/16);
  53.      P[5] = P[7] = P[9] = P[11] = xor(z,y)%2;
  54.      P[6] = 16*i[#-1,8+3*i1+2];
  55.      P[8] = 16*i[#-1,8+3*i2+2];
  56.      P[10] = 16*i[#-1,8+3*i3+2];
  57.      P[12] = 16*i[#-1,8+3*i4+2];
  58.      P"
  59.     +permute[primitives] cyzx y. j.. .,0,$off_p rm.
  60.  
  61.     # Render frame.
  62.     600,600,1,3
  63.     j3d. ..,50%,50%,-500,1,2,0,0,500 rm..
  64.   }
  65.   k[5--1] rs 320 a z n 0,255 s z round
  66.  
  67. # End of file.
  68.  
Tags: gmic
Advertisement
Add Comment
Please, Sign In to add comment