@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
84 lines (83 loc) • 3.4 kB
TypeScript
import { type LifecycleMethod, LifecycleMethodOptions } from "./engine_lifecycle_functions_internal.js";
/**
* Register a callback in the engine context created event.
* This happens once per context (after the context has been created and the first content has been loaded)
* @param cb The callback to be called
* @returns A function that can be called to unregister the callback
* @example
* ```ts
* onInitialized((ctx : Context) => {
* // do something
* }
* ```
* */
export declare function onInitialized(cb: LifecycleMethod, opts?: LifecycleMethodOptions): () => void;
/**
* Register a callback before the engine context is cleared.
* This happens if e.g. `<needle-engine src>` changes
*/
export declare function onClear(cb: LifecycleMethod, opts?: LifecycleMethodOptions): () => void;
/**
* Register a callback in the engine before the context is destroyed
* This happens once per context (before the context is destroyed)
*/
export declare function onDestroy(cb: LifecycleMethod, opts?: LifecycleMethodOptions): () => void;
/** Register a callback in the engine start event.
* This happens once at the beginning of a frame
* (e.g. once when the method is registered, after <needle-engine> is created or the src has changed)
* @param cb The callback to be called. Optionally return a function that will be called when the onStart callback is removed again
* @returns A function that can be called to unregister the callback
* @example
* ```ts
* onStart((ctx : Context) => {
* // do something
* console.log("Needle Engine: onStart registered")
* // optional to cleanup:
* return () => { console.log("OnStart removed") }
* }
* ```
* */
export declare function onStart(cb: LifecycleMethod, opts?: LifecycleMethodOptions): () => void;
/** Register a callback in the engine update event
* This is called every frame
* @param cb The callback to be called
* @returns A function that can be called to unregister the callback
* @example
* ```ts
* onUpdate((ctx : Context) => {
* // do something
* console.log("Needle Engine: onUpdate registered")
* // optional to cleanup:
* return () => { console.log("onUpdate removed") }
* }
* ```
* */
export declare function onUpdate(cb: LifecycleMethod, opts?: LifecycleMethodOptions): () => void;
/** Register a callback in the engine onBeforeRender event
* This is called every frame before the main camera renders
* @param cb The callback to be called
* @returns A function that can be called to unregister the callback
* @example
* ```ts
* onBeforeRender((ctx : Context) => {
* // do something
* }
* ```
* */
export declare function onBeforeRender(cb: LifecycleMethod, opts?: LifecycleMethodOptions): () => void;
/**
* Register a callback in the engine onAfterRender event
* This is called every frame after the main camera has rendered
* @param cb The callback to be called
* @returns A function that can be called to unregister the callback
* @example
* ```ts
* const unsubscribe = onAfterRender((ctx : Context) => {
* // do something...
* console.log("After render");
* // if you want to unsubscribe after the first call:
* unsubscribe();
* });
* ```
*/
export declare function onAfterRender(cb: LifecycleMethod, opts?: LifecycleMethodOptions): () => void;