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)
b : Int
b ← ᵛˣt̲errain h
f : Int
f ← ᵛˣw̲orldFaces b
k : Int
k ← w ˢᶜc̲amera! 0.75 0.55 3.0 0.25
keys : Int
one object for each chunk and kind of block: id 10 * chunk + block
keys ← u̲nique (10 × c) + 5 s̲elect₂ f
ᵘp̲ut : Int -> Int
ᵘ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