@hology/core 0.0.89 → 0.0.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gameplay/actors/camera/third-person-camera-component.js +1 -1
- package/dist/gameplay/services/physics/abstract-physics-system.d.ts +201 -0
- package/dist/gameplay/services/physics/abstract-physics-system.js +5 -0
- package/dist/gameplay/services/physics/physics-system.d.ts +282 -24
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as a}from"three";import{ViewController as r}from"../../services/render.js";import{DecimalInput as h,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as d,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as l}from"../../../shader/parameter.js";import{World as p}from"../../services/world.js";import{inject as u}from"../../inject.js";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let w=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.camera=new a(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new h(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(p),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}async onInit(){this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.viewController.setCamera(this.camera);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as a}from"three";import{ViewController as r}from"../../services/render.js";import{DecimalInput as h,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as d,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as l}from"../../../shader/parameter.js";import{World as p}from"../../services/world.js";import{inject as u}from"../../inject.js";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let w=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.camera=new a(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new h(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(p),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}async onInit(){this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.viewController.setCamera(this.camera);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((()=>{t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)})))}onLateUpdate(t){this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor(){null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(this.element.style.cursor="none",null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&(this.canvas.requestPointerLock(),this.isMouseLocked=!0))}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.checkForCollision(t);const e=n.clamp(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),i=Math.cos(this.rotationInput.rotation.x)*e,s=this.fixedBehind?0:this.rotationInput.rotation.y;this.offset.x=Math.sin(-s)*i,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(-s)*-i,this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),i=y;let s=!1,o=this.distance;const a=new m,r=this.camera.getWorldPosition(g);for(let t=-1;t<=1;t++){const n=k.subVectors(r,e);i.copy(r).add(n.multiplyScalar(1.2)),i.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,i,a,{debugLifetime:0,excludeActor:this.actor,excludeTriggers:!0}),a.hasHit&&a.distance<this.distance&&(o=Math.min(a.distance,o),s||=a.hasHit)}s||(this.restrictedDistance=n.lerp(this.restrictedDistance,this.distance,n.clamp(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=v;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.fixedBehind?(this.actor.object.updateWorldMatrix(!0,!1),this.camera.position.set(this.offset.x,this.offset.y,this.offset.z),this.camera.rotation.set(0,0,0),this.camera.scale.set(1,1,1),this.camera.applyMatrix4(this.actor.object.matrix)):this.camera.position.copy(this.actor.position).add(this.offset);const t=this.getLookAtPosition();this.camera.lookAt(t)}};t([l(),e("design:type",Number)],w.prototype,"near",void 0),t([l(),e("design:type",Number)],w.prototype,"far",void 0),t([l(),e("design:type",Number)],w.prototype,"viewAngle",void 0),w=t([s(),e("design:paramtypes",[r,d])],w);export{w as ThirdPersonCameraComponent};const v=new o,y=new o,k=(new o,new o),g=new o;export class ThirdPartyCameraComponent extends w{}
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -0,0 +1,201 @@
|
|
1
|
+
import { Subject, Observable } from "rxjs";
|
2
|
+
import { Vector3, Object3D } from "three";
|
3
|
+
import { BaseActor } from "../../actors/actor";
|
4
|
+
import { AbstractType } from "../../../utils/type";
|
5
|
+
import { CollisionShape } from "../../../index.js";
|
6
|
+
import { PhysicsBodyType } from "./physics-system";
|
7
|
+
import * as RAPIER from "@dimforge/rapier3d-compat";
|
8
|
+
export type ActorPhysicsOptions = {
|
9
|
+
isTrigger: boolean;
|
10
|
+
mass: number;
|
11
|
+
friction: number;
|
12
|
+
continousCollisionDetection: boolean;
|
13
|
+
density: number;
|
14
|
+
restitution: number;
|
15
|
+
type: PhysicsBodyType;
|
16
|
+
ignoreForNavMesh: boolean;
|
17
|
+
};
|
18
|
+
/**
|
19
|
+
* Abstract base class defining the interface for physics systems.
|
20
|
+
* This allows for different physics engine implementations while maintaining
|
21
|
+
* a consistent interface for game logic.
|
22
|
+
*/
|
23
|
+
export declare abstract class AbstractPhysicsSystem {
|
24
|
+
/**
|
25
|
+
* Promise that resolves when the physics system is ready
|
26
|
+
*/
|
27
|
+
abstract readonly ready: Promise<void>;
|
28
|
+
/**
|
29
|
+
* Event emitted before physics step
|
30
|
+
*/
|
31
|
+
abstract readonly beforeStep: Subject<number>;
|
32
|
+
/**
|
33
|
+
* Event emitted after physics step
|
34
|
+
*/
|
35
|
+
abstract readonly afterStep: Subject<number>;
|
36
|
+
/**
|
37
|
+
* Controls debug visualization of physics bodies
|
38
|
+
*/
|
39
|
+
abstract get showDebug(): boolean;
|
40
|
+
abstract set showDebug(value: boolean);
|
41
|
+
/**
|
42
|
+
* Initializes and starts the physics system
|
43
|
+
*/
|
44
|
+
abstract start(): Promise<void>;
|
45
|
+
/**
|
46
|
+
* Renders debug visualization of physics bodies and colliders
|
47
|
+
*/
|
48
|
+
abstract renderDebug(): void;
|
49
|
+
/**
|
50
|
+
* Sets the gravity vector for the physics world
|
51
|
+
*/
|
52
|
+
abstract setGravity(x: number, y: number, z: number): void;
|
53
|
+
/**
|
54
|
+
* Gets the current gravity vector of the physics world
|
55
|
+
*/
|
56
|
+
abstract getGravity(): Vector3;
|
57
|
+
/**
|
58
|
+
* Adds static collision bodies to the physics world based on an existing scene hierarchy
|
59
|
+
*/
|
60
|
+
abstract addFromScene(object: Object3D): void;
|
61
|
+
/**
|
62
|
+
* Creates a character controller for physics-based character movement
|
63
|
+
*/
|
64
|
+
abstract getCharacterController(offset?: number): RAPIER.KinematicCharacterController;
|
65
|
+
/**
|
66
|
+
* Computes the corrected movement vector for an actor using a character controller
|
67
|
+
*/
|
68
|
+
abstract getActorComputedMovement(actor: BaseActor, cc: RAPIER.KinematicCharacterController, desiredTranslation: Vector3, collisionGroup?: number): Vector3;
|
69
|
+
/**
|
70
|
+
* Sets the next kinematic translation for an actor
|
71
|
+
*/
|
72
|
+
abstract setNextKinematicTranslation(actor: BaseActor, vel: Vector3): void;
|
73
|
+
/**
|
74
|
+
* Sets the angular velocity of an actor's physics body
|
75
|
+
*/
|
76
|
+
abstract setAngularVelocity(actor: BaseActor, velocity: Vector3): void;
|
77
|
+
/**
|
78
|
+
* Sets the linear velocity of an actor's physics body
|
79
|
+
*/
|
80
|
+
abstract setLinearVelocity(actor: BaseActor, velocity: Vector3): void;
|
81
|
+
/**
|
82
|
+
* Gets the current linear velocity of an actor's physics body
|
83
|
+
*/
|
84
|
+
abstract getLinearVelocity(actor: BaseActor, target?: Vector3): Vector3;
|
85
|
+
/**
|
86
|
+
* Gets the current angular velocity of an actor's physics body
|
87
|
+
*/
|
88
|
+
abstract getAngularVelocity(actor: BaseActor, target?: Vector3): Vector3;
|
89
|
+
/**
|
90
|
+
* Sets the linear damping factor for an actor's physics body
|
91
|
+
*/
|
92
|
+
abstract setLinearDamping(actor: BaseActor, factor: number): void;
|
93
|
+
/**
|
94
|
+
* Sets the angular damping factor for an actor's physics body
|
95
|
+
*/
|
96
|
+
abstract setAngularDamping(actor: BaseActor, factor: number): void;
|
97
|
+
/**
|
98
|
+
* Creates a new character collision object
|
99
|
+
*/
|
100
|
+
abstract createCharacterCollision(): RAPIER.CharacterCollision;
|
101
|
+
/**
|
102
|
+
* Adds an actor to the physics world with the specified collision shapes and options
|
103
|
+
*/
|
104
|
+
abstract addActor<A extends BaseActor>(actor: A, collisionShapes: CollisionShape[], options?: Partial<ActorPhysicsOptions>): void;
|
105
|
+
/**
|
106
|
+
* Applies a torque to an actor's physics body
|
107
|
+
*/
|
108
|
+
abstract applyTorque(actor: BaseActor, torque: Vector3): void;
|
109
|
+
/**
|
110
|
+
* Applies an instantaneous torque impulse to an actor's physics body
|
111
|
+
*/
|
112
|
+
abstract applyTorqueImpulse(actor: BaseActor, torqueImpulse: Vector3): void;
|
113
|
+
/**
|
114
|
+
* Resets all accumulated forces on an actor's physics body
|
115
|
+
*/
|
116
|
+
abstract resetForces(actor: BaseActor): void;
|
117
|
+
/**
|
118
|
+
* Resets all accumulated torques on an actor's physics body
|
119
|
+
*/
|
120
|
+
abstract resetTorques(actor: BaseActor): void;
|
121
|
+
/**
|
122
|
+
* Applies a continuous force to an actor's physics body
|
123
|
+
*/
|
124
|
+
abstract applyForce(actor: BaseActor, force: Vector3): void;
|
125
|
+
/**
|
126
|
+
* Applies an instantaneous force impulse to an actor's physics body
|
127
|
+
*/
|
128
|
+
abstract applyImpulse(actor: BaseActor, force: Vector3): void;
|
129
|
+
/**
|
130
|
+
* Applies a force at a specific local point on an actor's physics body
|
131
|
+
*/
|
132
|
+
abstract applyLocalForce(actor: BaseActor, force: Vector3, localPoint?: Vector3): void;
|
133
|
+
/**
|
134
|
+
* Applies an instantaneous force impulse at a specific local point on an actor's physics body
|
135
|
+
*/
|
136
|
+
abstract applyLocalImpulse(actor: BaseActor, force: Vector3, localPoint?: Vector3): void;
|
137
|
+
/**
|
138
|
+
* Removes an actor from the physics world
|
139
|
+
*/
|
140
|
+
abstract removeActor(actor: BaseActor): void;
|
141
|
+
/**
|
142
|
+
* Removes physics bodies for objects that have been removed from the scene
|
143
|
+
*/
|
144
|
+
abstract removeRemoved(scene: Object3D): void;
|
145
|
+
/**
|
146
|
+
* Removes the physics body for a specific scene object
|
147
|
+
*/
|
148
|
+
abstract removeSceneObject(object: Object3D): void;
|
149
|
+
/**
|
150
|
+
* Gets an observable for when an actor begins contact with any object
|
151
|
+
*/
|
152
|
+
abstract onBeginContact(self: BaseActor): Observable<number>;
|
153
|
+
/**
|
154
|
+
* Gets an observable for when an actor ends contact with any object
|
155
|
+
*/
|
156
|
+
abstract onEndContact(self: BaseActor): Observable<number>;
|
157
|
+
/**
|
158
|
+
* Gets an observable that tracks whether an actor is in contact with any object
|
159
|
+
*/
|
160
|
+
abstract onHasContactChanged(self: BaseActor): Observable<boolean>;
|
161
|
+
/**
|
162
|
+
* Gets an observable for when an actor begins overlapping with actors of a specific type
|
163
|
+
*/
|
164
|
+
abstract onBeginOverlapWithActorType<T extends BaseActor, A extends BaseActor>(self: T, actorType: AbstractType<A>): Observable<A>;
|
165
|
+
/**
|
166
|
+
* Gets an observable for when an actor ends overlapping with actors of a specific type
|
167
|
+
*/
|
168
|
+
abstract onEndOverlapWithActorType<T extends BaseActor, A extends BaseActor>(self: T, actorType: AbstractType<A>): Observable<A>;
|
169
|
+
/**
|
170
|
+
* Gets an observable for when an actor begins overlapping with a specific actor
|
171
|
+
*/
|
172
|
+
abstract onBeginOverlapWithActor<T extends BaseActor, A extends BaseActor>(self: T, actor: A): Observable<A>;
|
173
|
+
/**
|
174
|
+
* Gets an observable for when an actor ends overlapping with a specific actor
|
175
|
+
*/
|
176
|
+
abstract onEndOverlapWithActor<T extends BaseActor, A extends BaseActor>(self: T, actor: A): Observable<A>;
|
177
|
+
/**
|
178
|
+
* Gets an observable for collision events with a specific actor
|
179
|
+
*/
|
180
|
+
abstract onCollisionWithActor<A extends BaseActor, S extends BaseActor>(self: S, actor: A): Observable<A>;
|
181
|
+
/**
|
182
|
+
* Gets an observable for collision events with actors of a specific type
|
183
|
+
*/
|
184
|
+
abstract onCollisionWithActorType<A extends BaseActor, S extends BaseActor>(self: S, actorType: AbstractType<A>): Observable<A>;
|
185
|
+
/**
|
186
|
+
* Updates the transform of an actor's physics body to match its visual representation
|
187
|
+
*/
|
188
|
+
abstract updateActorTransform(actor: BaseActor): void;
|
189
|
+
/**
|
190
|
+
* Gets the contact points between an actor and other objects in a specific direction
|
191
|
+
*/
|
192
|
+
abstract getActorContacts(actor: BaseActor, direction: Vector3): {
|
193
|
+
ri: Vector3;
|
194
|
+
rj: Vector3;
|
195
|
+
ni: Vector3;
|
196
|
+
}[];
|
197
|
+
/**
|
198
|
+
* Stops the physics simulation and cleans up resources
|
199
|
+
*/
|
200
|
+
abstract stop(): void;
|
201
|
+
}
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import * as RAPIER from "@dimforge/rapier3d-compat";
|
2
2
|
import { Observable, Subject } from "rxjs";
|
3
|
-
import * as THREE from "three";
|
4
3
|
import { ColorRepresentation, Object3D, Vector3 } from "three";
|
5
4
|
import { CollisionShape } from '../../../index.js';
|
6
5
|
import { AbstractType } from '../../../utils/type.js';
|
7
6
|
import { BaseActor } from '../../actors/actor.js';
|
8
7
|
import { ViewController } from '../render.js';
|
9
8
|
import { World } from '../world.js';
|
9
|
+
import { AbstractPhysicsSystem, ActorPhysicsOptions } from './abstract-physics-system.js';
|
10
10
|
export declare class RayTestResult {
|
11
11
|
actor?: BaseActor;
|
12
12
|
hasHit: boolean;
|
@@ -27,17 +27,11 @@ export declare enum PhysicsBodyType {
|
|
27
27
|
kinematic = 4,
|
28
28
|
kinematicVelocityBased = 8
|
29
29
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
density: number;
|
36
|
-
restitution: number;
|
37
|
-
type: PhysicsBodyType;
|
38
|
-
ignoreForNavMesh: boolean;
|
39
|
-
};
|
40
|
-
export declare class PhysicsSystem {
|
30
|
+
/**
|
31
|
+
* A physics system implementation using the Rapier physics engine.
|
32
|
+
* Handles rigid body physics, collisions, and physics-based character movement.
|
33
|
+
*/
|
34
|
+
export declare class PhysicsSystem extends AbstractPhysicsSystem {
|
41
35
|
viewController: ViewController;
|
42
36
|
private gameWorld;
|
43
37
|
readonly ready: Promise<void>;
|
@@ -58,51 +52,209 @@ export declare class PhysicsSystem {
|
|
58
52
|
constructor(viewController: ViewController, gameWorld: World);
|
59
53
|
private debugMesh;
|
60
54
|
private createDebugMesh;
|
55
|
+
/**
|
56
|
+
* Initializes and starts the physics system.
|
57
|
+
* @returns A promise that resolves when the physics system is ready
|
58
|
+
*/
|
61
59
|
start(): Promise<void>;
|
60
|
+
/**
|
61
|
+
* Renders debug visualization of physics bodies and colliders.
|
62
|
+
* Only active when showDebug is true.
|
63
|
+
*/
|
62
64
|
renderDebug(): void;
|
65
|
+
/**
|
66
|
+
* Sets up the physics world and initializes Rapier.
|
67
|
+
* @private
|
68
|
+
*/
|
63
69
|
private setup;
|
70
|
+
/**
|
71
|
+
* Handles the physics update tick, synchronizing physics bodies with their visual representations.
|
72
|
+
* @private
|
73
|
+
*/
|
64
74
|
private handleTick;
|
65
75
|
/**
|
66
|
-
*
|
67
|
-
*
|
68
|
-
*
|
76
|
+
* Updates the physics world state without advancing time.
|
77
|
+
* Used when physics simulation is paused but physics state needs updating.
|
78
|
+
* @private
|
69
79
|
*/
|
70
80
|
private _updateWorld;
|
81
|
+
/**
|
82
|
+
* Updates the physics simulation for the current frame.
|
83
|
+
* @param deltaTime - Time elapsed since last update in seconds
|
84
|
+
* @private
|
85
|
+
*/
|
71
86
|
private updatePhysics;
|
87
|
+
/**
|
88
|
+
* Performs a raycast test from the camera's perspective.
|
89
|
+
* @param distance - Maximum distance of the raycast
|
90
|
+
* @param result - Optional RayTestResult to store the result
|
91
|
+
* @param options - Optional configuration for the raycast
|
92
|
+
* @returns The result of the raycast test
|
93
|
+
*/
|
72
94
|
private _raycaster;
|
73
95
|
rayTestFromCamera(distance: number, result?: RayTestResult, options?: RayTestOptions): RayTestResult;
|
74
96
|
private _reusableResult;
|
75
97
|
private _raytestDiff;
|
76
98
|
private _raytestDirection;
|
99
|
+
/**
|
100
|
+
* Performs a raycast test between two points in world space.
|
101
|
+
* @param from - Starting point of the ray
|
102
|
+
* @param to - End point of the ray
|
103
|
+
* @param result - Optional RayTestResult to store the result
|
104
|
+
* @param options - Optional configuration for the raycast
|
105
|
+
* @returns The result of the raycast test
|
106
|
+
*/
|
77
107
|
rayTest(from: Vector3, to: Vector3, result?: RayTestResult, options?: RayTestOptions): RayTestResult;
|
108
|
+
/**
|
109
|
+
* Sets the gravity vector for the physics world.
|
110
|
+
* @param x - Gravity force along X axis
|
111
|
+
* @param y - Gravity force along Y axis
|
112
|
+
* @param z - Gravity force along Z axis
|
113
|
+
*/
|
78
114
|
setGravity(x: number, y: number, z: number): void;
|
115
|
+
/**
|
116
|
+
* Gets the current gravity vector of the physics world.
|
117
|
+
* @returns The gravity vector
|
118
|
+
*/
|
79
119
|
getGravity(): Vector3;
|
80
120
|
/**
|
81
|
-
*
|
121
|
+
* Adds static collision bodies to the physics world based on an existing scene hierarchy.
|
122
|
+
* @param object - The root object of the scene to add physics bodies for
|
82
123
|
*/
|
83
124
|
addFromScene(object: Object3D): void;
|
125
|
+
/**
|
126
|
+
* Recursively processes scene objects to add physics bodies.
|
127
|
+
* @param object - The object to process
|
128
|
+
* @private
|
129
|
+
*/
|
84
130
|
private addRecursively;
|
131
|
+
/**
|
132
|
+
* Creates physics bodies for each instance in an instanced mesh.
|
133
|
+
* @param instancedMesh - The instanced mesh to create bodies for
|
134
|
+
* @param collisionShapes - The collision shapes to use for each instance
|
135
|
+
* @private
|
136
|
+
*/
|
85
137
|
private createForInstancedMesh;
|
86
138
|
private readonly controlledActors;
|
139
|
+
/**
|
140
|
+
* Creates a character controller for physics-based character movement.
|
141
|
+
* @param offset - The skin offset for the character controller
|
142
|
+
* @returns A new kinematic character controller
|
143
|
+
*/
|
87
144
|
getCharacterController(offset?: number): RAPIER.KinematicCharacterController;
|
145
|
+
/**
|
146
|
+
* Computes the corrected movement vector for an actor using a character controller.
|
147
|
+
* @param actor - The actor to compute movement for
|
148
|
+
* @param cc - The character controller to use
|
149
|
+
* @param desiredTranslation - The desired movement vector
|
150
|
+
* @param collisionGroup - Optional collision group filter
|
151
|
+
* @returns The corrected movement vector accounting for collisions
|
152
|
+
*/
|
88
153
|
getActorComputedMovement(actor: BaseActor, cc: RAPIER.KinematicCharacterController, desiredTranslation: Vector3, collisionGroup?: number): Vector3;
|
154
|
+
/**
|
155
|
+
* Sets the next kinematic translation for an actor.
|
156
|
+
* @param actor - The actor to update
|
157
|
+
* @param vel - The velocity vector to apply
|
158
|
+
*/
|
89
159
|
setNextKinematicTranslation(actor: BaseActor, vel: Vector3): void;
|
160
|
+
/**
|
161
|
+
* Sets the angular velocity of an actor's physics body.
|
162
|
+
* @param actor - The actor to update
|
163
|
+
* @param velocity - The angular velocity vector to apply
|
164
|
+
*/
|
90
165
|
setAngularVelocity(actor: BaseActor, velocity: Vector3): void;
|
166
|
+
/**
|
167
|
+
* Sets the linear velocity of an actor's physics body.
|
168
|
+
* @param actor - The actor to update
|
169
|
+
* @param velocity - The linear velocity vector to apply
|
170
|
+
*/
|
91
171
|
setLinearVelocity(actor: BaseActor, velocity: Vector3): void;
|
92
|
-
|
93
|
-
|
172
|
+
/**
|
173
|
+
* Gets the current linear velocity of an actor's physics body.
|
174
|
+
* @param actor - The actor to query
|
175
|
+
* @param target - Optional vector to store the result in
|
176
|
+
* @returns The linear velocity vector
|
177
|
+
*/
|
178
|
+
getLinearVelocity(actor: BaseActor, target?: Vector3): Vector3;
|
179
|
+
/**
|
180
|
+
* Gets the current angular velocity of an actor's physics body.
|
181
|
+
* @param actor - The actor to query
|
182
|
+
* @param target - Optional vector to store the result in
|
183
|
+
* @returns The angular velocity vector
|
184
|
+
*/
|
185
|
+
getAngularVelocity(actor: BaseActor, target?: Vector3): Vector3;
|
186
|
+
/**
|
187
|
+
* Sets the linear damping factor for an actor's physics body.
|
188
|
+
* @param actor - The actor to update
|
189
|
+
* @param factor - The damping factor to apply
|
190
|
+
*/
|
94
191
|
setLinearDamping(actor: BaseActor, factor: number): void;
|
192
|
+
/**
|
193
|
+
* Sets the angular damping factor for an actor's physics body.
|
194
|
+
* @param actor - The actor to update
|
195
|
+
* @param factor - The damping factor to apply
|
196
|
+
*/
|
95
197
|
setAngularDamping(actor: BaseActor, factor: number): void;
|
96
|
-
|
198
|
+
/**
|
199
|
+
* Adds physics bodies for a landscape group.
|
200
|
+
* @param object - The landscape group to add physics for
|
201
|
+
* @private
|
202
|
+
*/
|
97
203
|
private addLandscapeGroup;
|
204
|
+
/**
|
205
|
+
* Adds an actor to the physics world with the specified collision shapes and options.
|
206
|
+
* @param actor - The actor to add
|
207
|
+
* @param collisionShapes - Array of collision shapes for the actor
|
208
|
+
* @param options - Physics options for the actor
|
209
|
+
*/
|
98
210
|
addActor<A extends BaseActor>(actor: A, collisionShapes: CollisionShape[], options?: Partial<ActorPhysicsOptions>): void;
|
211
|
+
/**
|
212
|
+
* Applies a torque to an actor's physics body.
|
213
|
+
* @param actor - The actor to apply torque to
|
214
|
+
* @param torque - The torque vector to apply
|
215
|
+
*/
|
99
216
|
applyTorque(actor: BaseActor, torque: Vector3): void;
|
217
|
+
/**
|
218
|
+
* Applies an instantaneous torque impulse to an actor's physics body.
|
219
|
+
* @param actor - The actor to apply the impulse to
|
220
|
+
* @param torqueImpulse - The torque impulse vector to apply
|
221
|
+
*/
|
100
222
|
applyTorqueImpulse(actor: BaseActor, torqueImpulse: Vector3): void;
|
223
|
+
/**
|
224
|
+
* Resets all accumulated forces on an actor's physics body.
|
225
|
+
* @param actor - The actor to reset forces for
|
226
|
+
*/
|
101
227
|
resetForces(actor: BaseActor): void;
|
228
|
+
/**
|
229
|
+
* Resets all accumulated torques on an actor's physics body.
|
230
|
+
* @param actor - The actor to reset torques for
|
231
|
+
*/
|
102
232
|
resetTorques(actor: BaseActor): void;
|
233
|
+
/**
|
234
|
+
* Applies a continuous force to an actor's physics body.
|
235
|
+
* @param actor - The actor to apply force to
|
236
|
+
* @param force - The force vector to apply
|
237
|
+
*/
|
103
238
|
applyForce(actor: BaseActor, force: Vector3): void;
|
239
|
+
/**
|
240
|
+
* Applies an instantaneous force impulse to an actor's physics body.
|
241
|
+
* @param actor - The actor to apply the impulse to
|
242
|
+
* @param force - The force impulse vector to apply
|
243
|
+
*/
|
104
244
|
applyImpulse(actor: BaseActor, force: Vector3): void;
|
245
|
+
/**
|
246
|
+
* Applies a force at a specific local point on an actor's physics body.
|
247
|
+
* @param actor - The actor to apply force to
|
248
|
+
* @param force - The force vector to apply
|
249
|
+
* @param localPoint - The local point at which to apply the force
|
250
|
+
*/
|
105
251
|
applyLocalForce(actor: BaseActor, force: Vector3, localPoint?: Vector3): void;
|
252
|
+
/**
|
253
|
+
* Applies an instantaneous force impulse at a specific local point on an actor's physics body.
|
254
|
+
* @param actor - The actor to apply the impulse to
|
255
|
+
* @param force - The force impulse vector to apply
|
256
|
+
* @param localPoint - The local point at which to apply the impulse
|
257
|
+
*/
|
106
258
|
applyLocalImpulse(actor: BaseActor, force: Vector3, localPoint?: Vector3): void;
|
107
259
|
/**
|
108
260
|
* Apply an impulse on all dynamic physics bodies in the direction away from the given
|
@@ -112,40 +264,146 @@ export declare class PhysicsSystem {
|
|
112
264
|
* @param forceAmount
|
113
265
|
*/
|
114
266
|
private applyRadiusImpulse;
|
267
|
+
/**
|
268
|
+
* Removes an actor from the physics world.
|
269
|
+
* @param actor - The actor to remove
|
270
|
+
*/
|
115
271
|
removeActor(actor: BaseActor): void;
|
272
|
+
/**
|
273
|
+
* Removes the physics body for a specific scene object.
|
274
|
+
* @param object - The object to remove physics for
|
275
|
+
*/
|
116
276
|
removeSceneObject(object: Object3D): void;
|
277
|
+
/**
|
278
|
+
* Activates collision event handling for an actor.
|
279
|
+
* @param actor - The actor to activate events for
|
280
|
+
* @private
|
281
|
+
*/
|
117
282
|
private activateActorEvents;
|
283
|
+
/**
|
284
|
+
* Gets an observable for collision events between actors.
|
285
|
+
* @param self - The actor to observe collisions for
|
286
|
+
* @param predicate - Function to filter collision events
|
287
|
+
* @param whenStarted - Whether to emit on collision start or end
|
288
|
+
* @returns Observable of colliding actors
|
289
|
+
* @private
|
290
|
+
*/
|
118
291
|
private _onCollisionWithActorEvent;
|
119
292
|
/**
|
120
|
-
*
|
121
|
-
*
|
293
|
+
* Gets an observable for when an actor begins contact with any object.
|
294
|
+
* @param self - The actor to observe contacts for
|
295
|
+
* @returns Observable of contact events
|
122
296
|
*/
|
123
297
|
onBeginContact(self: BaseActor): Observable<number>;
|
124
298
|
/**
|
125
|
-
*
|
126
|
-
*
|
299
|
+
* Gets an observable for when an actor ends contact with any object.
|
300
|
+
* @param self - The actor to observe contacts for
|
301
|
+
* @returns Observable of contact events
|
127
302
|
*/
|
128
303
|
onEndContact(self: BaseActor): Observable<number>;
|
304
|
+
/**
|
305
|
+
* Gets an observable that tracks whether an actor is in contact with any object.
|
306
|
+
* @param self - The actor to track contacts for
|
307
|
+
* @returns Observable boolean indicating contact state
|
308
|
+
*/
|
129
309
|
onHasContactChanged(self: BaseActor): Observable<boolean>;
|
310
|
+
/**
|
311
|
+
* Gets an observable for when an actor begins overlapping with actors of a specific type.
|
312
|
+
* @param self - The actor to observe overlaps for
|
313
|
+
* @param actorType - The type of actors to detect overlaps with
|
314
|
+
* @returns Observable of overlapping actors
|
315
|
+
*/
|
130
316
|
onBeginOverlapWithActorType<T extends BaseActor, A extends BaseActor>(self: T, actorType: AbstractType<A>): Observable<A>;
|
317
|
+
/**
|
318
|
+
* Gets an observable for when an actor ends overlapping with actors of a specific type.
|
319
|
+
* @param self - The actor to observe overlaps for
|
320
|
+
* @param actorType - The type of actors to detect overlaps with
|
321
|
+
* @returns Observable of overlapping actors
|
322
|
+
*/
|
131
323
|
onEndOverlapWithActorType<T extends BaseActor, A extends BaseActor>(self: T, actorType: AbstractType<A>): Observable<A>;
|
324
|
+
/**
|
325
|
+
* Gets an observable for when an actor begins overlapping with a specific actor.
|
326
|
+
* @param self - The actor to observe overlaps for
|
327
|
+
* @param actor - The specific actor to detect overlaps with
|
328
|
+
* @returns Observable of overlap events
|
329
|
+
*/
|
132
330
|
onBeginOverlapWithActor<T extends BaseActor, A extends BaseActor>(self: T, actor: A): Observable<A>;
|
331
|
+
/**
|
332
|
+
* Gets an observable for when an actor ends overlapping with a specific actor.
|
333
|
+
* @param self - The actor to observe overlaps for
|
334
|
+
* @param actor - The specific actor to detect overlaps with
|
335
|
+
* @returns Observable of overlap events
|
336
|
+
*/
|
133
337
|
onEndOverlapWithActor<T extends BaseActor, A extends BaseActor>(self: T, actor: A): Observable<A>;
|
338
|
+
/**
|
339
|
+
* Gets an observable for collision events with a specific actor.
|
340
|
+
* @param self - The actor to observe collisions for
|
341
|
+
* @param actor - The specific actor to detect collisions with
|
342
|
+
* @returns Observable of collision events
|
343
|
+
*/
|
134
344
|
onCollisionWithActor<A extends BaseActor, S extends BaseActor>(self: S, actor: A): Observable<A>;
|
345
|
+
/**
|
346
|
+
* Gets an observable for collision events with actors of a specific type.
|
347
|
+
* @param self - The actor to observe collisions for
|
348
|
+
* @param actorType - The type of actors to detect collisions with
|
349
|
+
* @returns Observable of collision events
|
350
|
+
*/
|
135
351
|
onCollisionWithActorType<A extends BaseActor, S extends BaseActor>(self: S, actorType: AbstractType<A>): Observable<A>;
|
352
|
+
/**
|
353
|
+
* Updates the transform of an actor's physics body to match its visual representation.
|
354
|
+
* @param actor - The actor to update
|
355
|
+
*/
|
136
356
|
updateActorTransform(actor: BaseActor): void;
|
357
|
+
/**
|
358
|
+
* Sets up the physics world with default gravity.
|
359
|
+
* @private
|
360
|
+
*/
|
137
361
|
private setupWorld;
|
362
|
+
/**
|
363
|
+
* Gets the contact points between an actor and other objects in a specific direction.
|
364
|
+
* @param actor - The actor to check contacts for
|
365
|
+
* @param direction - The direction to check in
|
366
|
+
* @returns Array of contact points with position and normal information
|
367
|
+
*/
|
138
368
|
getActorContacts(actor: BaseActor, direction: Vector3): {
|
139
369
|
ri: Vector3;
|
140
370
|
rj: Vector3;
|
141
371
|
ni: Vector3;
|
142
372
|
}[];
|
373
|
+
/**
|
374
|
+
* Stops the physics simulation and cleans up resources.
|
375
|
+
*/
|
143
376
|
stop(): void;
|
144
377
|
/**
|
145
|
-
*
|
378
|
+
* Creates a static physics body for a scene object.
|
379
|
+
* @param object - The object to create a body for
|
380
|
+
* @param collisionShapes - The collision shapes to use
|
381
|
+
* @param options - Optional physics settings
|
382
|
+
* @returns The created rigid body
|
383
|
+
* @private
|
146
384
|
*/
|
147
385
|
private createStaticBody;
|
386
|
+
/**
|
387
|
+
* Adds a collision shape to a rigid body.
|
388
|
+
* @param body - The rigid body to add the shape to
|
389
|
+
* @param shapeInfo - The collision shape information
|
390
|
+
* @param object - The object the shape is based on
|
391
|
+
* @returns The created collider
|
392
|
+
* @private
|
393
|
+
*/
|
148
394
|
private addShape;
|
395
|
+
/**
|
396
|
+
* Creates a Rapier collision shape from shape information and scale.
|
397
|
+
* @param shapeInfo - The collision shape information
|
398
|
+
* @param scale - The scale to apply to the shape
|
399
|
+
* @returns The created collider description
|
400
|
+
* @private
|
401
|
+
*/
|
149
402
|
private createShape;
|
403
|
+
/**
|
404
|
+
* Creates a new character collision object
|
405
|
+
* @returns A new RAPIER.CharacterCollision instance
|
406
|
+
*/
|
407
|
+
createCharacterCollision(): RAPIER.CharacterCollision;
|
150
408
|
}
|
151
409
|
export {};
|