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,188 @@
import { Vector } from "../math";
import { Collider, ColliderSet, InteractionGroups } from "../geometry";
import { QueryFilterFlags, QueryPipeline } from "../pipeline";
import { IntegrationParameters, RigidBodySet } from "../dynamics";
/**
* A collision between the character and an obstacle hit on its path.
*/
export declare class CharacterCollision {
/** The collider involved in the collision. Null if the collider no longer exists in the physics world. */
collider: Collider | null;
/** The translation delta applied to the character before this collision took place. */
translationDeltaApplied: Vector;
/** The translation delta the character would move after this collision if there is no other obstacles. */
translationDeltaRemaining: Vector;
/** The time-of-impact between the character and the obstacles. */
toi: number;
/** The world-space contact point on the collider when the collision happens. */
witness1: Vector;
/** The local-space contact point on the character when the collision happens. */
witness2: Vector;
/** The world-space outward contact normal on the collider when the collision happens. */
normal1: Vector;
/** The local-space outward contact normal on the character when the collision happens. */
normal2: Vector;
}
/**
* A character controller for controlling kinematic bodies and parentless colliders by hitting
* and sliding against obstacles.
*/
export declare class KinematicCharacterController {
private raw;
private rawCharacterCollision;
private params;
private bodies;
private colliders;
private queries;
private _applyImpulsesToDynamicBodies;
private _characterMass;
constructor(offset: number, params: IntegrationParameters, bodies: RigidBodySet, colliders: ColliderSet, queries: QueryPipeline);
/** @internal */
free(): void;
/**
* The direction that goes "up". Used to determine where the floor is, and the floors angle.
*/
up(): Vector;
/**
* Sets the direction that goes "up". Used to determine where the floor is, and the floors angle.
*/
setUp(vector: Vector): void;
applyImpulsesToDynamicBodies(): boolean;
setApplyImpulsesToDynamicBodies(enabled: boolean): void;
/**
* Returns the custom value of the character mass, if it was set by `this.setCharacterMass`.
*/
characterMass(): number | null;
/**
* Set the mass of the character to be used for impulse resolution if `self.applyImpulsesToDynamicBodies`
* is set to `true`.
*
* If no character mass is set explicitly (or if it is set to `null`) it is automatically assumed to be equal
* to the mass of the rigid-body the character collider is attached to; or equal to 0 if the character collider
* isnt attached to any rigid-body.
*
* @param mass - The mass to set.
*/
setCharacterMass(mass: number | null): void;
/**
* A small gap to preserve between the character and its surroundings.
*
* This value should not be too large to avoid visual artifacts, but shouldnt be too small
* (must not be zero) to improve numerical stability of the character controller.
*/
offset(): number;
/**
* Sets a small gap to preserve between the character and its surroundings.
*
* This value should not be too large to avoid visual artifacts, but shouldnt be too small
* (must not be zero) to improve numerical stability of the character controller.
*/
setOffset(value: number): void;
/**
* Is sliding against obstacles enabled?
*/
slideEnabled(): boolean;
/**
* Enable or disable sliding against obstacles.
*/
setSlideEnabled(enabled: boolean): void;
/**
* The maximum step height a character can automatically step over.
*/
autostepMaxHeight(): number | null;
/**
* The minimum width of free space that must be available after stepping on a stair.
*/
autostepMinWidth(): number | null;
/**
* Can the character automatically step over dynamic bodies too?
*/
autostepIncludesDynamicBodies(): boolean | null;
/**
* Is automatically stepping over small objects enabled?
*/
autostepEnabled(): boolean;
/**
* Enabled automatically stepping over small objects.
*
* @param maxHeight - The maximum step height a character can automatically step over.
* @param minWidth - The minimum width of free space that must be available after stepping on a stair.
* @param includeDynamicBodies - Can the character automatically step over dynamic bodies too?
*/
enableAutostep(maxHeight: number, minWidth: number, includeDynamicBodies: boolean): void;
/**
* Disable automatically stepping over small objects.
*/
disableAutostep(): void;
/**
* The maximum angle (radians) between the floors normal and the `up` vector that the
* character is able to climb.
*/
maxSlopeClimbAngle(): number;
/**
* Sets the maximum angle (radians) between the floors normal and the `up` vector that the
* character is able to climb.
*/
setMaxSlopeClimbAngle(angle: number): void;
/**
* The minimum angle (radians) between the floors normal and the `up` vector before the
* character starts to slide down automatically.
*/
minSlopeSlideAngle(): number;
/**
* Sets the minimum angle (radians) between the floors normal and the `up` vector before the
* character starts to slide down automatically.
*/
setMinSlopeSlideAngle(angle: number): void;
/**
* If snap-to-ground is enabled, should the character be automatically snapped to the ground if
* the distance between the ground and its feet are smaller than the specified threshold?
*/
snapToGroundDistance(): number | null;
/**
* Enables automatically snapping the character to the ground if the distance between
* the ground and its feet are smaller than the specified threshold.
*/
enableSnapToGround(distance: number): void;
/**
* Disables automatically snapping the character to the ground.
*/
disableSnapToGround(): void;
/**
* Is automatically snapping the character to the ground enabled?
*/
snapToGroundEnabled(): boolean;
/**
* Computes the movement the given collider is able to execute after hitting and sliding on obstacles.
*
* @param collider - The collider to move.
* @param desiredTranslationDelta - The desired collider movement.
* @param filterFlags - Flags for excluding whole subsets of colliders from the obstacles taken into account.
* @param filterGroups - Groups for excluding colliders with incompatible collision groups from the obstacles
* taken into account.
* @param filterPredicate - Any collider for which this closure returns `false` will be excluded from the
* obstacles taken into account.
*/
computeColliderMovement(collider: Collider, desiredTranslationDelta: Vector, filterFlags?: QueryFilterFlags, filterGroups?: InteractionGroups, filterPredicate?: (collider: Collider) => boolean): void;
/**
* The movement computed by the last call to `this.computeColliderMovement`.
*/
computedMovement(): Vector;
/**
* The result of ground detection computed by the last call to `this.computeColliderMovement`.
*/
computedGrounded(): boolean;
/**
* The number of collisions against obstacles detected along the path of the last call
* to `this.computeColliderMovement`.
*/
numComputedCollisions(): number;
/**
* Returns the collision against one of the obstacles detected along the path of the last
* call to `this.computeColliderMovement`.
*
* @param i - The i-th collision will be returned.
* @param out - If this argument is set, it will be filled with the collision information.
*/
computedCollision(i: number, out?: CharacterCollision): CharacterCollision | null;
}

View File

@@ -0,0 +1,2 @@
export * from "./character_controller";
export * from "./ray_cast_vehicle_controller";

View File

@@ -0,0 +1,252 @@
import { Vector } from "../math";
import { Collider, ColliderSet, InteractionGroups } from "../geometry";
import { QueryFilterFlags, QueryPipeline } from "../pipeline";
import { RigidBody, RigidBodySet } from "../dynamics";
/**
* A character controller to simulate vehicles using ray-casting for the wheels.
*/
export declare class DynamicRayCastVehicleController {
private raw;
private bodies;
private colliders;
private queries;
private _chassis;
constructor(chassis: RigidBody, bodies: RigidBodySet, colliders: ColliderSet, queries: QueryPipeline);
/** @internal */
free(): void;
/**
* Updates the vehicles velocity based on its suspension, engine force, and brake.
*
* This directly updates the velocity of its chassis rigid-body.
*
* @param dt - Time increment used to integrate forces.
* @param filterFlags - Flag to exclude categories of objects from the wheels ray-cast.
* @param filterGroups - Only colliders compatible with these groups will be hit by the wheels ray-casts.
* @param filterPredicate - Callback to filter out which collider will be hit by the wheels ray-casts.
*/
updateVehicle(dt: number, filterFlags?: QueryFilterFlags, filterGroups?: InteractionGroups, filterPredicate?: (collider: Collider) => boolean): void;
/**
* The current forward speed of the vehicle.
*/
currentVehicleSpeed(): number;
/**
* The rigid-body used as the chassis.
*/
chassis(): RigidBody;
/**
* The chassis local _up_ direction (`0 = x, 1 = y, 2 = z`).
*/
get indexUpAxis(): number;
/**
* Sets the chassis local _up_ direction (`0 = x, 1 = y, 2 = z`).
*/
set indexUpAxis(axis: number);
/**
* The chassis local _forward_ direction (`0 = x, 1 = y, 2 = z`).
*/
get indexForwardAxis(): number;
/**
* Sets the chassis local _forward_ direction (`0 = x, 1 = y, 2 = z`).
*/
set setIndexForwardAxis(axis: number);
/**
* Adds a new wheel attached to this vehicle.
* @param chassisConnectionCs - The position of the wheel relative to the chassis.
* @param directionCs - The direction of the wheels suspension, relative to the chassis. The ray-casting will
* happen following this direction to detect the ground.
* @param axleCs - The wheels axle axis, relative to the chassis.
* @param suspensionRestLength - The rest length of the wheels suspension spring.
* @param radius - The wheels radius.
*/
addWheel(chassisConnectionCs: Vector, directionCs: Vector, axleCs: Vector, suspensionRestLength: number, radius: number): void;
/**
* The number of wheels attached to this vehicle.
*/
numWheels(): number;
/**
* The position of the i-th wheel, relative to the chassis.
*/
wheelChassisConnectionPointCs(i: number): Vector | null;
/**
* Sets the position of the i-th wheel, relative to the chassis.
*/
setWheelChassisConnectionPointCs(i: number, value: Vector): void;
/**
* The rest length of the i-th wheels suspension spring.
*/
wheelSuspensionRestLength(i: number): number | null;
/**
* Sets the rest length of the i-th wheels suspension spring.
*/
setWheelSuspensionRestLength(i: number, value: number): void;
/**
* The maximum distance the i-th wheel suspension can travel before and after its resting length.
*/
wheelMaxSuspensionTravel(i: number): number | null;
/**
* Sets the maximum distance the i-th wheel suspension can travel before and after its resting length.
*/
setWheelMaxSuspensionTravel(i: number, value: number): void;
/**
* The i-th wheels radius.
*/
wheelRadius(i: number): number | null;
/**
* Sets the i-th wheels radius.
*/
setWheelRadius(i: number, value: number): void;
/**
* The i-th wheels suspension stiffness.
*
* Increase this value if the suspension appears to not push the vehicle strong enough.
*/
wheelSuspensionStiffness(i: number): number | null;
/**
* Sets the i-th wheels suspension stiffness.
*
* Increase this value if the suspension appears to not push the vehicle strong enough.
*/
setWheelSuspensionStiffness(i: number, value: number): void;
/**
* The i-th wheels suspensions damping when it is being compressed.
*/
wheelSuspensionCompression(i: number): number | null;
/**
* The i-th wheels suspensions damping when it is being compressed.
*/
setWheelSuspensionCompression(i: number, value: number): void;
/**
* The i-th wheels suspensions damping when it is being released.
*
* Increase this value if the suspension appears to overshoot.
*/
wheelSuspensionRelaxation(i: number): number | null;
/**
* Sets the i-th wheels suspensions damping when it is being released.
*
* Increase this value if the suspension appears to overshoot.
*/
setWheelSuspensionRelaxation(i: number, value: number): void;
/**
* The maximum force applied by the i-th wheels suspension.
*/
wheelMaxSuspensionForce(i: number): number | null;
/**
* Sets the maximum force applied by the i-th wheels suspension.
*/
setWheelMaxSuspensionForce(i: number, value: number): void;
/**
* The maximum amount of braking impulse applied on the i-th wheel to slow down the vehicle.
*/
wheelBrake(i: number): number | null;
/**
* Set the maximum amount of braking impulse applied on the i-th wheel to slow down the vehicle.
*/
setWheelBrake(i: number, value: number): void;
/**
* The steering angle (radians) for the i-th wheel.
*/
wheelSteering(i: number): number | null;
/**
* Sets the steering angle (radians) for the i-th wheel.
*/
setWheelSteering(i: number, value: number): void;
/**
* The forward force applied by the i-th wheel on the chassis.
*/
wheelEngineForce(i: number): number | null;
/**
* Sets the forward force applied by the i-th wheel on the chassis.
*/
setWheelEngineForce(i: number, value: number): void;
/**
* The direction of the i-th wheels suspension, relative to the chassis.
*
* The ray-casting will happen following this direction to detect the ground.
*/
wheelDirectionCs(i: number): Vector | null;
/**
* Sets the direction of the i-th wheels suspension, relative to the chassis.
*
* The ray-casting will happen following this direction to detect the ground.
*/
setWheelDirectionCs(i: number, value: Vector): void;
/**
* The i-th wheels axle axis, relative to the chassis.
*
* The axis index defined as 0 = X, 1 = Y, 2 = Z.
*/
wheelAxleCs(i: number): Vector | null;
/**
* Sets the i-th wheels axle axis, relative to the chassis.
*
* The axis index defined as 0 = X, 1 = Y, 2 = Z.
*/
setWheelAxleCs(i: number, value: Vector): void;
/**
* Parameter controlling how much traction the tire has.
*
* The larger the value, the more instantaneous braking will happen (with the risk of
* causing the vehicle to flip if its too strong).
*/
wheelFrictionSlip(i: number): number | null;
/**
* Sets the parameter controlling how much traction the tire has.
*
* The larger the value, the more instantaneous braking will happen (with the risk of
* causing the vehicle to flip if its too strong).
*/
setWheelFrictionSlip(i: number, value: number): void;
/**
* The multiplier of friction between a tire and the collider its on top of.
*
* The larger the value, the stronger side friction will be.
*/
wheelSideFrictionStiffness(i: number): number | null;
/**
* The multiplier of friction between a tire and the collider its on top of.
*
* The larger the value, the stronger side friction will be.
*/
setWheelSideFrictionStiffness(i: number, value: number): void;
/**
* The i-th wheels current rotation angle (radians) on its axle.
*/
wheelRotation(i: number): number | null;
/**
* The forward impulses applied by the i-th wheel on the chassis.
*/
wheelForwardImpulse(i: number): number | null;
/**
* The side impulses applied by the i-th wheel on the chassis.
*/
wheelSideImpulse(i: number): number | null;
/**
* The force applied by the i-th wheel suspension.
*/
wheelSuspensionForce(i: number): number | null;
/**
* The (world-space) contact normal between the i-th wheel and the floor.
*/
wheelContactNormal(i: number): Vector | null;
/**
* The (world-space) point hit by the wheels ray-cast for the i-th wheel.
*/
wheelContactPoint(i: number): Vector | null;
/**
* The suspension length for the i-th wheel.
*/
wheelSuspensionLength(i: number): number | null;
/**
* The (world-space) starting point of the ray-cast for the i-th wheel.
*/
wheelHardPoint(i: number): Vector | null;
/**
* Is the i-th wheel in contact with the ground?
*/
wheelIsInContact(i: number): boolean;
/**
* The collider hit by the ray-cast for the i-th wheel.
*/
wheelGroundObject(i: number): Collider | null;
}