build method

Shape3D? build(
  1. Collider3D collider,
  2. Vector3 entityScale, {
  3. SolidShapeSource? source,
})

collider's shape at entityScale; null while its triangles are not there yet, or when it cannot make one — a collider matching the shape of an entity with none (source null).

Implementation

Shape3D? build(
  Collider3D collider,
  Vector3 entityScale, {
  SolidShapeSource? source,
}) {
  final sx = collider.scale.x * entityScale.x;
  final sy = collider.scale.y * entityScale.y;
  final sz = collider.scale.z * entityScale.z;
  final ax = sx.abs(), ay = sy.abs(), az = sz.abs();
  final Shape3D? shape = switch (collider.shape) {
    ColliderShape3D.box => BoxShape3D(
      math.max(collider.size.x * ax / 2, minExtent),
      math.max(collider.size.y * ay / 2, minExtent),
      math.max(collider.size.z * az / 2, minExtent),
    ),
    ColliderShape3D.sphere => SphereShape3D(
      math.max(collider.radius * math.max(ax, math.max(ay, az)), minExtent),
    ),
    ColliderShape3D.capsule => _capsule(collider, ax, ay, az),
    ColliderShape3D.cylinder => CylinderShape3D(
      math.max(collider.height * ay / 2, minExtent),
      math.max(collider.radius * math.max(ax, az), minExtent),
    ),
    ColliderShape3D.convexHull ||
    ColliderShape3D.mesh => _model(collider, sx, sy, sz),
    ColliderShape3D.heightField => _heightField(collider, ax, ay),
    ColliderShape3D.matchShape =>
      source == null ? null : _solid(source, sx, sy, sz),
  };
  if (shape == null) return null;
  return _place(shape, collider, entityScale);
}