跳到正文
网页珍奇柜Web Curio

多引擎物理实验室

Phy,lo-th,2021 年

正在布展…

本柜的现场复刻:按原作的技术思路从零编写,不含原作的代码和素材。为什么不直接展出原作:原作体积很大,附带的大量模型和环境贴图没有注明来源和许可,所以本柜从零写了一个刚体物理引擎来复刻它。原作请点上方「去看原作」。

它是怎么做的

  1. 第 1 步统一 API 封装多个物理引擎(OimoPhysics、ammo.js、Rapier、Jolt 等)
  2. 第 2 步物理计算放在 Web Worker 中,通过共享数组同步变换
  3. 第 3 步three.js 渲染层与物理层解耦,换引擎不改场景代码
  4. 第 4 步鼠标拾取用约束关节拖拽刚体

复刻配方

一段技术配方,可以直接交给 AI 编程助手,也可以自己照着写。想指定技术栈、位置和性能预算,就把它加入实现方案。

Define an engine-agnostic scene description (bodies with shape, mass, position; joints) and write thin adapters that translate it to two different physics libraries such as Rapier and cannon-es. Run the physics step inside a Web Worker and send back positions and quaternions in a Float32Array each tick. On the main thread copy those into InstancedMesh matrices. Implement mouse dragging by raycasting a body and attaching a point-to-point constraint to a kinematic anchor that follows the cursor.

档案

能不能拿来用

原作以 MIT 许可开源:可以阅读源码学习,按许可证条款使用;在自己的项目里引用时保留原作者署名。

性能开销

视觉强度

实现难度

尺度为策展判断(1 到 5),用于比较和推荐。

核实记录:Demo loads (200); repo has MIT licence.