programextensions/scene/demos/voxels-world.xtl

Voxels, 4: a world of chunks. An island 64 by 32 by 64 -- 32 chunks of 16 cubed -- from value noise made by linear algebra (random heights on grids every 16, 8 and 4 blocks, each interpolated as M G M'), shaped by the chunk's rules over the whole world at once, with trees planted by folding one tree over a list of places. Its faces are found over the whole array (so faces between chunks hide each other), then sent to scene chunk by chunk, each chunk's kinds of block under their own ids -- the ids a later demo patches when a block changes. Run: just demo scene voxels-world (drag to turn it; q or close: quit)

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

h : Int

value · line 14
h ← ᵛˣh̲eights 64

b : Int

value · line 17
b ← ᵛˣt̲errain h

ts : Int

value · line 18
ts ← 12 2 r̲eshape 3 + r̲oll! 24 r̲eshape 58
Used in: b

b : Int

value · line 19
b ← ts ᵛˣf̲orest b

f : Int

value · line 24
f ← ᵛˣw̲orldFaces b

c : Int

value · line 29
c ← ᵛˣc̲hunkOf f

w : Int

value · line 33
w ← "Voxels 4: a world -- X_eTaL" ˢᶜo̲pen! 640 560

k : Int

value · line 34
k ← w ˢᶜc̲amera! 0.75 0.55 3.0 0.25

g : Int

value · line 35
g ← w ˢᶜf̲og! 2.6 5.0

keys : Int

value · line 38

one object for each chunk and kind of block: id 10 * chunk + block

keys ← u̲nique (10 × c) + 5 s̲elect₂ f
Used in: ᵘp̲ut, put

ᵘp̲ut : Int -> Int

function · line 39
ᵘp̲ut ← { i →
  key ← i s̲elect keys
  sel ← key = (10 × c) + 5 s̲elect₂ f
  head ← (f̲loat w c̲at key) c̲at (1 + key m̲od 10) s̲elect ᵛˣcolors
  q ← ᵛˣc̲orners sel r̲eplicate f
  x ← head ˢᶜq̲uads! (q − (s̲hape q) r̲eshape 32.0 12.0 32.0) ÷ 32.0
  i + 1
}
Used in: put

put : Int

value · line 47
put ← (t̲ally keys) 'ᵘp̲ut p̲ower 1

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

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

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

function · line 55
ᵘ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 61
last ← 100000 'ᵘf̲rame p̲ower 1