import Vector3 from './math/Vector3'; import Quaternion from './math/Quaternion'; import Matrix4 from './math/Matrix4'; import BoundingBox from './math/BoundingBox'; import Notifier from './core/Notifier'; import type Scene from './Scene'; import type Mesh from './Mesh'; import type Geometry from './Geometry'; import type Renderable from './Renderable'; import type Skeleton from './Skeleton'; import type Renderer from './Renderer'; import type InstancedMesh from './InstancedMesh'; export type GetBoundingBoxFilter = (el: ClayNode & { geometry: Geometry; }) => boolean; export interface ClayNodeOpts { /** * Scene node name */ name: string; /** * Position relative to its parent node. aka translation. */ position: Vector3; /** * Rotation relative to its parent node. Represented by a quaternion */ rotation: Quaternion; /** * Scale relative to its parent node */ scale: Vector3; /** * If the local transform is update from SRT(scale, rotation, translation, which is position here) each frame */ autoUpdateLocalTransform: boolean; /** * If node and its chilren invisible */ invisible?: boolean; /** * If not trigger event. Available in the App3D */ silent?: boolean; } interface ClayNode extends ClayNodeOpts { dispose(renderer: Renderer): void; } declare class ClayNode extends Notifier { readonly uid: number; readonly type: string; /** * Affine transform matrix relative to its root scene. */ worldTransform: Matrix4; /** * Affine transform matrix relative to its parent node. * Composited with position, rotation and scale. */ localTransform: Matrix4; /** * target of ClayNode */ target?: Vector3; protected _children: ClayNode[]; /** * Parent of current scene node */ protected _parent?: ClayNode; /** * The root scene mounted. Null if it is a isolated node */ protected _scene?: Scene; constructor(opts?: Partial); /** * If Node is a skinned mesh * @return {boolean} */ isSkinnedMesh(): this is Mesh & { skeleton: Skeleton; }; /** * Return true if it is a renderable scene node, like Mesh and ParticleSystem * @return {boolean} */ isRenderable(): this is Renderable; isInstancedMesh(): this is InstancedMesh; /** * Set the name of the scene node * @param {string} name */ setName(name: string): void; /** * Add a child node * @param {clay.Node} node */ add(node: ClayNode): void; /** * Remove the given child scene node * @param {clay.Node} node */ remove(node: ClayNode): void; /** * Remove all children */ removeAll(): void; /** * Get the scene mounted * @return {clay.Scene} */ getScene(): Scene | undefined; /** * Get parent node * @return {clay.Scene} */ getParent(): ClayNode | undefined; _removeSelfFromScene(descendant: ClayNode): void; _addSelfToScene(descendant: ClayNode): void; /** * Return true if it is ancestor of the given scene node * @param {clay.Node} node */ isAncestor(node: ClayNode): boolean; /** * Get a new created array of all children nodes * @return {clay.Node[]} */ children(): ClayNode[]; /** * Get the ref to children. */ childrenRef(): ClayNode[]; /** * Get child scene node at given index. * @param {number} idx * @return {clay.Node} */ childAt(idx: number): ClayNode | undefined; /** * Get first child with the given name * @param {string} name * @return {clay.Node} */ getChildByName(name: string): ClayNode | undefined; /** * Get first descendant have the given name * @param {string} name * @return {clay.Node} */ getDescendantByName(name: string): ClayNode | undefined; /** * Get query path, relative to rootNode(default is scene) * @param {clay.Node} [rootNode] * @return {string} */ getPath(rootNode: ClayNode): string | null; /** * Depth first traverse all its descendant scene nodes. * * **WARN** Don't do `add`, `remove` operation in the callback during traverse. * @param {Function} callback Return true to stop traverse */ traverse(callback: (node: ClayNode) => boolean | void): void; /** * Traverse all children nodes. * * **WARN** DON'T do `add`, `remove` operation in the callback during iteration. * * @param {Function} callback */ eachChild(callback: (node: ClayNode, i: number) => void): void; /** * Set the local transform and decompose to SRT * @param {clay.Matrix4} matrix */ setLocalTransform(matrix: Matrix4): void; /** * Decompose the local transform to SRT */ decomposeLocalTransform(keepScale?: boolean): void; /** * Set the world transform and decompose to SRT * @param {clay.Matrix4} matrix */ setWorldTransform(matrix: Matrix4): void; /** * Decompose the world transform to SRT * @function */ decomposeWorldTransform(keepScale?: boolean): void; /** * Update local transform from SRT * Notice that local transform will not be updated if _dirty mark of position, rotation, scale is all false */ updateLocalTransform(): void; /** * Update world transform, assume its parent world transform have been updated * @private */ _updateWorldTransformTopDown(): void; /** * Update world transform before whole scene is updated. */ updateWorldTransform(): void; /** * Update local transform and world transform recursively */ update(): void; /** * Get bounding box of node * @param {Function} [filter] * @param {clay.BoundingBox} [out] * @return {clay.BoundingBox} */ getBoundingBox(filter?: GetBoundingBoxFilter, out?: BoundingBox): BoundingBox; /** * Get world position, extracted from world transform * @param {clay.Vector3} [out] * @return {clay.Vector3} */ getWorldPosition(out?: Vector3): Vector3; /** * Clone a new node * @return {Node} */ clone(): ClayNode; /** * Rotate the node around a axis by angle degrees, axis passes through point * @param {clay.Vector3} point Center point * @param {clay.Vector3} axis Center axis * @param {number} angle Rotation angle * @see http://docs.unity3d.com/Documentation/ScriptReference/Transform.RotateAround.html * @function */ rotateAround(point: Vector3, axis: Vector3, angle: number): void; /** * @param {clay.Vector3} target * @param {clay.Vector3} [up] * @see http://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml * @function */ lookAt(target: Vector3, up?: Vector3): void; } export default ClayNode;