playcanvas-engine

playcanvas-engine

热门

轻量级 WebGL/WebGPU 游戏引擎,具备实体-组件架构和可视化编辑器集成。在构建基于浏览器的游戏、交互式 3D 应用或注重性能的 Web 体验时请使用此 Skill。当任务涉及 PlayCanvas、实体-组件系统、游戏引擎开发、WebGL 游戏、3D 浏览器应用、编辑器优先的工作流或实时 3D 渲染时将触发此 Skill。它是 Three.js 的替代方案,拥有游戏专用的特性及集成开发环境。

768Star
128Fork
更新于 2025/11/20
SKILL.md
只读
名称
playcanvas-engine
描述

轻量级 WebGL/WebGPU 游戏引擎,具备实体-组件架构和可视化编辑器集成。在构建基于浏览器的游戏、交互式 3D 应用或注重性能的 Web 体验时请使用此 Skill。当任务涉及 PlayCanvas、实体-组件系统、游戏引擎开发、WebGL 游戏、3D 浏览器应用、编辑器优先的工作流或实时 3D 渲染时将触发此 Skill。它是 Three.js 的替代方案,拥有游戏专用的特性及集成开发环境。

PlayCanvas Engine Skill

轻量级 WebGL/WebGPU 游戏引擎,具备实体-组件架构、可视化编辑器集成和注重性能的设计。

何时使用此 Skill

当出现以下关键词时触发此 Skill:

  • "PlayCanvas engine"
  • "WebGL game engine"
  • "entity component system"
  • "PlayCanvas application"
  • "3D browser games"
  • "online 3D editor"
  • "lightweight 3D engine"
  • 需要以编辑器优先(editor-first)的工作流

对比:

  • Three.js:更底层、更灵活,但需要更多的配置工作
  • Babylon.js:功能丰富但体积更重,虽然有编辑器但相对没那么成熟
  • A-Frame:专注于 VR,采用声明式 HTML 方式
  • 将 PlayCanvas 用于:游戏项目、编辑器优先的工作流、性能关键型应用

核心概念

1. Application(应用)

根 PlayCanvas 应用负责管理渲染循环。

import * as pc from 'playcanvas';

// 创建画布
const canvas = document.createElement('canvas');
document.body.appendChild(canvas);

// 创建应用
const app = new pc.Application(canvas, {
  keyboard: new pc.Keyboard(window),
  mouse: new pc.Mouse(canvas),
  touch: new pc.TouchDevice(canvas),
  gamepads: new pc.GamePads()
});

// 配置画布
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);

// 处理窗口大小调整
window.addEventListener('resize', () => app.resizeCanvas());

// 启动应用
app.start();

2. Entity-Component System(实体-组件系统)

PlayCanvas 使用 ECS 架构:实体(Entity)包含组件(Component)。

// 创建实体
const entity = new pc.Entity('myEntity');

// 添加到场景层级中
app.root.addChild(entity);

// 添加组件
entity.addComponent('model', {
  type: 'box'
});

entity.addComponent('script');

// 变换(Transform)
entity.setPosition(0, 1, 0);
entity.setEulerAngles(0, 45, 0);
entity.setLocalScale(2, 2, 2);

// 父子层级结构
const parent = new pc.Entity('parent');
const child = new pc.Entity('child');
parent.addChild(child);

3. Update Loop(更新循环)

应用会在更新循环期间触发事件。

app.on('update', (dt) => {
  // dt 是以秒为单位的 Delta Time
  entity.rotate(0, 10 * dt, 0);
});

app.on('prerender', () => {
  // 渲染前
});

app.on('postrender', () => {
  // 渲染后
});

4. Components(组件)

核心组件扩展实体的功能:

Model Component(模型组件):

entity.addComponent('model', {
  type: 'box',           // 'box', 'sphere', 'cylinder', 'cone', 'capsule', 'asset'
  material: material,
  castShadows: true,
  receiveShadows: true
});

Camera Component(摄像机组件):

entity.addComponent('camera', {
  clearColor: new pc.Color(0.1, 0.2, 0.3),
  fov: 45,
  nearClip: 0.1,
  farClip: 1000,
  projection: pc.PROJECTION_PERSPECTIVE  // 或 PROJECTION_ORTHOGRAPHIC
});

Light Component(光源组件):

entity.addComponent('light', {
  type: pc.LIGHTTYPE_DIRECTIONAL,  // DIRECTIONAL, POINT, SPOT
  color: new pc.Color(1, 1, 1),
  intensity: 1,
  castShadows: true,
  shadowDistance: 50
});

Rigidbody Component(刚体组件)(需要物理引擎支持):

entity.addComponent('rigidbody', {
  type: pc.BODYTYPE_DYNAMIC,  // STATIC, DYNAMIC, KINEMATIC
  mass: 1,
  friction: 0.5,
  restitution: 0.3
});

entity.addComponent('collision', {
  type: 'box',
  halfExtents: new pc.Vec3(0.5, 0.5, 0.5)
});

常见模式

模式 1:基础场景搭建

创建一个包含摄像机、光源和模型的完整场景。

import * as pc from 'playcanvas';

// 初始化应用
const canvas = document.createElement('canvas');
document.body.appendChild(canvas);

const app = new pc.Application(canvas);
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);
window.addEventListener('resize', () => app.resizeCanvas());

// 创建摄像机
const camera = new pc.Entity('camera');
camera.addComponent('camera', {
  clearColor: new pc.Color(0.2, 0.3, 0.4)
});
camera.setPosition(0, 2, 5);
camera.lookAt(0, 0, 0);
app.root.addChild(camera);

// 创建平行光
const light = new pc.Entity('light');
light.addComponent('light', {
  type: pc.LIGHTTYPE_DIRECTIONAL,
  castShadows: true
});
light.setEulerAngles(45, 30, 0);
app.root.addChild(light);

// 创建地面
const ground = new pc.Entity('ground');
ground.addComponent('model', {
  type: 'plane'
});
ground.setLocalScale(10, 1, 10);
app.root.addChild(ground);

// 创建立方体
const cube = new pc.Entity('cube');
cube.addComponent('model', {
  type: 'box',
  castShadows: true
});
cube.setPosition(0, 1, 0);
app.root.addChild(cube);

// 让立方体旋转动画
app.on('update', (dt) => {
  cube.rotate(10 * dt, 20 * dt, 30 * dt);
});

app.start();

模式 2:加载 GLTF 模型

利用资源管理加载外部 3D 模型。

// 为模型创建资源
const modelAsset = new pc.Asset('model', 'container', {
  url: '/models/character.glb'
});

// 添加到资源注册表
app.assets.add(modelAsset);

// 加载资源
modelAsset.ready((asset) => {
  // 从已加载的模型实例化渲染实体
  const entity = asset.resource.instantiateRenderEntity();

  app.root.addChild(entity);

  // 缩放和定位
  entity.setLocalScale(2, 2, 2);
  entity.setPosition(0, 0, 0);
});

app.assets.load(modelAsset);

带错误处理的版本:

modelAsset.ready((asset) => {
  console.log('Model loaded:', asset.name);
  const entity = asset.resource.instantiateRenderEntity();
  app.root.addChild(entity);
});

modelAsset.on('error', (err) => {
  console.error('Failed to load model:', err);
});

app.assets.load(modelAsset);

模式 3:材质与贴图

使用 PBR 工作流创建自定义材质。

// 创建材质
const material = new pc.StandardMaterial();
material.diffuse = new pc.Color(1, 0, 0);  // 红色
material.metalness = 0.5;
material.gloss = 0.8;
material.update();

// 应用到实体
entity.model.material = material;

// 带有贴图的材质
const textureAsset = new pc.Asset('diffuse', 'texture', {
  url: '/textures/brick_diffuse.jpg'
});

app.assets.add(textureAsset);
app.assets.load(textureAsset);

textureAsset.ready((asset) => {
  material.diffuseMap = asset.resource;
  material.update();
});

// 包含全套贴图的 PBR 材质
const pbrMaterial = new pc.StandardMaterial();

// 加载所有贴图
const textures = {
  diffuse: '/textures/albedo.jpg',
  normal: '/textures/normal.jpg',
  metalness: '/textures/metalness.jpg',
  gloss: '/textures/roughness.jpg',
  ao: '/textures/ao.jpg'
};

Object.keys(textures).forEach(key => {
  const asset = new pc.Asset(key, 'texture', { url: textures[key] });
  app.assets.add(asset);

  asset.ready((loadedAsset) => {
    switch(key) {
      case 'diffuse':
        pbrMaterial.diffuseMap = loadedAsset.resource;
        break;
      case 'normal':
        pbrMaterial.normalMap = loadedAsset.resource;
        break;
      case 'metalness':
        pbrMaterial.metalnessMap = loadedAsset.resource;
        break;
      case 'gloss':
        pbrMaterial.glossMap = loadedAsset.resource;
        break;
      case 'ao':
        pbrMaterial.aoMap = loadedAsset.resource;
        break;
    }
    pbrMaterial.update();
  });

  app.assets.load(asset);
});

模式 4:集成物理引擎

使用 Ammo.js 进行物理模拟。

import * as pc from 'playcanvas';

// 使用 Ammo.js 进行初始化
const app = new pc.Application(canvas, {
  keyboard: new pc.Keyboard(window),
  mouse: new pc.Mouse(canvas)
});

// 加载 Ammo.js
const ammoScript = document.createElement('script');
ammoScript.src = 'https://cdn.jsdelivr.net/npm/ammo.js@0.0.10/ammo.js';
document.body.appendChild(ammoScript);

ammoScript.onload = () => {
  Ammo().then((AmmoLib) => {
    window.Ammo = AmmoLib;

    // 创建静态地面
    const ground = new pc.Entity('ground');
    ground.addComponent('model', { type: 'plane' });
    ground.setLocalScale(10, 1, 10);

    ground.addComponent('rigidbody', {
      type: pc.BODYTYPE_STATIC
    });

    ground.addComponent('collision', {
      type: 'box',
      halfExtents: new pc.Vec3(5, 0.1, 5)
    });

    app.root.addChild(ground);

    // 创建动态立方体
    const cube = new pc.Entity('cube');
    cube.addComponent('model', { type: 'box' });
    cube.setPosition(0, 5, 0);

    cube.addComponent('rigidbody', {
      type: pc.BODYTYPE_DYNAMIC,
      mass: 1,
      friction: 0.5,
      restitution: 0.5
    });

    cube.addComponent('collision', {
      type: 'box',
      halfExtents: new pc.Vec3(0.5, 0.5, 0.5)
    });

    app.root.addChild(cube);

    // 施加力
    cube.rigidbody.applyForce(10, 0, 0);
    cube.rigidbody.applyTorque(0, 10, 0);

    app.start();
  });
};

模式 5:自定义脚本

创建可复用的脚本组件。

// 定义脚本类
const RotateScript = pc.createScript('rotate');

// 脚本属性(暴露给编辑器)
RotateScript.attributes.add('speed', {
  type: 'number',
  default: 10,
  title: 'Rotation Speed'
});

RotateScript.attributes.add('axis', {
  type: 'vec3',
  default: [0, 1, 0],
  title: 'Rotation Axis'
});

// 初始化方法
RotateScript.prototype.initialize = function() {
  console.log('RotateScript initialized');
};

// 更新方法(每帧调用)
RotateScript.prototype.update = function(dt) {
  this.entity.rotate(
    this.axis.x * this.speed * dt,
    this.axis.y * this.speed * dt,
    this.axis.z * this.speed * dt
  );
};

// 清理方法
RotateScript.prototype.destroy = function() {
  console.log('RotateScript destroyed');
};

// 使用方式
const entity = new pc.Entity('rotatingCube');
entity.addComponent('model', { type: 'box' });
entity.addComponent('script');
entity.script.create('rotate', {
  attributes: {
    speed: 20,
    axis: new pc.Vec3(0, 1, 0)
  }
});
app.root.addChild(entity);

脚本生命周期方法:

const MyScript = pc.createScript('myScript');

MyScript.prototype.initialize = function() {
  // 所有资源加载完毕后调用一次
};

MyScript.prototype.postInitialize = function() {
  // 所有实体初始化完毕后调用
};

MyScript.prototype.update = function(dt) {
  // 每帧在渲染前调用
};

MyScript.prototype.postUpdate = function(dt) {
  // 每帧在更新后调用
};

MyScript.prototype.swap = function(old) {
  // 支持热重载(Hot reload)
};

MyScript.prototype.destroy = function() {
  // 实体被销毁时进行清理
};

模式 6:输入处理

处理键盘、鼠标和触摸输入。

// 键盘
if (app.keyboard.isPressed(pc.KEY_W)) {
  entity.translate(0, 0, -speed * dt);
}

if (app.keyboard.wasPressed(pc.KEY_SPACE)) {
  entity.rigidbody.applyImpulse(0, 10, 0);
}

// 鼠标
app.mouse.on(pc.EVENT_MOUSEDOWN, (event) => {
  if (event.button === pc.MOUSEBUTTON_LEFT) {
    console.log('Left click at', event.x, event.y);
  }
});

app.mouse.on(pc.EVENT_MOUSEMOVE, (event) => {
  const dx = event.dx;
  const dy = event.dy;
  camera.rotate(-dy * 0.2, -dx * 0.2, 0);
});

// 触摸
app.touch.on(pc.EVENT_TOUCHSTART, (event) => {
  event.touches.forEach((touch) => {
    console.log('Touch at', touch.x, touch.y);
  });
});

// 射线检测(鼠标拾取)
app.mouse.on(pc.EVENT_MOUSEDOWN, (event) => {
  const camera = app.root.findByName('camera');
  const cameraComponent = camera.camera;

  const from = cameraComponent.screenToWorld(
    event.x,
    event.y,
    cameraComponent.nearClip
  );

  const to = cameraComponent.screenToWorld(
    event.x,
    event.y,
    cameraComponent.farClip
  );

  const result = app.systems.rigidbody.raycastFirst(from, to);

  if (result) {
    console.log('Hit:', result.entity.name);
    result.entity.model.material.emissive = new pc.Color(1, 0, 0);
  }
});

模式 7:动画

播放骨骼动画和补间动画(Tween)。

骨骼动画:

// 加载带有动画的模型
const modelAsset = new pc.Asset('character', 'container', {
  url: '/models/character.glb'
});

app.assets.add(modelAsset);

modelAsset.ready((asset) => {
  const entity = asset.resource.instantiateRenderEntity();
  app.root.addChild(entity);

  // 获取动画组件
  entity.addComponent('animation', {
    assets: [asset],
    speed: 1.0,
    loop: true,
    activate: true
  });

  // 播放特定动画
  entity.animation.play('Walk', 0.2);  // 0.2 秒混合时间

  // 稍后过渡到跑步
  entity.animation.play('Run', 0.5);
});

app.assets.load(modelAsset);

属性补间动画:

// 位置补间
entity.tween(entity.getLocalPosition())
  .to({ x: 5, y: 2, z: 0 }, 2.0, pc.SineInOut)
  .start();

// 旋转补间
entity.tween(entity.getLocalEulerAngles())
  .to({ x: 0, y: 180, z: 0 }, 1.0, pc.Linear)
  .loop(true)
  .yoyo(true)
  .start();

// 材质颜色补间
const color = material.emissive;
app.tween(color)
  .to(new pc.Color(1, 0, 0), 1.0, pc.SineInOut)
  .yoyo(true)
  .loop(true)
  .start();

// 链式补间
entity.tween(entity.getLocalPosition())
  .to({ y: 2 }, 1.0)
  .to({ y: 0 }, 1.0)
  .delay(0.5)
  .repeat(3)
  .start();

集成模式

集成 1:React 集成

将 PlayCanvas 封装在 React 组件中。

import React, { useEffect, useRef } from 'react';
import * as pc from 'playcanvas';

function PlayCanvasScene() {
  const canvasRef = useRef(null);
  const appRef = useRef(null);

  useEffect(() => {
    // 初始化
    const app = new pc.Application(canvasRef.current);
    appRef.current = app;

    app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
    app.setCanvasResolution(pc.RESOLUTION_AUTO);

    // 创建场景
    const camera = new pc.Entity('camera');
    camera.addComponent('camera', {
      clearColor: new pc.Color(0.1, 0.2, 0.3)
    });
    camera.setPosition(0, 0, 5);
    app.root.addChild(camera);

    const cube = new pc.Entity('cube');
    cube.addComponent('model', { type: 'box' });
    app.root.addChild(cube);

    const light = new pc.Entity('light');
    light.addComponent('light');
    light.setEulerAngles(45, 0, 0);
    app.root.addChild(light);

    app.on('update', (dt) => {
      cube.rotate(10 * dt, 20 * dt, 30 * dt);
    });

    app.start();

    // 清理
    return () => {
      app.destroy();
    };
  }, []);

  return (
    <canvas
      ref={canvasRef}
      style={{ width: '100%', height: '100vh' }}
    />
  );
}

export default PlayCanvasScene;

集成 2:编辑器导出

配合 PlayCanvas Editor 项目工作。

// 从 PlayCanvas Editor 导出
// 下载构建文件,然后在代码中加载:

import * as pc from 'playcanvas';

const app = new pc.Application(canvas);

// 加载导出的项目配置
fetch('/config.json')
  .then(response => response.json())
  .then(config => {
    // 加载场景
    app.scenes.loadSceneHierarchy(config.scene_url, (err, parent) => {
      if (err) {
        console.error('Failed to load scene:', err);
        return;
      }

      // 启动应用
      app.start();

      // 通过名称查找实体
      const player = app.root.findByName('Player');
      const enemy = app.root.findByName('Enemy');

      // 访问脚本
      player.script.myScript.doSomething();
    });
  });

性能优化

1. 对象池(Object Pooling)

复用实体而非频繁地创建和销毁。

class EntityPool {
  constructor(app, count) {
    this.app = app;
    this.pool = [];
    this.active = [];

    for (let i = 0; i < count; i++) {
      const entity = new pc.Entity('pooled');
      entity.addComponent('model', { type: 'box' });
      entity.enabled = false;
      app.root.addChild(entity);
      this.pool.push(entity);
    }
  }

  spawn(position) {
    let entity = this.pool.pop();

    if (!entity) {
      // 对象池已用尽,创建新实体
      entity = new pc.Entity('pooled');
      entity.addComponent('model', { type: 'box' });
      this.app.root.addChild(entity);
    }

    entity.enabled = true;
    entity.setPosition(position);
    this.active.push(entity);

    return entity;
  }

  despawn(entity) {
    entity.enabled = false;
    const index = this.active.indexOf(entity);
    if (index > -1) {
      this.active.splice(index, 1);
      this.pool.push(entity);
    }
  }
}

// 使用方式
const pool = new EntityPool(app, 100);
const bullet = pool.spawn(new pc.Vec3(0, 0, 0));

// 稍后回收
pool.despawn(bullet);

2. LOD(多细节层次)

降低远距离物体的几何体精度。

// 手动 LOD 切换
app.on('update', () => {
  const distance = camera.getPosition().distance(entity.getPosition());

  if (distance < 10) {
    entity.model.asset = highResModel;
  } else if (distance < 50) {
    entity.model.asset = mediumResModel;
  } else {
    entity.model.asset = lowResModel;
  }
});

// 或者禁用远距离实体
app.on('update', () => {
  entities.forEach(entity => {
    const distance = camera.getPosition().distance(entity.getPosition());
    entity.enabled = distance < 100;
  });
});

3. 合批(Batching)

合并静态网格以减少 Draw Call。

// 为实体启用静态合批
entity.model.batchGroupId = 1;

// 对具有相同组 ID 的所有实体进行合批
app.batcher.generate([entity1, entity2, entity3]);

4. 纹理压缩

使用压缩贴图格式。

// 创建贴图时,使用压缩格式
const texture = new pc.Texture(app.graphicsDevice, {
  width: 512,
  height: 512,
  format: pc.PIXELFORMAT_DXT5,  // GPU 压缩格式
  minFilter: pc.FILTER_LINEAR_MIPMAP_LINEAR,
  magFilter: pc.FILTER_LINEAR,
  mipmaps: true
});

常见陷阱

陷阱 1:未启动应用

问题:场景已渲染,但没有任何反应。

// ❌ 错误 - 忘记启动
const app = new pc.Application(canvas);
// ... 创建实体 ...
// 毫无反应!

// ✅ 正确
const app = new pc.Application(canvas);
// ... 创建实体 ...
app.start();  // 关键步骤!

陷阱 2:在 Update 循环中修改实体数组

问题:在遍历期间修改场景树/数组。

// ❌ 错误 - 在遍历期间修改数组
app.on('update', () => {
  entities.forEach(entity => {
    if (entity.shouldDestroy) {
      entity.destroy();  // 修改了正在遍历的数组!
    }
  });
});

// ✅ 正确 - 标记待删除实体,随后清理
const toDestroy = [];

app.on('update', () => {
  entities.forEach(entity => {
    if (entity.shouldDestroy) {
      toDestroy.push(entity);
    }
  });
});

app.on('postUpdate', () => {
  toDestroy.forEach(entity => entity.destroy());
  toDestroy.length = 0;
});

陷阱 3:资源未释放导致的内存泄漏

问题:未及时清理已加载的资源。

// ❌ 错误 - 资源永不清理
function loadModel() {
  const asset = new pc.Asset('model', 'container', { url: '/model.glb' });
  app.assets.add(asset);
  app.assets.load(asset);
  // 资源将永久留在内存中
}

// ✅ 正确 - 使用完毕后清理
function loadModel() {
  const asset = new pc.Asset('model', 'container', { url: '/model.glb' });
  app.assets.add(asset);

  asset.ready(() => {
    // 使用模型
  });

  app.assets.load(asset);

  // 稍后清理
  return () => {
    app.assets.remove(asset);
    asset.unload();
  };
}

const cleanup = loadModel();
// 稍后:cleanup();

陷阱 4:变换层级关系理解错误

问题:变换没有按预期在层级结构中传递。

// ❌ 错误 - 在子节点上混淆了世界变换与局部变换
const parent = new pc.Entity();
const child = new pc.Entity();
parent.addChild(child);

child.setPosition(5, 0, 0);  // 局部位置
parent.setPosition(10, 0, 0);
// 子节点在世界空间的位置变成了 (15, 0, 0)

// ✅ 正确 - 明确区分局部空间与世界空间
child.setLocalPosition(5, 0, 0);  // 显式设置局部位置
// 或者
const worldPos = new pc.Vec3(15, 0, 0);
child.setPosition(worldPos);  // 显式设置世界位置

陷阱 5:物理引擎未初始化

问题:物理组件无法正常工作。

// ❌ 错误 - 未加载 Ammo.js
const entity = new pc.Entity();
entity.addComponent('rigidbody', { type: pc.BODYTYPE_DYNAMIC });
// 报错:Ammo is not defined

// ✅ 正确 - 确保已加载 Ammo.js
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/ammo.js@0.0.10/ammo.js';
document.body.appendChild(script);

script.onload = () => {
  Ammo().then((AmmoLib) => {
    window.Ammo = AmmoLib;

    // 现在物理引擎可以正常工作
    const entity = new pc.Entity();
    entity.addComponent('rigidbody', { type: pc.BODYTYPE_DYNAMIC });
    entity.addComponent('collision', { type: 'box' });
  });
};

陷阱 6:Canvas 尺寸适配问题

问题:Canvas 未填满容器或无法响应缩放调整。

// ❌ 错误 - 固定尺寸 Canvas
const canvas = document.createElement('canvas');
canvas.width = 800;
canvas.height = 600;

// ✅ 正确 - 响应式 Canvas
const canvas = document.createElement('canvas');
const app = new pc.Application(canvas);

app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);

window.addEventListener('resize', () => app.resizeCanvas());

相关资源


快速参考

应用设置

const app = new pc.Application(canvas);
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);
app.start();

创建实体

const entity = new pc.Entity('name');
entity.addComponent('model', { type: 'box' });
entity.setPosition(x, y, z);
app.root.addChild(entity);

更新循环

app.on('update', (dt) => {
  // 此处编写逻辑
});

加载资源

const asset = new pc.Asset('name', 'type', { url: '/path' });
app.assets.add(asset);
asset.ready(() => { /* 使用资源 */ });
app.assets.load(asset);

相关 Skill:如需更底层的 WebGL 控制,请参考 threejs-webgl。如需 React 集成模式,请参阅 react-three-fiber。对于物理密集型模拟,请参考 babylonjs-engine。