• Sweep a 2D polygon cross-section along a 3D centreline path, producing extruded geometry.

    Useful for beams, mouldings, conduit, gutters, parapets, stair stringers — anything with a constant cross-section along a curve.

    The cross-section lies in the plane perpendicular to the path's tangent at each path vertex. The local frame (N, B) is computed via parallel transport along the path so the cross-section doesn't twist between vertices.

    • shape is a flat array [x0, y0, x1, y1, ...] defining the cross-section in its local plane. List vertices CCW (viewed from +T) so face normals point outward. For closed shapes the last vertex implicitly connects back to the first — don't repeat the first vertex.
    • path is a flat array [x0, y0, z0, x1, y1, z1, ...] defining the 3D centreline.
    • closedShape (default true) controls whether the cross-section closes into a loop. Open shapes produce a swept strip and never get caps.
    • closedPath (default false) controls whether the path itself closes into a loop. Closed paths skip caps.
    • caps (default true) fills the start and end with the cross-section polygon when both closedShape is true and closedPath is false. The cap triangulation is a simple fan from vertex 0; convex shapes work, non-convex shapes produce overlapping triangles and should not be capped via this builder.

    Sharp corners on the path bevel the cross-section (the per-vertex tangent averages the incoming and outgoing edge directions); for cleaner mitres pre-process the path to insert duplicated vertices at the corners with the desired offset.

    // 0.2 × 0.2 square beam swept along an L-bend in the XY plane.
    const result = buildExtrude({
    shape: [-0.1, -0.1, 0.1, -0.1, 0.1, 0.1, -0.1, 0.1],
    path: [0, 0, 0, 1, 0, 0, 1, 1, 0]
    });
    if (result.ok) {
    const geometry = result.value;
    // Pass to sceneModel.createGeometry(...)
    } else {
    console.error("Error creating extrusion:", result.error);
    }

    Parameters

    • cfg: {
          caps?: boolean;
          closedPath?: boolean;
          closedShape?: boolean;
          path: number[];
          shape: number[];
      }

      Configuration for the extrusion.

      • Optionalcaps?: boolean

        Whether to fill the start/end with the cross-section. Only applied when closedShape && !closedPath.

      • OptionalclosedPath?: boolean

        Whether the path closes into a loop.

      • OptionalclosedShape?: boolean

        Whether the cross-section is a closed loop.

      • path: number[]

        Centreline, flat [x0, y0, z0, x1, y1, z1, ...]. Must contain at least 2 vertices (length ≥ 6, multiple of 3).

      • shape: number[]

        Cross-section polygon, flat [x0, y0, x1, y1, ...]. Must contain at least 3 vertices (length ≥ 6, even).

    Returns SDKResult<GeometryArrays>

    Geometry arrays for the extrusion, or an error.