-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from taeuscherpferd/adding-locomotion-conveni…
…ence-hook Added a hook for simply adding locomotion
- Loading branch information
Showing
10 changed files
with
3,500 additions
and
3,128 deletions.
There are no files selected for viewing
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
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
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
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,47 @@ | ||
import { RootState, useFrame } from '@react-three/fiber' | ||
import { RefObject, useMemo } from 'react' | ||
import { Vector3, Object3D } from 'three' | ||
import { | ||
type ControllerLocomotionRotationOptions, | ||
type ControllerLocomotionTranslationOptions, | ||
createControllerLocomotionUpdate, | ||
} from '@pmndrs/xr/internals' | ||
import { useXRStore } from './xr.js' | ||
|
||
/** | ||
* A hook for handling basic locomotion in VR | ||
* @param target Either a `THREE.Group` ref, or a callback function. Recieves movement input (required). | ||
* @param translationOptions Options that control the translation of the user. Set to `false` to disable. | ||
* @param translationOptions.speed The speed at which the user moves. | ||
* @param rotationOptions Options that control the rotation of the user. Set to `false` to disable. | ||
* @param rotationOptions.deadZone How far the joystick must be pushed to trigger a turn. | ||
* @param rotationOptions.type Controls how rotation using the controller functions. Can be either 'smooth' or 'snap'. | ||
* @param rotationOptions.degrees If `type` is 'snap', this specifies the number of degrees to snap the user's view by. | ||
* @param rotationOptions.speed If `type` is 'smooth', this specifies the speed at which the user's view rotates. | ||
* @param translationControllerHand Specifies which hand will control the movement. Can be either 'left' or 'right'. | ||
*/ | ||
export function useControllerLocomotion( | ||
target: | ||
| RefObject<Object3D> | ||
| ((velocity: Vector3, rotationVelocityY: number, deltaTime: number, state: RootState, frame?: XRFrame) => void), | ||
translationOptions: ControllerLocomotionTranslationOptions = {}, | ||
rotationOptions: ControllerLocomotionRotationOptions = {}, | ||
translationControllerHand: Exclude<XRHandedness, 'none'> = 'left', | ||
) { | ||
const store = useXRStore() | ||
const update = useMemo(() => createControllerLocomotionUpdate(), []) | ||
useFrame((state, delta, frame: XRFrame | undefined) => | ||
update( | ||
typeof target === 'function' ? target : target.current, | ||
store, | ||
state.camera, | ||
delta, | ||
translationOptions, | ||
rotationOptions, | ||
translationControllerHand, | ||
delta, | ||
state, | ||
frame, | ||
), | ||
) | ||
} |
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
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
Oops, something went wrong.