isValid property
bool
get
isValid
Whether this shape is well formed: every size finite and above zero, a
hull of at least 4 points, a mesh of at least one triangle whose
indices are all in its vertex list, a height field of at least 4 × 4
samples, a compound of at least one part, every number finite, a
rotation of some length. A body of a shape that is not is never made
(createBody returns 0) and a query with one finds nothing, on every
backend. A backend can still refuse a well-formed shape it cannot build
— Jolt a hull whose points are all on one plane, or a mesh of only
degenerate triangles — so check what createBody returns.
Implementation
bool get isValid => switch (this) {
BoxShape3D(:final hx, :final hy, :final hz) =>
_positive(hx) && _positive(hy) && _positive(hz),
SphereShape3D(:final radius) => _positive(radius),
CapsuleShape3D(:final halfHeight, :final radius) =>
_positive(halfHeight) && _positive(radius),
CylinderShape3D(:final halfHeight, :final radius) =>
_positive(halfHeight) && _positive(radius),
ConvexHullShape3D(:final points) =>
points.length >= 12 && _allFinite(points),
MeshShape3D(:final positions, :final indices) => _validMesh(
positions,
indices,
),
HeightFieldShape3D(:final heights, :final sampleCount, :final cellSize) =>
sampleCount >= 4 &&
heights.length >= sampleCount * sampleCount &&
_positive(cellSize) &&
_allFinite(heights),
final TransformedShape3D t => _validTransformed(t),
CompoundShape3D(:final parts) =>
parts.isNotEmpty && parts.every((part) => part.isValid),
};