// demo_3d.rs —— 第 5 层：3D 视口（`ui_3d_*`，独立库 vml3d）
// demo_3d.rs -- 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/rust/3d/demo_3d.rs
//   桌面  vmlcli Examples/rust/3d/demo_3d.rs --frames /tmp/f3d
//
// ⚠ 声明来自 `Lib/rust/vml3d.rs`（GenLib `-u`，DocTable：只有注释）。**不能带函数体**：
//    带体会生成同名空壳把库实现顶掉（E215），视口恒返回 0。
// ⚠ Declarations come from Lib/rust/vml3d.rs (GenLib `-u`, DocTable: comments only).
//    **No function bodies** — a body shadows the library (E215).
// ⚠ 几何量是 4 字节 float ⇒ 用 `f32` 后缀。
// ⚠ Geometry is 4-byte float, so use the `f32` suffix.
// ⚠ 3D 透过 2D 层显示 ⇒ 先 `ui_2d_clear(0)`。
// ⚠ 3D shows through the 2D layer, so `ui_2d_clear(0)` comes first.

#include <vml_ui.rs>
#include <vml3d.rs>

fn main() {
    ui_win_open_ex("demo_3d (Rust)", 0, 0, 0, 0);
    let w = ui_scr_get_w();
    let h = ui_scr_get_h();
    let vp = ui_3d_viewport_create(0, 0, w, h, 0);
    if vp > 0 {
        ui_3d_viewport_set_camera(vp, 0.0f32, 1.5f32, 4.0f32, 0.0f32, 0.0f32, 0.0f32);
        ui_3d_viewport_set_fov(vp, 50.0f32, 0.1f32, 100.0f32);
        ui_3d_viewport_set_bg(vp, -15458257);              // 0xFF14202F
        ui_3d_viewport_set_light(vp, 0.4f32, 0.9f32, 0.6f32, -1, 0.3f32);
        ui_2d_clear(0);
        ui_3d_gltf_load(vp, "box.glb");
        let mut i = 0;
        while i < 20 {
            ui_2d_present();
            ui_msg_fetch_wait(40);
            i = i + 1;
        }
    }
    ui_win_close();
}
