Skip to content

Paths, meshes and rendering ​

Mesh algorithms return IGeometry: position:number[] with optional index / normal / uv / uv2 / tangent. Indices are local; attribute counts must match. BufferGeometry.setFromGeometry retains supplied attributes.

Paths and sweeps ​

Path supports empty, single-point and closed paths. tlen includes the closing edge. getPointByDistance returns point/direction/node information, or null outside the path. Mutating methods refresh caches; call init() after directly editing coordinates or path.array.

Curve.catmullRom uses alpha 0 / 0.5 / 1 for uniform / centripetal / chordal parameterization. The default is centripetal. Open parameters clamp to [0, 1]; closed curves wrap.

js
import { v3, extrudeNext, JoinType, EndType, Plane } from '@xort/cga';
const mesh = extrudeNext({
    shape: [v3(-1,-1,0), v3(1,-1,0), v3(1,1,0), v3(-1,1,0)],
    path: [v3(), v3(0,0,4), v3(4,0,4)],
    jtType: JoinType.Miter, etType: EndType.Butt,
    sealStart: true, sealEnd: true,
});
const halves = Plane.splitGeometry(new Plane(v3(1,0,0), -1), mesh, { cap: true });
  • Sweeps preserve shape/path/holes. Profiles default to XY with local Z along the path; transported frames distribute residual twist on closed paths.
  • Miter joins fall back to bevel beyond miterLimit; Round samples corners. Square caps extend the path. Round caps taper to a pole and require hole-free profiles.
  • Closed paths join the last segment and disable end caps. Hollow profile caps use hole triangulation. UVs follow profile/path distance; smoothing uses smoothAngle.
  • Avoid self-crossing profiles and paths. Sweeps do not repair solid self-intersections; volume requires closed, consistently wound input.

Plane mesh splits ​

Plane.splitGeometry(plane, geometry, { cap?, tolerance? }) returns positive / negative / common meshes and interpolates attributes. Capping assembles cut rings, identifies holes/islands and triangulates outward faces. Open or non-manifold cuts throw. splitPlaneGeometry adapts internal BufferGeometry with copied userData.

Optional display adapters ​

js
import { GLView, ThreeBSP, BreathLight } from '@xort/cga/three';
import { shaders } from '@xort/cga/shaders';

Install three separately. GLView owns its controls, postprocessing, environment targets, canvas and listeners; call dispose(). The host owns model geometries, materials and textures, including shared resources.

shaders exports cga, common and 12 noise chunks. CGA expects host u_time / u_resolution / u_mouse uniforms. Use noise chunks separately because helper names can collide. Raw GLSL and licenses ship in build/shaders.

Try mesh examples.

MIT licensed · Internal TypeScript algorithms