CameraFrame
[!caution]ai 生成,可能叙事逻辑和表述并不是很好,仅供参考。
相机数据,定义于 ranim_items::camera。它同时携带正交与透视两套投影参数,由 perspective_blend 在二者之间混合。
默认值(CameraFrame::default()):位于原点、朝 -Z、+Y 为上;perspective_blend = 0.0(纯 2D 正交);frame_height = 8.0;near = -1000、far = 1000;fovy = π/2。2D 场景用默认值即可。
投影
let view = cam.view_matrix; // look_to(pos, facing, up)
let proj = cam.projection_matrix;
// = orthographic_mat(aspect).lerp(perspective_mat(aspect), perspective_blend)
正交矩阵由 frame_height * scale 与宽高比推出;透视矩阵使用 fovy,且near 会被钳到至少 0.1。perspective_blend 取中间值时两矩阵逐元素插值,可用于「2D 场景平滑进入 3D 透视」的运镜(见examples/perspective_blend)。
3D 定位
// 球坐标定位(Z-up),看向原点;perspective_blend 自动设为 1.0
let cam = from_spherical;
// phi:与 +Z 的极角(0 = 正上方,π/2 = XY 平面)
// theta:方位角(0 = +X,π/2 = +Y)
// 或围绕任意目标点:
cam.set_spherical;
cam.look_at; // 只改朝向
注意 from_spherical / set_spherical 把 up 固定为 +Z。
其他
set_view_matrix/with_view_matrix:从视图矩阵反解pos/up/facing。center_canvas_in_frame(center, width, height, up, normal, aspect_ratio):透视模式下调整相机位置,使给定矩形画布恰好充满画面。CameraFrame实现了Interpolatable,可以直接用morph做运镜动画。
渲染插件
启用 items 的 render feature 后,裸 CameraFrame 的提取与 viewport 准备由ranim_items::camera::CameraFramePlugin 提供;默认渲染配置已包含它(经RanimItemsPlugin),自定义 RenderSetup 时安装 RanimItemsPlugin 或按需单个安装该插件。相机数据和运镜求值本身不需要 GPU。若完整动画输出是Transformed<CameraFrame, G> 等组合,另安装精确类型的 ExtractPlugin<T>。