From ee58f547fba7aee6b523fbe668fd1344ca0c0571 Mon Sep 17 00:00:00 2001 From: dmarcos Date: Tue, 14 Nov 2017 14:32:40 -0800 Subject: [PATCH] Add the ability to specify an alternative Object3D to the camera to apply the pose coming from a VRDevice --- src/renderers/webvr/WebVRManager.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/renderers/webvr/WebVRManager.js b/src/renderers/webvr/WebVRManager.js index fd7d8194a374e6..7874402aa90ce9 100644 --- a/src/renderers/webvr/WebVRManager.js +++ b/src/renderers/webvr/WebVRManager.js @@ -14,6 +14,8 @@ function WebVRManager( renderer ) { var device = null; var frameData = null; + var poseTarget = null; + if ( typeof window !== 'undefined' && 'VRFrameData' in window ) { frameData = new window.VRFrameData(); @@ -85,6 +87,12 @@ function WebVRManager( renderer ) { }; + this.setPoseTarget = function ( object ) { + + if ( object !== undefined ) poseTarget = object; + + }; + this.getCamera = function ( camera ) { if ( device === null ) return camera; @@ -97,20 +105,31 @@ function WebVRManager( renderer ) { // var pose = frameData.pose; + var poseObject; + + if ( poseTarget !== null ) { + + poseObject = poseTarget; + + } else { + + poseObject = camera; + + } if ( pose.position !== null ) { - camera.position.fromArray( pose.position ); + poseObject.position.fromArray( pose.position ); } else { - camera.position.set( 0, 0, 0 ); + poseObject.position.set( 0, 0, 0 ); } if ( pose.orientation !== null ) { - camera.quaternion.fromArray( pose.orientation ); + poseObject.quaternion.fromArray( pose.orientation ); }