physvr provides the BasicController class, which is ready to use for physics in webvr. Several implementations are also included, in js/controllers.
- VR Headset with controllers (tested with HTC Vive on Windows 10)
- WebVR compatible browser (tested with Firefox Nightly). See WebVR's site for more info
- See out/ directory. Docs created by jsdoc3
(Try the live demo of master at https://physvr.herokuapp.com)
- Start a node server locally
- Ensure that node is installed properly with
node -v
- Ensure that npm is installed properly with
npm -v
- Run
npm install
. (The only true dependency is express, which statically serves the directory. The python method below will work withoutnpm install
) - Run
node serve.js
- Ensure that node is installed properly with
- If you don't have node, you can use python
python -m http.server 5000
python3python -m SimpleHTTPServer 5000
python2
- Navigate to http://localhost:5000 on a WebVR compatible browser
- Hit "Start VR"
- Once on
vrmain.html
, hit the "Enter VR" button in the bottom middle of the window - Use the menu button on your controller (above the touchpad on the Vive) to switch controller modes. Most modes perform an action when you press the trigger.
- All controller modes are objects that extend the BasicController class. (This class in turn extends ViveController, which is a lower level class that stores gamepad data and doesn't include physics support)
- To add your own controller mode, create an object that extends the BasicController class (or copy an existing controller and modify the class name). I recommend you look at RefreshController (the very simplest controller) to figure out the javascript class syntax, which is a bit odd. Below is an example:
THREE.MyController = function ( id ) {
//args: this, an id unique to each controller, a hex color string, and a name
THREE.BasicController.call( this, id, "#000000", "MyName");
/**
* Do something when the trigger is pulled
*/
function onTriggerDown(){
console.log("trigger is down");
}
this.addEventListener( 'triggerdown', onTriggerDown );
};
THREE.MyController.prototype = Object.create( THREE.BasicController.prototype );
THREE.MyController.prototype.constructor = THREE.MyController;
- Call:
ctrlr1list.append(new MyController(0));
Adds to controller 0ctrlr2list.append(new MyController(1));
Adds to controller 1- 0 and 1 are unique controller IDs, that correspond to
controller1
andcontroller2
respectively. - if you want a Controller Class to be available to only one controller, only append to one list.
- Test object-oriented version (physvr++)
- Encapsulate large amount of global vars in their respective classes
- Create User class
- Setup PeerServer and implement peerjs to create multiplayer
- Use VRStageParameters from WebVR api to create walls where they are in Vive Chaperone