brepjs API Reference
    Preparing search index...

    Interface Sketcher

    Build 2D wire profiles on a 3D plane using a builder-pen API.

    The Sketcher accumulates 2D curves in the local coordinate system of the chosen plane, then lifts them to 3D edges at finalization.

    const sketch = new Sketcher("XZ", 5)
    .hLine(20)
    .vLine(10)
    .hLine(-20)
    .close();
    const solid = sketch.extrude(8);
    interface Sketcher {
        _nextCorner: ((f: Curve2D, s: Curve2D) => Curve2D[]) | null;
        firstPoint: Point2D;
        pendingCurves: Curve2D[];
        plane: Plane;
        pointer: Point2D;
        get penAngle(): number;
        get penPosition(): Point2D;
        _closeSketch(): void;
        _closeWithMirror(): void;
        _convertFromUV(__namedParameters: Point2D): Point2D;
        _convertToUV(__namedParameters: Point2D): Point2D;
        _customCornerLastWithFirst(
            radius: number | ((f: Curve2D, s: Curve2D) => Curve2D[]),
            mode?: "fillet" | "chamfer" | "dogbone",
        ): void;
        _lastCurve(): Curve2D | null;
        _requireLastCurve(caller: string, action: string): Curve2D;
        _resolveRelative(xDist: number, yDist: number): Point2D;
        _saveCurveAndAdvance(curve: Curve2D, end: Point2D): this;
        bezierCurveTo(end: Point2D, controlPoints: Point2D | Point2D[]): this;
        buildWire(): Wire;
        bulgeArc(xDist: number, yDist: number, bulge: number): this;
        bulgeArcTo(end: Point2D, bulge: number): this;
        close(): Sketch;
        closeWithCustomCorner(
            radius: number | ((f: Curve2D, s: Curve2D) => Curve2D[]),
            mode?: "fillet" | "chamfer" | "dogbone",
        ): Sketch;
        closeWithMirror(): Sketch;
        cubicBezierCurveTo(
            end: Point2D,
            startControlPoint: Point2D,
            endControlPoint: Point2D,
        ): this;
        customCorner(
            radius: number | ((first: Curve2D, second: Curve2D) => Curve2D[]),
            mode?: "fillet" | "chamfer",
        ): this;
        delete(): void;
        done(): Sketch;
        ellipse(
            xDist: number,
            yDist: number,
            horizontalRadius: number,
            verticalRadius: number,
            rotation?: number,
            longAxis?: boolean,
            sweep?: boolean,
        ): this;
        ellipseTo(
            end: Point2D,
            horizontalRadius: number,
            verticalRadius: number,
            rotation?: number,
            longAxis?: boolean,
            sweep?: boolean,
        ): this;
        halfEllipse(
            xDist: number,
            yDist: number,
            minorRadius: number,
            sweep?: boolean,
        ): this;
        halfEllipseTo(end: Point2D, minorRadius: number, sweep?: boolean): this;
        hBulgeArc(distance: number, bulge: number): this;
        hLine(distance: number): this;
        hLineTo(xPos: number): this;
        hSagittaArc(distance: number, sagitta: number): this;
        line(xDist: number, yDist: number): this;
        lineTo(point: Point2D): this;
        movePointerTo(point: Point2D): this;
        polarLine(distance: number, angle: number): this;
        polarLineTo(__namedParameters: Point2D): this;
        quadraticBezierCurveTo(end: Point2D, controlPoint: Point2D): this;
        sagittaArc(xDist: number, yDist: number, sagitta: number): this;
        sagittaArcTo(end: Point2D, sagitta: number): this;
        saveCurve(curve: Curve2D): void;
        smoothSpline(
            xDist: number,
            yDist: number,
            splineConfig?: SplineOptions,
        ): this;
        smoothSplineTo(end: Point2D, config?: SplineOptions): this;
        tangentArc(xDist: number, yDist: number): this;
        tangentArcTo(end: Point2D): this;
        tangentLine(distance: number): this;
        threePointsArc(
            xDist: number,
            yDist: number,
            viaXDist: number,
            viaYDist: number,
        ): this;
        threePointsArcTo(end: Point2D, midPoint: Point2D): this;
        vBulgeArc(distance: number, bulge: number): this;
        vLine(distance: number): this;
        vLineTo(yPos: number): this;
        vSagittaArc(distance: number, sagitta: number): this;
    }

    Hierarchy (View Summary)

    Implements

    Index

    Drawing State

    • get penAngle(): number

      Returns the current pen angle in degrees

      The angle represents the tangent direction at the current pen position, based on the last drawing operation (line, arc, bezier, etc.). Returns 0 if nothing has been drawn yet.

      Returns number

    Other

    _nextCorner: ((f: Curve2D, s: Curve2D) => Curve2D[]) | null
    firstPoint: Point2D
    pendingCurves: Curve2D[]
    plane: Plane
    pointer: Point2D
    • Draw an arc to a relative end point using a bulge factor.

      Parameters

      • xDist: number
      • yDist: number
      • bulge: number

      Returns this

    • Close the path and apply a custom corner treatment between the last and first segments.

      Parameters

      • radius: number | ((f: Curve2D, s: Curve2D) => Curve2D[])

        Fillet/chamfer radius, or a custom corner function.

      • mode: "fillet" | "chamfer" | "dogbone" = 'fillet'

        Corner treatment type.

      Returns Sketch

      The closed Sketch.

    • Close the path by mirroring all edges about the line from first to last point.

      Mirrors in 3D after assembling the partial wire to ensure exact endpoint matching across kernels.

      Returns Sketch

    • Release resources held by this sketcher (lightweight — no kernel handles during drawing).

      Returns void

    • Draw an elliptical arc to a relative end point (SVG-style parameters).

      Parameters

      • xDist: number
      • yDist: number
      • horizontalRadius: number
      • verticalRadius: number
      • rotation: number = 0
      • longAxis: boolean = false
      • sweep: boolean = false

      Returns this

    • Draw an elliptical arc to an absolute end point (SVG-style parameters).

      Parameters

      • end: Point2D
      • horizontalRadius: number
      • verticalRadius: number
      • rotation: number = 0
      • longAxis: boolean = false
      • sweep: boolean = false

      Returns this

    • Draw a half-ellipse arc to a relative end point with a given minor radius.

      Parameters

      • xDist: number
      • yDist: number
      • minorRadius: number
      • sweep: boolean = false

      Returns this

    • Draw a horizontal bulge arc of the given distance and bulge factor.

      Parameters

      • distance: number
      • bulge: number

      Returns this

    • Draw a horizontal sagitta arc of the given distance and bulge.

      Parameters

      • distance: number
      • sagitta: number

      Returns this

    • Draw a straight line by relative horizontal and vertical distances.

      Parameters

      • xDist: number
      • yDist: number

      Returns this

    • Draw a line in polar coordinates (distance and angle in degrees) from the current point.

      Parameters

      • distance: number
      • angle: number

      Returns this

    • Draw a circular arc to a relative end point, bulging by the given sagitta.

      Parameters

      • xDist: number
      • yDist: number
      • sagitta: number

      Returns this

    • Override to preserve the original Sketcher's sagitta direction convention.

      BaseSketcher2d computes the perpendicular as [-dy, dx] (counter-clockwise rotation), but the original Sketcher used cross(diff, plane.zDir) which produces [dy, -dx] (clockwise rotation) for standard planes. Negating the sagitta compensates for this, ensuring all sagitta/bulge arcs curve the same way as the original 3D implementation.

      Parameters

      Returns this

    • Draw a circular arc tangent to the previous curve, ending at a relative offset.

      Parameters

      • xDist: number
      • yDist: number

      Returns this

    • Draw a circular arc through a via-point to an end point, both as relative distances.

      Parameters

      • xDist: number
      • yDist: number
      • viaXDist: number
      • viaYDist: number

      Returns this

    • Draw a vertical bulge arc of the given distance and bulge factor.

      Parameters

      • distance: number
      • bulge: number

      Returns this

    • Draw a vertical sagitta arc of the given distance and bulge.

      Parameters

      • distance: number
      • sagitta: number

      Returns this