sourceextensions/three/lib/Three.xtl

1⍝│ Three.xtl -- the facade of the three extension: interactive 3D in a 2⍝│ browser. A scene is the calls of a player -- the text Cycles.xtl's 3⍝│ functions write (cy:s_tage, cy:f_acade, cy:b_oxes, cy:f_leet, cy:f_ly 4⍝│ and the rest) without cy:head, Blender's player. Here the player is 5⍝│ written with Three.js and draws the same calls in real time: ride 6⍝│ the camera's flight, fly or walk. A scene whose first call is view 7⍝│ is a game's board (view, camera, tiles, piece: a camera without 8⍝│ perspective, instanced tiles, each piece a model with its clip, moved 9⍝│ between a program's ticks), drawn by a second player and changed in 10⍝│ place when it is shown again. th:s_how! draws a scene in the 11⍝│ page the program runs in (X_eTaL as WebAssembly); th:p_age! writes a 12⍝│ directory to serve, from the command line. 13⍝│ Import: "th:" u_se< "Three" 14⍝│ Run with xetal-x (xetal-x --ext DIR puts this directory on XETAL_PATH). 15⍝│ Each signature line is written out by the binding macro (lib/Ffi.xtlm). 16 17"ffi:" u̲se< "Ffi" 18 19⍝│ th:a_bout @: the extension's name and version. 20"a_bout : unit -> text" ᶠᶠⁱb̲ind< "three/about"
ᶠᶠⁱb̲ind< expands to
ˡa̲bout ← { @ →
  ⎕N̲GET "ext:three/about"
}
21⍝│ th:s_how! scene: draws the scene in the page, in place of the one 22⍝│ shown before; how many calls it holds. From the command line there 23⍝│ is no page and nothing is drawn (the count is still given). 24"s_how! : text -> int" ᶠᶠⁱb̲ind< "three/show"
ᶠᶠⁱb̲ind< expands to
ˡs̲how! ← { a →
  pa ← a ⎕N̲PUT "ext:three/show?text"
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:three/show"
}
25⍝│ dir th:p_age! scene: writes a directory to serve (under the working 26⍝│ directory, or XETAL_THREE_ROOT) -- index.html, the players, Three.js 27⍝│ and the scene's calls -- made whole each time; how many files. 28"p_age! : text text -> int" ᶠᶠⁱb̲ind< "three/page"
ᶠᶠⁱb̲ind< expands to
ˡp̲age! ← { a b →
  pa ← a ⎕N̲PUT "ext:three/page?text"
  pb ← b ⎕N̲PUT "ext:three/page?text"
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:three/page"
}
29 30⍝│ The native package behind these functions. 31ˡpackage ← "three"