SuperAPI AI 工具集

blecsd-3d

编程与开发

查看项目

更新于 10-16 06:21

技能介绍

用途:为 blECSd 终端应用提供完整 3D 渲染管线,在终端中渲染 3D 图形和模型。

安装与依赖:

  • 安装:pnpm add @blecsd/3d
  • 对等依赖:blecsd >= 0.7.0 可采用子路径导入(如 @blecsd/3d/math、/backends、/components、/loaders、/rasterizer、/systems、/stores)或命名空间 API。

主要能力:

  • 3D 数学:Vec3 运算、Mat4 变换/求逆/转置、TRS 构建、透视与正交投影、lookAt、MVP、顶点投影与反投影。
  • 视锥剔除:extractFrustumPlanes、isPointInFrustum、isSphereInFrustum、clipLine。
  • 渲染后端:braille(2x4/单元,兼容最广)、halfblock(1x2)、sextant(2x3)、sixel 与 kitty(像素级,需终端支持),可用 detectBestBackend() 自动选择,或用 createBackendByType 指定。
  • ECS 组件:Transform3D、Camera3D、Mesh、Material3D,支持世界矩阵缓存与脏标记。
  • 基础网格:createCubeMesh、createSphereMesh、createPlaneMesh、createCylinderMesh。
  • 软件光栅化:像素帧缓冲、深度测试、直线绘制(含渐变/深度/抗锯齿/混合)、三角形填充与平面着色。
  • 渲染系统管线:sceneGraphSystem → projectionSystem → rasterSystem → viewportOutputSystem,另有 animation3DSystem、mouseInteraction3DSystem 与共享 store。
  • OBJ 加载:parseObj、loadObjAsMesh、computeBoundingBox。
  • Viewport3D 组件:createViewport3D 封装相机、帧缓冲、后端与网格渲染;addMeshToViewport / removeMeshFromViewport 管理网格。

使用方式:每帧按管线顺序调用四个系统;用 setTranslation/setRotation/setScale/setMesh/setMaterial3D/setCamera3D 配置实体;网格先 registerMesh 注册再复用。

适用场景:终端内的 3D 可视化、旋转立方体等模型展示、动画与鼠标交互的 3D 界面。

限制:sixel 与 kitty 后端需相应终端支持;braille 为最安全的默认选择;需遵守 blECSd 函数式规则(无类、纯函数、边界使用 Zod)。具体性能、收费与平台细节暂未提供。