programextensions/scene/demos/voxels-faces.xtl

Voxels, 2: which faces to draw. A face shows where a solid block's neighbor is not solid: six rotations of the solid mask, each compared with the mask itself (the idiom of Life), give every exposed face of the chunk at once; the faces become a list, one row each: x y z direction block. Checked on shapes with known answers, then the chunk's faces drawn as outlines in a 3D window, turning. Run: just demo scene voxels-faces (drag to turn it; q or close: quit)

source · imports vx: extensions/scene/demos/Voxels.xtl; sc: extensions/scene/lib/Scene.xtl

ones : Int

value · line 12
ones ← 16 16 16 r̲eshape 4096 r̲eshape 1

inside : Int

value · line 13
inside ← 16 16 16 r̲eshape (ᵛˣxs > 0) × (ᵛˣxs < 15) × (ᵛˣys > 0) × (ᵛˣys < 15) × (ᵛˣzs > 0) × ᵛˣzs < 15

one : Int

value · line 14
one ← 16 16 16 r̲eshape (ᵛˣxs = 8) × (ᵛˣys = 8) × ᵛˣzs = 8

checker : Bool

value · line 15
checker ← 16 16 16 r̲eshape 0 = (ᵛˣxs + ᵛˣys + ᵛˣzs) m̲od 2

b : Int

value · line 22
b ← ᵛˣc̲hunk ᵛˣh̲ills 0.0

f : Int

value · line 23
f ← ᵛˣf̲aces b

w : Int

value · line 31
w ← "Voxels 2: the faces -- X_eTaL" ˢᶜo̲pen! 560 560

k : Int

value · line 32
k ← w ˢᶜc̲amera! 0.7 0.5 3.4 0.35

ᵘp̲ut : Int -> Int

function · line 35

each kind of block as one object, in its color

ᵘp̲ut ← { t →
  sel ← (5 s̲elect₂ f) = t
  0 = '+ r̲/ sel ? t + 1
  head ← (f̲loat w c̲at t) c̲at (t + 1) s̲elect ᵛˣcolors
  x ← head ˢᶜs̲egments! ᵛˣe̲dges sel r̲eplicate f
  t + 1
}
Used in: put

put : Int

value · line 42
put ← 7 'ᵘp̲ut p̲ower 1

ᵘq̲uit : (Any a, Num b) => a -> b

function · line 44
ᵘq̲uit ← { n →
  z ← ˢᶜc̲lose! w
  0
}
Used in: ᵘf̲rame

ᵘf̲rame : Num a => a -> a

function · line 48
ᵘf̲rame ← { n →
  n = 0 ? 0
  v ← ˢᶜn̲ext! w
  ((v m̲atch "close") + v m̲atch "key q") > 0 ? ᵘq̲uit n
  n
}
Used in: last

last : Int

value · line 54
last ← 100000 'ᵘf̲rame p̲ower 1