Browse Source

Merge pull request #12651 from dmarcos/headObject

Add the ability to specify an alternative Object3D to the camera to apply the pose coming from a VRDevice
Mr.doob 7 years ago
parent
commit
1ec24e59f6
1 changed files with 23 additions and 4 deletions
  1. 23 4
      src/renderers/webvr/WebVRManager.js

+ 23 - 4
src/renderers/webvr/WebVRManager.js

@@ -14,6 +14,8 @@ function WebVRManager( renderer ) {
 	var device = null;
 	var device = null;
 	var frameData = null;
 	var frameData = null;
 
 
+	var poseTarget = null;
+
 	if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
 	if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
 
 
 		frameData = new window.VRFrameData();
 		frameData = new window.VRFrameData();
@@ -85,6 +87,12 @@ function WebVRManager( renderer ) {
 
 
 	};
 	};
 
 
+	this.setPoseTarget = function ( object ) {
+
+		if ( object !== undefined ) poseTarget = object;
+
+	};
+
 	this.getCamera = function ( camera ) {
 	this.getCamera = function ( camera ) {
 
 
 		if ( device === null ) return camera;
 		if ( device === null ) return camera;
@@ -97,24 +105,35 @@ function WebVRManager( renderer ) {
 		//
 		//
 
 
 		var pose = frameData.pose;
 		var pose = frameData.pose;
+		var poseObject;
+
+		if ( poseTarget !== null ) {
+
+			poseObject = poseTarget;
+
+		} else {
+
+			poseObject = camera;
+
+		}
 
 
 		if ( pose.position !== null ) {
 		if ( pose.position !== null ) {
 
 
-			camera.position.fromArray( pose.position );
+			poseObject.position.fromArray( pose.position );
 
 
 		} else {
 		} else {
 
 
-			camera.position.set( 0, 0, 0 );
+			poseObject.position.set( 0, 0, 0 );
 
 
 		}
 		}
 
 
 		if ( pose.orientation !== null ) {
 		if ( pose.orientation !== null ) {
 
 
-			camera.quaternion.fromArray( pose.orientation );
+			poseObject.quaternion.fromArray( pose.orientation );
 
 
 		}
 		}
 
 
-		camera.updateMatrixWorld();
+		poseObject.updateMatrixWorld();
 
 
 		var stageParameters = device.stageParameters;
 		var stageParameters = device.stageParameters;