@@ -26,6 +26,10 @@ module.exports.Component = registerComponent('look-controls', {
2626 this . previousHMDPosition = new THREE . Vector3 ( ) ;
2727 this . hmdQuaternion = new THREE . Quaternion ( ) ;
2828 this . hmdEuler = new THREE . Euler ( ) ;
29+ this . poseMatrix = new THREE . Matrix4 ( ) ;
30+ this . posePosition = new THREE . Vector3 ( ) ;
31+ this . poseRotation = new THREE . Quaternion ( ) ;
32+ this . poseScale = new THREE . Vector3 ( ) ;
2933 this . position = new THREE . Vector3 ( ) ;
3034 // To save / restore camera pose
3135 this . savedRotation = new THREE . Vector3 ( ) ;
@@ -38,6 +42,7 @@ module.exports.Component = registerComponent('look-controls', {
3842 this . pointerLocked = false ;
3943 this . setupMouseControls ( ) ;
4044 this . bindMethods ( ) ;
45+ this . el . object3D . matrixAutoUpdate = false ;
4146
4247 this . savedPose = {
4348 position : new THREE . Vector3 ( ) ,
@@ -180,11 +185,26 @@ module.exports.Component = registerComponent('look-controls', {
180185 * Mouse-drag only enabled if HMD is not active.
181186 */
182187 updateOrientation : function ( ) {
183- var el = this . el ;
184188 var hmdEuler = this . hmdEuler ;
189+ var object3D = this . el . object3D ;
185190 var pitchObject = this . pitchObject ;
186191 var yawObject = this . yawObject ;
187192 var sceneEl = this . el . sceneEl ;
193+ var poseMatrix = this . poseMatrix ;
194+ var posePosition = this . posePosition ;
195+ var poseRotation = this . poseRotation ;
196+ var poseScale = this . poseScale ;
197+
198+ // WebXR API updates applies headset pose to the object3D matrixWorld internally.
199+ // Reflect values back on position, rotation, scale so setAttribute returns expected values.
200+ if ( sceneEl . is ( 'vr-mode' ) && utils . device . isWebXRAvailable ) {
201+ poseMatrix . elements = sceneEl . renderer . vr . getCameraPose ( ) . poseModelMatrix ;
202+ poseMatrix . decompose ( posePosition , poseRotation , poseScale ) ;
203+ object3D . position . copy ( posePosition ) ;
204+ object3D . quaternion . copy ( poseRotation ) ;
205+ } else {
206+ object3D . updateMatrix ( ) ;
207+ }
188208
189209 // In VR mode, THREE is in charge of updating the camera rotation.
190210 if ( sceneEl . is ( 'vr-mode' ) && sceneEl . checkHeadsetConnected ( ) ) { return ; }
@@ -193,8 +213,8 @@ module.exports.Component = registerComponent('look-controls', {
193213 hmdEuler . setFromQuaternion ( this . polyfillObject . quaternion , 'YXZ' ) ;
194214
195215 // On mobile, do camera rotation with touch events and sensors.
196- el . object3D . rotation . x = hmdEuler . x + pitchObject . rotation . x ;
197- el . object3D . rotation . y = hmdEuler . y + yawObject . rotation . y ;
216+ object3D . rotation . x = hmdEuler . x + pitchObject . rotation . x ;
217+ object3D . rotation . y = hmdEuler . y + yawObject . rotation . y ;
198218 } ,
199219
200220 /**
@@ -323,6 +343,8 @@ module.exports.Component = registerComponent('look-controls', {
323343 */
324344 onEnterVR : function ( ) {
325345 this . saveCameraPose ( ) ;
346+ this . el . object3D . position . set ( 0 , 0 , 0 ) ;
347+ this . el . object3D . updateMatrix ( ) ;
326348 } ,
327349
328350 /**
0 commit comments