/** * A collision volume. Use this in conjunction with a {@link RigidBodyComponent} to make a * collision volume that can be simulated using the physics engine. * * If the {@link Entity} does not have a {@link RigidBodyComponent} then this collision volume will * act as a trigger volume. When an entity with a dynamic or kinematic body enters or leaves an * entity with a trigger volume, both entities will receive trigger events. * * The following table shows all the events that can be fired between two Entities: * * | | Rigid Body (Static) | Rigid Body (Dynamic or Kinematic) | Trigger Volume | * | ------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------- | * | **Rigid Body (Static)** | | | | * | **Rigid Body (Dynamic or Kinematic)** | | | | * | **Trigger Volume** | | | | * * @category Physics */ export class CollisionComponent extends Component { /** * Fired when a contact occurs between two rigid bodies. The handler is passed a * {@link ContactResult} object which contains details of the contact between the two rigid * bodies. * * @event * @example * entity.collision.on('contact', (result) => { * console.log(`Contact between ${entity.name} and ${result.other.name}`); * }); */ static EVENT_CONTACT: string; /** * Fired when two rigid bodies start touching. The handler is passed the {@link ContactResult} * object which contains details of the contact between the two rigid bodies. * * @event * @example * entity.collision.on('collisionstart', (result) => { * console.log(`${entity.name} started touching ${result.other.name}`); * }); */ static EVENT_COLLISIONSTART: string; /** * Fired when two rigid bodies stop touching. The handler is passed an {@link Entity} that * represents the other rigid body involved in the collision. * * @event * @example * entity.collision.on('collisionend', (other) => { * console.log(`${entity.name} stopped touching ${other.name}`); * }); */ static EVENT_COLLISIONEND: string; /** * Fired when a rigid body enters a trigger volume. The handler is passed an {@link Entity} * representing the rigid body that entered this collision volume. * * @event * @example * entity.collision.on('triggerenter', (other) => { * console.log(`${other.name} entered trigger volume ${entity.name}`); * }); */ static EVENT_TRIGGERENTER: string; /** * Fired when a rigid body exits a trigger volume. The handler is passed an {@link Entity} * representing the rigid body that exited this collision volume. * * @event * @example * entity.collision.on('triggerleave', (other) => { * console.log(`${other.name} exited trigger volume ${entity.name}`); * }); */ static EVENT_TRIGGERLEAVE: string; /** * Create a new CollisionComponent. * * @param {import('./system.js').CollisionComponentSystem} system - The ComponentSystem that * created this Component. * @param {import('../../entity.js').Entity} entity - The Entity that this Component is * attached to. */ constructor(system: import("./system.js").CollisionComponentSystem, entity: import("../../entity.js").Entity); /** @private */ private _compoundParent; _hasOffset: boolean; /** * @type {import('./data.js').CollisionComponentData} * @ignore */ get data(): import("./data.js").CollisionComponentData; /** * Sets the type of the collision volume. Can be: * * - "box": A box-shaped collision volume. * - "capsule": A capsule-shaped collision volume. * - "compound": A compound shape. Any descendant entities with a collision component of type * box, capsule, cone, cylinder or sphere will be combined into a single, rigid shape. * - "cone": A cone-shaped collision volume. * - "cylinder": A cylinder-shaped collision volume. * - "mesh": A collision volume that uses a model asset as its shape. * - "sphere": A sphere-shaped collision volume. * * Defaults to "box". * * @type {string} */ set type(arg: string); /** * Gets the type of the collision volume. * * @type {string} */ get type(): string; /** * Sets the half-extents of the box-shaped collision volume in the x, y and z axes. Defaults to * `[0.5, 0.5, 0.5]`. * * @type {Vec3} */ set halfExtents(arg: Vec3); /** * Gets the half-extents of the box-shaped collision volume in the x, y and z axes. * * @type {Vec3} */ get halfExtents(): Vec3; /** * Sets the positional offset of the collision shape from the Entity position along the local * axes. Defaults to `[0, 0, 0]`. * * @type {Vec3} */ set linearOffset(arg: Vec3); /** * Gets the positional offset of the collision shape from the Entity position along the local * axes. * * @type {Vec3} */ get linearOffset(): Vec3; /** * Sets the rotational offset of the collision shape from the Entity rotation in local space. * Defaults to identity. * * @type {Quat} */ set angularOffset(arg: Quat); /** * Gets the rotational offset of the collision shape from the Entity rotation in local space. * * @type {Quat} */ get angularOffset(): Quat; /** * Sets the radius of the sphere, capsule, cylinder or cone-shaped collision volumes. * Defaults to 0.5. * * @type {number} */ set radius(arg: number); /** * Gets the radius of the sphere, capsule, cylinder or cone-shaped collision volumes. * * @type {number} */ get radius(): number; /** * Sets the local space axis with which the capsule, cylinder or cone-shaped collision volume's * length is aligned. 0 for X, 1 for Y and 2 for Z. Defaults to 1 (Y-axis). * * @type {number} */ set axis(arg: number); /** * Gets the local space axis with which the capsule, cylinder or cone-shaped collision volume's * length is aligned. * * @type {number} */ get axis(): number; /** * Sets the total height of the capsule, cylinder or cone-shaped collision volume from tip to * tip. Defaults to 2. * * @type {number} */ set height(arg: number); /** * Gets the total height of the capsule, cylinder or cone-shaped collision volume from tip to * tip. * * @type {number} */ get height(): number; /** * Sets the asset or asset id for the model of the mesh collision volume. Defaults to null. * * @type {Asset|number|null} */ set asset(arg: Asset | number | null); /** * Gets the asset or asset id for the model of the mesh collision volume. * * @type {Asset|number|null} */ get asset(): Asset | number | null; /** * Sets the render asset or asset id of the mesh collision volume. Defaults to null. * If not set then the asset property will be checked instead. * * @type {Asset|number|null} */ set renderAsset(arg: Asset | number | null); /** * Gets the render asset id of the mesh collision volume. * * @type {Asset|number|null} */ get renderAsset(): Asset | number | null; /** * Sets whether the collision mesh should be treated as a convex hull. When false, the mesh can * only be used with a static body. When true, the mesh can be used with a static, dynamic or * kinematic body. Defaults to `false`. * * @type {boolean} */ set convexHull(arg: boolean); /** * Gets whether the collision mesh should be treated as a convex hull. * * @type {boolean} */ get convexHull(): boolean; set shape(arg: any); get shape(): any; /** * Sets the model that is added to the scene graph for the mesh collision volume. * * @type {import('../../../scene/model.js').Model | null} */ set model(arg: import("../../../scene/model.js").Model | null); /** * Gets the model that is added to the scene graph for the mesh collision volume. * * @type {import('../../../scene/model.js').Model | null} */ get model(): import("../../../scene/model.js").Model | null; set render(arg: any); get render(): any; /** * Sets whether checking for duplicate vertices should be enabled when creating collision meshes. * * @type {boolean} */ set checkVertexDuplicates(arg: boolean); /** * Gets whether checking for duplicate vertices should be enabled when creating collision meshes. * * @type {boolean} */ get checkVertexDuplicates(): boolean; /** @ignore */ _setValue(name: any, value: any): void; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetType; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetHalfExtents; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetOffset; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetRadius; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetHeight; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetAxis; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetAsset; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetRenderAsset; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetModel; /** * @param {string} name - Property name. * @param {*} oldValue - Previous value of the property. * @param {*} newValue - New value of the property. * @private */ private onSetRender; /** * @param {Asset} asset - Asset that was removed. * @private */ private onAssetRemoved; /** * @param {Asset} asset - Asset that was removed. * @private */ private onRenderAssetRemoved; /** * @param {*} shape - Ammo shape. * @returns {number|null} The shape's index in the child array of the compound shape. * @private */ private getCompoundChildShapeIndex; /** * @param {import('../../../scene/graph-node.js').GraphNode} parent - The parent node. * @private */ private _onInsert; /** @private */ private _updateCompound; /** * Returns the world position for the collision shape, taking into account of any offsets. * * @returns {Vec3} The world position for the collision shape. */ getShapePosition(): Vec3; /** * Returns the world rotation for the collision shape, taking into account of any offsets. * * @returns {Quat} The world rotation for the collision. */ getShapeRotation(): Quat; /** @private */ private onBeforeRemove; } import { Component } from '../component.js'; import { Vec3 } from '../../../core/math/vec3.js'; import { Quat } from '../../../core/math/quat.js'; import { Asset } from '../../asset/asset.js';