G-code Preview — API Reference
    Preparing search index...

    The minimal renderer contract the controller drives. 3D-only members are honored by the 2D renderer as documented no-ops or renderer-unsupported disclosures — never fabricated output.

    interface PreviewRenderer {
        hasColorChanges: boolean;
        hasRetractions: boolean;
        layerCount: number;
        segmentCount: number;
        appendPartial(slice: ToolpathIR): void;
        capture?(opts?: CaptureOptions): Promise<Blob>;
        dispose(): void;
        frame(): void;
        getCameraState(): CameraState | null;
        getRenderStats(): RenderStats | null;
        isColorModeAvailable(
            mode:
                | "object"
                | "single"
                | "tool"
                | "feature"
                | "colorChange"
                | "filament"
                | "feedrate"
                | "layerHeight"
                | "power"
                | "moveKind",
        ): boolean;
        onEvent(cb: (e: PreviewRendererEvent) => void): () => void;
        pickSegment(ndcX: number, ndcY: number, threshold?: number): number | null;
        resize(width: number, height: number): void;
        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;
        setIR(ir: ToolpathIR): void;
        setKindVisible(kind: MoveKindToggle, visible: boolean): void;
        setLayerRange(startLayer: number, endLayer: number): void;
        setPixelRatio?(ratio: PixelRatioOption): void;
        setProgress(p: MappedProgress | null): void;
        setProgressivePreview(mode: ProgressivePreview): void;
        setQuality(quality: "auto" | QualityMode): void;
        setQualityMode(mode: QualityPolicy): void;
        setScrubPosition(segIndex: number | null): void;
        setShowRetractions(visible: boolean): void;
        setTheme(theme: Theme): void;
        setView(view: CameraView): void;
    }

    Implemented by

    Index
    hasColorChanges: boolean

    True when the current IR carries M600 color-change boundaries (DD-031 G6).

    hasRetractions: boolean

    True when the current IR carries retraction/deretraction events the markers can show (DD-031 G6).

    layerCount: number
    segmentCount: number
    • Capture the current view as an image Blob (DD-030 D1). Optional: the 3D renderer implements it via render-to-target; a renderer that cannot (the 2D renderer) omits it, and the controller reports renderer-unsupported / rejects. Never fabricated output.

      Parameters

      Returns Promise<Blob>

    • Render diagnostics snapshot (DD-027) — backend/GPU/geometry-mode/parallelism/timings — or null before the first render / on a renderer that produces none (the 2D view). Exposed through the public surface so diagnostics are reachable without the raw handle (DD-031 G1).

      Returns RenderStats | null

    • Capability gate for a color mode (DD-001 honesty): false when the IR lacks the channel the mode reads (e.g. feature on a file with no feature roles). Lets a consumer build capability-aware UI without the raw handle (DD-031 G6). single/tool/moveKind are always available.

      Parameters

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

      Returns boolean

    • Pick the IR segment under a pointer (normalized device coords in [-1, 1]), or null (#184). The 3D renderer raycasts the toolpath; the 2D renderer returns null (no picking yet).

      Parameters

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

      Returns number | null

    • Perspective lens in degrees (DD-032 §4.2). Optional, so an existing custom renderer still satisfies the interface (the controller skips it when absent); the bundled 2D renderer discloses via renderer-unsupported.

      Parameters

      • fov: number

      Returns void

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

      Parameters

      • mode: "off" | "auto"

      Returns void

    • Resting pixel ratio of the interactive canvas: a number in (0, 4] or 'device'. Optional, so an existing custom renderer still satisfies the interface (the controller skips it when absent); the bundled 2D renderer discloses via renderer-unsupported.

      Parameters

      Returns void