跳转到内容

调试绘制

物理调试绘制叠加层渲染所有碰撞体的线框轮廓、速度箭头和接触点。使用引擎的 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, // 接触点标记
});
属性类型默认值说明
enabledbooleanfalse调试绘制主开关
showCollidersbooleantrue绘制碰撞体线框
showVelocitybooleanfalse绘制动态刚体的速度箭头
showContactsbooleanfalse绘制碰撞进入时的接触点

颜色编码

碰撞体轮廓按刚体类型着色:

刚体类型颜色
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);

参见