调试绘制
物理调试绘制叠加层渲染所有碰撞体的线框轮廓、速度箭头和接触点。使用引擎的 Draw API,在编辑器和运行时均可使用。
启用调试绘制
import { Physics } from 'esengine/physics';
// 开启/关闭调试绘制Physics.setDebugDraw(app, true);配置
控制显示哪些元素:
import { Physics } from 'esengine/physics';
Physics.setDebugDrawConfig(app, { enabled: true, showColliders: true, // 碰撞体线框轮廓 showVelocity: true, // 动态刚体的速度箭头 showContacts: false, // 接触点标记});| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
enabled | boolean | false | 调试绘制主开关 |
showColliders | boolean | true | 绘制碰撞体线框 |
showVelocity | boolean | false | 绘制动态刚体的速度箭头 |
showContacts | boolean | false | 绘制碰撞进入时的接触点 |
颜色编码
碰撞体轮廓按刚体类型着色:
| 刚体类型 | 颜色 |
|---|---|
| Static | 蓝色 |
| Dynamic | 绿色 |
| Kinematic | 青色 |
| Sensor | 黄色(半透明) |
速度箭头为红色。接触点显示为红色圆点。
PhysicsDebugDraw 资源
如需高级控制,可直接访问 PhysicsDebugDraw 资源:
import { PhysicsDebugDraw } from 'esengine/physics';
const config = app.getResource(PhysicsDebugDraw);config.enabled = true;config.showVelocity = true;app.insertResource(PhysicsDebugDraw, config);