import type { DeepImmutable, Nullable } from "../types"; import { Observable } from "../Misc/observable"; import type { Camera } from "../Cameras/camera"; import type { Scene } from "../scene"; import { Quaternion, Matrix, Vector3 } from "../Maths/math.vector"; import { Node } from "../node"; import type { Bone } from "../Bones/bone"; import type { AbstractMesh } from "../Meshes/abstractMesh"; import { Space } from "../Maths/math.axis"; /** * A TransformNode is an object that is not rendered but can be used as a center of transformation. This can decrease memory usage and increase rendering speed compared to using an empty mesh as a parent and is less complicated than using a pivot matrix. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/transform_node */ export declare class TransformNode extends Node { /** * Object will not rotate to face the camera */ static BILLBOARDMODE_NONE: number; /** * Object will rotate to face the camera but only on the x axis */ static BILLBOARDMODE_X: number; /** * Object will rotate to face the camera but only on the y axis */ static BILLBOARDMODE_Y: number; /** * Object will rotate to face the camera but only on the z axis */ static BILLBOARDMODE_Z: number; /** * Object will rotate to face the camera */ static BILLBOARDMODE_ALL: number; /** * Object will rotate to face the camera's position instead of orientation */ static BILLBOARDMODE_USE_POSITION: number; /** * Child transform with Billboard flags should or should not apply parent rotation (default if off) */ static BillboardUseParentOrientation: boolean; private static _TmpRotation; private static _TmpScaling; private static _TmpTranslation; private _forward; private _up; private _right; private _position; private _rotation; private _rotationQuaternion; protected _scaling: Vector3; private _transformToBoneReferal; private _currentParentWhenAttachingToBone; private _isAbsoluteSynced; private _billboardMode; /** * Gets or sets the billboard mode. Default is 0. * * | Value | Type | Description | * | --- | --- | --- | * | 0 | BILLBOARDMODE_NONE | | * | 1 | BILLBOARDMODE_X | | * | 2 | BILLBOARDMODE_Y | | * | 4 | BILLBOARDMODE_Z | | * | 7 | BILLBOARDMODE_ALL | | * */ get billboardMode(): number; set billboardMode(value: number); private _preserveParentRotationForBillboard; /** * Gets or sets a boolean indicating that parent rotation should be preserved when using billboards. * This could be useful for glTF objects where parent rotation helps converting from right handed to left handed */ get preserveParentRotationForBillboard(): boolean; set preserveParentRotationForBillboard(value: boolean); private _computeUseBillboardPath; /** * Multiplication factor on scale x/y/z when computing the world matrix. Eg. for a 1x1x1 cube setting this to 2 will make it a 2x2x2 cube */ scalingDeterminant: number; private _infiniteDistance; /** * Gets or sets the distance of the object to max, often used by skybox */ get infiniteDistance(): boolean; set infiniteDistance(value: boolean); /** * Gets or sets a boolean indicating that non uniform scaling (when at least one component is different from others) should be ignored. * By default the system will update normals to compensate */ ignoreNonUniformScaling: boolean; /** * Gets or sets a boolean indicating that even if rotationQuaternion is defined, you can keep updating rotation property and Babylon.js will just mix both */ reIntegrateRotationIntoRotationQuaternion: boolean; /** @internal */ _poseMatrix: Nullable; /** @internal */ _localMatrix: Matrix; private _usePivotMatrix; private _absolutePosition; private _absoluteScaling; private _absoluteRotationQuaternion; private _pivotMatrix; private _pivotMatrixInverse; /** @internal */ _postMultiplyPivotMatrix: boolean; protected _isWorldMatrixFrozen: boolean; /** @internal */ _indexInSceneTransformNodesArray: number; /** * An event triggered after the world matrix is updated */ onAfterWorldMatrixUpdateObservable: Observable; constructor(name: string, scene?: Nullable, isPure?: boolean); /** * Gets a string identifying the name of the class * @returns "TransformNode" string */ getClassName(): string; /** * Gets or set the node position (default is (0.0, 0.0, 0.0)) */ get position(): Vector3; set position(newPosition: Vector3); /** * return true if a pivot has been set * @returns true if a pivot matrix is used */ isUsingPivotMatrix(): boolean; /** * @returns true if pivot matrix must be cancelled in the world matrix. When this parameter is set to true (default), the inverse of the pivot matrix is also applied at the end to cancel the transformation effect. */ isUsingPostMultiplyPivotMatrix(): boolean; /** * Gets or sets the rotation property : a Vector3 defining the rotation value in radians around each local axis X, Y, Z (default is (0.0, 0.0, 0.0)). * If rotation quaternion is set, this Vector3 will be ignored and copy from the quaternion */ get rotation(): Vector3; set rotation(newRotation: Vector3); /** * Gets or sets the scaling property : a Vector3 defining the node scaling along each local axis X, Y, Z (default is (1.0, 1.0, 1.0)). */ get scaling(): Vector3; set scaling(newScaling: Vector3); /** * Gets or sets the rotation Quaternion property : this a Quaternion object defining the node rotation by using a unit quaternion (undefined by default, but can be null). * If set, only the rotationQuaternion is then used to compute the node rotation (ie. node.rotation will be ignored) */ get rotationQuaternion(): Nullable; set rotationQuaternion(quaternion: Nullable); /** * The forward direction of that transform in world space. */ get forward(): Vector3; /** * The up direction of that transform in world space. */ get up(): Vector3; /** * The right direction of that transform in world space. */ get right(): Vector3; /** * Copies the parameter passed Matrix into the mesh Pose matrix. * @param matrix the matrix to copy the pose from * @returns this TransformNode. */ updatePoseMatrix(matrix: Matrix): TransformNode; /** * Returns the mesh Pose matrix. * @returns the pose matrix */ getPoseMatrix(): Matrix; /** @internal */ _isSynchronized(): boolean; /** @internal */ _initCache(): void; /** * Returns the current mesh absolute position. * Returns a Vector3. */ get absolutePosition(): Vector3; /** * Returns the current mesh absolute scaling. * Returns a Vector3. */ get absoluteScaling(): Vector3; /** * Returns the current mesh absolute rotation. * Returns a Quaternion. */ get absoluteRotationQuaternion(): Quaternion; /** * Sets a new matrix to apply before all other transformation * @param matrix defines the transform matrix * @returns the current TransformNode */ setPreTransformMatrix(matrix: Matrix): TransformNode; /** * Sets a new pivot matrix to the current node * @param matrix defines the new pivot matrix to use * @param postMultiplyPivotMatrix defines if the pivot matrix must be cancelled in the world matrix. When this parameter is set to true (default), the inverse of the pivot matrix is also applied at the end to cancel the transformation effect * @returns the current TransformNode */ setPivotMatrix(matrix: DeepImmutable, postMultiplyPivotMatrix?: boolean): TransformNode; /** * Returns the mesh pivot matrix. * Default : Identity. * @returns the matrix */ getPivotMatrix(): Matrix; /** * Instantiate (when possible) or clone that node with its hierarchy * @param newParent defines the new parent to use for the instance (or clone) * @param options defines options to configure how copy is done * @param options.doNotInstantiate defines if the model must be instantiated or just cloned * @param onNewNodeCreated defines an option callback to call when a clone or an instance is created * @returns an instance (or a clone) of the current node with its hierarchy */ instantiateHierarchy(newParent?: Nullable, options?: { doNotInstantiate: boolean | ((node: TransformNode) => boolean); }, onNewNodeCreated?: (source: TransformNode, clone: TransformNode) => void): Nullable; /** * Prevents the World matrix to be computed any longer * @param newWorldMatrix defines an optional matrix to use as world matrix * @param decompose defines whether to decompose the given newWorldMatrix or directly assign * @returns the TransformNode. */ freezeWorldMatrix(newWorldMatrix?: Nullable, decompose?: boolean): TransformNode; /** * Allows back the World matrix computation. * @returns the TransformNode. */ unfreezeWorldMatrix(): this; /** * True if the World matrix has been frozen. */ get isWorldMatrixFrozen(): boolean; /** * Returns the mesh absolute position in the World. * @returns a Vector3. */ getAbsolutePosition(): Vector3; /** * Sets the mesh absolute position in the World from a Vector3 or an Array(3). * @param absolutePosition the absolute position to set * @returns the TransformNode. */ setAbsolutePosition(absolutePosition: Vector3): TransformNode; /** * Sets the mesh position in its local space. * @param vector3 the position to set in localspace * @returns the TransformNode. */ setPositionWithLocalVector(vector3: Vector3): TransformNode; /** * Returns the mesh position in the local space from the current World matrix values. * @returns a new Vector3. */ getPositionExpressedInLocalSpace(): Vector3; /** * Translates the mesh along the passed Vector3 in its local space. * @param vector3 the distance to translate in localspace * @returns the TransformNode. */ locallyTranslate(vector3: Vector3): TransformNode; private static _LookAtVectorCache; /** * Orients a mesh towards a target point. Mesh must be drawn facing user. * @param targetPoint the position (must be in same space as current mesh) to look at * @param yawCor optional yaw (y-axis) correction in radians * @param pitchCor optional pitch (x-axis) correction in radians * @param rollCor optional roll (z-axis) correction in radians * @param space the chosen space of the target * @returns the TransformNode. */ lookAt(targetPoint: Vector3, yawCor?: number, pitchCor?: number, rollCor?: number, space?: Space): TransformNode; /** * Returns a new Vector3 that is the localAxis, expressed in the mesh local space, rotated like the mesh. * This Vector3 is expressed in the World space. * @param localAxis axis to rotate * @returns a new Vector3 that is the localAxis, expressed in the mesh local space, rotated like the mesh. */ getDirection(localAxis: Vector3): Vector3; /** * Sets the Vector3 "result" as the rotated Vector3 "localAxis" in the same rotation than the mesh. * localAxis is expressed in the mesh local space. * result is computed in the World space from the mesh World matrix. * @param localAxis axis to rotate * @param result the resulting transformnode * @returns this TransformNode. */ getDirectionToRef(localAxis: Vector3, result: Vector3): TransformNode; /** * Sets this transform node rotation to the given local axis. * @param localAxis the axis in local space * @param yawCor optional yaw (y-axis) correction in radians * @param pitchCor optional pitch (x-axis) correction in radians * @param rollCor optional roll (z-axis) correction in radians * @returns this TransformNode */ setDirection(localAxis: Vector3, yawCor?: number, pitchCor?: number, rollCor?: number): TransformNode; /** * Sets a new pivot point to the current node * @param point defines the new pivot point to use * @param space defines if the point is in world or local space (local by default) * @returns the current TransformNode */ setPivotPoint(point: Vector3, space?: Space): TransformNode; /** * Returns a new Vector3 set with the mesh pivot point coordinates in the local space. * @returns the pivot point */ getPivotPoint(): Vector3; /** * Sets the passed Vector3 "result" with the coordinates of the mesh pivot point in the local space. * @param result the vector3 to store the result * @returns this TransformNode. */ getPivotPointToRef(result: Vector3): TransformNode; /** * Returns a new Vector3 set with the mesh pivot point World coordinates. * @returns a new Vector3 set with the mesh pivot point World coordinates. */ getAbsolutePivotPoint(): Vector3; /** * Sets the Vector3 "result" coordinates with the mesh pivot point World coordinates. * @param result vector3 to store the result * @returns this TransformNode. */ getAbsolutePivotPointToRef(result: Vector3): TransformNode; /** * Flag the transform node as dirty (Forcing it to update everything) * @param property if set to "rotation" the objects rotationQuaternion will be set to null * @returns this node */ markAsDirty(property?: string): Node; /** * Defines the passed node as the parent of the current node. * The node will remain exactly where it is and its position / rotation will be updated accordingly. * Note that if the mesh has a pivot matrix / point defined it will be applied after the parent was updated. * In that case the node will not remain in the same space as it is, as the pivot will be applied. * To avoid this, you can set updatePivot to true and the pivot will be updated to identity * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/parent * @param node the node ot set as the parent * @param preserveScalingSign if true, keep scaling sign of child. Otherwise, scaling sign might change. * @param updatePivot if true, update the pivot matrix to keep the node in the same space as before * @returns this TransformNode. */ setParent(node: Nullable, preserveScalingSign?: boolean, updatePivot?: boolean): TransformNode; private _nonUniformScaling; /** * True if the scaling property of this object is non uniform eg. (1,2,1) */ get nonUniformScaling(): boolean; /** * @internal */ _updateNonUniformScalingState(value: boolean): boolean; /** * Attach the current TransformNode to another TransformNode associated with a bone * @param bone Bone affecting the TransformNode * @param affectedTransformNode TransformNode associated with the bone * @returns this object */ attachToBone(bone: Bone, affectedTransformNode: TransformNode): TransformNode; /** * Detach the transform node if its associated with a bone * @param resetToPreviousParent Indicates if the parent that was in effect when attachToBone was called should be set back or if we should set parent to null instead (defaults to the latter) * @returns this object */ detachFromBone(resetToPreviousParent?: boolean): TransformNode; private static _RotationAxisCache; /** * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in the given space. * space (default LOCAL) can be either Space.LOCAL, either Space.WORLD. * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used. * The passed axis is also normalized. * @param axis the axis to rotate around * @param amount the amount to rotate in radians * @param space Space to rotate in (Default: local) * @returns the TransformNode. */ rotate(axis: Vector3, amount: number, space?: Space): TransformNode; /** * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in world space. * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used. * The passed axis is also normalized. . * Method is based on http://www.euclideanspace.com/maths/geometry/affine/aroundPoint/index.htm * @param point the point to rotate around * @param axis the axis to rotate around * @param amount the amount to rotate in radians * @returns the TransformNode */ rotateAround(point: Vector3, axis: Vector3, amount: number): TransformNode; /** * Translates the mesh along the axis vector for the passed distance in the given space. * space (default LOCAL) can be either Space.LOCAL, either Space.WORLD. * @param axis the axis to translate in * @param distance the distance to translate * @param space Space to rotate in (Default: local) * @returns the TransformNode. */ translate(axis: Vector3, distance: number, space?: Space): TransformNode; /** * Adds a rotation step to the mesh current rotation. * x, y, z are Euler angles expressed in radians. * This methods updates the current mesh rotation, either mesh.rotation, either mesh.rotationQuaternion if it's set. * This means this rotation is made in the mesh local space only. * It's useful to set a custom rotation order different from the BJS standard one YXZ. * Example : this rotates the mesh first around its local X axis, then around its local Z axis, finally around its local Y axis. * ```javascript * mesh.addRotation(x1, 0, 0).addRotation(0, 0, z2).addRotation(0, 0, y3); * ``` * Note that `addRotation()` accumulates the passed rotation values to the current ones and computes the .rotation or .rotationQuaternion updated values. * Under the hood, only quaternions are used. So it's a little faster is you use .rotationQuaternion because it doesn't need to translate them back to Euler angles. * @param x Rotation to add * @param y Rotation to add * @param z Rotation to add * @returns the TransformNode. */ addRotation(x: number, y: number, z: number): TransformNode; /** * @internal */ protected _getEffectiveParent(): Nullable; /** * Returns whether the transform node world matrix computation needs the camera information to be computed. * This is the case when the node is a billboard or has an infinite distance for instance. * @returns true if the world matrix computation needs the camera information to be computed */ isWorldMatrixCameraDependent(): boolean; /** * Computes the world matrix of the node * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch * @param camera defines the camera used if different from the scene active camera (This is used with modes like Billboard or infinite distance) * @returns the world matrix */ computeWorldMatrix(force?: boolean, camera?: Nullable): Matrix; /** * Resets this nodeTransform's local matrix to Matrix.Identity(). * @param independentOfChildren indicates if all child nodeTransform's world-space transform should be preserved. */ resetLocalMatrix(independentOfChildren?: boolean): void; protected _afterComputeWorldMatrix(): void; /** * If you'd like to be called back after the mesh position, rotation or scaling has been updated. * @param func callback function to add * * @returns the TransformNode. */ registerAfterWorldMatrixUpdate(func: (mesh: TransformNode) => void): TransformNode; /** * Removes a registered callback function. * @param func callback function to remove * @returns the TransformNode. */ unregisterAfterWorldMatrixUpdate(func: (mesh: TransformNode) => void): TransformNode; /** * Gets the position of the current mesh in camera space * @param camera defines the camera to use * @returns a position */ getPositionInCameraSpace(camera?: Nullable): Vector3; /** * Returns the distance from the mesh to the active camera * @param camera defines the camera to use * @returns the distance */ getDistanceToCamera(camera?: Nullable): number; /** * Clone the current transform node * @param name Name of the new clone * @param newParent New parent for the clone * @param doNotCloneChildren Do not clone children hierarchy * @returns the new transform node */ clone(name: string, newParent: Nullable, doNotCloneChildren?: boolean): Nullable; /** * Serializes the objects information. * @param currentSerializationObject defines the object to serialize in * @returns the serialized object */ serialize(currentSerializationObject?: any): any; /** * Returns a new TransformNode object parsed from the source provided. * @param parsedTransformNode is the source. * @param scene the scene the object belongs to * @param rootUrl is a string, it's the root URL to prefix the `delayLoadingFile` property with * @returns a new TransformNode object parsed from the source provided. */ static Parse(parsedTransformNode: any, scene: Scene, rootUrl: string): TransformNode; /** * Get all child-transformNodes of this node * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored * @returns an array of TransformNode */ getChildTransformNodes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): TransformNode[]; /** * Releases resources associated with this transform node. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default) * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default) */ dispose(doNotRecurse?: boolean, disposeMaterialAndTextures?: boolean): void; /** * Uniformly scales the mesh to fit inside of a unit cube (1 X 1 X 1 units) * @param includeDescendants Use the hierarchy's bounding box instead of the mesh's bounding box. Default is false * @param ignoreRotation ignore rotation when computing the scale (ie. object will be axis aligned). Default is false * @param predicate predicate that is passed in to getHierarchyBoundingVectors when selecting which object should be included when scaling * @returns the current mesh */ normalizeToUnitCube(includeDescendants?: boolean, ignoreRotation?: boolean, predicate?: Nullable<(node: AbstractMesh) => boolean>): TransformNode; private _syncAbsoluteScalingAndRotation; }