Viewer core interface.

interface IViewer {
    canvas: HTMLCanvasElement;
    canvasEvents: string[];
    client: Client;
    components: string[];
    draggers: string[];
    options: IOptions;
    activeDragger(): IDragger;
    addEventListener(type: string, listener: (event: IEvent) => void): this;
    cancel(): this;
    clear(): this;
    clearOverlay(): void;
    clearSelected(): void;
    clearSlices(): void;
    collect(): void;
    createViewpoint(): IViewpoint;
    dispose(): this;
    drawViewpoint(viewpoint: IViewpoint): void;
    emit(type: string | object, ...args: any[]): boolean;
    emitEvent(event: IEvent): boolean;
    executeCommand(id: string, ...args: any[]): any;
    explode(index: number): void;
    getComponent(name: string): IComponent;
    getSelected(): string[];
    hideSelected(): void;
    initialize(
        canvas: HTMLCanvasElement,
        onProgress?: (event: ProgressEvent) => void,
    ): Promise<IViewer>;
    is3D(): boolean;
    isInitialized(): boolean;
    isolateSelected(): void;
    off(type: string, listener: (event: any) => void): this;
    on(type: string, listener: (event: any) => void): this;
    open(
        file: FileSource,
        params: { format?: string; mode?: string },
    ): Promise<IViewer>;
    removeAllListeners(type?: string): this;
    removeEventListener(type: string, listener: (event: IEvent) => void): this;
    resetActiveDragger(): void;
    setActiveDragger(name: string): IDragger;
    setSelected(handles?: string[]): void;
    showAll(): void;
    syncOverlay(): void;
    update(force?: boolean): void;
}

Hierarchy (View Summary)

Implemented by

Properties

canvas: HTMLCanvasElement

HTMLCanvasElement for the viewer used to operate on. Defined only while the viewer is initialized.

canvasEvents: string[]

List of canvas events, such as mouse events or pointer events or touch events that the viewer should listen and redirect to the draggers and components.

By default, the following events are redirected:

  • click
  • contextmenu
  • dblclick
  • mousedown
  • mouseleave
  • mousemove
  • mouseup
  • pointercancel
  • pointerdown
  • pointerleave
  • pointermove
  • pointerup
  • touchcancel
  • touchend
  • touchmove
  • touchstart
  • wheel
client: Client

The Client instance that is used to load model reference files from the Open Cloud Server.

components: string[]

List of names of available components.

draggers: string[]

List of names of available draggers.

The following draggers are available by default:

  • Pan
  • Orbit
  • Zoom
  • MeasureLine
  • CuttingPlaneXAxis
  • CuttingPlaneYAxis
  • CuttingPlaneZAxis
  • Walk

For a quick reference on how to implement your own dragger, see IDragger.

options: IOptions

Viewer options.

Methods

  • Returns the active dragger reference, or null if there is no active dragger.

    Returns IDragger

  • Registers a new listener for the event type.

    Parameters

    • type: string

      The type of event to listen to.

    • listener: (event: IEvent) => void

      The function that gets called when the event is fired.

    Returns this

  • Cancels asynchronous file loading started with open().

    Fires:

    Returns this

  • Unloads an open file, clears the canvas and markups, deactivates the active dragger.

    Fires:

    Returns this

  • Clears the overlay view.

    Returns void

  • Unselects all objects.

    Fires:

    Returns void

  • Removes all cutting planes.

    Returns void

  • Collect model objects back. Alias to explode(0).

    Fires:

    Returns void

  • Saves the viewer state at the viewpoint.

    To save a viewpoint to the server for a specific file, use the File.saveViewpoint().

    Returns IViewpoint

  • Unloads an open file, clears the canvas and markups, and releases resources allocated by this viewer instance. Call this method before release the Viewer instance.

    Returns this

  • Sets the viewer state to the specified viewpoint.

    To get a list of available viewpoints from the server for a specific file, use the File.getViewpoints().

    Parameters

    Returns void

  • Fires the event. Alias to emitEvent().

    Parameters

    • type: string | object

      The type of event that gets fired.

    • ...args: any[]

      The event properties.

    Returns boolean

  • Fires the event. Calls each of the listeners registered for the event type event.type, in the order they were registered.

    Parameters

    • event: IEvent

      The event that gets fired.

    Returns boolean

  • Executes the command denoted by the given command ID.

    Parameters

    • id: string

      ID of the command to execute.

    • ...args: any[]

      Parameters passed to the command handler function.

    Returns any

    Returns the result of the command handler function. Returns undefined when the command doesn't exists.

  • Breaks the model into its component objects. To collect objects back use index 0.

    Fires:

    Parameters

    • index: number

      Explode index. Range is 0 to 100.

    Returns void

  • Returns the component reference, or null if there is no component with the specified name.

    Parameters

    • name: string

    Returns IComponent

  • Returns a list of original handles for the selected objects.

    Returns string[]

  • Makes the selected objects invisible.

    Fires:

    Returns void

  • Initializes the viewer it with the specified canvas. Call dispose() to release allocated resources.

    Fires:

    Parameters

    • canvas: HTMLCanvasElement

      HTMLCanvasElement for the viewer used to operate on.

    • OptionalonProgress: (event: ProgressEvent) => void

      A callback function that handles events measuring progress of viewer initialization.

    Returns Promise<IViewer>

  • Returns true if current opened model is 3D model.

    Returns boolean

  • Returns true if viewer has been initialized.

    Returns boolean

  • Hides all objects except selected.

    Fires:

    Returns void

  • Removes the listener from an event type. Alias to removeEventListener().

    Parameters

    • type: string

      The type of the event that gets removed.

    • listener: (event: any) => void

      The listener function that gets removed.

    Returns this

  • Registers a new listener for the event type. Alias to addEventListener()

    Parameters

    • type: string

      The type of event to listen to.

    • listener: (event: any) => void

      The function that gets called when the event is fired.

    Returns this

  • Loads a file into the viewer.

    The viewer must be initialized before opening the file. Otherwise, open() does nothing.

    This method requires a Client instance to be specified to load file from the Open Cloud Server. The file geometry data on the Open Cloud Server must be converted into a format siutable for the viewer, otherwise an exception will be thrown.

    For files from Open Cloud Server, the default model will be loaded. If there is no default model, first availiable model will be loaded. If no models are found in the file, an exception will be thrown.

    The file extension is used to determine the file format. For a ArrayBuffer, Blob and Data URL, a file format must be specified using params.format parameter (see below). If no appropriate loader is found for the specified format, an exception will be thrown.

    If there was an active dragger before opening the file, it will be deactivated. After opening the file, you must manually activate the required dragger.

    To open a large files, enable partial streaming mode before opening. For example:

    viewer.options.enableStreamingMode = true;
    viewer.options.enablePartialMode = true;
    await viewer.open(file);

    Fires:

    Parameters

    • file: FileSource

      File to load.

    • params: { format?: string; mode?: string }

      Loading parameters.

      • Optionalformat?: string

        File format string. Required when loading a file as ArrayBuffer, Blob or Data URL.

      • Optionalmode?: string

        File opening mode. Can be one of:

        • open - Unloads an open file and opens a new one. This is default mode.
        • append - Appends a file to an already open file. This mode is not supported for all formats.

    Returns Promise<IViewer>

  • If type is specified, removes all registered listeners for type, otherwise removes all registered listeners.

    Parameters

    • Optionaltype: string

      The type of the listener that gets removed.

    Returns this

  • Removes the listener for the event type.

    Parameters

    • type: string

      The type of the event that gets removed.

    • listener: (event: IEvent) => void

      The listener function that gets removed.

    Returns this

  • Resets the state of the active dragger.

    Returns void

  • Changes the active dragger. The viewer must be initialized before activating the dragger, otherwise an exception will be thrown.

    Fires:

    Parameters

    • name: string

      Dragger name. Can be one of the draggers list or an ampty string to deactivate the current dragger.

    Returns IDragger

    Returns the new active dragger reference or null if there is no dragger with the given name.

  • Selects the objects by original handles.

    Fires:

    Parameters

    • Optionalhandles: string[]

      The list of original handles.

    Returns void

  • Makes all objects visible.

    Fires:

    Returns void

  • Creates an overlay view. Overlay view is used to draw cutting planes and markups.

    Returns void

  • Updates the viewer.

    Fires:

    Parameters

    • Optionalforce: boolean

      If true updates the viewer immidietly. Otherwise the update will be scheduled for the next animation frame. Default is false.

    Returns void