Class ThreeViewer

Three Viewer

The ThreeViewer is the main class in the framework to manage a scene, render and add plugins to it.

Hierarchy

Constructors

Properties

_canvas: HTMLCanvasElement
_container: HTMLElement
_defaultConfig: ISerializedViewerConfig = ...
_isRenderingFrame: boolean = false
_lastCameraPosition: Vector3 = ...
_lastCameraQuat: Quaternion = ...
_lastCameraTarget: Vector3 = ...
_lastSize: Vector2 = ...
_needsReset: boolean = true
_needsResize: boolean = false
_objectProcessor: IObjectProcessor = ...
_scene: RootScene

The Scene attached to the viewer, this cannot be changed.

_tempQuat: Quaternion = ...
_tempVec: Vector3 = ...
assetManager: AssetManager
debug: boolean
enabled: boolean = true

If the viewer is enabled. Set this false to disable RAF loop.

maxFramePerLoop: number = 1

Specifies how many frames to render in a single request animation frame. Keep to 1 for realtime rendering. Note: should be max (screen refresh rate / animation frame rate) like 60Hz / 30fps

plugins: Record<string, IViewerPlugin<ThreeViewer, boolean>> = {}
renderEnabled: boolean = true

Enable or disable all rendering, Animation loop including any frame/render events won't be fired when this is false.

renderManager: ViewerRenderManager
renderStats: GLStatsJS
resizeObserver: undefined | ResizeObserver = ...

The ResizeObserver observing the canvas element. Add more elements to this observer to resize viewer on their size change.

type: "ThreeViewer" = 'ThreeViewer'
uiConfig: UiObjectConfig<any, string, any>
ConfigTypeSlug: "vjson" = 'vjson'
Console: IConsoleWrapper = ...
Dialog: IDialogWrapper = windowDialogWrapper
VERSION: "0.0.16" = VERSION

Accessors

  • get canvas(): HTMLCanvasElement
  • Get the HTML Canvas Element where the viewer is rendering

    Returns HTMLCanvasElement

Methods

  • Add a plugin to the viewer.

    Type Parameters

    Parameters

    • plugin: T | Class<T>

      The instance of the plugin to add or the class of the plugin to add.

    • Rest ...args: any[]

      Arguments for the constructor of the plugin, in case a class is passed.

    Returns Promise<T>

    • The plugin added.
  • Disposes the viewer and frees up all resource and events. Do not use the viewer after calling dispose.

    Note

    • If you want to reuse the viewer, set viewer.enabled to false instead, then set it to true again when required. To dispose all the objects, materials in the scene use viewer.scene.disposeSceneModels() This function is not fully implemented yet. There might be some memory leaks.

    Todo

    • return promise?

    Returns void

  • Type Parameters

    • TRet

    Parameters

    • event: "update" | "dispose" | "preRender" | "postRender" | "preFrame" | "postFrame" | "addPlugin" | "renderEnabled" | "renderDisabled"
    • func: ((...args) => TRet)
        • (...args): TRet
        • Parameters

          • Rest ...args: any[]

          Returns TRet

    Returns Promise<TRet>

  • Serialize all the viewer and plugin settings.

    Parameters

    • binary: boolean = false

      Indicate that the output will be converted and saved as binary data. (default: false)

    • Optional pluginFilter: string[]

      List of PluginType to include. If empty, no plugins will be serialized. If undefined, all plugins will be serialized.

    Returns ISerializedViewerConfig

  • Parameters

    • Optional selected: Object3D<Event, string>
    • distanceMultiplier: number = 1.5
    • Optional duration: number
    • Optional ease: "linear" | Easing | "easeIn" | "easeOut" | "easeInOut" | "circIn" | "circOut" | "circInOut" | "backIn" | "backOut" | "backInOut" | "anticipate" | "bounceOut" | "bounceIn" | "bounceInOut" | "easeInOutSine"

    Returns Promise<void>

  • Get the Plugin by a constructor type or add a new plugin of the specified type if it doesn't exist.

    Type Parameters

    Parameters

    • type: Class<T>
    • Rest ...args: any[]

      arguments for the constructor of the plugin, used when a new plugin is created.

    Returns Promise<T>

  • Get the Plugin by a constructor type or add a new plugin to the viewer of the specified type if it doesn't exist(sync).

    Type Parameters

    Parameters

    • type: Class<T>
    • Rest ...args: any[]

      arguments for the constructor of the plugin, used when a new plugin is created.

    Returns T

  • Get the Plugin by a constructor type or by the string type. Use string type if the plugin is not a dependency and you don't want to bundle the plugin.

    Type Parameters

    Parameters

    • type: string | Class<T>

      The class of the plugin to get, or the string type of the plugin to get which is in the static PluginType property of the plugin

    Returns undefined | T

    • The plugin of the specified type.
  • Parameters

    • __namedParameters: {
          mimeType: undefined | string;
          quality: undefined | number;
      } = {}
      • mimeType: undefined | string
      • quality: undefined | number

    Returns Promise<null | Blob>

  • Parameters

    • __namedParameters: {
          mimeType: undefined | string;
          quality: undefined | number;
      } = {}
      • mimeType: undefined | string
      • quality: undefined | number

    Returns Promise<null | string>

  • Mark that the canvas is resized. If the size is changed, the renderer and all render targets are resized. This happens before the render of the next frame.

    Returns void

  • Serialize all the plugins and their settings to save or create presets. Used in toJSON.

    Parameters

    • meta: SerializationMetaType

      The meta object.

    • Optional filter: string[]

      List of PluginType for the to include. If empty, no plugins will be serialized. If undefined, all plugins will be serialized.

    Returns any[]

  • Set the background image of the scene from url or an IAsset object.

    Parameters

    • map: undefined | null | string | ITexture | IAsset
    • __namedParameters: {
          forceImport?: boolean;
          importedFile?: IFile;
          mimeType?: string;
          pathOverride?: string;
          reimportDisposed?: boolean;
      } & {
          _testDataTextureComplete?: boolean;
          autoImportZipContents?: boolean;
          forceImporterReprocess?: boolean;
          generateMipmaps?: boolean;
          processImported?: boolean;
          processRaw?: boolean;
          rootPath?: string;
      } & AnyOptions & LoadFileOptions & {
          setBackground?: boolean;
      } = {}

    Returns Promise<null | ITexture>

  • Set the viewer to dirty and trigger render of the next frame.

    Parameters

    • Optional source: any

      The source of the dirty event. like plugin or 3d object

    • Optional event: Event

      The event that triggered the dirty event.

    Returns void

  • Set the environment map of the scene from url or an IAsset object.

    Parameters

    • map: undefined | null | string | ITexture | IAsset
    • __namedParameters: {
          forceImport?: boolean;
          importedFile?: IFile;
          mimeType?: string;
          pathOverride?: string;
          reimportDisposed?: boolean;
      } & {
          _testDataTextureComplete?: boolean;
          autoImportZipContents?: boolean;
          forceImporterReprocess?: boolean;
          generateMipmaps?: boolean;
          processImported?: boolean;
          processRaw?: boolean;
          rootPath?: string;
      } & AnyOptions & LoadFileOptions & {
          setBackground?: boolean;
      } = {}

    Returns Promise<null | ITexture>

  • Set size of the canvas and update the renderer. If no width/height is passed, canvas is set to 100% of the container.

    Parameters

    • Optional size: {
          height?: number;
          width?: number;
      }
      • Optional height?: number
      • Optional width?: number

    Returns void

  • Serialize all the viewer and plugin settings and versions.

    Parameters

    • binary: boolean = true

      Indicate that the output will be converted and saved as binary data. (default: true)

    • Optional pluginFilter: string[]

      List of PluginType to include. If empty, no plugins will be serialized. If undefined, all plugins will be serialized.

    Returns ISerializedViewerConfig

    • Serializable JSON object.

Generated using TypeDoc