Optionalargs: ContextArgsAn alias for the context
access animation mixer used by components in the scene
access application state (e.g. if all audio should be muted)
The effect composer can be used to render postprocessing effects. If assigned then it will automatically render the scene every frame.
access networking methods (use it to send or listen to messages or join a networking backend)
The <needle-engine> web component
ReadonlyfocusSettings when a focus rect is set. Use setCameraFocusRect(...) to do so.
This can be used to offset the renderer center e.g. to a specific DOM element.
Optionalhashused to append to loaded assets
access input data (e.g. click or touch events)
When the renderer or camera are managed by an external process (e.g. when running in r3f context).
When this is false you are responsible to call update(timestamp, xframe.
It is also currently assumed that rendering is handled performed by an external process
set to true to pause the update loop. You can receive an event for it in your components. Note that script updates will not be called when paused
ReadonlylodsAccess the LODs manager to control LOD behavior in the context
The main camera component of the scene - this camera is used for rendering.
Use setCurrentCamera for updating the main camera.
The main light in the scene
OptionalmaxClamps the renderer max resolution. If undefined the max resolution is not clamped. Default is undefined
ReadonlymenuAccess the needle menu to add or remove buttons to the menu element
The name of the context
access physics related methods (e.g. raycasting). To access the phyiscs engine use context.physics.engine
Readonlypost_called every frame after rendering (after all component events)
Readonlypost_callbacks called once after the context has been created
Readonlypre_called every frame before rendering (after all component events)
Readonlypre_called every frame at the beginning of the frame (after component start events and before earlyUpdate)
Readonlypre_called every frame befroe update (this list is emptied every frame)
The renderer is used to render the scene. It is automatically created when the context is created.
When enabled the application will run while not visible on the page
The scene contains all objects in the hierarchy and is automatically rendered by the context every frane.
Access the scene lighting manager to control lighting settings in the context
OptionaltargetSet to the target framerate you want your application to run in (you can use ?stats to check the fps) Set to undefined if you want to run at the maximum framerate
access timings (current frame number, deltaTime, timeScale, ...)
shorthand for NeedleXRSession.active
Automatically set by NeedleXRSession when a XR session is active
The AR overlay element is used to display 2D HTML elements while a AR session is active.
Current event of the update cycle (e.g. FrameEvent.EarlyUpdate or FrameEvent.OnBeforeRender)
Control the renderer devicePixelRatio.
Options
auto - Needle Engine automatically sets the pixel ratio to the current window.devicePixelRatio.manual - Needle Engine will not change the renderer pixel ratio. You can set it manually.number - Needle Engine will set the pixel ratio to the given number. The change will be applied to the renderer and the composer (if used) at the end of the current frame.Control the renderer devicePixelRatio.
Options
auto - Needle Engine automatically sets the pixel ratio to the current window.devicePixelRatio.manual - Needle Engine will not change the renderer pixel ratio. You can set it manually.number - Needle Engine will set the pixel ratio to the given number. The change will be applied to the renderer and the composer (if used) at the end of the current frame.The height of the <needle-engine> element on the website
The width of the <needle-engine> element on the website
the X position of the <needle-engine> element on the website
the Y position of the <needle-engine> element on the website
Checks if the context is fully created and ready
true if the context is fully created and ready
Shorthand for this.xrSessionMode === "immersive-ar"
true if a webxr AR session is currently active.
If a XR session is active and in pass through mode (immersive-ar on e.g. Quest)
true if the XR session is in pass through mode
Shorthand for this.xrSessionMode === "immersive-vr"
true if a webxr VR session is currently active.
Is a XR session currently active and presenting?
true if the xr renderer is currently presenting
true while the WebGL renderer is rendering (between onBeforeRender and onAfterRender events)
true if the <needle-engine> DOM element is visible on screen (context.domElement)
The main camera of the scene - this camera is used for rendering
Use setCurrentCamera for updating the main camera.
Set the main camera of the scene. If set to null the camera of the mainCameraComponent will be used - this camera is used for rendering
use to scale the resolution up or down of the renderer. default is 1
use to scale the resolution up or down of the renderer. default is 1
The source identifier(s) of the root scene(s) loaded into this context.
When using <needle-engine> web component this will be the src attribute(s).
The source identifier for of the root scene
The needle engine version
the current WebXR camera while the WebXRManager is active (shorthand for context.renderer.xr.getCamera())
the latest XRFrame (if a XRSession is currently active)
access the raw XRSession object (shorthand for context.renderer.xr.getSession()). For more control use NeedleXRSession.active
Shorthand for this.xr?.mode. AR or VR
the current XR session mode (immersive-vr or immersive-ar)
StaticAllStaticCurrentThe currently active context. Only set during the update loops
StaticDefaultWhen a new context is created this is the framerate that will be used by default
When a new context is created this is the framerate that will be used by default
StaticDefaultSubscribe to onAfterRender events on threejs objects
Use to subscribe to onBeforeRender events on threejs objects.
Clears the context and destroys all scenes and objects in the scene.
The ContextCleared event is called at the end.
This is automatically called when e.g. the src attribute changes on <needle-engine>
or when the web component is removed from the DOM
Calling this function will dispose the current renderer and create a new one which will then be assigned to the context. It can be used to create a new renderer with custom WebGLRendererParameters.
Note: Instead you can also modify the static Context.DefaultWebGlRendererParameters before the context is created.
Note: This method is recommended because it re-uses an potentially already existing canvas element. This is necessary to keep input event handlers from working (e.g. components like OrbitControls subscribe to input events on the canvas)
Optionalparams: WebGLRendererParametersthe newly created renderer
Dispose all allocated resources and clears the scene. This is automatically called e.g. when the <needle-engine> component is removed from the DOM.
Optionalopts: ContextCreateArgsThis will recreate the whole needle engine context and dispose the whole scene content
All content will be reloaded (loading times might be faster due to browser caches)
All scripts will be recreated
Remove from onAfterRender events on threejs objects
Remove callback from three onBeforeRender event (if it has been added with addBeforeRenderListener(...))
Remove the camera from the mainCamera stack (if it has been set before with setCurrentCamera)
Optionalcam: null | CameraOptionalcamera: Camerawill request a renderer size update the next render call (will call updateSize the next update)
Sets the animation loop.
Can not be done while creating the context or when disposed
Set a rect or dom element. The camera center will be moved to the center of the rect.
This is useful if you have Needle Engine embedded in a HTML layout and while you want the webgl background to fill e.g. the whole screen you want to move the camera center to free space.
For that you can simply pass in the rect or HMTL div that you want the camera to center on.
The focus rect or null to disable
Optionalsettings: Partial<FocusRectSettings>Optional settings for the focus rect. These will override the focusRectSettings property
Performs a full update step including script callbacks, rendering (unless isManagedExternally is set to false) and post render callbacks
Optionalframe: null | XRFrameUpdate the camera aspect ratio or orthorgraphic camera size. This is automatically called when a DOM size change is detected.
Optionalwidth: numberOptionalheight: numberCall to manually perform physics steps.
By default the context uses the physicsSteps property to perform steps during the update loop
If you just want to increase the accuracy of physics you can instead set the physicsSteps property to a higher value
Update the renderer and canvas size. This is also automatically called when a DOM size change is detected.
The Needle Engine context is the main access point that holds all the data and state of a Needle Engine application. It can be used to access the Context.scene, Context.renderer, Context.mainCamera, Context.input, Context.physics, Context.time, Context.connection (networking), and more.
The context is automatically created when using the
<needle-engine>web component.Example: Accessing the context from a [component](https://engine.needle.tools/docs/api/Behaviour):
Example: Accessing the context from a [hook](https://engine.needle.tools/docs/scripting.html#hooks) without a component e.g. from a javascript module or svelte or react component.