G-code Preview — API Reference
    Preparing search index...
    interface GcodePreviewControls {
        capture(opts?: CaptureOptions): Promise<Blob>;
        frame(): void;
        getCameraState(): CameraState | null;
        getRenderStats(): RenderStats | null;
        isColorModeAvailable(
            mode:
                | "object"
                | "single"
                | "tool"
                | "feature"
                | "colorChange"
                | "filament"
                | "feedrate"
                | "layerHeight"
                | "power"
                | "moveKind",
        ): boolean;
        pickSegment(ndcX: number, ndcY: number, threshold?: number): number | null;
        setBuildVolume(def: BuildVolumeDef | MachineGeometry): void;
        setBuildVolumeCage(visible: boolean): void;
        setCameraFov(fov: number): void;
        setCameraMode(mode: CameraMode): void;
        setCameraState(state: CameraState): void;
        setColorMode(mode: ColorMode): boolean;
        setFeatureRoleVisible(role: FeatureRoleValue, visible: boolean): void;
        setFrameContent(mode: "object" | "all"): void;
        setInteractionQuality(mode: "off" | "auto"): void;
        setKindVisible(kind: MoveKindToggle, visible: boolean): void;
        setLayerRange(startLayer: number, endLayer: number): void;
        setPixelRatio(ratio: PixelRatioOption): void;
        setProgressivePreview(mode: ProgressivePreview): void;
        setQuality(quality: "auto" | QualityMode): void;
        setQualityMode(mode: QualityPolicy): void;
        setScrubPosition(segIndex: number | null): void;
        setScrubTime(ms: number | null): void;
        setShowRetractions(visible: boolean): void;
        setTheme(theme: Theme): void;
        setView(view: CameraView): void;
    }
    Index
    • Capture the currently displayed view as an image Blob (DD-030 D1) — for a user-selected thumbnail, a large-file fallback, or a screenshot. Rejects with E_CAPTURE_UNSUPPORTED before the 3D renderer is ready or on the 2D renderer (which cannot render-to-target). The caller owns the Blob.

      Parameters

      Returns Promise<Blob>

    • Render diagnostics snapshot (DD-027, DD-031 G1) — backend, WebGL version, GPU (hardware/software), geometry mode, build parallelism + worker count, draw calls, tube-byte budget, and parse/build/ first-frame timings — or null before the first render and on the 2D renderer (which produces none). Reachable through the public surface so a diagnostics panel needs no raw.renderer().

      Returns RenderStats | null

    • Capability gate for a color mode against the current file (DD-031 G6) — mirrors GcodePreviewState.availableColorModes for a one-off query. false when the file lacks the channel the mode reads; always true before a parse (optimistic, like setColorMode).

      Parameters

      • mode:
            | "object"
            | "single"
            | "tool"
            | "feature"
            | "colorChange"
            | "filament"
            | "feedrate"
            | "layerHeight"
            | "power"
            | "moveKind"

      Returns boolean

    • Pick the IR segment under a pointer in normalized device coords ([-1, 1], y up), or null (DD-031 G2, #184). Powers source-mapping/inspection UI. The 3D renderer raycasts the toolpath; the 2D renderer returns null (no picking yet). threshold widens the hit test (world units).

      Parameters

      • ndcX: number
      • ndcY: number
      • Optionalthreshold: number

      Returns number | null

    • Show/hide the build-volume wireframe cage independently of the bed/plate (#306/#6).

      Parameters

      • visible: boolean

      Returns void

    • Change the perspective lens (DD-032 §4.2), degrees. The camera dollies to keep the framing, without a re-fit and without a camera-changed event; while orthographic the lens is remembered and applied on the switch back. Throws RangeError synchronously outside [10, 120] (never clamped), even before the 3D renderer has loaded. Kept across canvas rebinds. The 2D renderer discloses this via renderer-unsupported.

      Parameters

      • fov: number

      Returns void

    • Show/hide a single feature role — e.g. hide Skirt/Brim to declutter a part preview. Gate the UI on capabilities.featureRoles === 'known' (like the feature color mode); a no-op on the 2D renderer and on files without feature annotations. Import FeatureRole from @chestnutlabs/toolpath-core.

      Parameters

      Returns void

    • Frame the printed 'object' (excl. skirt/prime) vs 'all' extrusion, and re-frame (#306/#6).

      Parameters

      • mode: "object" | "all"

      Returns void

    • Interaction-aware quality: 'auto' reduces detail while the camera moves (#306/2, DD-020).

      Parameters

      • mode: "off" | "auto"

      Returns void

    • Change the resting pixel ratio: a number in (0, 4], or 'device' (DPR capped at 2, followed live). A gesture in progress keeps its interaction-quality reduction and settles on the new ratio. Throws RangeError synchronously otherwise (never clamped), even before the 3D renderer has loaded. Kept across canvas rebinds. The default capture() size does not change; pass width/height for a crisper image. The 2D renderer discloses this via renderer-unsupported.

      Parameters

      Returns void

    • Time-based scrub (#181): cut the toolpath at print time ms (kinematic axis). null clears the cut. Resolves to a segment-index scrub; no-op before a successful parse.

      Parameters

      • ms: number | null

      Returns void

    • Opt-in retraction/deretraction markers (DD-009 D1, #148). Off by default.

      Parameters

      • visible: boolean

      Returns void