/** * Options of the `collision` component accepted by {@link CollisionComponentSystem} that differ * from the properties of {@link CollisionComponent}. Each replaces the same-named property of the * options that {@link Entity#addComponent} derives from the component class; see * {@link ComponentOptionsOverrides}. */ export type CollisionComponentOptionsOverrides = { /** * - Same as {@link CollisionComponent#angularOffset}, * also accepting `[x, y, z]` Euler angles in degrees or an `[x, y, z, w]` quaternion array. */ angularOffset?: Quat | number[]; /** * - Same as {@link CollisionComponent#halfExtents}, also * accepting an `[x, y, z]` array. */ halfExtents?: Vec3 | number[]; /** * - Same as {@link CollisionComponent#linearOffset}, * also accepting an `[x, y, z]` array. */ linearOffset?: Vec3 | number[]; }; /** * Manages the {@link CollisionComponent}s of an application. Reach it through * `app.systems.collision`; components are created with {@link Entity#addComponent}, never by * calling the system directly. * * @category Physics */ export class CollisionComponentSystem extends ComponentSystem { /** * The mesh components with a built shape, watched for changes to their entity world scale. * Maintained by createMeshShape and beforeRemove. * * @type {CollisionComponent[]} * @private */ private _meshComponents; id: string; ComponentType: typeof CollisionComponent; /** * The physics backend installed on the rigid body system, or null. * * @type {*} * @ignore */ get physicsWorld(): any; initializeComponentData(component: any, data: any): void; cloneComponent(entity: any, clone: any): import("../component.js").Component; /** * Destroys the shape of a component that is being removed and discards the collisions * stored for its entity. * * @param {Entity} entity - The entity the component is being removed from. * @param {CollisionComponent} component - The component being removed. * @private */ private onBeforeRemove; /** * Takes the entity's rigid body out of the simulation and destroys its trigger. Runs once the * component has been removed, and when its shape is torn down to be rebuilt. * * @param {Entity} entity - The entity of the component. * @private */ private onRemove; /** * Writes a compound child's pose relative to its compound root into the compound shape, * adding the child when it is absent. Disabled children are skipped. Unless forced, the * write is also skipped when no local transform between the child and the root has changed * since the last write, which is decided from stored local vectors without any matrix math, * so the root moving as a whole costs nothing beyond the comparison. * * @param {Entity} entity - The compound child's entity. * @param {boolean} forceUpdate - Write regardless, for a child known to be absent from the * compound. * @returns {boolean} True if the compound shape was written. * @ignore */ updateCompoundChildTransform(entity: Entity, forceUpdate: boolean): boolean; /** * Returns true if a compound child is wired to a compound that is still one of its ancestors * and nothing between them has changed since its shape was last written, so the shape is * already where the hierarchy says it should be. * * @param {CollisionComponent} component - The compound child. * @returns {boolean} True if the child's shape is in place. * @ignore */ isCompoundChildInPlace(component: CollisionComponent): boolean; _removeCompoundChild(collision: any, shape: any): void; /** * Starts watching a mesh component's entity world scale (see _updateMeshScales). * * @param {CollisionComponent} component - The mesh collision component. * @private */ private _watchMeshScale; /** * Stops watching a component's entity world scale. * * @param {CollisionComponent} component - The collision component. * @private */ private _unwatchMeshScale; /** * Rebuilds the mesh shapes whose entity world scale no longer matches the scale they were * built with. Driven by the rigid body system at the start of each physics step, so like * the other entity to physics syncs it pauses with the simulation and the first step after * resuming catches up. * * @ignore */ _updateMeshScales(): void; changeType(component: any, previousType: any, newType: any): void; recreatePhysicalShapes(component: any): void; /** * Rebuilds a mesh component's shape from its current model or render sources, skipping any * asset loading. Used by the mesh source setters, which assign the resource directly. * * @param {CollisionComponent} component - The mesh collision component to rebuild. * @ignore */ doRecreatePhysicalShape(component: CollisionComponent): void; /** * An {@link Entity#forEach} callback that wires a descendant of a compound root to it and * rebuilds the descendant's shape. Invoked with `this` set to the compound root component. * * @param {Entity} entity - The visited descendant entity. * @private */ private _addEachDescendant; /** * Writes the transform of a node relative to one of its ancestors to the shared scratch * matrix: the signed world scale of the ancestor, followed by the local transforms of the * nodes below it down to the node itself. * * @param {GraphNode} node - The node. * @param {GraphNode} relative - The ancestor. * @private */ private _calculateNodeRelativeTransform; /** * Computes a node's pose (with any collision component offsets applied), optionally * relative to an ancestor node, ignoring scale. * * @param {GraphNode} node - The node to read. * @param {GraphNode|null} relative - The ancestor to compute the pose relative to, or null * for the world pose. * @param {Vec3} position - The vector to write the position to. * @param {Quat} rotation - The quaternion to write the rotation to. * @private */ private _getNodeTransform; } import { Quat } from '../../../core/math/quat.js'; import { Vec3 } from '../../../core/math/vec3.js'; import { ComponentSystem } from '../system.js'; import { CollisionComponent } from './component.js'; import type { Entity } from '../../entity.js';