The <needle-engine> web component. See NeedleEngineAttributes attributes for supported attributes
The web component creates and manages a Needle Engine context, which is responsible for rendering a 3D scene using threejs.
The context is created when the src attribute is set, and disposed when the element is removed from the DOM. You can prevent cleanup by setting the keep-alive attribute to true.
The context is accessible from the <needle-engine> element: document.querySelector("needle-engine").context. See https://engine.needle.tools/docs/reference/needle-engine-attributes

<needle-engine src="https://example.com/scene.glb"></needle-engine>
<needle-engine src="https://example.com/scene.glb" camera-controls="false"></needle-engine>

Hierarchy

Implements

Constructors

Accessors

  • get cameraControls(): null | boolean

    If set to false the camera controls are disabled. Default is true.

    Returns null | boolean

    if the attribute is not set it returns null

    NeedleEngineAttributes

    <needle-engine camera-controls="false"></needle-engine>
    
    <needle-engine camera-controls="true"></needle-engine>
    
    <needle-engine camera-controls></needle-engine>
    
    <needle-engine></needle-engine>
    
  • set cameraControls(value: null | boolean): void

    Parameters

    • value: null | boolean

    Returns void

  • get context(): Context

    Get the context that is created when the src attribute is set and the loading has finished.

    Returns Context

  • get loadingFinished(): boolean

    Returns boolean

  • get loadingProgress01(): number

    Returns number

  • get toneMapping(): undefined | null | TonemappingAttributeOptions

    The tonemapping setting configured as an attribute on the component

    Returns undefined | null | TonemappingAttributeOptions

  • get observedAttributes(): string[]

    Returns string[]

Methods

  • Emitted when loading begins for the scene. The event is cancelable — calling preventDefault() will stop the default loading UI behavior, so apps can implement custom loading flows.

    Parameters

    • type: "loadstart"
    • listener: (ev: CustomEvent<{ alias: null | string; context: Context }>) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted repeatedly while loading resources. Use the event detail to show progress.

    Parameters

    • type: "progress"
    • listener: (
          ev: CustomEvent<
              {
                  context: Context;
                  count: number;
                  index: number;
                  name: string;
                  progress: ProgressEvent<EventTarget>;
                  totalProgress01: number;
              },
          >,
      ) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when scene loading has finished.

    Parameters

    • type: "loadfinished"
    • listener: (
          ev: CustomEvent<
              { context: Context; loadedFiles: LoadedModel[]; src: null
              | string },
          >,
      ) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when an XR session ends.

    Parameters

    • type: "xr-session-ended"
    • listener: (
          ev: CustomEvent<
              {
                  context: Context;
                  session: null
                  | XRSession;
                  sessionMode: undefined | XRSessionMode;
              },
          >,
      ) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when entering an AR session.

    Parameters

    • type: "enter-ar"
    • listener: (
          ev: CustomEvent<
              {
                  context: Context;
                  htmlContainer: null
                  | HTMLElement;
                  session: XRSession;
              },
          >,
      ) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when exiting an AR session.

    Parameters

    • type: "exit-ar"
    • listener: (
          ev: CustomEvent<
              {
                  context: Context;
                  htmlContainer: null
                  | HTMLElement;
                  session: XRSession;
              },
          >,
      ) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when entering a VR session.

    Parameters

    • type: "enter-vr"
    • listener: (ev: CustomEvent<{ context: Context; session: XRSession }>) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when exiting a VR session.

    Parameters

    • type: "exit-vr"
    • listener: (ev: CustomEvent<{ context: Context; session: XRSession }>) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when the engine has rendered its first frame and is ready.

    Parameters

    • type: "ready"
    • listener: (ev: Event) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when an XR session is started. You can do additional setup here.

    Parameters

    • type: "xr-session-started"
    • listener: (ev: CustomEvent<{ context: Context; session: XRSession }>) => void
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when loading begins for the scene. The event is cancelable — calling preventDefault() will stop the default loading UI behavior, so apps can implement custom loading flows.

    Type Parameters

    • K extends keyof HTMLElementEventMap

    Parameters

    • type: K
    • listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => unknown
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when loading begins for the scene. The event is cancelable — calling preventDefault() will stop the default loading UI behavior, so apps can implement custom loading flows.

    Type Parameters

    • K extends keyof HTMLElementEventMap

    Parameters

    • type: K
    • listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Emitted when loading begins for the scene. The event is cancelable — calling preventDefault() will stop the default loading UI behavior, so apps can implement custom loading flows.

    Parameters

    • type: string
    • listener: EventListenerOrEventListenerObject
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Returns void

  • Get the current context for this web component instance. The context is created when the src attribute is set and the loading has finished.
    The context is disposed when the needle engine is removed from the document (you can prevent this by setting the keep-alive attribute to true).

    Returns Promise<Context>

    a promise that resolves to the context when the loading has finished