angular-three-rapier
Version:
Physics Rapier for Angular Three
118 lines (115 loc) • 4.44 kB
TypeScript
import * as _angular_core from '@angular/core';
import { RigidBody, InteractionGroups } from '@dimforge/rapier3d-compat';
import * as THREE from 'three';
/**
* Applies attractor force to a rigid body based on its distance from the attractor.
* Used internally by NgtrAttractor but can be called manually for custom behavior.
*
* @param rigidBody - The rigid body to apply the force to
* @param options - The attractor configuration including position, strength, and type
*
* @example
* ```typescript
* beforePhysicsStep((world) => {
* world.bodies.forEach((body) => {
* if (body.isDynamic()) {
* applyAttractorForceOnRigidBody(body, {
* object: attractorMesh,
* strength: 10,
* range: 20,
* type: 'newtonian',
* gravitationalConstant: 6.673e-11
* });
* }
* });
* });
* ```
*/
declare function applyAttractorForceOnRigidBody(rigidBody: RigidBody, { object, strength, range, gravitationalConstant, collisionGroups, type, }: NgtrAttactorOptions & {
object: THREE.Object3D;
}): void;
/**
* Type of gravity calculation for attractors.
* - `'static'` - Constant force regardless of distance
* - `'linear'` - Force scales linearly with distance (closer = stronger)
* - `'newtonian'` - Force follows Newton's law of universal gravitation (inverse square)
*/
type NgtrAttractorGravityType = 'static' | 'linear' | 'newtonian';
/**
* Configuration options for the attractor directive.
*/
interface NgtrAttactorOptions {
/**
* The strength of the attractor.
* Positive values attract, negative values repel.
*
* @defaultValue 1
*/
strength: number;
/**
* The range of the attractor. Will not affect objects outside of this range.
*
* @defaultValue 10
* @min 0
*/
range: number;
/**
* The type of gravity to use.
* - static: The gravity is constant and does not change over time.
* - linear: The gravity is linearly interpolated the closer the object is to the attractor.
* - newtonian: The gravity is calculated using the newtonian gravity formula.
* @defaultValue "static"
*/
type: NgtrAttractorGravityType;
/**
* The mass of the attractor. Used when type is `newtonian`.
* @defaultValue 6.673e-11
*/
gravitationalConstant: number;
/**
* The collision groups that this attractor will apply effects to. If a RigidBody contains one or more colliders that are in one of the mask group, it will be affected by this attractor.
* If not specified, the attractor will apply effects to all RigidBodies.
*/
collisionGroups?: InteractionGroups;
}
/**
* Directive that creates a gravitational attractor point in the physics world.
* All dynamic rigid bodies within range will be attracted (or repelled) towards this point.
*
* The attractor can use different gravity models:
* - Static: constant force
* - Linear: force increases as objects get closer
* - Newtonian: realistic inverse-square law
*
* @example
* ```html
* <!-- Simple attractor at origin with default options -->
* <ngt-object3D attractor />
*
* <!-- Attractor with custom options -->
* <ngt-object3D [attractor]="{ strength: 5, range: 20 }" />
*
* <!-- Repeller (negative strength) -->
* <ngt-object3D [attractor]="{ strength: -10, range: 15 }" [position]="[5, 0, 0]" />
*
* <!-- Newtonian gravity -->
* <ngt-object3D [attractor]="{
* strength: 1000,
* range: 50,
* type: 'newtonian',
* gravitationalConstant: 0.01
* }" />
* ```
*/
declare class NgtrAttractor {
position: _angular_core.InputSignal<number | THREE.Vector3 | [x: number, y: number, z: number]>;
options: _angular_core.InputSignalWithTransform<NgtrAttactorOptions, "" | Partial<NgtrAttactorOptions>>;
private objectRef;
private collisionGroups;
linkedCollisionGroups: _angular_core.WritableSignal<number | undefined>;
constructor();
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgtrAttractor, never>;
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgtrAttractor, "ngt-object3D[attractor]", never, { "position": { "alias": "position"; "required": false; "isSignal": true; }; "options": { "alias": "attractor"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
}
export { NgtrAttractor, applyAttractorForceOnRigidBody };
export type { NgtrAttactorOptions, NgtrAttractorGravityType };