-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
5,458 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Object3D } from 'three'; | ||
import { PhysicsControls, PhysicsOptions } from './base/PhysicsControls'; | ||
/** | ||
* Actions that can be performed via keyboard input. | ||
*/ | ||
type Actions = 'forward' | 'backward' | 'leftward' | 'rightward' | 'turnLeft' | 'turnRight' | 'turnUp' | 'turnDown' | 'jump' | 'accelerate'; | ||
/** | ||
* Configuration for key mappings to actions. | ||
*/ | ||
type ActionKeys = { | ||
[K in Actions]?: string[]; | ||
}; | ||
/** | ||
* Configuration options for camera control. | ||
*/ | ||
type CameraOptions = { | ||
enableZoom?: boolean; | ||
zoomSpeed?: number; | ||
}; | ||
/** | ||
* Extended physics options specific to keyboard controls. | ||
*/ | ||
type KeyboardPhysicsOptions = PhysicsOptions & { | ||
eyeHeight?: number; | ||
jumpForce?: number; | ||
groundMoveSpeed?: number; | ||
floatMoveSpeed?: number; | ||
rotateSpeed?: number; | ||
enableDiagonalMovement?: boolean; | ||
enableAcceleration?: boolean; | ||
accelerationFactor?: number; | ||
}; | ||
type FirstPersonKeyboardControlsProps = { | ||
object: Object3D; | ||
domElement: HTMLElement | null; | ||
worldObject: Object3D; | ||
actionKeys?: ActionKeys; | ||
physicsOptions?: KeyboardPhysicsOptions; | ||
cameraOptions?: CameraOptions; | ||
}; | ||
/** | ||
* FirstPersonKeyboardControls class allows controlling a 3D object using the keyboard, | ||
*/ | ||
declare class FirstPersonKeyboardControls extends PhysicsControls { | ||
actionKeys: ActionKeys; | ||
enableZoom: boolean; | ||
zoomSpeed: number; | ||
eyeHeight: number; | ||
jumpForce: number; | ||
groundMoveSpeed: number; | ||
floatMoveSpeed: number; | ||
rotateSpeed: number; | ||
enableDiagonalMovement: boolean; | ||
enableAcceleration: boolean; | ||
accelerationFactor: number; | ||
private _keyCount; | ||
private _objectLocalDirection; | ||
private _accumulatedDirection; | ||
private _worldYDirection; | ||
private onKeyDown; | ||
private onKeyUp; | ||
private onMouseWheel; | ||
constructor({ object, domElement, worldObject, actionKeys, cameraOptions, physicsOptions, }: FirstPersonKeyboardControlsProps); | ||
/** | ||
* Retrieves the forward _objectWorldDirection vector of the object, ignoring the Y-axis. | ||
* @returns A normalized Vector3 representing the forward _objectWorldDirection. | ||
*/ | ||
private _getForwardVector; | ||
/** | ||
* Gets the side (right) direction vector based on the camera's orientation. | ||
* @returns Normalized side vector. | ||
*/ | ||
private _getSideVector; | ||
private _accumulateDirection; | ||
private _getMostRecentDirection; | ||
/** | ||
* Updates movement and rotation based on the current keyboard input. | ||
* @param delta - The time delta for frame-independent movement. | ||
*/ | ||
private updateControls; | ||
/** | ||
* Main update function that integrates controls, physics, camera, and animations. | ||
* @param delta - The time delta for consistent updates. | ||
*/ | ||
update(delta: number): void; | ||
/** | ||
* Connects the keyboard controls by adding event listeners. | ||
*/ | ||
connect(): void; | ||
/** | ||
* Disconnects the keyboard controls by removing event listeners. | ||
*/ | ||
disconnect(): void; | ||
/** | ||
* Disposes of the keyboard controls, cleaning up event listeners and animations. | ||
*/ | ||
dispose(): void; | ||
/** Handles keydown events, updating the key state. */ | ||
private _onKeyDown; | ||
/** Handles keyup events, updating the key state. */ | ||
private _onKeyUp; | ||
private _onMouseWheel; | ||
} | ||
export { FirstPersonKeyboardControls }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { Object3D } from 'three'; | ||
import { PhysicsControls, PhysicsOptions } from './base/PhysicsControls'; | ||
/** | ||
* Actions that can be performed via keyboard input. | ||
*/ | ||
type Actions = 'forward' | 'backward' | 'leftward' | 'rightward' | 'jump' | 'accelerate'; | ||
/** | ||
* Configuration for key mappings to actions. | ||
*/ | ||
type ActionKeys = { | ||
[K in Actions]?: string[]; | ||
}; | ||
/** | ||
* Configuration options for camera control. | ||
*/ | ||
type CameraOptions = { | ||
enableZoom?: boolean; | ||
zoomSpeed?: number; | ||
}; | ||
/** | ||
* Extended physics options specific to mouse drag controls. | ||
*/ | ||
type MouseDragPhysicsOptions = PhysicsOptions & { | ||
eyeHeight?: number; | ||
jumpForce?: number; | ||
groundMoveSpeed?: number; | ||
floatMoveSpeed?: number; | ||
rotateSpeed?: number; | ||
enableDiagonalMovement?: boolean; | ||
enableAcceleration?: boolean; | ||
accelerationFactor?: number; | ||
}; | ||
type FirstPersonMouseDragControlsProps = { | ||
object: Object3D; | ||
domElement: HTMLElement | null; | ||
worldObject: Object3D; | ||
actionKeys?: ActionKeys; | ||
physicsOptions?: MouseDragPhysicsOptions; | ||
cameraOptions?: CameraOptions; | ||
}; | ||
/** | ||
* FirstPersonMouseDragControls class allows controlling a 3D object using the mouse drag, | ||
*/ | ||
declare class FirstPersonMouseDragControls extends PhysicsControls { | ||
actionKeys: ActionKeys; | ||
enableZoom: boolean; | ||
zoomSpeed: number; | ||
eyeHeight: number; | ||
jumpForce: number; | ||
groundMoveSpeed: number; | ||
floatMoveSpeed: number; | ||
rotateSpeed: number; | ||
enableDiagonalMovement: boolean; | ||
enableAcceleration: boolean; | ||
accelerationFactor: number; | ||
private _keyCount; | ||
private _isMouseDown; | ||
private _objectLocalDirection; | ||
private _accumulatedDirection; | ||
private _worldYDirection; | ||
private onKeyDown; | ||
private onKeyUp; | ||
private onMouseDown; | ||
private onMouseUp; | ||
private onMouseMove; | ||
private onMouseWheel; | ||
/** | ||
* Constructs a new FirstPersonMouseDragControls instance. | ||
* @param object - The 3D object to control. | ||
* @param domElement - The HTML element for event listeners (optional). | ||
* @param worldObject - The world object used for physics collision. | ||
* @param actionKeys - Key mappings for actions. | ||
* @param cameraOptions - Configuration for the camera (optional). | ||
* @param animationOptions - Configuration for animations (optional). | ||
* @param physicsOptions - Physics configuration options (optional). | ||
*/ | ||
constructor({ object, domElement, worldObject, actionKeys, cameraOptions, physicsOptions, }: FirstPersonMouseDragControlsProps); | ||
/** | ||
* Retrieves the forward _objectWorldDirection vector of the object, ignoring the Y-axis. | ||
* @returns A normalized Vector3 representing the forward _objectWorldDirection. | ||
*/ | ||
private _getForwardVector; | ||
/** | ||
* Gets the side (right) direction vector based on the camera's orientation. | ||
* @returns Normalized side vector. | ||
*/ | ||
private _getSideVector; | ||
private _accumulateDirection; | ||
private _getMostRecentDirection; | ||
/** | ||
* Updates movement based on physics and camera rotation. | ||
* @param delta - The time delta for frame-independent movement. | ||
*/ | ||
private updateControls; | ||
/** | ||
* Main update function that integrates controls, physics, camera, and animations. | ||
* @param delta - The time delta for consistent updates. | ||
*/ | ||
update(delta: number): void; | ||
/** | ||
* Connects the keyboard controls by adding event listeners. | ||
*/ | ||
connect(): void; | ||
/** | ||
* Disconnects the keyboard controls by removing event listeners. | ||
*/ | ||
disconnect(): void; | ||
/** | ||
* Disposes of the keyboard controls, cleaning up event listeners and animations. | ||
*/ | ||
dispose(): void; | ||
/** Handles keydown events, updating the key state. */ | ||
private _onKeyDown; | ||
/** Handles keyup events, updating the key state. */ | ||
private _onKeyUp; | ||
/** Handles mousedown events to set _isMouseDown flag. */ | ||
private _onMouseDown; | ||
/** Handles mouseup events to reset _isMouseDown flag. */ | ||
private _onMouseUp; | ||
/** Handles mousemove events to update camera angles when mouse is down. */ | ||
private _onMouseMove; | ||
private _onMouseWheel; | ||
} | ||
export { FirstPersonMouseDragControls }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { Object3D } from 'three'; | ||
import { PhysicsControls, PhysicsOptions } from './base/PhysicsControls'; | ||
/** | ||
* Possible actions that can be mapped to keyboard inputs. | ||
*/ | ||
type Actions = 'forward' | 'backward' | 'leftward' | 'rightward' | 'jump' | 'accelerate'; | ||
/** | ||
* Configuration for key mappings to actions. | ||
*/ | ||
type ActionKeys = { | ||
[K in Actions]?: string[]; | ||
}; | ||
/** | ||
* Configuration options for camera control. | ||
*/ | ||
type CameraOptions = { | ||
enableZoom?: boolean; | ||
zoomSpeed?: number; | ||
}; | ||
/** | ||
* Extended physics options specific to pointer lock controls. | ||
*/ | ||
type PointerLockPhysicsOptions = PhysicsOptions & { | ||
eyeHeight?: number; | ||
jumpForce?: number; | ||
groundMoveSpeed?: number; | ||
floatMoveSpeed?: number; | ||
rotateSpeed?: number; | ||
enableDiagonalMovement?: boolean; | ||
enableAcceleration?: boolean; | ||
accelerationFactor?: number; | ||
}; | ||
type FirstPersonPointerLockControlsProps = { | ||
object: Object3D; | ||
domElement: HTMLElement | null; | ||
worldObject: Object3D; | ||
actionKeys?: ActionKeys; | ||
physicsOptions?: PointerLockPhysicsOptions; | ||
cameraOptions?: CameraOptions; | ||
}; | ||
/** | ||
* FirstPersonPointerLockControls class allows controlling a 3D object using the Pointer Lock API and mouse input. | ||
*/ | ||
declare class FirstPersonPointerLockControls extends PhysicsControls { | ||
actionKeys: ActionKeys; | ||
enableZoom: boolean; | ||
zoomSpeed: number; | ||
eyeHeight: number; | ||
jumpForce: number; | ||
groundMoveSpeed: number; | ||
floatMoveSpeed: number; | ||
rotateSpeed: number; | ||
enableDiagonalMovement: boolean; | ||
enableAcceleration: boolean; | ||
accelerationFactor: number; | ||
private _keyCount; | ||
private _objectLocalDirection; | ||
private _accumulatedDirection; | ||
private _worldYDirection; | ||
private onKeyDown; | ||
private onKeyUp; | ||
private onMouseMove; | ||
private onMouseDown; | ||
private onMouseWheel; | ||
constructor({ object, domElement, worldObject, actionKeys, cameraOptions, physicsOptions, }: FirstPersonPointerLockControlsProps); | ||
/** | ||
* Retrieves the forward _objectWorldDirection vector of the object, ignoring the Y-axis. | ||
* @returns A normalized Vector3 representing the forward _objectWorldDirection. | ||
*/ | ||
private _getForwardVector; | ||
/** | ||
* Gets the side (right) direction vector based on the camera's orientation. | ||
* @returns Normalized side vector. | ||
*/ | ||
private _getSideVector; | ||
private _accumulateDirection; | ||
private _getMostRecentDirection; | ||
/** | ||
* Updates movement based on physics and camera rotation. | ||
* @param delta - The time delta for frame-independent movement. | ||
*/ | ||
private updateControls; | ||
/** | ||
* Main update function that integrates controls, physics, and camera. | ||
* @param delta - The time delta for consistent updates. | ||
*/ | ||
update(delta: number): void; | ||
/** | ||
* Connects the pointer lock controls by adding event listeners. | ||
*/ | ||
connect(): void; | ||
/** | ||
* Disconnects the pointer lock controls by removing event listeners. | ||
*/ | ||
disconnect(): void; | ||
/** | ||
* Disposes of the pointer lock controls, cleaning up event listeners and animations. | ||
*/ | ||
dispose(): void; | ||
/** Handles keydown events, updating the key state. */ | ||
private _onKeyDown; | ||
/** Handles keyup events, updating the key state. */ | ||
private _onKeyUp; | ||
/** | ||
* Requests pointer lock on the DOM element. | ||
*/ | ||
private _onMouseDown; | ||
/** Handles mousemove events to update camera angles with separate clamping for upward and downward movements. */ | ||
private _onMouseMove; | ||
private _onMouseWheel; | ||
} | ||
export { FirstPersonPointerLockControls }; |
Oops, something went wrong.