From 5ae8be89b55fd916700576809ccf370e774316e9 Mon Sep 17 00:00:00 2001 From: Bela Bohlender Date: Fri, 1 Nov 2024 19:49:15 +0100 Subject: [PATCH] deprecate useControllerLocomotion in favor of useXRControllerLocomotion --- docs/getting-started/all-hooks.md | 6 +++--- examples/minecraft/src/VRPlayerControl.tsx | 4 ++-- examples/rag-doll/src/App.jsx | 4 ++-- packages/react/xr/src/controller-locomotion.ts | 14 +++++++------- packages/xr/src/controller-locomotion.ts | 12 ++++++------ pnpm-lock.yaml | 14 +++++++------- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/docs/getting-started/all-hooks.md b/docs/getting-started/all-hooks.md index 3cfacebe..f5e67dcf 100644 --- a/docs/getting-started/all-hooks.md +++ b/docs/getting-started/all-hooks.md @@ -141,7 +141,7 @@ Hook for getting the geometry from the detected plane. Hook for getting all detected planes with the provided semantic label. -### `useControllerLocomotion` +### `useXRControllerLocomotion` Hook for abstracting boilerplate needed to use controller based locomotion in XR. @@ -159,7 +159,7 @@ Hook for abstracting boilerplate needed to use controller based locomotion in XR // Example showing basic usage export const userMovement = () => { const originRef = useRef(null); - useControllerLocomotion(originRef); + useXRControllerLocomotion(originRef); return } @@ -176,7 +176,7 @@ export const userMovementWithPhysics = () => { } } - useControllerLocomotion(userMove) + useXRControllerLocomotion(userMove) return <> { if (controllerRight?.gamepad?.['a-button']?.state === 'pressed') { diff --git a/examples/rag-doll/src/App.jsx b/examples/rag-doll/src/App.jsx index b1053a0d..633962eb 100644 --- a/examples/rag-doll/src/App.jsx +++ b/examples/rag-doll/src/App.jsx @@ -4,7 +4,7 @@ import { Physics, usePlane } from '@react-three/cannon' import { Cursor } from './helpers/Drag.js' import { Guy } from './components/Guy.jsx' import { Mug, Chair, Table, Lamp } from './components/Furniture.jsx' -import { createXRStore, noEvents, useControllerLocomotion, XR, XROrigin, PointerEvents } from '@react-three/xr' +import { createXRStore, noEvents, useXRControllerLocomotion, XR, XROrigin, PointerEvents } from '@react-three/xr' import { useRef, Suspense } from 'react' const store = createXRStore({ @@ -72,7 +72,7 @@ export function App() { function ControlledXROrigin() { const ref = useRef(null) - useControllerLocomotion(ref, { speed: 10 }) + useXRControllerLocomotion(ref, { speed: 10 }) return } diff --git a/packages/react/xr/src/controller-locomotion.ts b/packages/react/xr/src/controller-locomotion.ts index cece6f01..f6b6111d 100644 --- a/packages/react/xr/src/controller-locomotion.ts +++ b/packages/react/xr/src/controller-locomotion.ts @@ -2,9 +2,9 @@ import { RootState, useFrame } from '@react-three/fiber' import { RefObject, useMemo } from 'react' import { Vector3, Object3D } from 'three' import { - type ControllerLocomotionRotationOptions, - type ControllerLocomotionTranslationOptions, - createControllerLocomotionUpdate, + type XRControllerLocomotionRotationOptions, + type XRControllerLocomotionTranslationOptions, + createXRControllerLocomotionUpdate, } from '@pmndrs/xr/internals' import { useXRStore } from './xr.js' @@ -20,16 +20,16 @@ import { useXRStore } from './xr.js' * @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( +export function useXRControllerLocomotion( target: | RefObject | ((velocity: Vector3, rotationVelocityY: number, deltaTime: number, state: RootState, frame?: XRFrame) => void), - translationOptions: ControllerLocomotionTranslationOptions = {}, - rotationOptions: ControllerLocomotionRotationOptions = {}, + translationOptions: XRControllerLocomotionTranslationOptions = {}, + rotationOptions: XRControllerLocomotionRotationOptions = {}, translationControllerHand: Exclude = 'left', ) { const store = useXRStore() - const update = useMemo(() => createControllerLocomotionUpdate(), []) + const update = useMemo(() => createXRControllerLocomotionUpdate(), []) useFrame((state, delta, frame: XRFrame | undefined) => update( typeof target === 'function' ? target : target.current, diff --git a/packages/xr/src/controller-locomotion.ts b/packages/xr/src/controller-locomotion.ts index d49be786..29227a96 100644 --- a/packages/xr/src/controller-locomotion.ts +++ b/packages/xr/src/controller-locomotion.ts @@ -1,18 +1,18 @@ import { Vector3, Quaternion, Euler, MathUtils, Object3D, Camera } from 'three' import { XRControllerState, XRInputSourceState, XRStore } from './internals.js' -export type ControllerLocomotionTranslationOptions = +export type XRControllerLocomotionTranslationOptions = | { speed?: number } | boolean -export type ControllerLocomotionRotationOptions = +export type XRControllerLocomotionRotationOptions = | ({ deadZone?: number } & ({ type?: 'snap'; degrees?: number } | { type: 'smooth'; speed?: number })) | boolean -// useControllerLocomotion defaults and constants +// useXRControllerLocomotion defaults and constants const defaultSpeed = 2 const defaultSmoothTurningSpeed = 2 const defaultSnapDegrees = 45 @@ -37,15 +37,15 @@ const scaleHelper = new Vector3() * @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 translation. Can be either 'left' or 'right'. */ -export function createControllerLocomotionUpdate() { +export function createXRControllerLocomotionUpdate() { let canRotate = true return >( target: Object3D | undefined | null | ((velocity: Vector3, rotationVelocityY: number, ...params: T) => void), store: XRStore, camera: Camera, delta: number, - translationOptions: ControllerLocomotionTranslationOptions = {}, - rotationOptions: ControllerLocomotionRotationOptions = {}, + translationOptions: XRControllerLocomotionTranslationOptions = {}, + rotationOptions: XRControllerLocomotionRotationOptions = {}, translationControllerHand: Exclude = 'left', ...params: T ) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f7be344b..c093db0c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -367,8 +367,8 @@ importers: packages/xr: dependencies: '@iwer/devui': - specifier: ^0.2.0 - version: 0.2.0(iwer@1.0.4) + specifier: ^0.2.1 + version: 0.2.1(iwer@1.0.4) '@pmndrs/pointer-events': specifier: workspace:^ version: link:../pointer-events @@ -974,8 +974,8 @@ packages: wrap-ansi-cjs: /wrap-ansi@7.0.0 dev: false - /@iwer/devui@0.2.0(iwer@1.0.4): - resolution: {integrity: sha512-/D9QlbC+JGco0NuG2WiyVWo7SJatrNZ8kotS2rV1r/z4A+bcDbDfiU+PhOwz7oktwIzdr83cFK/V7IDUe0iSSg==} + /@iwer/devui@0.2.1(iwer@1.0.4): + resolution: {integrity: sha512-fS4dxZn7FqBg77f9zQJxufG7gR6r2Q0TjCaCqLM1z0Br1Q/z/FjBJhUMRbTT4aKNRJIHdkRdTxIMWu8sLWca8Q==} peerDependencies: iwer: ^1.0.3 dependencies: @@ -986,7 +986,7 @@ packages: react: 18.3.1 react-dom: 18.3.1(react@18.3.1) styled-components: 6.1.13(react-dom@18.3.1)(react@18.3.1) - three: 0.169.0 + three: 0.168.0 dev: false /@jridgewell/gen-mapping@0.3.5: @@ -5350,8 +5350,8 @@ packages: /three@0.167.1: resolution: {integrity: sha512-gYTLJA/UQip6J/tJvl91YYqlZF47+D/kxiWrbTon35ZHlXEN0VOo+Qke2walF1/x92v55H6enomymg4Dak52kw==} - /three@0.169.0: - resolution: {integrity: sha512-Ed906MA3dR4TS5riErd4QBsRGPcx+HBDX2O5yYE5GqJeFQTPU+M56Va/f/Oph9X7uZo3W3o4l2ZhBZ6f6qUv0w==} + /three@0.168.0: + resolution: {integrity: sha512-6m6jXtDwMJEK/GGMbAOTSAmxNdzKvvBzgd7q8bE/7Tr6m7PaBh5kKLrN7faWtlglXbzj7sVba48Idwx+NRsZXw==} dev: false /tiny-inflate@1.0.3: