@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
72 lines (71 loc) • 3.47 kB
TypeScript
import { type IComponent, type IContext, type LoadedModel } from "./engine_types.js";
/** The various events that can be dispatched by a Needle Engine {@link IContext} instance
*/
export declare enum ContextEvent {
/** called when the context is registered to the registry, the context is not fully initialized at this point */
ContextRegistered = "ContextRegistered",
/** called before the first glb is loaded, can be used to initialize physics engine, is awaited */
ContextCreationStart = "ContextCreationStart",
/** Called when the context has been created, before the first frame */
ContextCreated = "ContextCreated",
/** Called after the first frame has been rendered after creation */
ContextFirstFrameRendered = "ContextFirstFrameRendered",
/** Called before the context gets destroyed */
ContextDestroying = "ContextDestroying",
/** Called when the context has been destroyed */
ContextDestroyed = "ContextDestroyed",
/** Called when the context could not find a camera during creation */
MissingCamera = "MissingCamera",
/** Called before the context is being cleared (all objects in the scene are being destroyed and state is reset) */
ContextClearing = "ContextClearing",
/** Called after the context has been cleared (all objects in the scene have been destroyed and state has been reset) */
ContextCleared = "ContextCleared"
}
export type ContextEventArgs = {
event: ContextEvent;
context: IContext;
files?: LoadedModel[];
};
export type ContextCallback = (evt: ContextEventArgs) => void | Promise<any> | IComponent;
/** Use to register to various Needle Engine context events and to get access to all current instances
* e.g. when being created in the DOM
* @example
* ```typescript
* import { NeedleEngine } from "./engine/engine_context_registry.js";
* NeedleEngine.addContextCreatedCallback((evt) => {
* console.log("Context created", evt.context);
* });
* ```
* */
export declare class ContextRegistry {
/** The currently active (rendering) Needle Engine context */
static get Current(): IContext;
/** @internal */
static set Current(ctx: IContext);
/** Returns the array of all registered Needle Engine contexts. Do not modify */
static get All(): import("./engine_context.js").Context[];
/** All currently registered Needle Engine contexts. Do not modify */
static Registered: IContext[];
/** @internal Internal use only */
static register(ctx: IContext): void;
/** @internal Internal use only */
static unregister(ctx: IContext): void;
private static _callbacks;
/**
* Register a callback to be called when the given event occurs
*/
static registerCallback(evt: ContextEvent, callback: ContextCallback): void;
/** Unregister a callback */
static unregisterCallback(evt: ContextEvent, callback: ContextCallback): void;
/** @internal */
static dispatchCallback(evt: ContextEvent, context: IContext, extras?: object): true | Promise<any[]>;
/**
* Register a callback to be called when a context is created
*/
static addContextCreatedCallback(callback: ContextCallback): void;
/**
* Register a callback to be called when a context is registered
*/
static addContextDestroyedCallback(callback: ContextCallback): void;
}
export { ContextRegistry as NeedleEngine };