Giter VIP home page Giter VIP logo

threevr's Introduction

threeVR

####An orientation-aware Virtual Reality controller for three.js ####

threeVR is a virtual reality controller that makes it easy to build device-orientation aware applications on top of the three.js library.

threeVR listens for device orientation event changes and orients a three.js scene in the direction the user is facing. This library also provides manual user override controls so users can drag to look around a scene and pinch to zoom in on scene features. Once user interaction is complete, the threeVR library snaps the scene's camera back to the current device orientation position. threeVR also provides a set of custom event callbacks that web applications can use to build their own compelling user interfaces.

Live Demo | Basic Usage | API | Reference Material | License

Basic Usage

Add three.js and DeviceOrientationController.js to your project:

<script src="/lib/three.min.js"></script>
<script src="/js/DeviceOrientationController.js"></script>

Create a new DeviceOrientationController object in JavaScript passing in your scene's camera (required) and the target domElement object (optional, defaults to the document object).

Then call connect() to start the controller.

<script>
  controls = new DeviceOrientationController( camera, renderer.domElement );
  controls.connect();
</script>

API

connect()

Start the controller and register all required deviceorientation and manual interaction override event listeners

Example:

controls.connect(); // start listening for device orientation changes
disconnect()

Stop the controller and de-register all required deviceorientation and manual interaction override event listeners

Example:

controls.disconnect(); // stop listening for device orientation changes
addEventListener(type, callback)

Register an event handler when events fire in the DeviceOrientationController object.

Available event types are:

  • compassneedscalibration - when the system compass indicates that it needs calibration
  • orientationchange - when the screen orientation changes (e.g. the user rotates their screen from portrait to landscape or vice-versa). The current screen orientation can subsequently be read from controls.screenOrientation.
  • userinteractionstart - when the user starts manually overriding deviceorientation controls by interacting with the renderer DOM element.
  • userinteractionend - when the user ends manually overriding deviceorientation controls by interacting with the renderer DOM element.
  • zoomstart - when the user manually starts zooming the scene in the renderer DOM element.
  • zoomend - when the user manually ends zooming the scene in the renderer DOM element.
  • rotatestart - when the user manually starts rotating the scene in the renderer DOM element.
  • rotateend - when the user manually ends rotating the scene in the renderer DOM element.

Example usage:

controls.addEventListener('userinteractionstart', function() {
  controls.element.style.cursor = 'move';
});

controls.addEventListener('userinteractionend', function() {
  controls.element.style.cursor = 'normal';
});
removeEventListener(type, callback)

De-register an event handler previously registered with addEventListener(type, callback).

freeze

Prevent device orientation from updating the camera position.

Example:

controls.freeze = true; // pause deviceorientation affecting camera rotation
enableManualDrag

Whether to allow the user to manually override the automatic deviceorientation controls by dragging the scene to rotate the camera manually.

The camera will automatically snap back to the deviceorientation when the user stops interacting with the scene.

Default is true.

Example:

controls.enableManualDrag = false; // disable user manual scene drag-to-rotate override
enableManualZoom

Whether to allow the user to manually override the automatic deviceorientation controls by pinching the scene to zoom manually.

The camera will automatically snap back to the deviceorientation when the user stops interacting with the scene.

Default is true.

Example:

controls.enableManualZoom = false; // disable user manual scene pinch-to-zoom override
useQuaternions

Whether to use quaternions to calculate the device orientation (true) or rotation matrices (false).

Default is true.

Example:

controls.useQuaternions = false; // use rotation matrix math

Reference Material

License

MIT. Copyright (c) Rich Tibbett

threevr's People

Contributors

richtr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.