shape static method
Draws the wireframe of a physics shape posed by transform.
sim.TriMeshShape draws every triangle edge and sim.ConvexHullShape marks its points, either of which can exhaust maxVertexLimit on dense collision geometry. sim.HeightFieldShape draws nothing.
Implementation
static void shape(
sim.Shape shape,
vm.Matrix4 transform, {
vm.Vector4? color,
int segments = 16,
}) {
vm.Vector3 at(double x, double y, double z) =>
transform.transform3(vm.Vector3(x, y, z));
switch (shape) {
case sim.SphereShape(:final radius):
for (var axis = 0; axis < 3; axis++) {
_ring(at, radius, 0, axis, segments, color);
}
case sim.BoxShape(:final halfExtents):
final e = halfExtents;
final corners = [
for (final sx in const [-1.0, 1.0])
for (final sy in const [-1.0, 1.0])
for (final sz in const [-1.0, 1.0])
at(e.x * sx, e.y * sy, e.z * sz),
];
for (final (i, j) in _boxEdges) {
line(corners[i], corners[j], color: color);
}
case sim.CapsuleShape(:final radius, :final halfHeight):
_ring(at, radius, halfHeight, 1, segments, color);
_ring(at, radius, -halfHeight, 1, segments, color);
_cap(at, radius, halfHeight, 1, segments, color);
_cap(at, radius, -halfHeight, -1, segments, color);
_sides(at, radius, halfHeight, color);
case sim.CylinderShape(:final radius, :final halfHeight):
_ring(at, radius, halfHeight, 1, segments, color);
_ring(at, radius, -halfHeight, 1, segments, color);
_sides(at, radius, halfHeight, color);
case sim.TriMeshShape(:final vertices, :final indices):
for (var i = 0; i + 2 < indices.length; i += 3) {
final a = indices[i] * 3;
final b = indices[i + 1] * 3;
final c = indices[i + 2] * 3;
final va = at(vertices[a], vertices[a + 1], vertices[a + 2]);
final vb = at(vertices[b], vertices[b + 1], vertices[b + 2]);
final vc = at(vertices[c], vertices[c + 1], vertices[c + 2]);
line(va, vb, color: color);
line(vb, vc, color: color);
line(vc, va, color: color);
}
case sim.ConvexHullShape(:final points):
// The hull's topology is the backend's, so mark the input points.
for (var i = 0; i + 2 < points.length; i += 3) {
final v = at(points[i], points[i + 1], points[i + 2]);
for (final axis in _unitAxes) {
line(v - axis * 0.02, v + axis * 0.02, color: color);
}
}
case sim.CompoundShape(:final children):
for (final child in children) {
DebugDraw.shape(
child.shape,
transform.multiplied(child.localPose),
color: color,
segments: segments,
);
}
case sim.HeightFieldShape():
// TODO(debug-draw): stride the heightfield grid into a wire mesh.
break;
}
}