@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.
111 lines (110 loc) • 6.41 kB
TypeScript
import { Object3D, Scene } from "three";
import type { ComponentInit, Constructor, ConstructorConcrete, IComponent } from "./engine_types.js";
export declare function removeComponent<T extends IComponent>(go: Object3D, componentInstance: T): T;
export declare function getOrAddComponent<T extends IComponent>(go: Object3D, typeName: ConstructorConcrete<T>, init?: ComponentInit<T>): T;
export declare function addNewComponent<T extends IComponent>(obj: Object3D, componentInstance: T, callAwake?: boolean): T;
export declare function addComponent<T extends IComponent>(obj: Object3D, componentInstance: T | ConstructorConcrete<T>, init?: ComponentInit<T>, opts?: {
callAwake: boolean;
}): T;
export declare function destroyComponentInstance(componentInstance: IComponent): void;
/**
* Searches for a given component type in the given object.
* @param obj The object to search in.
* @param componentType The type of the component to search for.
* @returns The first component of the given type found in the given object.
* @example
* ```typescript
* const myComponent = getComponent(myObject, MyComponent);
* ```
*/
export declare function getComponent<T extends IComponent>(obj: Object3D, componentType: Constructor<T>): T | null;
/**
* Searches for a given component type in the children of the given object.
* @param obj The object to start the search from - this object is also included in the search.
* @param componentType The type of the component to search for.
* @param arr An optional array to store the found components in. If not provided, a new array is created.
* @param clearArray If true, the array is cleared before storing the found components. Default is true.
* @returns An array of components of the given type found in the children of the given object.
* @example
* ```typescript
* const myComponents = getComponents(myObject, MyComponent);
* ```
*/
export declare function getComponents<T extends IComponent>(obj: Object3D, componentType: Constructor<T>, arr?: T[] | null, clearArray?: boolean): T[];
/**
* Searches for a given component type in the children of the given object.
* @param obj The object to start the search from - this object is also included in the search.
* @param componentType The type of the component to search for.
* @param includeInactive If true, also inactive components are returned. Default is true.
* @returns The first component of the given type found in the children of the given object.
* @example
* ```typescript
* const myComponent = getComponentInChildren(myObject, MyComponent);
* ```
*/
export declare function getComponentInChildren<T extends IComponent>(obj: Object3D, componentType: Constructor<T>, includeInactive?: boolean): T | null;
/**
* Searches for a given component type in the children of the given object.
* @param obj The object to start the search from - this object is also included in the search.
* @param componentType The type of the component to search for.
* @param arr An optional array to store the found components in. If not provided, a new array is created.
* @param clearArray If true, the array is cleared before storing the found components. Default is true.
* @returns An array of components of the given type found in the children of the given object.
* @example
* ```typescript
* const myComponents = getComponentsInChildren(myObject, MyComponent);
* ```
*/
export declare function getComponentsInChildren<T extends IComponent>(obj: Object3D, componentType: Constructor<T>, arr?: T[], clearArray?: boolean): T[];
/**
* Searches for a given component type in the parent hierarchy of the given object.
* @param obj The object to start the search from - this object is also included in the search.
* @param componentType The type of the component to search for.
* @returns The first component of the given type found in the parent hierarchy of the given object.
* @example
* ```typescript
* const myComponent = getComponentInParent(myObject, MyComponent);
* ```
*/
export declare function getComponentInParent<T extends IComponent>(obj: Object3D, componentType: Constructor<T>): T | null;
/**
* Searches for a given component type in the parent hierarchy of the given object.
* @param obj The object to start the search from - this object is also included in the search.
* @param componentType The type of the component to search for.
* @param arr An optional array to store the found components in. If not provided, a new array is created.
* @param clearArray If true, the array is cleared before storing the found components. Default is true.
* @returns An array of components of the given type found in the parent hierarchy of the given object.
* @example
* ```typescript
* const myComponents = getComponentsInParent(myObject, MyComponent);
* ```
*/
export declare function getComponentsInParent<T extends IComponent>(obj: Object3D, componentType: Constructor<T>, arr?: T[] | null, clearArray?: boolean): T[];
/**
* Searches the the scene for a component of the given type.
* If the contextOrScene is not provided, the current context is used.
* @param type The type of the component to search for.
* @param contextOrScene The context or scene to search in. If not provided, the current context is used.
* @param includeInactive If true, also inactive components are returned. Default is true.
* @returns The first component of the given type found in the scene or null if none was found.
* @example
* ```typescript
* const myComponent = findObjectOfType(MyComponent);
* ```
*/
export declare function findObjectOfType<T extends IComponent>(type: Constructor<T>, contextOrScene?: undefined | Object3D | {
scene: Scene;
}, includeInactive?: boolean): T | null;
/**
* Searches the the scene for all components of the given type.
* If the contextOrScene is not provided, the current context is used.
* @param type The type of the component to search for.
* @param contextOrScene The context or scene to search in. If not provided, the current context is used.
* @example
* ```typescript
* const myComponents = findObjectsOfType(MyComponent);
* ```
*/
export declare function findObjectsOfType<T extends IComponent>(type: Constructor<T>, array?: T[], contextOrScene?: undefined | Object3D | {
scene: Scene;
}): T[];