Explorar o código

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 %!s(int64=7) %!d(string=hai) anos
pai
achega
1ec24e59f6
Modificáronse 1 ficheiros con 23 adicións e 4 borrados
  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 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,24 +105,35 @@ 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 );
 
 		}
 
-		camera.updateMatrixWorld();
+		poseObject.updateMatrixWorld();
 
 		var stageParameters = device.stageParameters;