main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import { RawBroadPhase } from "../raw";
/**
* The broad-phase used for coarse collision-detection.
*
* To avoid leaking WASM resources, this MUST be freed manually with `broadPhase.free()`
* once you are done using it.
*/
export declare class BroadPhase {
raw: RawBroadPhase;
/**
* Release the WASM memory occupied by this broad-phase.
*/
free(): void;
constructor(raw?: RawBroadPhase);
}

View File

@@ -0,0 +1,763 @@
import { Rotation, Vector } from "../math";
import { CoefficientCombineRule, RigidBody, RigidBodySet } from "../dynamics";
import { ActiveHooks, ActiveEvents } from "../pipeline";
import { InteractionGroups } from "./interaction_groups";
import { Shape, ShapeType } from "./shape";
import { Ray, RayIntersection } from "./ray";
import { PointProjection } from "./point";
import { ShapeColliderTOI, ShapeTOI } from "./toi";
import { ShapeContact } from "./contact";
import { ColliderSet } from "./collider_set";
/**
* Flags affecting whether collision-detection happens between two colliders
* depending on the type of rigid-bodies they are attached to.
*/
export declare enum ActiveCollisionTypes {
/**
* Enable collision-detection between a collider attached to a dynamic body
* and another collider attached to a dynamic body.
*/
DYNAMIC_DYNAMIC = 1,
/**
* Enable collision-detection between a collider attached to a dynamic body
* and another collider attached to a kinematic body.
*/
DYNAMIC_KINEMATIC = 12,
/**
* Enable collision-detection between a collider attached to a dynamic body
* and another collider attached to a fixed body (or not attached to any body).
*/
DYNAMIC_FIXED = 2,
/**
* Enable collision-detection between a collider attached to a kinematic body
* and another collider attached to a kinematic body.
*/
KINEMATIC_KINEMATIC = 52224,
/**
* Enable collision-detection between a collider attached to a kinematic body
* and another collider attached to a fixed body (or not attached to any body).
*/
KINEMATIC_FIXED = 8704,
/**
* Enable collision-detection between a collider attached to a fixed body (or
* not attached to any body) and another collider attached to a fixed body (or
* not attached to any body).
*/
FIXED_FIXED = 32,
/**
* The default active collision types, enabling collisions between a dynamic body
* and another body of any type, but not enabling collisions between two non-dynamic bodies.
*/
DEFAULT = 15,
/**
* Enable collisions between any kind of rigid-bodies (including between two non-dynamic bodies).
*/
ALL = 60943
}
/**
* The integer identifier of a collider added to a `ColliderSet`.
*/
export declare type ColliderHandle = number;
/**
* A geometric entity that can be attached to a body so it can be affected
* by contacts and proximity queries.
*/
export declare class Collider {
private colliderSet;
readonly handle: ColliderHandle;
private _shape;
private _parent;
constructor(colliderSet: ColliderSet, handle: ColliderHandle, parent: RigidBody | null, shape?: Shape);
/** @internal */
finalizeDeserialization(bodies: RigidBodySet): void;
private ensureShapeIsCached;
/**
* The shape of this collider.
*/
get shape(): Shape;
/**
* Checks if this collider is still valid (i.e. that it has
* not been deleted from the collider set yet).
*/
isValid(): boolean;
/**
* The world-space translation of this rigid-body.
*/
translation(): Vector;
/**
* The world-space orientation of this rigid-body.
*/
rotation(): Rotation;
/**
* Is this collider a sensor?
*/
isSensor(): boolean;
/**
* Sets whether or not this collider is a sensor.
* @param isSensor - If `true`, the collider will be a sensor.
*/
setSensor(isSensor: boolean): void;
/**
* Sets the new shape of the collider.
* @param shape - The colliders new shape.
*/
setShape(shape: Shape): void;
/**
* Sets whether this collider is enabled or not.
*
* @param enabled - Set to `false` to disable this collider (its parent rigid-body wont be disabled automatically by this).
*/
setEnabled(enabled: boolean): void;
/**
* Is this collider enabled?
*/
isEnabled(): boolean;
/**
* Sets the restitution coefficient of the collider to be created.
*
* @param restitution - The restitution coefficient in `[0, 1]`. A value of 0 (the default) means no bouncing behavior
* while 1 means perfect bouncing (though energy may still be lost due to numerical errors of the
* constraints solver).
*/
setRestitution(restitution: number): void;
/**
* Sets the friction coefficient of the collider to be created.
*
* @param friction - The friction coefficient. Must be greater or equal to 0. This is generally smaller than 1. The
* higher the coefficient, the stronger friction forces will be for contacts with the collider
* being built.
*/
setFriction(friction: number): void;
/**
* Gets the rule used to combine the friction coefficients of two colliders
* colliders involved in a contact.
*/
frictionCombineRule(): CoefficientCombineRule;
/**
* Sets the rule used to combine the friction coefficients of two colliders
* colliders involved in a contact.
*
* @param rule The combine rule to apply.
*/
setFrictionCombineRule(rule: CoefficientCombineRule): void;
/**
* Gets the rule used to combine the restitution coefficients of two colliders
* colliders involved in a contact.
*/
restitutionCombineRule(): CoefficientCombineRule;
/**
* Sets the rule used to combine the restitution coefficients of two colliders
* colliders involved in a contact.
*
* @param rule The combine rule to apply.
*/
setRestitutionCombineRule(rule: CoefficientCombineRule): void;
/**
* Sets the collision groups used by this collider.
*
* Two colliders will interact iff. their collision groups are compatible.
* See the documentation of `InteractionGroups` for details on teh used bit pattern.
*
* @param groups - The collision groups used for the collider being built.
*/
setCollisionGroups(groups: InteractionGroups): void;
/**
* Sets the solver groups used by this collider.
*
* Forces between two colliders in contact will be computed iff their solver
* groups are compatible.
* See the documentation of `InteractionGroups` for details on the used bit pattern.
*
* @param groups - The solver groups used for the collider being built.
*/
setSolverGroups(groups: InteractionGroups): void;
/**
* Get the physics hooks active for this collider.
*/
activeHooks(): number;
/**
* Set the physics hooks active for this collider.
*
* Use this to enable custom filtering rules for contact/intersecstion pairs involving this collider.
*
* @param activeHooks - The hooks active for contact/intersection pairs involving this collider.
*/
setActiveHooks(activeHooks: ActiveHooks): void;
/**
* The events active for this collider.
*/
activeEvents(): ActiveEvents;
/**
* Set the events active for this collider.
*
* Use this to enable contact and/or intersection event reporting for this collider.
*
* @param activeEvents - The events active for contact/intersection pairs involving this collider.
*/
setActiveEvents(activeEvents: ActiveEvents): void;
/**
* Gets the collision types active for this collider.
*/
activeCollisionTypes(): ActiveCollisionTypes;
/**
* Sets the total force magnitude beyond which a contact force event can be emitted.
*
* @param threshold - The new force threshold.
*/
setContactForceEventThreshold(threshold: number): void;
/**
* The total force magnitude beyond which a contact force event can be emitted.
*/
contactForceEventThreshold(): number;
/**
* Set the collision types active for this collider.
*
* @param activeCollisionTypes - The hooks active for contact/intersection pairs involving this collider.
*/
setActiveCollisionTypes(activeCollisionTypes: ActiveCollisionTypes): void;
/**
* Sets the uniform density of this collider.
*
* This will override any previous mass-properties set by `this.setDensity`,
* `this.setMass`, `this.setMassProperties`, `ColliderDesc.density`,
* `ColliderDesc.mass`, or `ColliderDesc.massProperties` for this collider.
*
* The mass and angular inertia of this collider will be computed automatically based on its
* shape.
*/
setDensity(density: number): void;
/**
* Sets the mass of this collider.
*
* This will override any previous mass-properties set by `this.setDensity`,
* `this.setMass`, `this.setMassProperties`, `ColliderDesc.density`,
* `ColliderDesc.mass`, or `ColliderDesc.massProperties` for this collider.
*
* The angular inertia of this collider will be computed automatically based on its shape
* and this mass value.
*/
setMass(mass: number): void;
/**
* Sets the mass of this collider.
*
* This will override any previous mass-properties set by `this.setDensity`,
* `this.setMass`, `this.setMassProperties`, `ColliderDesc.density`,
* `ColliderDesc.mass`, or `ColliderDesc.massProperties` for this collider.
*/
setMassProperties(mass: number, centerOfMass: Vector, principalAngularInertia: Vector, angularInertiaLocalFrame: Rotation): void;
/**
* Sets the translation of this collider.
*
* @param tra - The world-space position of the collider.
*/
setTranslation(tra: Vector): void;
/**
* Sets the translation of this collider relative to its parent rigid-body.
*
* Does nothing if this collider isn't attached to a rigid-body.
*
* @param tra - The new translation of the collider relative to its parent.
*/
setTranslationWrtParent(tra: Vector): void;
/**
* Sets the rotation quaternion of this collider.
*
* This does nothing if a zero quaternion is provided.
*
* @param rotation - The rotation to set.
*/
setRotation(rot: Rotation): void;
/**
* Sets the rotation quaternion of this collider relative to its parent rigid-body.
*
* This does nothing if a zero quaternion is provided or if this collider isn't
* attached to a rigid-body.
*
* @param rotation - The rotation to set.
*/
setRotationWrtParent(rot: Rotation): void;
/**
* The type of the shape of this collider.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
shapeType(): ShapeType;
/**
* The half-extents of this collider if it is a cuboid shape.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
halfExtents(): Vector;
/**
* Sets the half-extents of this collider if it is a cuboid shape.
*
* @param newHalfExtents - desired half extents.
*/
setHalfExtents(newHalfExtents: Vector): void;
/**
* The radius of this collider if it is a ball, cylinder, capsule, or cone shape.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
radius(): number;
/**
* Sets the radius of this collider if it is a ball, cylinder, capsule, or cone shape.
*
* @param newRadius - desired radius.
*/
setRadius(newRadius: number): void;
/**
* The radius of the round edges of this collider if it is a round cylinder.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
roundRadius(): number;
/**
* Sets the radius of the round edges of this collider if it has round edges.
*
* @param newBorderRadius - desired round edge radius.
*/
setRoundRadius(newBorderRadius: number): void;
/**
* The half height of this collider if it is a cylinder, capsule, or cone shape.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
halfHeight(): number;
/**
* Sets the half height of this collider if it is a cylinder, capsule, or cone shape.
*
* @param newHalfheight - desired half height.
*/
setHalfHeight(newHalfheight: number): void;
/**
* If this collider has a triangle mesh, polyline, convex polygon, or convex polyhedron shape,
* this returns the vertex buffer of said shape.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
vertices(): Float32Array;
/**
* If this collider has a triangle mesh, polyline, or convex polyhedron shape,
* this returns the index buffer of said shape.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
indices(): Uint32Array | undefined;
/**
* If this collider has a heightfield shape, this returns the heights buffer of
* the heightfield.
* In 3D, the returned height matrix is provided in column-major order.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
heightfieldHeights(): Float32Array;
/**
* If this collider has a heightfield shape, this returns the scale
* applied to it.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
heightfieldScale(): Vector;
/**
* If this collider has a heightfield shape, this returns the number of
* rows of its height matrix.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
heightfieldNRows(): number;
/**
* If this collider has a heightfield shape, this returns the number of
* columns of its height matrix.
* @deprecated this field will be removed in the future, please access this field on `shape` member instead.
*/
heightfieldNCols(): number;
/**
* The rigid-body this collider is attached to.
*/
parent(): RigidBody | null;
/**
* The friction coefficient of this collider.
*/
friction(): number;
/**
* The restitution coefficient of this collider.
*/
restitution(): number;
/**
* The density of this collider.
*/
density(): number;
/**
* The mass of this collider.
*/
mass(): number;
/**
* The volume of this collider.
*/
volume(): number;
/**
* The collision groups of this collider.
*/
collisionGroups(): InteractionGroups;
/**
* The solver groups of this collider.
*/
solverGroups(): InteractionGroups;
/**
* Tests if this collider contains a point.
*
* @param point - The point to test.
*/
containsPoint(point: Vector): boolean;
/**
* Find the projection of a point on this collider.
*
* @param point - The point to project.
* @param solid - If this is set to `true` then the collider shapes are considered to
* be plain (if the point is located inside of a plain shape, its projection is the point
* itself). If it is set to `false` the collider shapes are considered to be hollow
* (if the point is located inside of an hollow shape, it is projected on the shape's
* boundary).
*/
projectPoint(point: Vector, solid: boolean): PointProjection | null;
/**
* Tests if this collider intersects the given ray.
*
* @param ray - The ray to cast.
* @param maxToi - The maximum time-of-impact that can be reported by this cast. This effectively
* limits the length of the ray to `ray.dir.norm() * maxToi`.
*/
intersectsRay(ray: Ray, maxToi: number): boolean;
castShape(collider1Vel: Vector, shape2: Shape, shape2Pos: Vector, shape2Rot: Rotation, shape2Vel: Vector, maxToi: number, stopAtPenetration: boolean): ShapeTOI | null;
castCollider(collider1Vel: Vector, collider2: Collider, collider2Vel: Vector, maxToi: number, stopAtPenetration: boolean): ShapeColliderTOI | null;
intersectsShape(shape2: Shape, shapePos2: Vector, shapeRot2: Rotation): boolean;
/**
* Computes one pair of contact points between the shape owned by this collider and the given shape.
*
* @param shape2 - The second shape.
* @param shape2Pos - The initial position of the second shape.
* @param shape2Rot - The rotation of the second shape.
* @param prediction - The prediction value, if the shapes are separated by a distance greater than this value, test will fail.
* @returns `null` if the shapes are separated by a distance greater than prediction, otherwise contact details. The result is given in world-space.
*/
contactShape(shape2: Shape, shape2Pos: Vector, shape2Rot: Rotation, prediction: number): ShapeContact | null;
/**
* Computes one pair of contact points between the collider and the given collider.
*
* @param collider2 - The second collider.
* @param prediction - The prediction value, if the shapes are separated by a distance greater than this value, test will fail.
* @returns `null` if the shapes are separated by a distance greater than prediction, otherwise contact details. The result is given in world-space.
*/
contactCollider(collider2: Collider, prediction: number): ShapeContact | null;
castRay(ray: Ray, maxToi: number, solid: boolean): number;
/**
* Find the closest intersection between a ray and this collider.
*
* This also computes the normal at the hit point.
* @param ray - The ray to cast.
* @param maxToi - The maximum time-of-impact that can be reported by this cast. This effectively
* limits the length of the ray to `ray.dir.norm() * maxToi`.
* @param solid - If `false` then the ray will attempt to hit the boundary of a shape, even if its
* origin already lies inside of a shape. In other terms, `true` implies that all shapes are plain,
* whereas `false` implies that all shapes are hollow for this ray-cast.
*/
castRayAndGetNormal(ray: Ray, maxToi: number, solid: boolean): RayIntersection | null;
}
export declare enum MassPropsMode {
Density = 0,
Mass = 1,
MassProps = 2
}
export declare class ColliderDesc {
enabled: boolean;
shape: Shape;
massPropsMode: MassPropsMode;
mass: number;
centerOfMass: Vector;
principalAngularInertia: Vector;
angularInertiaLocalFrame: Rotation;
density: number;
friction: number;
restitution: number;
rotation: Rotation;
translation: Vector;
isSensor: boolean;
collisionGroups: InteractionGroups;
solverGroups: InteractionGroups;
frictionCombineRule: CoefficientCombineRule;
restitutionCombineRule: CoefficientCombineRule;
activeEvents: ActiveEvents;
activeHooks: ActiveHooks;
activeCollisionTypes: ActiveCollisionTypes;
contactForceEventThreshold: number;
/**
* Initializes a collider descriptor from the collision shape.
*
* @param shape - The shape of the collider being built.
*/
constructor(shape: Shape);
/**
* Create a new collider descriptor with a ball shape.
*
* @param radius - The radius of the ball.
*/
static ball(radius: number): ColliderDesc;
/**
* Create a new collider descriptor with a capsule shape.
*
* @param halfHeight - The half-height of the capsule, along the `y` axis.
* @param radius - The radius of the capsule basis.
*/
static capsule(halfHeight: number, radius: number): ColliderDesc;
/**
* Creates a new segment shape.
*
* @param a - The first point of the segment.
* @param b - The second point of the segment.
*/
static segment(a: Vector, b: Vector): ColliderDesc;
/**
* Creates a new triangle shape.
*
* @param a - The first point of the triangle.
* @param b - The second point of the triangle.
* @param c - The third point of the triangle.
*/
static triangle(a: Vector, b: Vector, c: Vector): ColliderDesc;
/**
* Creates a new triangle shape with round corners.
*
* @param a - The first point of the triangle.
* @param b - The second point of the triangle.
* @param c - The third point of the triangle.
* @param borderRadius - The radius of the borders of this triangle. In 3D,
* this is also equal to half the thickness of the triangle.
*/
static roundTriangle(a: Vector, b: Vector, c: Vector, borderRadius: number): ColliderDesc;
/**
* Creates a new collider descriptor with a polyline shape.
*
* @param vertices - The coordinates of the polyline's vertices.
* @param indices - The indices of the polyline's segments. If this is `undefined` or `null`,
* the vertices are assumed to describe a line strip.
*/
static polyline(vertices: Float32Array, indices?: Uint32Array | null): ColliderDesc;
/**
* Creates a new collider descriptor with a triangle mesh shape.
*
* @param vertices - The coordinates of the triangle mesh's vertices.
* @param indices - The indices of the triangle mesh's triangles.
*/
static trimesh(vertices: Float32Array, indices: Uint32Array): ColliderDesc;
/**
* Creates a new collider descriptor with a cuboid shape.
*
* @param hx - The half-width of the rectangle along its local `x` axis.
* @param hy - The half-width of the rectangle along its local `y` axis.
* @param hz - The half-width of the rectangle along its local `z` axis.
*/
static cuboid(hx: number, hy: number, hz: number): ColliderDesc;
/**
* Creates a new collider descriptor with a rectangular shape with round borders.
*
* @param hx - The half-width of the rectangle along its local `x` axis.
* @param hy - The half-width of the rectangle along its local `y` axis.
* @param hz - The half-width of the rectangle along its local `z` axis.
* @param borderRadius - The radius of the cuboid's borders.
*/
static roundCuboid(hx: number, hy: number, hz: number, borderRadius: number): ColliderDesc;
/**
* Creates a new collider descriptor with a heightfield shape.
*
* @param nrows The number of rows in the heights matrix.
* @param ncols - The number of columns in the heights matrix.
* @param heights - The heights of the heightfield along its local `y` axis,
* provided as a matrix stored in column-major order.
* @param scale - The scale factor applied to the heightfield.
*/
static heightfield(nrows: number, ncols: number, heights: Float32Array, scale: Vector): ColliderDesc;
/**
* Create a new collider descriptor with a cylinder shape.
*
* @param halfHeight - The half-height of the cylinder, along the `y` axis.
* @param radius - The radius of the cylinder basis.
*/
static cylinder(halfHeight: number, radius: number): ColliderDesc;
/**
* Create a new collider descriptor with a cylinder shape with rounded corners.
*
* @param halfHeight - The half-height of the cylinder, along the `y` axis.
* @param radius - The radius of the cylinder basis.
* @param borderRadius - The radius of the cylinder's rounded edges and vertices.
*/
static roundCylinder(halfHeight: number, radius: number, borderRadius: number): ColliderDesc;
/**
* Create a new collider descriptor with a cone shape.
*
* @param halfHeight - The half-height of the cone, along the `y` axis.
* @param radius - The radius of the cone basis.
*/
static cone(halfHeight: number, radius: number): ColliderDesc;
/**
* Create a new collider descriptor with a cone shape with rounded corners.
*
* @param halfHeight - The half-height of the cone, along the `y` axis.
* @param radius - The radius of the cone basis.
* @param borderRadius - The radius of the cone's rounded edges and vertices.
*/
static roundCone(halfHeight: number, radius: number, borderRadius: number): ColliderDesc;
/**
* Computes the convex-hull of the given points and use the resulting
* convex polyhedron as the shape for this new collider descriptor.
*
* @param points - The point that will be used to compute the convex-hull.
*/
static convexHull(points: Float32Array): ColliderDesc | null;
/**
* Creates a new collider descriptor that uses the given set of points assumed
* to form a convex polyline (no convex-hull computation will be done).
*
* @param vertices - The vertices of the convex polyline.
*/
static convexMesh(vertices: Float32Array, indices?: Uint32Array | null): ColliderDesc | null;
/**
* Computes the convex-hull of the given points and use the resulting
* convex polyhedron as the shape for this new collider descriptor. A
* border is added to that convex polyhedron to give it round corners.
*
* @param points - The point that will be used to compute the convex-hull.
* @param borderRadius - The radius of the round border added to the convex polyhedron.
*/
static roundConvexHull(points: Float32Array, borderRadius: number): ColliderDesc | null;
/**
* Creates a new collider descriptor that uses the given set of points assumed
* to form a round convex polyline (no convex-hull computation will be done).
*
* @param vertices - The vertices of the convex polyline.
* @param borderRadius - The radius of the round border added to the convex polyline.
*/
static roundConvexMesh(vertices: Float32Array, indices: Uint32Array | null, borderRadius: number): ColliderDesc | null;
/**
* Sets the position of the collider to be created relative to the rigid-body it is attached to.
*/
setTranslation(x: number, y: number, z: number): ColliderDesc;
/**
* Sets the rotation of the collider to be created relative to the rigid-body it is attached to.
*
* @param rot - The rotation of the collider to be created relative to the rigid-body it is attached to.
*/
setRotation(rot: Rotation): ColliderDesc;
/**
* Sets whether or not the collider being created is a sensor.
*
* A sensor collider does not take part of the physics simulation, but generates
* proximity events.
*
* @param sensor - Set to `true` of the collider built is to be a sensor.
*/
setSensor(sensor: boolean): ColliderDesc;
/**
* Sets whether the created collider will be enabled or disabled.
* @param enabled If set to `false` the collider will be disabled at creation.
*/
setEnabled(enabled: boolean): ColliderDesc;
/**
* Sets the density of the collider being built.
*
* The mass and angular inertia tensor will be computed automatically based on this density and the colliders shape.
*
* @param density - The density to set, must be greater or equal to 0. A density of 0 means that this collider
* will not affect the mass or angular inertia of the rigid-body it is attached to.
*/
setDensity(density: number): ColliderDesc;
/**
* Sets the mass of the collider being built.
*
* The angular inertia tensor will be computed automatically based on this mass and the colliders shape.
*
* @param mass - The mass to set, must be greater or equal to 0.
*/
setMass(mass: number): ColliderDesc;
/**
* Sets the mass properties of the collider being built.
*
* This replaces the mass-properties automatically computed from the collider's density and shape.
* These mass-properties will be added to the mass-properties of the rigid-body this collider will be attached to.
*
* @param mass The mass of the collider to create.
* @param centerOfMass The center-of-mass of the collider to create.
* @param principalAngularInertia The initial principal angular inertia of the collider to create.
* These are the eigenvalues of the angular inertia matrix.
* @param angularInertiaLocalFrame The initial local angular inertia frame of the collider to create.
* These are the eigenvectors of the angular inertia matrix.
*/
setMassProperties(mass: number, centerOfMass: Vector, principalAngularInertia: Vector, angularInertiaLocalFrame: Rotation): ColliderDesc;
/**
* Sets the restitution coefficient of the collider to be created.
*
* @param restitution - The restitution coefficient in `[0, 1]`. A value of 0 (the default) means no bouncing behavior
* while 1 means perfect bouncing (though energy may still be lost due to numerical errors of the
* constraints solver).
*/
setRestitution(restitution: number): ColliderDesc;
/**
* Sets the friction coefficient of the collider to be created.
*
* @param friction - The friction coefficient. Must be greater or equal to 0. This is generally smaller than 1. The
* higher the coefficient, the stronger friction forces will be for contacts with the collider
* being built.
*/
setFriction(friction: number): ColliderDesc;
/**
* Sets the rule used to combine the friction coefficients of two colliders
* colliders involved in a contact.
*
* @param rule The combine rule to apply.
*/
setFrictionCombineRule(rule: CoefficientCombineRule): ColliderDesc;
/**
* Sets the rule used to combine the restitution coefficients of two colliders
* colliders involved in a contact.
*
* @param rule The combine rule to apply.
*/
setRestitutionCombineRule(rule: CoefficientCombineRule): ColliderDesc;
/**
* Sets the collision groups used by this collider.
*
* Two colliders will interact iff. their collision groups are compatible.
* See the documentation of `InteractionGroups` for details on teh used bit pattern.
*
* @param groups - The collision groups used for the collider being built.
*/
setCollisionGroups(groups: InteractionGroups): ColliderDesc;
/**
* Sets the solver groups used by this collider.
*
* Forces between two colliders in contact will be computed iff their solver
* groups are compatible.
* See the documentation of `InteractionGroups` for details on the used bit pattern.
*
* @param groups - The solver groups used for the collider being built.
*/
setSolverGroups(groups: InteractionGroups): ColliderDesc;
/**
* Set the physics hooks active for this collider.
*
* Use this to enable custom filtering rules for contact/intersecstion pairs involving this collider.
*
* @param activeHooks - The hooks active for contact/intersection pairs involving this collider.
*/
setActiveHooks(activeHooks: ActiveHooks): ColliderDesc;
/**
* Set the events active for this collider.
*
* Use this to enable contact and/or intersection event reporting for this collider.
*
* @param activeEvents - The events active for contact/intersection pairs involving this collider.
*/
setActiveEvents(activeEvents: ActiveEvents): ColliderDesc;
/**
* Set the collision types active for this collider.
*
* @param activeCollisionTypes - The hooks active for contact/intersection pairs involving this collider.
*/
setActiveCollisionTypes(activeCollisionTypes: ActiveCollisionTypes): ColliderDesc;
/**
* Sets the total force magnitude beyond which a contact force event can be emitted.
*
* @param threshold - The force threshold to set.
*/
setContactForceEventThreshold(threshold: number): ColliderDesc;
}

View File

@@ -0,0 +1,72 @@
import { RawColliderSet } from "../raw";
import { Collider, ColliderDesc, ColliderHandle } from "./collider";
import { ImpulseJointHandle, IslandManager, RigidBodyHandle } from "../dynamics";
import { RigidBodySet } from "../dynamics";
/**
* A set of rigid bodies that can be handled by a physics pipeline.
*
* To avoid leaking WASM resources, this MUST be freed manually with `colliderSet.free()`
* once you are done using it (and all the rigid-bodies it created).
*/
export declare class ColliderSet {
raw: RawColliderSet;
private map;
/**
* Release the WASM memory occupied by this collider set.
*/
free(): void;
constructor(raw?: RawColliderSet);
/** @internal */
castClosure<Res>(f?: (collider: Collider) => Res): (handle: ColliderHandle) => Res | undefined;
/** @internal */
finalizeDeserialization(bodies: RigidBodySet): void;
/**
* Creates a new collider and return its integer handle.
*
* @param bodies - The set of bodies where the collider's parent can be found.
* @param desc - The collider's description.
* @param parentHandle - The integer handle of the rigid-body this collider is attached to.
*/
createCollider(bodies: RigidBodySet, desc: ColliderDesc, parentHandle: RigidBodyHandle): Collider;
/**
* Remove a collider from this set.
*
* @param handle - The integer handle of the collider to remove.
* @param bodies - The set of rigid-body containing the rigid-body the collider is attached to.
* @param wakeUp - If `true`, the rigid-body the removed collider is attached to will be woken-up automatically.
*/
remove(handle: ColliderHandle, islands: IslandManager, bodies: RigidBodySet, wakeUp: boolean): void;
/**
* Internal function, do not call directly.
* @param handle
*/
unmap(handle: ImpulseJointHandle): void;
/**
* Gets the rigid-body with the given handle.
*
* @param handle - The handle of the rigid-body to retrieve.
*/
get(handle: ColliderHandle): Collider | null;
/**
* The number of colliders on this set.
*/
len(): number;
/**
* Does this set contain a collider with the given handle?
*
* @param handle - The collider handle to check.
*/
contains(handle: ColliderHandle): boolean;
/**
* Applies the given closure to each collider contained by this set.
*
* @param f - The closure to apply.
*/
forEach(f: (collider: Collider) => void): void;
/**
* Gets all colliders in the list.
*
* @returns collider list.
*/
getAll(): Collider[];
}

View File

@@ -0,0 +1,31 @@
import { Vector } from "../math";
import { RawShapeContact } from "../raw";
/**
* The contact info between two shapes.
*/
export declare class ShapeContact {
/**
* Distance between the two contact points.
* If this is negative, this contact represents a penetration.
*/
distance: number;
/**
* Position of the contact on the first shape.
*/
point1: Vector;
/**
* Position of the contact on the second shape.
*/
point2: Vector;
/**
* Contact normal, pointing towards the exterior of the first shape.
*/
normal1: Vector;
/**
* Contact normal, pointing towards the exterior of the second shape.
* If these contact data are expressed in world-space, this normal is equal to -normal1.
*/
normal2: Vector;
constructor(dist: number, point1: Vector, point2: Vector, normal1: Vector, normal2: Vector);
static fromRaw(raw: RawShapeContact): ShapeContact;
}

View File

@@ -0,0 +1,6 @@
export declare enum FeatureType {
Vertex = 0,
Edge = 1,
Face = 2,
Unknown = 3
}

View File

@@ -0,0 +1,11 @@
export * from "./broad_phase";
export * from "./narrow_phase";
export * from "./shape";
export * from "./collider";
export * from "./collider_set";
export * from "./feature";
export * from "./ray";
export * from "./point";
export * from "./toi";
export * from "./interaction_groups";
export * from "./contact";

View File

@@ -0,0 +1,18 @@
/**
* Pairwise filtering using bit masks.
*
* This filtering method is based on two 16-bit values:
* - The interaction groups (the 16 left-most bits of `self.0`).
* - The interaction mask (the 16 right-most bits of `self.0`).
*
* An interaction is allowed between two filters `a` and `b` two conditions
* are met simultaneously:
* - The interaction groups of `a` has at least one bit set to `1` in common with the interaction mask of `b`.
* - The interaction groups of `b` has at least one bit set to `1` in common with the interaction mask of `a`.
* In other words, interactions are allowed between two filter iff. the following condition is met:
*
* ```
* ((a >> 16) & b) != 0 && ((b >> 16) & a) != 0
* ```
*/
export declare type InteractionGroups = number;

View File

@@ -0,0 +1,71 @@
import { RawNarrowPhase, RawContactManifold } from "../raw";
import { ColliderHandle } from "./collider";
import { Vector } from "../math";
/**
* The narrow-phase used for precise collision-detection.
*
* To avoid leaking WASM resources, this MUST be freed manually with `narrowPhase.free()`
* once you are done using it.
*/
export declare class NarrowPhase {
raw: RawNarrowPhase;
tempManifold: TempContactManifold;
/**
* Release the WASM memory occupied by this narrow-phase.
*/
free(): void;
constructor(raw?: RawNarrowPhase);
/**
* Enumerates all the colliders potentially in contact with the given collider.
*
* @param collider1 - The second collider involved in the contact.
* @param f - Closure that will be called on each collider that is in contact with `collider1`.
*/
contactPairsWith(collider1: ColliderHandle, f: (collider2: ColliderHandle) => void): void;
/**
* Enumerates all the colliders intersecting the given colliders, assuming one of them
* is a sensor.
*/
intersectionPairsWith(collider1: ColliderHandle, f: (collider2: ColliderHandle) => void): void;
/**
* Iterates through all the contact manifolds between the given pair of colliders.
*
* @param collider1 - The first collider involved in the contact.
* @param collider2 - The second collider involved in the contact.
* @param f - Closure that will be called on each contact manifold between the two colliders. If the second argument
* passed to this closure is `true`, then the contact manifold data is flipped, i.e., methods like `localNormal1`
* actually apply to the `collider2` and fields like `localNormal2` apply to the `collider1`.
*/
contactPair(collider1: ColliderHandle, collider2: ColliderHandle, f: (manifold: TempContactManifold, flipped: boolean) => void): void;
/**
* Returns `true` if `collider1` and `collider2` intersect and at least one of them is a sensor.
* @param collider1 The first collider involved in the intersection.
* @param collider2 The second collider involved in the intersection.
*/
intersectionPair(collider1: ColliderHandle, collider2: ColliderHandle): boolean;
}
export declare class TempContactManifold {
raw: RawContactManifold;
free(): void;
constructor(raw: RawContactManifold);
normal(): Vector;
localNormal1(): Vector;
localNormal2(): Vector;
subshape1(): number;
subshape2(): number;
numContacts(): number;
localContactPoint1(i: number): Vector | null;
localContactPoint2(i: number): Vector | null;
contactDist(i: number): number;
contactFid1(i: number): number;
contactFid2(i: number): number;
contactImpulse(i: number): number;
contactTangentImpulseX(i: number): number;
contactTangentImpulseY(i: number): number;
numSolverContacts(): number;
solverContactPoint(i: number): Vector;
solverContactDist(i: number): number;
solverContactFriction(i: number): number;
solverContactRestitution(i: number): number;
solverContactTangentVelocity(i: number): Vector;
}

View File

@@ -0,0 +1,47 @@
import { Collider } from "./collider";
import { Vector } from "../math";
import { RawPointColliderProjection, RawPointProjection } from "../raw";
import { FeatureType } from "./feature";
import { ColliderSet } from "./collider_set";
/**
* The projection of a point on a collider.
*/
export declare class PointProjection {
/**
* The projection of the point on the collider.
*/
point: Vector;
/**
* Is the point inside of the collider?
*/
isInside: boolean;
constructor(point: Vector, isInside: boolean);
static fromRaw(raw: RawPointProjection): PointProjection;
}
/**
* The projection of a point on a collider (includes the collider handle).
*/
export declare class PointColliderProjection {
/**
* The collider hit by the ray.
*/
collider: Collider;
/**
* The projection of the point on the collider.
*/
point: Vector;
/**
* Is the point inside of the collider?
*/
isInside: boolean;
/**
* The type of the geometric feature the point was projected on.
*/
featureType: FeatureType;
/**
* The id of the geometric feature the point was projected on.
*/
featureId: number | undefined;
constructor(collider: Collider, point: Vector, isInside: boolean, featureType?: FeatureType, featureId?: number);
static fromRaw(colliderSet: ColliderSet, raw: RawPointColliderProjection): PointColliderProjection;
}

View File

@@ -0,0 +1,97 @@
import { Vector } from "../math";
import { RawRayColliderIntersection, RawRayColliderToi, RawRayIntersection } from "../raw";
import { Collider } from "./collider";
import { FeatureType } from "./feature";
import { ColliderSet } from "./collider_set";
/**
* A ray. This is a directed half-line.
*/
export declare class Ray {
/**
* The starting point of the ray.
*/
origin: Vector;
/**
* The direction of propagation of the ray.
*/
dir: Vector;
/**
* Builds a ray from its origin and direction.
*
* @param origin - The ray's starting point.
* @param dir - The ray's direction of propagation.
*/
constructor(origin: Vector, dir: Vector);
pointAt(t: number): Vector;
}
/**
* The intersection between a ray and a collider.
*/
export declare class RayIntersection {
/**
* The time-of-impact of the ray with the collider.
*
* The hit point is obtained from the ray's origin and direction: `origin + dir * toi`.
*/
toi: number;
/**
* The normal of the collider at the hit point.
*/
normal: Vector;
/**
* The type of the geometric feature the point was projected on.
*/
featureType: FeatureType;
/**
* The id of the geometric feature the point was projected on.
*/
featureId: number | undefined;
constructor(toi: number, normal: Vector, featureType?: FeatureType, featureId?: number);
static fromRaw(raw: RawRayIntersection): RayIntersection;
}
/**
* The intersection between a ray and a collider (includes the collider handle).
*/
export declare class RayColliderIntersection {
/**
* The collider hit by the ray.
*/
collider: Collider;
/**
* The time-of-impact of the ray with the collider.
*
* The hit point is obtained from the ray's origin and direction: `origin + dir * toi`.
*/
toi: number;
/**
* The normal of the collider at the hit point.
*/
normal: Vector;
/**
* The type of the geometric feature the point was projected on.
*/
featureType: FeatureType;
/**
* The id of the geometric feature the point was projected on.
*/
featureId: number | undefined;
constructor(collider: Collider, toi: number, normal: Vector, featureType?: FeatureType, featureId?: number);
static fromRaw(colliderSet: ColliderSet, raw: RawRayColliderIntersection): RayColliderIntersection;
}
/**
* The time of impact between a ray and a collider.
*/
export declare class RayColliderToi {
/**
* The handle of the collider hit by the ray.
*/
collider: Collider;
/**
* The time-of-impact of the ray with the collider.
*
* The hit point is obtained from the ray's origin and direction: `origin + dir * toi`.
*/
toi: number;
constructor(collider: Collider, toi: number);
static fromRaw(colliderSet: ColliderSet, raw: RawRayColliderToi): RayColliderToi;
}

View File

@@ -0,0 +1,489 @@
import { Vector, Rotation } from "../math";
import { RawColliderSet, RawShape } from "../raw";
import { ShapeContact } from "./contact";
import { PointProjection } from "./point";
import { Ray, RayIntersection } from "./ray";
import { ShapeTOI } from "./toi";
import { ColliderHandle } from "./collider";
export declare abstract class Shape {
abstract intoRaw(): RawShape;
/**
* The concrete type of this shape.
*/
abstract get type(): ShapeType;
/**
* instant mode without cache
*/
static fromRaw(rawSet: RawColliderSet, handle: ColliderHandle): Shape;
/**
* Computes the time of impact between two moving shapes.
* @param shapePos1 - The initial position of this sahpe.
* @param shapeRot1 - The rotation of this shape.
* @param shapeVel1 - The velocity of this shape.
* @param shape2 - The second moving shape.
* @param shapePos2 - The initial position of the second shape.
* @param shapeRot2 - The rotation of the second shape.
* @param shapeVel2 - The velocity of the second shape.
* @param maxToi - The maximum time when the impact can happen.
* @param stopAtPenetration - If set to `false`, the linear shape-cast wont immediately stop if
* the shape is penetrating another shape at its starting point **and** its trajectory is such
* that its on a path to exist that penetration state.
* @returns If the two moving shapes collider at some point along their trajectories, this returns the
* time at which the two shape collider as well as the contact information during the impact. Returns
* `null`if the two shapes never collide along their paths.
*/
castShape(shapePos1: Vector, shapeRot1: Rotation, shapeVel1: Vector, shape2: Shape, shapePos2: Vector, shapeRot2: Rotation, shapeVel2: Vector, maxToi: number, stopAtPenetration: boolean): ShapeTOI | null;
/**
* Tests if this shape intersects another shape.
*
* @param shapePos1 - The position of this shape.
* @param shapeRot1 - The rotation of this shape.
* @param shape2 - The second shape to test.
* @param shapePos2 - The position of the second shape.
* @param shapeRot2 - The rotation of the second shape.
* @returns `true` if the two shapes intersect, `false` if they dont.
*/
intersectsShape(shapePos1: Vector, shapeRot1: Rotation, shape2: Shape, shapePos2: Vector, shapeRot2: Rotation): boolean;
/**
* Computes one pair of contact points between two shapes.
*
* @param shapePos1 - The initial position of this sahpe.
* @param shapeRot1 - The rotation of this shape.
* @param shape2 - The second shape.
* @param shapePos2 - The initial position of the second shape.
* @param shapeRot2 - The rotation of the second shape.
* @param prediction - The prediction value, if the shapes are separated by a distance greater than this value, test will fail.
* @returns `null` if the shapes are separated by a distance greater than prediction, otherwise contact details. The result is given in world-space.
*/
contactShape(shapePos1: Vector, shapeRot1: Rotation, shape2: Shape, shapePos2: Vector, shapeRot2: Rotation, prediction: number): ShapeContact | null;
containsPoint(shapePos: Vector, shapeRot: Rotation, point: Vector): boolean;
projectPoint(shapePos: Vector, shapeRot: Rotation, point: Vector, solid: boolean): PointProjection;
intersectsRay(ray: Ray, shapePos: Vector, shapeRot: Rotation, maxToi: number): boolean;
castRay(ray: Ray, shapePos: Vector, shapeRot: Rotation, maxToi: number, solid: boolean): number;
castRayAndGetNormal(ray: Ray, shapePos: Vector, shapeRot: Rotation, maxToi: number, solid: boolean): RayIntersection;
}
/**
* An enumeration representing the type of a shape.
*/
export declare enum ShapeType {
Ball = 0,
Cuboid = 1,
Capsule = 2,
Segment = 3,
Polyline = 4,
Triangle = 5,
TriMesh = 6,
HeightField = 7,
ConvexPolyhedron = 9,
Cylinder = 10,
Cone = 11,
RoundCuboid = 12,
RoundTriangle = 13,
RoundCylinder = 14,
RoundCone = 15,
RoundConvexPolyhedron = 16,
HalfSpace = 17
}
/**
* A shape that is a sphere in 3D and a circle in 2D.
*/
export declare class Ball extends Shape {
readonly type = ShapeType.Ball;
/**
* The balls radius.
*/
radius: number;
/**
* Creates a new ball with the given radius.
* @param radius - The balls radius.
*/
constructor(radius: number);
intoRaw(): RawShape;
}
export declare class HalfSpace extends Shape {
readonly type = ShapeType.HalfSpace;
/**
* The outward normal of the half-space.
*/
normal: Vector;
/**
* Creates a new halfspace delimited by an infinite plane.
*
* @param normal - The outward normal of the plane.
*/
constructor(normal: Vector);
intoRaw(): RawShape;
}
/**
* A shape that is a box in 3D and a rectangle in 2D.
*/
export declare class Cuboid extends Shape {
readonly type = ShapeType.Cuboid;
/**
* The half extent of the cuboid along each coordinate axis.
*/
halfExtents: Vector;
/**
* Creates a new 3D cuboid.
* @param hx - The half width of the cuboid.
* @param hy - The half height of the cuboid.
* @param hz - The half depth of the cuboid.
*/
constructor(hx: number, hy: number, hz: number);
intoRaw(): RawShape;
}
/**
* A shape that is a box in 3D and a rectangle in 2D, with round corners.
*/
export declare class RoundCuboid extends Shape {
readonly type = ShapeType.RoundCuboid;
/**
* The half extent of the cuboid along each coordinate axis.
*/
halfExtents: Vector;
/**
* The radius of the cuboid's round border.
*/
borderRadius: number;
/**
* Creates a new 3D cuboid.
* @param hx - The half width of the cuboid.
* @param hy - The half height of the cuboid.
* @param hz - The half depth of the cuboid.
* @param borderRadius - The radius of the borders of this cuboid. This will
* effectively increase the half-extents of the cuboid by this radius.
*/
constructor(hx: number, hy: number, hz: number, borderRadius: number);
intoRaw(): RawShape;
}
/**
* A shape that is a capsule.
*/
export declare class Capsule extends Shape {
readonly type = ShapeType.Capsule;
/**
* The radius of the capsule's basis.
*/
radius: number;
/**
* The capsule's half height, along the `y` axis.
*/
halfHeight: number;
/**
* Creates a new capsule with the given radius and half-height.
* @param halfHeight - The balls half-height along the `y` axis.
* @param radius - The balls radius.
*/
constructor(halfHeight: number, radius: number);
intoRaw(): RawShape;
}
/**
* A shape that is a segment.
*/
export declare class Segment extends Shape {
readonly type = ShapeType.Segment;
/**
* The first point of the segment.
*/
a: Vector;
/**
* The second point of the segment.
*/
b: Vector;
/**
* Creates a new segment shape.
* @param a - The first point of the segment.
* @param b - The second point of the segment.
*/
constructor(a: Vector, b: Vector);
intoRaw(): RawShape;
}
/**
* A shape that is a segment.
*/
export declare class Triangle extends Shape {
readonly type = ShapeType.Triangle;
/**
* The first point of the triangle.
*/
a: Vector;
/**
* The second point of the triangle.
*/
b: Vector;
/**
* The second point of the triangle.
*/
c: Vector;
/**
* Creates a new triangle shape.
*
* @param a - The first point of the triangle.
* @param b - The second point of the triangle.
* @param c - The third point of the triangle.
*/
constructor(a: Vector, b: Vector, c: Vector);
intoRaw(): RawShape;
}
/**
* A shape that is a triangle with round borders and a non-zero thickness.
*/
export declare class RoundTriangle extends Shape {
readonly type = ShapeType.RoundTriangle;
/**
* The first point of the triangle.
*/
a: Vector;
/**
* The second point of the triangle.
*/
b: Vector;
/**
* The second point of the triangle.
*/
c: Vector;
/**
* The radius of the triangles's rounded edges and vertices.
* In 3D, this is also equal to half the thickness of the round triangle.
*/
borderRadius: number;
/**
* Creates a new triangle shape with round corners.
*
* @param a - The first point of the triangle.
* @param b - The second point of the triangle.
* @param c - The third point of the triangle.
* @param borderRadius - The radius of the borders of this triangle. In 3D,
* this is also equal to half the thickness of the triangle.
*/
constructor(a: Vector, b: Vector, c: Vector, borderRadius: number);
intoRaw(): RawShape;
}
/**
* A shape that is a triangle mesh.
*/
export declare class Polyline extends Shape {
readonly type = ShapeType.Polyline;
/**
* The vertices of the polyline.
*/
vertices: Float32Array;
/**
* The indices of the segments.
*/
indices: Uint32Array;
/**
* Creates a new polyline shape.
*
* @param vertices - The coordinates of the polyline's vertices.
* @param indices - The indices of the polyline's segments. If this is `null` or not provided, then
* the vertices are assumed to form a line strip.
*/
constructor(vertices: Float32Array, indices?: Uint32Array);
intoRaw(): RawShape;
}
/**
* A shape that is a triangle mesh.
*/
export declare class TriMesh extends Shape {
readonly type = ShapeType.TriMesh;
/**
* The vertices of the triangle mesh.
*/
vertices: Float32Array;
/**
* The indices of the triangles.
*/
indices: Uint32Array;
/**
* Creates a new triangle mesh shape.
*
* @param vertices - The coordinates of the triangle mesh's vertices.
* @param indices - The indices of the triangle mesh's triangles.
*/
constructor(vertices: Float32Array, indices: Uint32Array);
intoRaw(): RawShape;
}
/**
* A shape that is a convex polygon.
*/
export declare class ConvexPolyhedron extends Shape {
readonly type = ShapeType.ConvexPolyhedron;
/**
* The vertices of the convex polygon.
*/
vertices: Float32Array;
/**
* The indices of the convex polygon.
*/
indices?: Uint32Array | null;
/**
* Creates a new convex polygon shape.
*
* @param vertices - The coordinates of the convex polygon's vertices.
* @param indices - The index buffer of this convex mesh. If this is `null`
* or `undefined`, the convex-hull of the input vertices will be computed
* automatically. Otherwise, it will be assumed that the mesh you provide
* is already convex.
*/
constructor(vertices: Float32Array, indices?: Uint32Array | null);
intoRaw(): RawShape;
}
/**
* A shape that is a convex polygon.
*/
export declare class RoundConvexPolyhedron extends Shape {
readonly type = ShapeType.RoundConvexPolyhedron;
/**
* The vertices of the convex polygon.
*/
vertices: Float32Array;
/**
* The indices of the convex polygon.
*/
indices?: Uint32Array;
/**
* The radius of the convex polyhedron's rounded edges and vertices.
*/
borderRadius: number;
/**
* Creates a new convex polygon shape.
*
* @param vertices - The coordinates of the convex polygon's vertices.
* @param indices - The index buffer of this convex mesh. If this is `null`
* or `undefined`, the convex-hull of the input vertices will be computed
* automatically. Otherwise, it will be assumed that the mesh you provide
* is already convex.
* @param borderRadius - The radius of the borders of this convex polyhedron.
*/
constructor(vertices: Float32Array, indices: Uint32Array | null | undefined, borderRadius: number);
intoRaw(): RawShape;
}
/**
* A shape that is a heightfield.
*/
export declare class Heightfield extends Shape {
readonly type = ShapeType.HeightField;
/**
* The number of rows in the heights matrix.
*/
nrows: number;
/**
* The number of columns in the heights matrix.
*/
ncols: number;
/**
* The heights of the heightfield along its local `y` axis,
* provided as a matrix stored in column-major order.
*/
heights: Float32Array;
/**
* The dimensions of the heightfield's local `x,z` plane.
*/
scale: Vector;
/**
* Creates a new heightfield shape.
*
* @param nrows The number of rows in the heights matrix.
* @param ncols - The number of columns in the heights matrix.
* @param heights - The heights of the heightfield along its local `y` axis,
* provided as a matrix stored in column-major order.
* @param scale - The dimensions of the heightfield's local `x,z` plane.
*/
constructor(nrows: number, ncols: number, heights: Float32Array, scale: Vector);
intoRaw(): RawShape;
}
/**
* A shape that is a 3D cylinder.
*/
export declare class Cylinder extends Shape {
readonly type = ShapeType.Cylinder;
/**
* The radius of the cylinder's basis.
*/
radius: number;
/**
* The cylinder's half height, along the `y` axis.
*/
halfHeight: number;
/**
* Creates a new cylinder with the given radius and half-height.
* @param halfHeight - The balls half-height along the `y` axis.
* @param radius - The balls radius.
*/
constructor(halfHeight: number, radius: number);
intoRaw(): RawShape;
}
/**
* A shape that is a 3D cylinder with round corners.
*/
export declare class RoundCylinder extends Shape {
readonly type = ShapeType.RoundCylinder;
/**
* The radius of the cylinder's basis.
*/
radius: number;
/**
* The cylinder's half height, along the `y` axis.
*/
halfHeight: number;
/**
* The radius of the cylinder's rounded edges and vertices.
*/
borderRadius: number;
/**
* Creates a new cylinder with the given radius and half-height.
* @param halfHeight - The balls half-height along the `y` axis.
* @param radius - The balls radius.
* @param borderRadius - The radius of the borders of this cylinder.
*/
constructor(halfHeight: number, radius: number, borderRadius: number);
intoRaw(): RawShape;
}
/**
* A shape that is a 3D cone.
*/
export declare class Cone extends Shape {
readonly type = ShapeType.Cone;
/**
* The radius of the cone's basis.
*/
radius: number;
/**
* The cone's half height, along the `y` axis.
*/
halfHeight: number;
/**
* Creates a new cone with the given radius and half-height.
* @param halfHeight - The balls half-height along the `y` axis.
* @param radius - The balls radius.
*/
constructor(halfHeight: number, radius: number);
intoRaw(): RawShape;
}
/**
* A shape that is a 3D cone with round corners.
*/
export declare class RoundCone extends Shape {
readonly type = ShapeType.RoundCone;
/**
* The radius of the cone's basis.
*/
radius: number;
/**
* The cone's half height, along the `y` axis.
*/
halfHeight: number;
/**
* The radius of the cylinder's rounded edges and vertices.
*/
borderRadius: number;
/**
* Creates a new cone with the given radius and half-height.
* @param halfHeight - The balls half-height along the `y` axis.
* @param radius - The balls radius.
* @param borderRadius - The radius of the borders of this cone.
*/
constructor(halfHeight: number, radius: number, borderRadius: number);
intoRaw(): RawShape;
}

View File

@@ -0,0 +1,46 @@
import { Collider } from "./collider";
import { Vector } from "../math";
import { RawShapeTOI, RawShapeColliderTOI } from "../raw";
import { ColliderSet } from "./collider_set";
/**
* The intersection between a ray and a collider.
*/
export declare class ShapeTOI {
/**
* The time of impact of the two shapes.
*/
toi: number;
/**
* The local-space contact point on the first shape, at
* the time of impact.
*/
witness1: Vector;
/**
* The local-space contact point on the second shape, at
* the time of impact.
*/
witness2: Vector;
/**
* The local-space normal on the first shape, at
* the time of impact.
*/
normal1: Vector;
/**
* The local-space normal on the second shape, at
* the time of impact.
*/
normal2: Vector;
constructor(toi: number, witness1: Vector, witness2: Vector, normal1: Vector, normal2: Vector);
static fromRaw(colliderSet: ColliderSet, raw: RawShapeTOI): ShapeTOI;
}
/**
* The intersection between a ray and a collider.
*/
export declare class ShapeColliderTOI extends ShapeTOI {
/**
* The handle of the collider hit by the ray.
*/
collider: Collider;
constructor(collider: Collider, toi: number, witness1: Vector, witness2: Vector, normal1: Vector, normal2: Vector);
static fromRaw(colliderSet: ColliderSet, raw: RawShapeColliderTOI): ShapeColliderTOI;
}