EditMesh.cuboid constructor

EditMesh.cuboid({
  1. Vector3? size,
})

An axis-aligned box of size, centred on the origin, as six quads.

Quads and not triangles, which is the whole reason this exists beside CuboidShape: that one builds what a GPU draws — twenty-four vertices, because a corner carries three different normals — and a loop cut through a triangulated cube has nothing to cut along.

Implementation

factory EditMesh.cuboid({Vector3? size}) {
  final half = (size ?? Vector3(1, 1, 1)) * 0.5;
  return EditMesh.fromFaces(
    <Vector3>[
      Vector3(-half.x, -half.y, -half.z),
      Vector3(half.x, -half.y, -half.z),
      Vector3(half.x, half.y, -half.z),
      Vector3(-half.x, half.y, -half.z),
      Vector3(-half.x, -half.y, half.z),
      Vector3(half.x, -half.y, half.z),
      Vector3(half.x, half.y, half.z),
      Vector3(-half.x, half.y, half.z),
    ],
    <List<int>>[
      <int>[4, 5, 6, 7], // +Z
      <int>[1, 0, 3, 2], // −Z
      <int>[5, 1, 2, 6], // +X
      <int>[0, 4, 7, 3], // −X
      <int>[3, 7, 6, 2], // +Y
      <int>[0, 1, 5, 4], // −Y
    ],
  );
}