Skip to content
glyphcss

Creating Shapes

Loading…

Choose a built-in shape; Code shows the matching geometry call in JavaScript, React, or Vue. resolveGeometry(name, options) and the named helpers return Polygon[] for scene.add() or GlyphMesh.

HelperShape / size convention
tetrahedronPolygonsFour triangles; circumradius
cubePolygonsSix quads; edge length
octahedronPolygonsEight triangles; center-to-pole distance
dodecahedronPolygonsTwelve pentagons; circumradius
icosahedronPolygonsTwenty triangles; circumradius
planePolygonsOne quad; size is half-extent; axis: 0=YZ, 1=XZ, 2=XY
ringPolygonsAnnulus; axis, radius, halfThickness, segments
axesHelperPolygonsXYZ bars; size, thickness, negative, axis colors
import { cubePolygons, planePolygons } from "@glyphcss/core";
const cube = cubePolygons({ center: [0, 0, 0], size: 1, color: "#4488ff" });
const floor = planePolygons({ axis: 1, size: 2, offset: 0 });

planePolygons defaults offset to size * 2; pass 0 to center it. Other helper dimensions vary by shape: do not assume every size means edge length.

import type { Polygon } from "@glyphcss/core";
const triangle: Polygon = {
vertices: [[-1, 0, 0], [1, 0, 0], [0, 1, 0]],
color: "#44ffcc",
};

Vertices use [x, y, z]; wind faces counterclockwise from outside. Color is optional. N-gons are fan-triangulated, so split concave faces into triangles yourself. Add the polygon with scene.add([triangle]).

import { gridSurfacePolygons } from "@glyphcss/core";
const { polygons: waves } = gridSurfacePolygons({
z: [[0, 0.3, 0], [0.3, 0.6, 0.3], [0, 0.3, 0]],
});

Pass the generated polygons to a mesh. Use mesh.setPolygons(nextPolygons) when the surface changes; rebuild geometry only when its data changes.

scene.add(cube, { position: [-2, 0, 0] });
scene.add(floor, { position: [0, -1, 0] });

Each call returns a handle with setTransform, setPolygons, and dispose. Framework bindings compose multiple GlyphMesh children. For file-based geometry, see loading meshes.