Skip to content

3D ​

cici 提供基础 3D 相机与图元,并使用真正的深度缓冲(Depth32Float)处理遮挡。

rust
set_camera_3d(Camera3D::new(
    Vec3::new(0.0, 1.5, 4.0),
    Vec3::ZERO,
    Vec3::Y,
));

draw_plane(Vec3::new(0.0, -1.0, 0.0), Vec2::new(4.0, 4.0), GRAY);
draw_cube(Vec3::new(-1.2, 0.0, 0.0), Vec3::splat(1.0), ORANGE);
draw_sphere(Vec3::new(1.2, 0.0, 0.0), 0.7, SKYBLUE);
draw_cube_wires(Vec3::ZERO, Vec3::splat(2.0), WHITE);

set_default_camera();

API ​

函数说明
Camera3D::new(position, target, up)透视相机
.with_fov(fov_y) / .with_range(near, far)视野与裁剪范围
set_camera_3d(camera)启用 3D
set_default_camera()恢复默认 2D
draw_line_3d(a, b, color)线段
draw_triangle_3d(a, b, c, color)三角形
draw_cube(center, size, color)立方体
draw_cube_wires(center, size, color)线框立方体
draw_sphere(center, radius, color)球体
draw_plane(center, size, color)水平面(XZ)
project_3d(point)手动投影到屏幕坐标
load_model(path) / load_model_from_bytes(&[u8])加载 OBJ 模型
draw_model(&model, position, scale, color)普通着色
draw_model_textured(&model, position, scale, &texture, color)使用 OBJ UV 贴图

Model 解析 v / vt / vn / f,面会自动三角化;法线来自 OBJ,缺失时自动计算。Vec3 提供 new、dot、cross、normalize、length 与四则运算。

模型 ​

rust
let model = load_model("assets/cube.obj")?;
draw_model(&model, Vec3::ZERO, 1.0, ORANGE);

let texture = load_texture("assets/cube.png")?;
texture.set_filter(FilterMode::Nearest);
draw_model_textured(&model, Vec3::ZERO, 1.0, &texture, WHITE);

简单、强力、跨平台的 2D 游戏库