Skip to main content

Function: surfaceMesh()

surfaceMesh<S>(sport, league, o?): SurfaceMesh

Defined in: packages/sdvplot/src/three/surface.ts:232

sporty's playing surface for sport and league (sporty's own league keys, e.g. surfaceMesh("baseball", "mlb"), surfaceMesh("hockey", "nhl")) as one triangle mesh in the z = 0 plane: plain buffers (positions, linear-sRGB vertex colours, indices), with no three.js import, ready for new BufferGeometry() in three.js or the <Surface3D> component in sdvplot/react. World units: the surface's own (feet for a baseball field or a rink, metres for a pitch), in sporty's frame: a baseball field has home plate's point at the origin and +y towards centre field, Statcast's frame, so statcastPitchPath points draw over it unconverted; the other surfaces have the origin at their centre. The surface's background colour (a baseball field's outfield grass) is the first loop, over the extent; then each closed loop of each polygon feature, in sporty's drawing order (a faceoff circle is two loops, its half rings), filled with its colour, alpha included. Hidden features (a #rrggbb00 fill) and text (a football field's numbers) are left out, and sporty's heights (goal frames, backboards) are flattened: z is 0 throughout. Every loop lies in one plane, so draw the mesh in order without depth writes (depthWrite: false), first (renderOrder -1), with vertexColors, transparent and toneMapped: false, as <Surface3D> does: later loops then paint over earlier ones with no z-fighting. o is passed to sporty's surface() (colorUpdates, units, rotation, ...).

Type Parameters​

S​

S extends Sport

Parameters​

sport​

S

league​

LeagueOf<S>

o?​

OptionsOf<S> = ...

Returns​

SurfaceMesh

Example​

import { surfaceMesh } from "@sportsdataverse/sdvplot/three";

const field = surfaceMesh("baseball", "mlb");
// in three.js: geometry.setAttribute("position", new BufferAttribute(field.positions, 3)), and so on
field.loops.map((l) => l.name);