sourceextensions/scene/demos/voxels-faces.xtl

1⍝# Voxels, 2: which faces to draw. A face shows where a solid block's 2⍝# neighbor is not solid: six rotations of the solid mask, each compared 3⍝# with the mask itself (the idiom of Life), give every exposed face of 4⍝# the chunk at once; the faces become a list, one row each: x y z 5⍝# direction block. Checked on shapes with known answers, then the 6⍝# chunk's faces drawn as outlines in a 3D window, turning. 7⍝# Run: just demo scene voxels-faces (drag to turn it; q or close: quit) 8 9ᵛˣ⁼u̲se< "Voxels" 10ˢᶜ⁼u̲se< "Scene" 11 12ones ← 16 16 16 r̲eshape 4096 r̲eshape 1 13inside ← 16 16 16 r̲eshape (ᵛˣxs > 0) × (ᵛˣxs < 15) × (ᵛˣys > 0) × (ᵛˣys < 15) × (ᵛˣzs > 0) × ᵛˣzs < 15 14one ← 16 16 16 r̲eshape (ᵛˣxs = 8) × (ᵛˣys = 8) × ᵛˣzs = 8 15checker ← 16 16 16 r̲eshape 0 = (ᵛˣxs + ᵛˣys + ᵛˣzs) m̲od 2 16"faces west east down up north south: one block, all solid, a hollow box, a 3D checkerboard:" 17ᵛˣc̲ount ᵛˣf̲aces one 18ᵛˣc̲ount ᵛˣf̲aces ones 19ᵛˣc̲ount ᵛˣf̲aces ones − inside 20ᵛˣc̲ount ᵛˣf̲aces checker 21 22b ← ᵛˣc̲hunk ᵛˣh̲ills 0.0 23f ← ᵛˣf̲aces b 24"the chunk: faces by direction, then all of them, then 6 per solid block if none were hidden:" 25ᵛˣc̲ount f 26t̲ally f 276 × '+ r̲/ r̲avel ᵛˣs̲olid b 28"the first faces (x y z direction block):" 294 t̲ake f 30 31w ← "Voxels 2: the faces -- X_eTaL" ˢᶜo̲pen! 560 560 32k ← w ˢᶜc̲amera! 0.7 0.5 3.4 0.35 33 34⍝# each kind of block as one object, in its color 35ᵘp̲ut ← { t → 36 sel ← (5 s̲elect₂ f) = t 37 0 = '+ r̲/ sel ? t + 1 38 head ← (f̲loat w c̲at t) c̲at (t + 1) s̲elect ᵛˣcolors 39 x ← head ˢᶜs̲egments! ᵛˣe̲dges sel r̲eplicate f 40 t + 1 41} 42put ← 7 'ᵘp̲ut p̲ower 1 43 44ᵘq̲uit ← { n → 45 z ← ˢᶜc̲lose! w 46 0 47} 48ᵘf̲rame ← { n → 49 n = 0 ? 0 50 v ← ˢᶜn̲ext! w 51 ((v m̲atch "close") + v m̲atch "key q") > 0 ? ᵘq̲uit n 52 n 53} 54last ← 100000 'ᵘf̲rame p̲ower 1 55"bye"