@inweb/viewer-visualize
    Preparing search index...

    Interface IViewer

    Viewer core interface.

    interface IViewer {
        canvas: HTMLCanvasElement;
        canvasEvents: string[];
        client: Client;
        components: string[];
        draggers: string[];
        info: IInfo;
        loaders: ILoader[];
        models: IModel[];
        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;
        deselect(handles: string | string[]): void;
        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;
        getHidden(multimodel?: boolean): string[];
        getIsolated(multimodel?: boolean): string[];
        getSelected(multimodel?: boolean): string[];
        getSelected2(): string[];
        getSnapshot(type?: string, quality?: number): string;
        hide(handles: string | string[]): void;
        hideAll(): void;
        hideSelected(): void;
        initialize(
            canvas: HTMLCanvasElement,
            onProgress?: (event: ProgressEvent) => void,
        ): Promise<IViewer>;
        is3D(): boolean;
        isInitialized(): boolean;
        isolate(handles: string | string[]): void;
        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;
                modelId?: string;
                requestHeader?: HeadersInit;
                withCredentials?: boolean;
            },
        ): Promise<IViewer>;
        removeAllListeners(type?: string): this;
        removeEventListener(type: string, listener: (event: IEvent) => void): this;
        resetActiveDragger(): void;
        select(handles: string | string[]): void;
        setActiveDragger(name: string): IDragger;
        setSelected(handles?: string | string[]): void;
        setSelected2(handles?: string | string[]): void;
        setSize(width: number, height: number, updateStyle?: boolean): void;
        show(handles: string | string[]): void;
        showAll(): void;
        syncOverlay(): void;
        toggleSelection(handles: string | string[]): void;
        update(force?: number | boolean): void;
        zoomExtents(): void;
        zoomTo(handles: string | string[]): void;
        zoomToSelected(): void;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    canvas: HTMLCanvasElement

    HTMLCanvasElement that the viewer operates on. Defined only when 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 to 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.

    info: IInfo

    Statistical information about the GPU memory and the rendering process.

    loaders: ILoader[]

    List of active loaders used to load models into the viewer.

    models: IModel[]

    List of models loaded into the viewer.

    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, and deactivates the active dragger.

      Fires:

      Returns this

    • Clears the markup overlay view.

      Fires:

      Returns void

    • Deselects all objects.

      Fires:

      Returns void

    • Removes all cutting planes.

      Fires:

      Returns void

    • Collects the model objects back together. Alias to explode(0).

      Fires:

      Returns void

    • Saves the viewer state as a viewpoint.

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

      Fires:

      Returns IViewpoint

    • Deselects the specified objects by handles.

      Fires:

      Parameters

      • handles: string | string[]

        The object handle or list of handles. To avoid collisions across models in multi-model scenes, use composite handles in the form "model:handle". All handles in the list must be in the same format.

      Returns void

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

      Returns this

    • Sets the viewer state to the specified viewpoint.

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

      Fires:

      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. If the command is not found, tries to set active dragger with the specified name.

      Parameters

      • id: string

        Command ID or dragger name.

      • ...args: any[]

        Parameters passed to the command handler function.

      Returns any

      Returns the result of the command handler function or new active dragger instance. Returns undefined if neither the command nor the dragger exists.

    • Breaks the model into its component objects. To collect it 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

        Component name. Can be one of the components list.

      Returns IComponent

    • Returns a list of handles for the hidden objects.

      Special cases:

      • Returns an empty array if there are isolated objects in the scene.
      • Returns an array containing the single synthetic handle "$all" if all objects in the scene are hidden.

      Parameters

      • Optionalmultimodel: boolean

        Specifies if the returned handles should be formatted for a multi-model scene:

        • false (default): Returns raw handles as stored in the file. Useful for single-model scenes.
        • true: Returns composite handles in the form model:handle. Useful for multi-model scenes.

      Returns string[]

    • Returns a list of handles for the isolated objects.

      Parameters

      • Optionalmultimodel: boolean

        Specifies if the returned handles should be formatted for a multi-model scene:

        • false (default): Returns raw handles as stored in the file. Useful for single-model scenes.
        • true: Returns composite handles in the form model:handle. Useful for multi-model scenes.

      Returns string[]

    • Returns a list of handles for the selected objects.

      Parameters

      • Optionalmultimodel: boolean

        Specifies if the returned handles should be formatted for a multi-model scene:

        • false (default): Returns raw handles as stored in the file. Useful for single-model scenes.
        • true: Returns composite handles in the form model:handle. Useful for multi-model scenes.

      Returns string[]

    • Deprecated since 27.11. Use getSelected instead.

      Returns string[]

    • Creates a snapshot image of the current viewer state.

      If the viewer has an active markup, combines the viewer canvas with the markup overlay. Otherwise, captures only the viewer canvas.

      Parameters

      • Optionaltype: string

        The MIME type of the image format. Can be one of:

        • image/png - PNG format with lossless compression (recommended for quality)
        • image/jpeg - JPEG format with lossy compression (smaller file size)
        • image/webp - WebP format (modern browsers only)

        If not specified, uses snapshotMimeType option.

      • Optionalquality: number

        A number between 0 and 1 indicating the image quality for lossy formats. If not specified, uses snapshotQuality option.

      Returns string

      A Data URL string containing the snapshot image.

    • Hides the specified objects. The hidden objects become unselected.

      Fires:

      Parameters

      • handles: string | string[]

        The object handle or list of handles. To avoid collisions across models in multi-model scenes, use composite handles in the form "model:handle". All handles in the list must be in the same format.

      Returns void

    • Hides all objects.

      Fires:

      Returns void

    • Deselects and hides the selected objects.

      Fires:

      Returns void

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

      Fires:

      Parameters

      • canvas: HTMLCanvasElement

        HTMLCanvasElement that the viewer operates on.

      • OptionalonProgress: (event: ProgressEvent) => void

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

      Returns Promise<IViewer>

    • Returns true if the currently opened model is a 3D model.

      Returns boolean

    • Returns true if viewer has been initialized.

      Returns boolean

    • Isolates the specified objects. If selected objects are hidden during isolation, they become unselected.

      If no objects specified then all objects became hidden.

      Fires:

      Parameters

      • handles: string | string[]

        The object handle or list of handles. To avoid collisions across models in multi-model scenes, use composite handles in the form "model:handle". All handles in the list must be in the same format.

      Returns void

    • Hides all objects except the selected ones.

      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 suitable for the viewer, otherwise an exception will be thrown.

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

      For URLs, the file extension is used to determine the file format. For a ArrayBuffer and Data URL, a file format must be specified using params.format parameter. 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.

      Fires:

      Parameters

      • file: FileSource

        File to load. Can be:

      • params: {
            format?: string;
            mode?: string;
            modelId?: string;
            requestHeader?: HeadersInit;
            withCredentials?: boolean;
        }

        Loading parameters.

        • Optionalformat?: string

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

        • Optionalmode?: string

          File opening mode. Can be one of:

          • file - Single file mode. Unloads an open file and opens a new one. This is default mode.
          • assembly - Multi-model mode. Appends a file to an already open file. This mode is not supported for all viewers.
        • OptionalmodelId?: string

          Unique model ID for opened file in the multi-model scene. Used as a model prefix when selecting, hiding or isolating objects. Must not contain the ":" (colon). Required when loading a file as ArrayBuffer or Data URL. Default value depends on the FileSource:

          • file ID - when loading a file from Open Cloud Server.
          • file name - when loading from local File or URL.
        • OptionalrequestHeader?: HeadersInit

          The request header used in HTTP request.

        • OptionalwithCredentials?: boolean

          Whether the HTTP request uses credentials such as cookies, authorization headers or TLS client certificates. See XMLHttpRequest.withCredentials for more details.

      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

    • Selects the specified objects by handles. The selected objects become visible.

      Fires:

      Parameters

      • handles: string | string[]

        The object handle or list of handles. To avoid collisions across models in multi-model scenes, use composite handles in the form "model:handle". All handles in the list must be in the same format.

      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 empty 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 handles. The selected objects become visible.

      Fires:

      Parameters

      • Optionalhandles: string | string[]

        The object handle or list of handles. To avoid collisions across models in multi-model scenes, use composite handles in the form "model:handle". All handles in the list must be in the same format.

      Returns void

    • Deprecated since 27.11. Use setSelected instead.

      Parameters

      • Optionalhandles: string | string[]

      Returns void

    • Resizes the output canvas to (width, height) with device pixel ratio taken into account.

      Fires:

      Parameters

      • width: number

        The width of the canvas.

      • height: number

        The height of the canvas.

      • OptionalupdateStyle: boolean

        Setting updateStyle to false prevents any style changes to the output canvas.

      Returns void

    • Makes the specified objects visible.

      Fires:

      Parameters

      • handles: string | string[]

        The object handle or list of handles. To avoid collisions across models in multi-model scenes, use composite handles in the form "model:handle". All handles in the list must be in the same format.

      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

    • Toggles the selection of the specified objects by handles:

      • If an object is not selected, it will be selected and made visible.
      • If it is already selected, it will be deselected.

      Fires:

      Parameters

      • handles: string | string[]

        The object handle or list of handles. To avoid collisions across models in multi-model scenes, use composite handles in the form "model:handle". All handles in the list must be in the same format.

      Returns void

    • Updates the viewer.

      Fires:

      Parameters

      • Optionalforce: number | boolean

        If true, updates the viewer immediately. If a number is specified and more than the given amount of milliseconds has elapsed since the last rendering, the update is performed immediately as well. Otherwise, the update will be scheduled for the next animation frame. Default is false.

      Returns void

    • Fits the camera to the extents (bounding box) of the entire scene.

      Fires:

      Returns void

    • Fits the camera to the specified objects by handles.

      Fires:

      Parameters

      • handles: string | string[]

        The object handle or list of handles. To avoid collisions across models in multi-model scenes, use composite handles in the form "model:handle". All handles in the list must be in the same format.

      Returns void

    • Fits the camera to the selected objects.

      Fires:

      Returns void