Viewer
    Preparing search index...

    Interface IViewportApi

    The api for viewports.

    Viewports are created by calling the createViewport method.

    Each viewport has corresponding [cameras]ICameraApi and [lights]ILightApi.

    Additionally, there are various other settings to adjust the behavior and rendering of the viewport.

    By default a new viewport displays the complete scene tree. Viewports can be excluded from displaying geometry for specific sessions by using the excludeViewports property of ISessionApi.

    interface IViewportApi {
        animations: { [key: string]: IAnimationData };
        arRotation: vec3;
        arScale: vec3;
        arTranslation: vec3;
        automaticColorAdjustment: boolean;
        automaticResizing: boolean;
        beautyRenderBlendingDuration: number;
        beautyRenderDelay: number;
        camera: ICameraApi | null;
        cameras: { [key: string]: ICameraApi };
        canvas: HTMLCanvasElement;
        clearAlpha: number;
        clearColor: Color;
        contactShadowBlur: number;
        contactShadowDarkness: number;
        contactShadowHeight: number;
        contactShadowOpacity: number;
        contactShadowVisibility: boolean;
        defaultLineMaterial: MaterialBasicLineData;
        defaultMaterial: MaterialStandardData;
        defaultMaterialColor: Color;
        defaultPointMaterial: MaterialPointData;
        enableAR: boolean;
        environmentMap: string | string[];
        environmentMapAsBackground: boolean;
        environmentMapBlurriness: number;
        environmentMapForUnlitMaterials: boolean;
        environmentMapIntensity: number;
        environmentMapResolution: string;
        environmentMapRotation: quat;
        gridColor: Color;
        gridVisibility: boolean;
        groundPlaneColor: Color;
        groundPlaneShadowColor: Color;
        groundPlaneShadowVisibility: boolean;
        groundPlaneVisibility: boolean;
        id: string;
        isBusy: boolean;
        lights: boolean;
        lightScene: ILightSceneApi | null;
        lightScenes: { [key: string]: ILightSceneApi };
        loadDefaultCameras: boolean;
        materialOverrideType: MATERIAL_TYPE | undefined;
        maximumRenderingSize: { height: number; width: number };
        outputEncoding: TEXTURE_ENCODING;
        physicallyCorrectLights: boolean;
        pointSize: number;
        postProcessing: IPostProcessingApi;
        shadows: boolean;
        show: boolean;
        showStatistics: boolean;
        softShadows: boolean;
        textureEncoding: TEXTURE_ENCODING;
        threeJsCoreObjects: {
            camera: Camera;
            renderer: WebGLRenderer;
            scene: Scene;
        };
        toneMapping: TONE_MAPPING;
        toneMappingExposure: number;
        type: RENDERER_TYPE;
        visualizeAttributes: | (
            (
                overview: ISDTFOverview,
                itemData?: ISDTFItemData,
            ) => ISDTFAttributeVisualizationData
        )
        | undefined;
        addCanvasEventListener(listener: IDomEventListener): string;
        addFlag(flag: FLAG_TYPE): string;
        addRestrictedCanvasListenerToken(token: string): void;
        applyViewportSettings(
            settings: ISettings,
            sections?: {
                ar?: boolean;
                camera?: boolean;
                environment?: boolean;
                general?: boolean;
                light?: boolean;
                postprocessing?: boolean;
                scene?: boolean;
            },
        ): Promise<void>;
        assignCamera(id: string): boolean;
        assignLightScene(id: string): boolean;
        close(): Promise<void>;
        continueRendering(): void;
        convert3Dto2D(p: vec3): IConvert3Dto2DResult;
        convertToGlTF(node?: ITreeNode, convertForAR?: boolean): Promise<Blob>;
        createArSessionLink(
            node?: ITreeNode,
            qrCode?: boolean,
            fallbackUrl?: string,
        ): Promise<string>;
        createLightScene(
            properties?: { name?: string; standard?: boolean },
        ): ILightSceneApi;
        createOrthographicCamera(id?: string): IOrthographicCameraApi;
        createPerspectiveCamera(id?: string): IPerspectiveCameraApi;
        createSDTFOverview(node: ITreeNode): ISDTFOverview;
        displayErrorMessage(message: string): void;
        getEnvironmentMapImageUrl(): string;
        getScreenshot(type?: string, quality?: number): string;
        getScreenshotAdvanced(
            type?: string,
            quality?: number,
            resolution?: { height: number; width: number },
            camera?: OrthographicCameraProperties | PerspectiveCameraProperties,
        ): Promise<string>;
        getViewportSettings(): ISettings;
        isMobileDeviceWithoutBrowserARSupport(): boolean;
        pauseRendering(): void;
        pointerEventToRay(event: PointerEvent): { direction: vec3; origin: vec3 };
        raytraceScene(
            origin: vec3,
            direction: vec3,
            filterCriteria?: IIntersectionFilter[],
        ): { distance: number; node: ITreeNode; data?: IGeometryData }[];
        removeCamera(id: string): boolean;
        removeCanvasEventListener(token: string): boolean;
        removeFlag(token: string): boolean;
        removeLightScene(id: string): boolean;
        removeRestrictedCanvasListenerToken(token: string): void;
        render(): void;
        resetToDefaultCameras(): void;
        resize(width: number, height: number): void;
        restrictEventListeners(
            allowedListeners: {
                contextmenu?: boolean;
                keydown?: boolean;
                keyup?: boolean;
                mousewheel?: boolean;
                pointerdown?: boolean;
                pointermove?: boolean;
                pointerout?: boolean;
                pointerup?: boolean;
            },
        ): void;
        update(): void;
        updateDefaultLineMaterial(value: MaterialBasicLineData): void;
        updateDefaultMaterial(value: MaterialStandardData): void;
        updateDefaultPointMaterial(value: MaterialPointData): void;
        updateEnvironmentGeometry(): void;
        updateGeometryData(geometryData: IGeometryData): void;
        updateNode(node: ITreeNode): void;
        updateNodeTransformation(node: ITreeNode): void;
        viewableInAR(): boolean;
        viewInAR(node?: ITreeNode): Promise<void>;
        postRenderingCallback?: (
            renderer: WebGLRenderer,
            scene: Scene,
            camera: Camera,
        ) => void;
        preRenderingCallback?: (renderer: WebGLRenderer) => void;
        sessionSettingsId?: string;
        sessionSettingsMode?: SESSION_SETTINGS_MODE;
    }
    Index

    Properties

    Methods

    Properties

    animations: { [key: string]: IAnimationData }

    A dictionary of all animations that are currently present in the parts of the scene tree relevant to this viewport.

    arRotation: vec3

    The rotation factor that is used when exporting the scene for AR (Augmented Reality). The unit system used by AR is meter.

    arScale: vec3

    The scaling factor that is used when exporting the scene for AR (Augmented Reality).

    The unit system used by AR is meter, therefore this scaling factor needs to be chosen such that scene coordinates are transformed to meters.

    arTranslation: vec3

    The translation factor that is used when exporting the scene for AR (Augmented Reality). The unit system used by AR is meter.

    automaticColorAdjustment: boolean

    Option to enable / disable the automatic color space adaption. This converts all color inputs to the chosen outputEncoding. (default: true)

    automaticResizing: boolean

    Option to enable / disable the automatic resizing of the viewport to changes of the canvas. (default: true)

    beautyRenderBlendingDuration: number

    The duration used by the beauty rendering to blend in (milliseconds).

    beautyRenderDelay: number

    The delay after which the beauty rendering starts (milliseconds).

    camera: ICameraApi | null

    The current [camera]ICameraApi.

    cameras: { [key: string]: ICameraApi }

    The [cameras]ICameraApi of the viewport.

    canvas: HTMLCanvasElement

    The canvas that is used to render the viewport.

    clearAlpha: number

    The clear alpha value of the viewport. Use this to influence the background appearance of the viewport.

    clearColor: Color

    The clear color value of the viewport. Use this to influence the background appearance of the viewport.

    contactShadowBlur: number

    The blur amount of the contact shadow. (default: 1.5)

    contactShadowDarkness: number

    The darkness of the contact shadow. (default: 2.5)

    contactShadowHeight: number

    The maximum percentage of height that is still considered for the creation of the contact shadow. (default: 0.25) The maximum height is equal to the width and height of the ground plane.

    contactShadowOpacity: number

    The opacity of the contact shadow. (default: 1)

    contactShadowVisibility: boolean

    Option to enable / disable the contact shadow. (default: false)

    defaultLineMaterial: MaterialBasicLineData

    The default line material that is used for line geometry without a specified material. Please use updateDefaultLineMaterial to update the material.

    defaultMaterial: MaterialStandardData

    The default material that is used for geometry without a specified material. Please use updateDefaultMaterial to update the material.

    defaultMaterialColor: Color

    The color that is used when no material is specified. (default: #199b9b)

    defaultPointMaterial: MaterialPointData

    The default point material that is used for point geometry without a specified material. Please use updateDefaultPointMaterial to update the material.

    enableAR: boolean

    Option to enable / disable the AR (Augmented Reality) functionality for this viewport. (default: true) This setting is used purely for UI purposes, it does not have any influence on the viewport itself.

    environmentMap: string | string[]

    The environment map used by the viewport. You can either use the HDR maps at ENVIRONMENT_MAP or the LDR legacy maps at ENVIRONMENT_MAP_CUBE. Additionally, you can specify your own maps. For HDR maps, provide a link to a .hdr file, for LDR provide the folder where the six cube map images are located.

    environmentMapAsBackground: boolean

    Option to set the environment map as the background of the viewport. (default: false)

    environmentMapBlurriness: number

    The amount of which the environment map is blurred. (default: 0)

    environmentMapForUnlitMaterials: boolean

    Option to set the environment map for unlit materials. (default: false) For unlit materials, which use the three.js MeshBasicMaterial, per default we don't set the environment map to keep the colors as realistic as possible.

    environmentMapIntensity: number

    Scales how much the environment map effects the materials. (default: 1)

    environmentMapResolution: string

    The environment map resolution that is used for preset cube maps.

    environmentMapRotation: quat

    The rotation quaternion that is used on the environment map. (default: [0,0,0,1])

    gridColor: Color

    The color of the grid.

    gridVisibility: boolean

    Option to enable / disable the grid. (default: true)

    groundPlaneColor: Color

    The color of the ground plane.

    groundPlaneShadowColor: Color

    The color of the ground plane shadow.

    groundPlaneShadowVisibility: boolean

    Option to enable / disable the ground plane shadow. (default: false)

    groundPlaneVisibility: boolean

    Option to enable / disable the ground plane. (default: true)

    id: string

    The id of the viewport.

    isBusy: boolean

    If the viewer is currently busy. This is set by the viewer [addFlag]addFlag and [removeFlag]removeFlag methods.

    lights: boolean

    Option to enable / disable lights. (default: true)

    lightScene: ILightSceneApi | null

    The current [light scene]ILightSceneApi.

    lightScenes: { [key: string]: ILightSceneApi }

    The [light scenes]ILightSceneApi of the viewport.

    loadDefaultCameras: boolean

    Option to load the default cameras when the viewport is created. (default: true) This will create 6 orthographic cameras (top, bottom, left, right, front, back).

    materialOverrideType: MATERIAL_TYPE | undefined

    The type of material that is used as an override for all materials in the scene. This can be used to enforce a specific material type for all materials in the scene.

    As point and line materials are not supported by all three.js materials, the override will be ignored for these materials.

    If no override is set, the materials will be used as they are.

    maximumRenderingSize: { height: number; width: number }

    The maximum size of the renderings. The renderings will be upscaled to the actual resolution if these values are lower than the resolution of the canvas. This setting exists, as for higher resolutions the performance can drop due to the rendering effort. (default: { width: 1920, height: 1080 })

    outputEncoding: TEXTURE_ENCODING

    The encoding that is used for the output texture. (default: TEXTURE_ENCODING.SRGB) This is the texture that is rendered to the screen.

    physicallyCorrectLights: boolean

    Option to enable / disable the physically correct lights. (default: true)

    pointSize: number

    The point size that is used for rendering point data.

    postProcessing: IPostProcessingApi

    The [post processing api]IPostProcessingApi of the viewport.

    Note: The post-processing API is still WIP. Breaking changes are to be expected.

    shadows: boolean

    Option to enable / disable rendering of shadows. (default: true)

    show: boolean

    Option to show / hide the viewport. This will disable rendering, and hide the canvas behind the logo. Using this setting especially makes sense with VISIBILITY_MODE.MANUAL where you can decide at what point you first want to show the scene.

    showStatistics: boolean

    Option to show / hide rendering statistics overlayed to the viewport. (default: false)

    softShadows: boolean

    Option if the soft shadows should be rendered when the camera is not moving. (default: true)

    textureEncoding: TEXTURE_ENCODING

    The encoding that is used for textures. (default: TEXTURE_ENCODING.SRGB)

    threeJsCoreObjects: { camera: Camera; renderer: WebGLRenderer; scene: Scene }

    Some of the three.js core objects so that you are free to use and adjust them yourself.

    Please note that the camera will be replaced when you change it via the API. The same goes for the children in the scene tree that are auto-generated and properties of the renderer that are adjusted internally.

    toneMapping: TONE_MAPPING

    The tone mapping that is used. (default: TONE_MAPPING.NONE)

    toneMappingExposure: number

    The intensity of the tone mapping.

    The type of rendering of this viewport.

    visualizeAttributes:
        | (
            (
                overview: ISDTFOverview,
                itemData?: ISDTFItemData,
            ) => ISDTFAttributeVisualizationData
        )
        | undefined

    A possibility to visualize the attributes of the scene in any way you want. Please have a look at the desk documentation for more information.

    Provide a callback that transforms a ISDTFItemData to a ISDTFAttributeVisualizationData. The ISDTFOverview provides general information like min and max values for numbers or the available options for strings.

    postRenderingCallback?: (
        renderer: WebGLRenderer,
        scene: Scene,
        camera: Camera,
    ) => void

    Optional callback that is called after the rendering of the scene.

    preRenderingCallback?: (renderer: WebGLRenderer) => void

    Optional callback that is called before the rendering of the scene.

    sessionSettingsId?: string

    Optional identifier of the session to be used for loading / persisting settings of the viewport. This is ignored in case sessionSettingsMode is not SESSION_SETTINGS_MODE.MANUAL.

    sessionSettingsMode?: SESSION_SETTINGS_MODE

    Allows to control which session to use for loading / persisting settings of the viewport. (default: SESSION_SETTINGS_MODE.FIRST).

    Methods

    • Add an event listener that receives all canvas events.

      Parameters

      Returns string

    • Add a flag for this viewport. Adding/removing flags allows to influence the render loop. If you want to stop this again call removeFlag with the returned token.

      Parameters

      Returns string

    • Add a token to the list of restricted canvas listener tokens. This can be used to restrict events for a viewport. Only listeners with a token in this list will receive events (if there is at least one item in the list).

      Parameters

      • token: string

      Returns void

    • Apply the settings of a viewport manually. You can get the settings via getViewportSettings. You can choose which sections will be applied, by default they are all set to false.

      Parameters

      • settings: ISettings
      • Optionalsections: {
            ar?: boolean;
            camera?: boolean;
            environment?: boolean;
            general?: boolean;
            light?: boolean;
            postprocessing?: boolean;
            scene?: boolean;
        }

      Returns Promise<void>

      {@type ShapeDiverViewerError}

    • Assign the camera with the specified id to the viewport. This will make the given camera the current one.

      Parameters

      • id: string

        The id of the camera.

      Returns boolean

      camera

    • Assign the light scene with the current id to the viewport. This will make the given light scene the current one.

      Parameters

      • id: string

        The id of the light scene.

      Returns boolean

    • Closes the viewport and will remove all traces of the canvas element.

      Returns Promise<void>

    • Continue the rendering of the scene. Can be used with pauseRendering to continue/pause the rendering at will.

      Returns void

    • Convert the given 3D position to different 2D coordinates of HTML Elements. If the point is hidden by geometry, the hidden property will be set to true.

      The returned coordinates all have their origin in the top left corner of the element. For container, the position is relative to the canvas element. For client, the position is relative to the canvas element, including the results of https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect|getBoundingClientRect. For page, the position is relative to the whole page.

      Parameters

      • p: vec3

      Returns IConvert3Dto2DResult

    • Convert the current visible elements (or just from the node specified) in the viewport into a glTF file.

      The ground plane and grid will not be included, as well as additionally added data that was added to the scene other than through a GeometryData property.

      Parameters

      • Optionalnode: ITreeNode

        Optional node to provide to transform into a glTF. (default: scene tree)

      • OptionalconvertForAR: boolean

        Option to convert the scene for AR. In this case some specific use cases are target to ensure the best AR performance. (default: false)

      Returns Promise<Blob>

      {@type ShapeDiverViewerError}

    • Create a link / QRCode that can be opened by mobile devices to display in AR.

      As some models might have a different scale then the AR apps (meters), the scaling can be chosen freely arScale.

      Internally, the scene will first be converted into a glTF. This glTF will be uploaded to our backend and converted into a USDZ to be able to start AR on iOS and Android.

      Parameters

      • Optionalnode: ITreeNode

        Optional node to display in AR. (default: scene tree)

      • OptionalqrCode: boolean

        Option to receive a QR Code instead of a link (default: true)

      • OptionalfallbackUrl: string

        Optional fallback url if the link was opened by an unsupported device or an error occurred. If none was provided, the user will be redirected to shapediver.com/app

      Returns Promise<string>

      {@type ShapeDiverViewerError}

    • Create a new light scene. An id can be provided. If not, a unique id will be created. If the standard option is chosen, the default lights will be added from the start.

      Parameters

      • Optionalproperties: { name?: string; standard?: boolean }
        • Optionalname?: string
        • Optionalstandard?: boolean

          The option to add the standard lights.

      Returns ILightSceneApi

    • Create an orthographic camera. An id can be provided. If not, a unique id will be created.

      Parameters

      • Optionalid: string

        The id of the camera.

      Returns IOrthographicCameraApi

    • Create a perspective camera. An id can be provided. If not, a unique id will be created.

      Parameters

      • Optionalid: string

        The id of the camera.

      Returns IPerspectiveCameraApi

    • Display an error message on the canvas.

      Parameters

      • message: string

        The message to display.

      Returns void

    • Get the complete URL of the current environment map, if it is a single file. This can be used in case environmentMap is set to a preset environment map.

      Returns string

    • Create a screenshot for the requested type and options.

      Parameters

      • Optionaltype: string

        The type as string, default is 'image/png'.

      • Optionalquality: number

        The quality of the screenshot, default is 1.

      Returns string

    • Create a screenshot for the requested type and options.

      Parameters

      • Optionaltype: string

        The type as string, default is 'image/png'.

      • Optionalquality: number

        The quality of the screenshot, default is 1.

      • Optionalresolution: { height: number; width: number }

        The resolution of the screenshot, default is the current canvas size.

      • Optionalcamera: OrthographicCameraProperties | PerspectiveCameraProperties

        The camera that should be used for the screenshot, default is the current camera.

      Returns Promise<string>

    • Get the current settings object of this viewport. Can be re-applied at a later point with applyViewportSettings.

      Returns ISettings

    • Determines if the current device is a mobile device (or tablet) but still doesn't support to view the content in AR.

      Can be used in combination with viewableInAR to display a warning to use a different browser if viewableInAR is false and isMobileDeviceWithoutBrowserARSupport is true.

      Reasons for that can be:

      • Firefox on Android
      • Instagram in App browser

      Returns boolean

    • Calculate the ray that is created by the pointer event and the camera.

      Parameters

      • event: PointerEvent

      Returns { direction: vec3; origin: vec3 }

    • From the provided origin and direction, trace the ray through the scene. The intersections with GeometryData will be returned including the corresponding nodes, sorted by their smallest distance.

      If you want to raytrace the scene from an interaction with the the canvas, please use pointerEventToRay to create a ray first.

      Parameters

      • origin: vec3

        The origin of the ray.

      • direction: vec3

        The direction of the ray.

      • OptionalfilterCriteria: IIntersectionFilter[]

        Optional filter criteria to filter the intersections.

      Returns { distance: number; node: ITreeNode; data?: IGeometryData }[]

    • Remove the camera with the specified id and destroys it. If you remove the current active camera, the rendering will be stopped until a new camera is assigned.

      Parameters

      • id: string

        The id of the camera.

      Returns boolean

    • Remove an event listener that received all canvas events.

      Parameters

      Returns boolean

    • Removes the registered flag. Adding/removing flags allows to influence the render loop.

      Parameters

      • token: string

        The token that was returned by addFlag.

      Returns boolean

    • Remove the light scene with the specified id. If you remove the current active light scene, no lights will be shown.

      Parameters

      • id: string

        The id of the light scene.

      Returns boolean

    • Remove the token from the list of restricted canvas listener tokens. Only listeners with a token in this list will receive events (if there is at least one item in the list).

      Parameters

      • token: string

      Returns void

    • Manual call to render the scene.

      Returns void

    • Delete all current cameras and create our 7 default cameras.

      A perspective one (default) and 6 orthographic ones (top, bottom, left, right, front, back).

      Returns void

    • If the automaticResizing is option is set to false, this function resizes the Viewport.

      Parameters

      • width: number

        The new width of the Viewport.

      • height: number

        The new height of the Viewport.

      Returns void

    • Restrict events. This can be used to disable events for a viewport.

      Example use case: If you don't want to allow mouse wheel events for a specific viewport so that users can scroll past the viewport.

      Be aware that this might cause some issues with the the camera controls if the pointer events are disabled only partially.

      Parameters

      • allowedListeners: {
            contextmenu?: boolean;
            keydown?: boolean;
            keyup?: boolean;
            mousewheel?: boolean;
            pointerdown?: boolean;
            pointermove?: boolean;
            pointerout?: boolean;
            pointerup?: boolean;
        }

      Returns void

    • Update the viewport with the current changes of the complete scene tree. This carries out preparations for rendering. Call it after doing direct changes to the scene tree.

      Returns void

    • Update the default point material of the viewport.

      Parameters

      Returns void

    • Update the position of the environment geometry (grid, groundplane, etc) to the current viewport bounding box. Internally, this functions is called whenever a session is customized, but if you manually change parts of the scene, it might get necessary to call this function. Make sure to call update before, to apply the last changes.

      Returns void

    • Update the material of the given geometry data on the GPU without triggering a full scene tree reconversion. Use this instead of calling IGeometryData.updateVersion when only the effect material has changed, e.g. during hover interactions, to avoid the overhead of reconstructing Three.js objects.

      Parameters

      • geometryData: IGeometryData

        The geometry data whose material should be updated.

      Returns void

    • Update the viewport with the current changes of given scene tree node and its descendants. This carries out preparations for rendering. Call it after doing direct changes to the scene tree.

      Parameters

      Returns void

    • Update the viewport with the current changes in transformation of given scene tree node and its descendants. This carries out preparations for rendering. Call it after doing direct changes to the scene tree transformations.

      Parameters

      Returns void

    • View the current scene in AR.

      Please check first if the device supports the viewing of models in AR, see viewableInAR. As some models might have a different scale then the AR apps (meters), the scaling can be chosen freely arScale.

      Internally, the scene will first be converted into a glTF. This glTF will be uploaded to our backend to be able to start AR.

      Parameters

      • Optionalnode: ITreeNode

        Optional node to display in AR. (default: scene tree)

      Returns Promise<void>

      {@type ShapeDiverViewerError}