• Stars
    star
    438
  • Rank 99,453 (Top 2 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An orientation-aware Virtual Reality controller for web browsers built on top of three.js

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

More Repositories

1

NoSleep.js

Prevent display sleep and enable wake lock in any Android or iOS web browser.
JavaScript
2,215
star
2

guessLanguage.js

A natural language detection library based on trigram statistical analysis for Node.js and the Web.
JavaScript
212
star
3

baseapp

Bootstrap-based web application scaffolding built in Go on top of the Revel Web Framework w/ Docker build support
Go
91
star
4

Marine-Compass

A 3-dimensional floating compass for the web
JavaScript
65
star
5

doe

An emulator for building and debugging device orientation and screen orientation based web applications
JavaScript
49
star
6

plug.play.js

A Network Service Messaging framework for use on top of the W3C Network Service Discovery specification
JavaScript
40
star
7

Opera-Translate

Translate for Opera adds in-page language translation functionality to any web page.
JavaScript
22
star
8

Artificial-Horizon

A JavaScript implementation of an Artifical Horizon Instrument
JavaScript
12
star
9

go-tls-srp

Snapshot of https://bitbucket.org/mjl/go-tls-srp @ 6th Nov 2014
Go
6
star
10

html-media-focus

[DEPRECATED] Connecting remote control interfaces and events with web content
JavaScript
4
star
11

sensortest.org

[DISCONTINUED] How well does your browser support DeviceOrientation Events?
PHP
3
star
12

appearin-handoff-extension

Handoff Appear.in sessions from your desktop to Android mobile web browser
JavaScript
3
star
13

devopera

Repository for Dev.Opera source code
HTML
3
star
14

universal-remote-control-access

A demonstration of how web apps can access media-centric remote control events to control any other web content
JavaScript
3
star
15

Opera-11-Extensions--Auto-I18N-Library

Auto-translation library for Opera 11+ Extensions
JavaScript
2
star
16

docker-jobber

A minimal Docker container for running Jobber (cron-replacement) tasks
2
star
17

Opera-Firebug-Lite-Extension

Firebug Lite extensions for Opera 11+
JavaScript
1
star
18

Browser-to-Phone

Browser to Phone lets you share links, maps, phone numbers and text content between your desktop browser and phone.
Java
1
star