perl/3d/demo_3d.pl · 2006 字节 · 下载原文
# demo_3d.pl —— Perl 3D 层:**加载 glTF 立方体并画 20 帧**
# demo_3d.pl -- Perl 3D layer: **load a glTF cube and draw 20 frames**
#
# 跑法(桌面 vmlcli):
# How to run (desktop vmlcli):
# dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/perl/3d/demo_3d.pl
# 同目录的 box.glb 是 CC0 立方体(复制自 Examples/c/3d/models/BoxVertexColors.glb)。
# box.glb next to this file is a CC0 cube (copied from Examples/c/3d/models/BoxVertexColors.glb).
#
# 本前端的写法要求:
# Coding rules of this frontend:
# ① 3D 接口没有独立声明文件,直接按名字写;`Lib/perl/builtin.vml` 之外的模块靠 vml3d 自动挂上。
# ① there is no separate 3D declaration file; call by name (vml3d is auto-linked).
# ② **浮点形参按 float32 的位模式传**:本前端的库调用实参一律压 32 位整数
# ② **float parameters are passed as float32 bit patterns**: library-call arguments are pushed as 32-bit ints
# (浮点字面量的值在 D0,`PUSH R0` 拿到的是别的寄存器)⇒ 1.5 写成 1069547520。
# (a float literal's value lives in D0, so PUSH R0 grabs another register) => 1.5 is written as 1069547520.
# 每个数后面都标了它对应的浮点值。
# Each carries its float value.
my $w = 0;
my $h = 0;
my $vp = 0;
my $sc = 0;
my $k = 0;
$k = ui_win_open_ex("demo_3d", 0, 0, 0, 0);
$w = ui_scr_get_w();
$h = ui_scr_get_h();
$vp = ui_3d_viewport_create(0, 0, $w, $h, 0);
$k = ui_3d_viewport_set_camera($vp, 0, 1069547520, 1082130432, 0, 0, 0);
$k = ui_3d_viewport_set_fov($vp, 1112014848, 1036831949, 1120403456);
$k = ui_3d_viewport_set_bg($vp, -15458257); # 0xFF14202F
$k = ui_3d_viewport_set_light($vp, 1053609165, 1063675494, 1058642330, -1, 1050253722);
$k = ui_2d_clear(0);
$sc = ui_3d_gltf_load($vp, "box.glb");
for (my $i = 0; $i < 20; $i++) {
$k = ui_2d_present();
$k = ui_msg_fetch_wait(40);
}
$k = ui_win_close();
print "Perl 3D demo: done\n";