UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

240 lines • 7.12 kB
/** * A Transform represents the position, rotation, and scale of an object in 3D space. * Think of it like the object's location, orientation, and size. * It has properties for {@link position} (like coordinates), {@link rotation} (how it's oriented), and {@link scale} (how big it is). * * @example * const t = new Transform(); * t.position.set(1,2,3); * * @author Alex Goldring * @copyright Company Named Limited (c) 2025 */ export class Transform { /** * * @param json * @returns {Transform} */ static fromJSON(json: any): Transform; /** * * @param {number[]|Float32Array} mat * @returns {Transform} */ static fromMatrix(mat: number[] | Float32Array): Transform; /** * @deprecated use {@link Quaternion.rotateTowards} instead * @param {Quaternion} sourceQuaternion * @param {Vector3} targetVector * @param {Number} limit */ static adjustRotation(sourceQuaternion: Quaternion, targetVector: Vector3, limit?: number): void; /** * @type {Vector3} * @readonly */ readonly position: Vector3; /** * Orientation represented as a quaternion. * If Euler (XYZ) angles are required - consult {@link Quaternion} for relevant method * @type {Quaternion} * @readonly */ readonly rotation: Quaternion; /** * @type {Vector3} * @readonly */ readonly scale: Vector3; /** * Affine transform matrix, {@link position}, {@link rotation}, and {@link scale} must match, but shear can be different. * Note: this is managed by the {@link Transform} itself unless {@link TransformFlags.AutomaticChangeDetection} is disabled; do not modify the matrix directly. * Generally, if you want to modify it - use {@link fromMatrix} method instead. * * If you're not comfortable with matrices, just leave defaults on and stick to primary attributes i.e. {@link position}, {@link rotation}, and {@link scale}. * @readonly * @type {Float32Array} */ readonly matrix: Float32Array; /** * Various bit flags, see {@link TransformFlags} * This should generally be accessed through {@link getFlag}/{@link setFlag} instead of modifying the value directly * @type {number} */ flags: number; /** * Current "forward" direction * NOTE that this vector is not live, meaning that if you modify transform, previously-obtained result will no longer be valid * @returns {Vector3} */ get forward(): Vector3; /** * Current "up" direction * @return {Vector3} */ get up(): Vector3; /** * Current "right" direction * @return {Vector3} */ get right(): Vector3; /** * Attach change listener * @param {function} handler * @param {*} [thisArg] */ subscribe(handler: Function, thisArg?: any): void; /** * Disconnect change listener * @param {function} handler * @param {*} [thisArg] */ unsubscribe(handler: Function, thisArg?: any): void; /** * * @param {number|TransformFlags} flag * @returns {void} */ setFlag(flag: number | TransformFlags): void; /** * * @param {number|TransformFlags} flag * @returns {void} */ clearFlag(flag: number | TransformFlags): void; /** * * @param {number|TransformFlags} flag * @param {boolean} value */ writeFlag(flag: number | TransformFlags, value: boolean): void; /** * * @param {number|TransformFlags} flag * @returns {boolean} */ getFlag(flag: number | TransformFlags): boolean; /** * Update {@link matrix} attribute from current {@link position}/{@link rotation}/{@link scale} * * Useful for when {@link TransformFlags.AutomaticChangeDetection} is disabled. */ updateMatrix(): void; /** * * @param {Vector3} target * @param {Vector3} [up] */ lookAt(target: Vector3, up?: Vector3): void; fromJSON(json: any): void; toJSON(): { position: { x: number; y: number; z: number; }; rotation: { x: number; y: number; z: number; w: number; }; scale: { x: number; y: number; z: number; }; }; /** * Set this transform to match `other`. * Afterward `this.equals(other) === true`. * The `other` is unchanged in the process. * @param {Transform} other */ copy(other: Transform): void; /** * * @returns {Transform} */ clone(): Transform; /** * Strict equality check * @param {Transform} other * @returns {boolean} */ equals(other: Transform): boolean; /** * * @returns {number} */ hash(): number; /** * This is a post-multiplication, `this = this * other`. * The result of the multiplication is written into this transform. * * @param {Transform} other * @returns {this} */ multiply(other: Transform): this; /** * Multiply two transforms, result it written into this one * @param {Transform} a * @param {Transform} b * @returns {this} */ multiplyTransforms(a: Transform, b: Transform): this; /** * * @param {mat4|number[]|Float32Array} matrix 4x4 affine matrix * @returns {this} */ fromMatrix(matrix: mat4 | number[] | Float32Array): this; /** * Write out the current transform to a supplied container * @param {number[]|Float32Array} [result] if not provided, `Float32Array` of size 16 will be created * @returns {number[]} same as the input */ toMatrix(result?: number[] | Float32Array): number[]; /** * reset transform, resulting transform is an identity matrix * - position: [0,0,0] * - rotation: [0,0,0,1] * - scale: [1,1,1] */ makeIdentity(): void; /** * Identity Transform is where position is 0, rotation is 0 (un-rotated) and scale is 1 * @returns {boolean} */ isIdentity(): boolean; toString(): string; /** * Enables a fast type check, without having to import the class separately. * @readonly * @type {boolean} * @example * if(t.isTransform){ * // t is a Transform, do stuff * } */ readonly isTransform: boolean; /** * @readonly * @deprecated use {@link Transform.prototype.toMatrix} instead */ readonly toMatrix4: (result?: number[] | Float32Array) => number[]; /** * @readonly * @deprecated use {@link Transform.prototype.fromMatrix} instead */ readonly fromMatrix4: (matrix: mat4 | number[] | Float32Array) => this; #private; } export namespace Transform { let typeName: string; } import Vector3 from "../../../core/geom/Vector3.js"; import Quaternion from "../../../core/geom/Quaternion.js"; import { TransformFlags } from "./TransformFlags.js"; //# sourceMappingURL=Transform.d.ts.map