scheme/3d/demo_3d.scm · 1903 字节 · 下载原文
; demo_3d.scm —— 第 5 层:3D 视口(`ui_3d_*`,独立库 vml3d)
; demo_3d.scm -- Layer 5: 3D viewport (`ui_3d_*`, the separate vml3d library)
;
; 开窗 → 建视口(相机/视场/背景/灯光)→ 从同目录 `box.glb`(CC0)载入 → 20 帧 → 关窗。
; Open window -> viewport -> load `box.glb` (CC0) -> 20 frames -> close.
;
; 跑法 / How to run:
; 手机 vml run examples/scheme/3d/demo_3d.scm
; 桌面 vmlcli Examples/scheme/3d/demo_3d.scm --frames /tmp/f3d
;
; ⚠ 声明来自 `Lib/scheme/vml3d.scm`(GenLib `-u`,DocTable:只有注释)。**不能带函数体**:
; 带体会生成同名空壳把库实现顶掉(E215),视口恒返回 0。
; ⚠ Declarations come from Lib/scheme/vml3d.scm (GenLib `-u`, DocTable: comments only).
; **No function bodies** — a body shadows the library (E215).
; ⚠ 几何量是 4 字节 float,而本前端浮点是 8 字节 ⇒ 传 **float32 位模式整数**(右侧为数值)。
; ⚠ Geometry is 4-byte float but this front end's floats are 8-byte, so **float32 bit
; patterns** are passed as integers (values on the right).
; ⚠ 3D 透过 2D 层显示 ⇒ 先 `ui_2d_clear 0`。
; ⚠ 3D shows through the 2D layer, so `ui_2d_clear 0` comes first.
#include <vml_ui.scm>
#include <vml3d.scm>
(ui_win_open_ex "demo_3d (Scheme)" 0 0 0 0)
(define w (ui_scr_get_w))
(define h (ui_scr_get_h))
(define vp (ui_3d_viewport_create 0 0 w h 0))
(if (> vp 0)
(begin
(ui_3d_viewport_set_camera vp 0 1069547520 1082130432 0 0 0)
(ui_3d_viewport_set_fov vp 1112014848 1036831949 1120403456)
(ui_3d_viewport_set_bg vp -15458257)
(ui_3d_viewport_set_light vp 1053609165 1063675494 1058642330 -1 1050253722)
(ui_2d_clear 0)
(ui_3d_gltf_load vp "box.glb")
(do ((i 0 (+ i 1)))
((= i 20))
(ui_2d_present)
(ui_msg_fetch_wait 40))))
(ui_win_close)