gcode-preview - v3.0.0-alpha.5
    Preparing search index...

    Class GCodePreview

    Main G-code preview class that orchestrates rendering and parsing

    import { GCodePreview } from 'gcode-preview';

    const preview = new GCodePreview({
    canvas: document.getElementById('canvas'),
    buildVolume: { x: 200, y: 200, z: 200 }
    });

    // Use the sceneManager directly for most operations
    preview.sceneManager.backgroundColor = '#000000';
    preview.sceneManager.extrusionColor = '#00ff00';

    // Process G-code
    preview.processGCode(gcodeString);
    Index

    Constructors

    Properties

    job: Job

    Job containing parsed G-code data

    onJobUpdated?: (job: Job) => void

    Called whenever parsed commands have been folded into the job.

    Holds a single callback: assigning it replaces any previous one. Wrap multiple listeners in one function if several consumers need the signal.

    onStreamEnd?: () => void

    Called once a streamed G-code file has been read to the end.

    Holds a single callback: assigning it replaces any previous one.

    Accessors

    • get countLayers(): number

      Gets the total number of layers in the job

      Returns number

      Number of layers

    Methods

    • Clears the preview and resets the parser, sceneManager, gui and job

      Returns void

    • Executes already-parsed commands into the current job, without rendering.

      Parameters

      • commands: GCodeCommand[]

        Parsed G-code commands (e.g. from parser.parseGCode(...).commands)

      Returns void

      Feeds the commands to the interpreter, which folds the resulting paths and state changes into job, then fires onJobUpdated. Nothing is drawn: call sceneManager.render() (or a processGCode variant) to see the result.

      Safe to call repeatedly: each call resumes the job's in-progress path before executing and finishes it after, so commands delivered across many calls accumulate into the job exactly as one big call would. This is how the streaming path executes each chunk, and it lets external tools (such as debuggers) step through a file command by command.

    • Processes G-code and renders the preview

      Parameters

      • gcode: string | string[]

        G-code string or array of lines

      Returns Promise<void>

      Promise that resolves when the animated render has completed

    • Processes G-code using the sceneManager's built-in streaming method

      Parameters

      • gcode: string | string[] | ReadableStream<any>

        G-code string or array of strings to process

      • options: { render?: boolean } = ...

        Options for rendering: { render: boolean }

      Returns Promise<void>

      Parses the G-code, executes commands, and renders the paths if render is true.

    • Parameters

      • stream: ReadableStream
      • options: { render?: boolean } = {}

      Returns Promise<void>