ada/3d/demo_3d.adb · 1843 字节 · 下载原文
-- demo_3d.adb —— 第 5 层:3D 视口(`ui_3d_*`,独立库 vml3d)
-- demo_3d.adb -- Layer 5: 3D viewport (`ui_3d_*`, the separate vml3d library)
--
-- 开窗 → 建视口(相机 / 视场 / 背景 / 一盏平行光)→ 从同目录 `box.glb`(CC0)载入模型
-- → 交 20 帧 → 关窗。3D 是**透过** 2D 层显示的,所以必须先 `ui_2d_clear(0)`。
-- Open window -> viewport (camera / FOV / background / one directional light) -> load
-- `box.glb` (CC0) next to this file -> present 20 frames -> close. 3D shows **through**
-- the 2D layer, so `ui_2d_clear(0)` comes first.
--
-- 跑法 / How to run:
-- 手机 vml run examples/ada/3d/demo_3d.adb
-- 桌面 vmlcli Examples/ada/3d/demo_3d.adb --screen 640x480 --frames /tmp/f3d
--
-- 声明来自 `Lib/ada/vml3d.adb`(GenLib 生成)—— `with vml3d;` 是**真加载**。
-- Declarations come from `Lib/ada/vml3d.adb` (GenLib output); `with vml3d;` really loads it.
with VML_UI;
with vml3d;
procedure Demo_3D is
W : Integer := 0;
H : Integer := 0;
Vp : Integer := 0;
Sc : Integer := 0;
Frame : Integer := 0;
K : Integer := 0;
begin
K := ui_win_open_ex("demo_3d (Ada)", 0, 0, 0, 0);
W := ui_scr_get_w();
H := ui_scr_get_h();
Vp := ui_3d_viewport_create(0, 0, W, H, 0);
if Vp > 0 then
K := ui_3d_viewport_set_camera(Vp, 0.0, 1.5, 4.0, 0.0, 0.0, 0.0);
K := ui_3d_viewport_set_fov(Vp, 50.0, 0.1, 100.0);
K := ui_3d_viewport_set_bg(Vp, -15458257); -- 0xFF14202F
K := ui_3d_viewport_set_light(Vp, 0.4, 0.9, 0.6, -1, 0.3);
K := ui_2d_clear(0);
Sc := ui_3d_gltf_load(Vp, "box.glb");
while Frame < 20 loop
K := ui_2d_present();
K := ui_msg_fetch_wait(40);
Frame := Frame + 1;
end loop;
end if;
K := ui_win_close();
end Demo_3D;