Commit 850b992a authored by Amanda Ghassaei's avatar Amanda Ghassaei

cleaning up

parent cd18c1a8
/**
* @author dmarcos / https://github.com/dmarcos
* @author mrdoob / http://mrdoob.com
*/
THREE.VRControls = function ( object, onError ) {
var scope = this;
var vrDisplay, vrDisplays;
var standingMatrix = new THREE.Matrix4();
var frameData = null;
if ( 'VRFrameData' in window ) {
frameData = new VRFrameData();
}
function gotVRDisplays( displays ) {
vrDisplays = displays;
if ( displays.length > 0 ) {
vrDisplay = displays[ 0 ];
} else {
if ( onError ) onError( 'VR input not available.' );
}
}
if ( navigator.getVRDisplays ) {
navigator.getVRDisplays().then( gotVRDisplays ).catch( function () {
console.warn( 'THREE.VRControls: Unable to get VR Displays' );
} );
}
// the Rift SDK returns the position in meters
// this scale factor allows the user to define how meters
// are converted to scene units.
this.scale = 1;
// If true will use "standing space" coordinate system where y=0 is the
// floor and x=0, z=0 is the center of the room.
this.standing = false;
// Distance from the users eyes to the floor in meters. Used when
// standing=true but the VRDisplay doesn't provide stageParameters.
this.userHeight = 1.6;
this.getVRDisplay = function () {
return vrDisplay;
};
this.setVRDisplay = function ( value ) {
vrDisplay = value;
};
this.getVRDisplays = function () {
console.warn( 'THREE.VRControls: getVRDisplays() is being deprecated.' );
return vrDisplays;
};
this.getStandingMatrix = function () {
return standingMatrix;
};
this.update = function () {
if ( vrDisplay ) {
var pose;
if ( vrDisplay.getFrameData ) {
vrDisplay.getFrameData( frameData );
pose = frameData.pose;
} else if ( vrDisplay.getPose ) {
pose = vrDisplay.getPose();
}
if ( pose.orientation !== null ) {
object.quaternion.fromArray( pose.orientation );
}
if ( pose.position !== null ) {
object.position.fromArray( pose.position );
} else {
object.position.set( 0, 0, 0 );
}
if ( this.standing ) {
if ( vrDisplay.stageParameters ) {
object.updateMatrix();
standingMatrix.fromArray( vrDisplay.stageParameters.sittingToStandingTransform );
object.applyMatrix( standingMatrix );
} else {
object.position.setY( object.position.y + this.userHeight );
}
}
object.position.multiplyScalar( scope.scale );
}
};
this.dispose = function () {
vrDisplay = null;
};
};
This diff is collapsed.
/**
* @author mrdoob / http://mrdoob.com
* @author stewdio / http://stewd.io
*/
THREE.ViveController = function ( id ) {
THREE.Object3D.call( this );
var scope = this;
var gamepad;
var axes = [ 0, 0 ];
var thumbpadIsPressed = false;
var triggerIsPressed = false;
var gripsArePressed = false;
var menuIsPressed = false;
function findGamepad( id ) {
// Iterate across gamepads as Vive Controllers may not be
// in position 0 and 1.
var gamepads = navigator.getGamepads();
for ( var i = 0, j = 0; i < 4; i ++ ) {
var gamepad = gamepads[ i ];
if ( gamepad && ( gamepad.id === 'OpenVR Gamepad' || gamepad.id === 'Oculus Touch (Left)' || gamepad.id === 'Oculus Touch (Right)' ) ) {
if ( j === id ) return gamepad;
j ++;
}
}
}
this.matrixAutoUpdate = false;
this.standingMatrix = new THREE.Matrix4();
this.getGamepad = function () {
return gamepad;
};
this.getButtonState = function ( button ) {
if ( button === 'thumbpad' ) return thumbpadIsPressed;
if ( button === 'trigger' ) return triggerIsPressed;
if ( button === 'grips' ) return gripsArePressed;
if ( button === 'menu' ) return menuIsPressed;
};
this.update = function () {
gamepad = findGamepad( id );
//not working in chrome https://github.com/mrdoob/three.js/issues/9723
if ( gamepad !== undefined && gamepad.pose !== undefined ) {
if ( gamepad.pose === null ) return; // No user action yet
// Position and orientation.
var pose = gamepad.pose;
if ( pose.position !== null ) scope.position.fromArray( pose.position );
if ( pose.orientation !== null ) scope.quaternion.fromArray( pose.orientation );
scope.matrix.compose( scope.position, scope.quaternion, scope.scale );
scope.matrix.multiplyMatrices( scope.standingMatrix, scope.matrix );
scope.matrixWorldNeedsUpdate = true;
scope.visible = true;
// Thumbpad and Buttons.
if ( axes[ 0 ] !== gamepad.axes[ 0 ] || axes[ 1 ] !== gamepad.axes[ 1 ] ) {
axes[ 0 ] = gamepad.axes[ 0 ]; // X axis: -1 = Left, +1 = Right.
axes[ 1 ] = gamepad.axes[ 1 ]; // Y axis: -1 = Bottom, +1 = Top.
scope.dispatchEvent( { type: 'axischanged', axes: axes } );
}
if ( thumbpadIsPressed !== gamepad.buttons[ 0 ].pressed ) {
thumbpadIsPressed = gamepad.buttons[ 0 ].pressed;
scope.dispatchEvent( { type: thumbpadIsPressed ? 'thumbpaddown' : 'thumbpadup' } );
}
if ( triggerIsPressed !== gamepad.buttons[ 1 ].pressed ) {
triggerIsPressed = gamepad.buttons[ 1 ].pressed;
scope.dispatchEvent( { type: triggerIsPressed ? 'triggerdown' : 'triggerup' } );
}
if ( gripsArePressed !== gamepad.buttons[ 2 ].pressed ) {
gripsArePressed = gamepad.buttons[ 2 ].pressed;
scope.dispatchEvent( { type: gripsArePressed ? 'gripsdown' : 'gripsup' } );
}
if ( menuIsPressed !== gamepad.buttons[ 3 ].pressed ) {
menuIsPressed = gamepad.buttons[ 3 ].pressed;
scope.dispatchEvent( { type: menuIsPressed ? 'menudown' : 'menuup' } );
}
} else {
scope.visible = false;
}
};
};
THREE.ViveController.prototype = Object.create( THREE.Object3D.prototype );
THREE.ViveController.prototype.constructor = THREE.ViveController;
......@@ -751,9 +751,6 @@
<!--<script type="text/javascript" src="dependencies/RenderPass.js"></script>-->
<script type="text/javascript" src="dependencies/WebVR.js"></script>
<!--<script type="text/javascript" src="dependencies/VREffect.js"></script>-->
<!--<script type="text/javascript" src="dependencies/ViveController.js"></script>-->
<!--<script type="text/javascript" src="dependencies/VRControls.js"></script>-->
<script type="text/javascript" src="dependencies/VRController.js"></script>
<script type="text/javascript" src="dependencies/datguivr.js"></script>
......
......@@ -14,28 +14,9 @@ function initViveInterface(globals){
}
$status.html("No device connected.");
var geo = new THREE.CylinderGeometry(0, 0.05, 0.25, 4);
geo.applyMatrix(new THREE.Matrix4().makeRotationX(-Math.PI/2));
var mesh = new THREE.Mesh(geo, new THREE.MeshLambertMaterial({color:0x444444}));
mesh.position.set(0,0,0.125);
mesh.visible = false;
// var controls = new THREE.VRControls(globals.threeView.camera);
// controls.standing = true;
// controllers
// var controller1 = new THREE.ViveController( 0 );
// controller1.standingMatrix = controls.getStandingMatrix();
// controller1.head = globals.threeView.camera;
// globals.threeView.scene.add( controller1 );
//
// var controller2 = new THREE.ViveController( 1 );
// controller2.standingMatrix = controls.getStandingMatrix();
// controller2.head = globals.threeView.camera;
// globals.threeView.scene.add( controller2 );
//
// controller1.add(mesh.clone());
// controller2.add(mesh.clone());
var renderer = globals.threeView.renderer;
var scene = globals.threeView.scene;
var camera = globals.threeView.camera;
var controllers = [];
// var controllerStates = [false, false];
......@@ -44,26 +25,24 @@ function initViveInterface(globals){
var highlighters = [new Node(new THREE.Vector3()), new Node(new THREE.Vector3())];
_.each(highlighters, function(highlighter){
highlighter.setTransparentVR();
globals.threeView.scene.add(highlighter.getObject3D());
scene.add(highlighter.getObject3D());
});
var nodes = [null, null];
var releaseEvent = [false, false];
// var effect = new THREE.VREffect(globals.threeView.renderer);
connect();
var yOffset = 1.6;
var scale = 0.5;
window.addEventListener( 'vr controller connected', function( event ){
var controller = event.detail;
globals.threeView.scene.add( controller );
scene.add( controller );
controller.standingMatrix = globals.threeView.renderer.vr.getStandingMatrix();
controller.head = globals.threeView.camera;
controller.standingMatrix = renderer.vr.getStandingMatrix();
controller.head = camera;
var
meshColorOff = 0xFF4040,
......@@ -119,24 +98,22 @@ function initViveInterface(globals){
}
$status.html("VR device detected. Hit the button below to enter VR. If you have problems, check that you are connected to Steam VR and your HMD has the latest firmware updates.");
$("#VRoptions").show();
var button = WEBVR.getButton( display, globals.threeView.renderer.domElement );
var button = WEBVR.getButton( display, renderer.domElement );
$link.show();
$link.html("ENTER VR");
var callback = button.onclick;
$link.click(function(e){
e.preventDefault();
globals.vrEnabled = !display.isPresenting;
console.log(globals.vrEnabled);
// globals.threeView.renderer.setSize( window.innerWidth, window.innerHeight );
globals.threeView.renderer.vr.enabled = globals.vrEnabled;
renderer.vr.enabled = globals.vrEnabled;
var y = 0;
var vrScale = 1;
if (globals.vrEnabled) {
y = yOffset;
vrScale = scale;
$link.html("EXIT VR");
globals.threeView.renderer.vr.setDevice( display );
globals.threeView.renderer.vr.standing = true;
renderer.vr.setDevice( display );
renderer.vr.standing = true;
} else {
globals.model.reset();
globals.threeView.resetCamera();
......@@ -144,12 +121,11 @@ function initViveInterface(globals){
}
globals.threeView.modelWrapper.scale.set(vrScale, vrScale, vrScale);
globals.threeView.modelWrapper.position.set(0,y,0);
// _.each(controller1.children, function(child){
// child.visible = globals.vrEnabled;
// });
// _.each(controller2.children, function(child){
// child.visible = globals.vrEnabled;
// });
_.each(controllers, function(controller){
_.each(controller.children, function(child){
child.visible = globals.vrEnabled;
});
});
if (callback) callback();
});
} );
......@@ -158,9 +134,7 @@ function initViveInterface(globals){
function render(){
THREE.VRController.update();
// checkForIntersections();
// controls.update();
globals.threeView.renderer.render( globals.threeView.scene, globals.threeView.camera );
// effect.render( globals.threeView.scene, globals.threeView.camera );
renderer.render( scene, camera );
}
// function checkForIntersections(){
......@@ -237,7 +211,6 @@ function initViveInterface(globals){
// }
return {
// effect: effect,
render: render
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment