@@ -106,11 +106,11 @@ export class PlayerLocal extends Entity {
106106 prevTransform : new THREE . Matrix4 ( ) ,
107107 }
108108
109- this . xrControllerModelFactory = null
110- this . xrControllerModel1 = null
111- this . xrControllerModel2 = null
112109 this . xrRig = new THREE . Object3D ( )
113110 this . xrRig . rotation . reorder ( 'YXZ' )
111+ this . xrControllerFactory = null
112+ this . xrControllerLeft = null
113+ this . xrControllerRight = null
114114
115115 this . mode = Modes . IDLE
116116 this . axis = new THREE . Vector3 ( )
@@ -323,14 +323,14 @@ export class PlayerLocal extends Entity {
323323
324324 onXRSession = session => {
325325 if ( session ) {
326- if ( ! this . xrControllerModel1 ) {
327- this . xrControllerModelFactory = new XRControllerModelFactory ( )
328- this . xrControllerModel1 = this . world . graphics . renderer . xr . getControllerGrip ( 0 )
329- this . xrControllerModel1 . add ( this . xrControllerModelFactory . createControllerModel ( this . xrControllerModel1 ) )
330- this . xrRig . add ( this . xrControllerModel1 )
331- this . xrControllerModel2 = this . world . graphics . renderer . xr . getControllerGrip ( 1 )
332- this . xrControllerModel2 . add ( this . xrControllerModelFactory . createControllerModel ( this . xrControllerModel2 ) )
333- this . xrRig . add ( this . xrControllerModel2 )
326+ if ( ! this . xrControllerFactory ) {
327+ this . xrControllerFactory = new XRControllerModelFactory ( )
328+ this . xrControllerLeft = this . world . graphics . renderer . xr . getControllerGrip ( 0 )
329+ this . xrControllerLeft . add ( this . xrControllerFactory . createControllerModel ( this . xrControllerLeft ) )
330+ this . xrRig . add ( this . xrControllerLeft )
331+ this . xrControllerRight = this . world . graphics . renderer . xr . getControllerGrip ( 1 )
332+ this . xrControllerRight . add ( this . xrControllerFactory . createControllerModel ( this . xrControllerRight ) )
333+ this . xrRig . add ( this . xrControllerRight )
334334 }
335335 this . world . stage . scene . add ( this . xrRig )
336336 this . xrRig . add ( this . world . camera )
@@ -758,14 +758,15 @@ export class PlayerLocal extends Entity {
758758 const zeroAngular = v4 . set ( 0 , 0 , 0 )
759759 this . capsule . setAngularVelocity ( zeroAngular . toPxVec3 ( ) )
760760
761- // if not in build mode, cancel flying
762- if ( ! this . world . builder ?. enabled ) {
761+ // if non-xr and not in build mode, cancel flying
762+ if ( ! this . world . builder ?. enabled && ! this . isXR ) {
763763 this . toggleFlying ( )
764764 }
765765 }
766766
767- // double jump in build, mode toggle flying
768- if ( this . jumpPressed && this . world . builder ?. enabled ) {
767+ // double jump in build mode, toggle flying
768+ // double jump in xr and "can" build, toggle flying
769+ if ( this . jumpPressed && ( this . world . builder ?. enabled || ( this . isXR && this . world . builder ?. canBuild ( ) ) ) ) {
769770 if ( this . world . time - this . lastJumpAt < 0.4 ) {
770771 this . toggleFlying ( )
771772 }
@@ -1038,6 +1039,11 @@ export class PlayerLocal extends Entity {
10381039 }
10391040 }
10401041
1042+ if ( xr ) {
1043+ // hint to controls that xr rig is in a new position
1044+ this . world . controls . applyXRRig ( this . xrRig )
1045+ }
1046+
10411047 // apply locomotion
10421048 this . avatar ?. instance ?. setLocomotion ( this . mode , this . axis , this . gaze )
10431049
0 commit comments