import { Mesh, type MeshOptions } from "../Mesh"; import type { Scene } from "../Scene"; export type PlaneOptions = Omit & { size?: number; width?: number; depth?: number; }; function dimension(value: number, name: string) { if (!Number.isFinite(value) || value <= 0) throw new RangeError(name); return value / 2; } /** A horizontal, upward-facing plane centered on its transform. */ export class Plane extends Mesh { constructor(scene: Scene, options: PlaneOptions = {}) { const { size = 1, width = size, depth = size, ...meshOptions } = options; const x = dimension(width, "width"); const z = dimension(depth, "depth"); super(scene, { ...meshOptions, vertexData: { positions: [-x, 0, -z, x, 0, -z, x, 0, z, -x, 0, z], normals: [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0], uvs: [0, 0, 1, 0, 1, 1, 0, 1], indices: [0, 2, 1, 0, 3, 2], }, }); } }