Threedog.js

为 AI 设计的 three.js 游戏引擎

19 星标v1.4.0MITJavaScript

npm install threedog@1 three@~0.187.0

能力

Threedog 让 AI 用普通 JavaScript 和 three.js 做游戏。引擎负责时间、输入、资源、存档、物理和世界管理,并提供运行、检查和调试项目的工具。

  • 画面仍是 three.js

    材质、灯光、模型和场景对象都是 three.js 对象。项目可以写自己的着色器和渲染通道,引擎不规定画风。

  • 精简的基础运行时

    createEngine() 提供时间、输入、资源、存档和模块生命周期。逻辑放在固定步长的 onFixed,每帧显示放在 onFrame。

  • 30 个可选模块

    地形、植被、天气、水面、Rapier 物理、Recast 寻路、角色、相机、任务与对话、时间线、粒子等,用 engine.use() 按需安装。

  • WebGPU 与 WebGL2

    新项目默认用 WebGPU 和 TSL;浏览器不支持 WebGPU 时,同一个游戏在 three.js 的 WebGL2 后端上运行。

  • 给 AI 的命令行和 MCP

    @threedog/tools 提供 how、check、play、describe、shot、verify 等命令,命令行和 MCP 用的是同一套入口。开发服务器上按 F2 打开浏览器内编辑器。

  • 大世界分区

    地形、世界内容和物理碰撞体按区块随玩家流式加载,并提供 LOD、HLOD、遮挡剔除和批处理。

代码

import { createEngine, THREE } from 'threedog';

const engine = createEngine({
  canvas: document.getElementById('view'),
  renderer: 'webgl',
  lights: false,
});

engine.scene.background = new THREE.Color(0x20242c);
engine.camera.position.set(3, 2, 5);
engine.camera.lookAt(0, 0, 0);

const cube = new THREE.Mesh(
  new THREE.BoxGeometry(1, 1, 1),
  new THREE.MeshStandardMaterial({ color: 0x78a6ff }),
);
const sun = new THREE.DirectionalLight(0xffffff, 3);
sun.position.set(3, 5, 2);
engine.scene.add(cube, new THREE.HemisphereLight(0xffffff, 0x303040, 2), sun);

engine.onFrame(dt => {
  cube.rotation.y += dt * 0.5;
});

await engine.start();

评论

正在载入…