@@ -4,29 +4,38 @@ import { Group } from 'three'
4
4
import { xrSpaceContext } from './contexts.js'
5
5
import { useXR } from './xr.js'
6
6
7
+ export type XROriginProps = ThreeElements [ 'group' ] & {
8
+ disabled ?: boolean
9
+ }
10
+
7
11
/**
8
12
* Component for setting the origin of the player (their feet)
9
13
*
10
14
* @param props
11
15
* Accepts the same props as a ThreeJs [Group](https://threejs.org/docs/#api/en/objects/Group)
12
16
* @function
13
17
*/
14
- export const XROrigin = forwardRef < Group , ThreeElements [ 'group' ] > ( ( { children, ...props } , ref ) => {
18
+ export const XROrigin = forwardRef < Group , XROriginProps > ( ( { children, disabled , ...props } , ref ) => {
15
19
const xrCamera = useThree ( ( s ) => s . gl . xr . getCamera ( ) )
16
20
const internalRef = useRef < Group > ( null )
17
- useImperativeHandle ( ref , ( ) => internalRef . current ! , [ ] )
18
21
const referenceSpace = useXR ( ( xr ) => xr . originReferenceSpace )
22
+
23
+ useImperativeHandle ( ref , ( ) => internalRef . current ! , [ ] )
24
+
19
25
useEffect ( ( ) => {
20
26
const group = internalRef . current
21
- if ( group == null ) {
27
+ if ( ! group || disabled ) {
22
28
return
23
29
}
30
+
24
31
group . add ( xrCamera )
32
+
25
33
return ( ) => void group . remove ( xrCamera )
26
- } , [ xrCamera ] )
34
+ } , [ disabled , xrCamera ] )
35
+
27
36
return (
28
37
< group ref = { internalRef } { ...props } >
29
- { referenceSpace != null && < xrSpaceContext . Provider value = { referenceSpace } > { children } </ xrSpaceContext . Provider > }
38
+ { referenceSpace && < xrSpaceContext . Provider value = { referenceSpace } > { children } </ xrSpaceContext . Provider > }
30
39
</ group >
31
40
)
32
41
} )
0 commit comments