• Stars
    star
    139
  • Rank 262,954 (Top 6 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 8 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

Ray Input: default WebVR interaction

Ray Input is a JavaScript library that provides an input abstraction for interacting with 3D VR content in the browser. It supports a variety of environments: desktop, mobile, and VR. In VR mode, behavior depends on if there's a motion controller, and whether the controller has positional tracking in addition to orientation tracking. For a higher level description of the library, see sane defaults for VR input.

Ray.js depends on THREE.js. You register interactive objects with Ray.js and subscribe to events on those objects. Events include:

  • raydown: an object is activated (eg. clicked)
  • rayup: an object is deactivated (eg. finger lifted)
  • raycancel: something stops activation (eg. you mouse-scroll to look around)
  • rayover: an object is selected (eg. hovered on, looked at)
  • rayout: an object is no longer selected (eg. blurred, looked away from)

Usage

Get the module from npm:

npm install ray-input

Then, in your code, import the ES6 module:

import RayInput from 'ray-input'

You can also use require.js:

require('./ray-input')

Or you can use the script standalone, but you may need to use new RayInput.default():

<script src="build/ray.min.js"></script>

API

How to instantiate the input library:

// Here, camera is an instance of THREE.Camera,
// If second HTMLElement arg is provided, it will be addEventListener'ed.
var input = new RayInput(camera, renderer.domElement);

How to register objects that can be interacted with:

input.add(object);

// Register a callback whenever an object is acted on.
input.on('raydown', (opt_mesh) => {
  // Called when an object was activated. If there is a selected object,
  // opt_mesh is that object.
});

// Register a callback when an object is selected.
input.on('rayover', (mesh) => {
  // Called when an object was selected.
});

How to unregister objects so that they can't be interacted with:

input.remove(object);

How to set basic attributes on the input system:.

// Sets the size of the input surface for ray casting. Generally this is
// the same as the renderer.domElement.
input.setSize(renderer.getSize());

// Update the input system in a game loop.
input.update();

Future

Open to pull requests that allow customization. Ideas include:

  • Adjust the length of the ray.
  • Specify the shape of the reticle.
  • Support for multiple controllers (especially 6DOF).
  • Support for left handed Daydream arm models.
  • Support a mode where only the closest object gets ray events. This has some implications. For example, when ray moves from background to foreground object, the background gets a rayout, while the foreground gets a rayover.

More Repositories

1

webvr-boilerplate

A starting point for web-based VR experiences that work on all VR headsets.
JavaScript
1,798
star
2

sonicnet.js

Ultrasonic Networking with the Web Audio API
JavaScript
859
star
3

device.js

Semantic client-side device detection with Media Queries
JavaScript
765
star
4

pointer.js

[deprecated] Pointer.js consolidates pointer-like input models across browsers and devices.
JavaScript
453
star
5

osmus

Multiplayer HTML5 Osmos
JavaScript
401
star
6

keysocket

JavaScript
381
star
7

srcset-polyfill

[Warning: not for production code]
JavaScript
351
star
8

MagicTouch

Spec-compatible touch events based on npTuioClient callbacks
JavaScript
347
star
9

spectrogram

Web Audio Spectrogram
HTML
288
star
10

oauth2-extensions

[Deprecated] An OAuth 2.0 Library for Chrome Extensions (please use chrome.identity)
JavaScript
220
star
11

markdown-preview

Enables Chrome to render markdown files as HTML
JavaScript
218
star
12

webaudioapi.com

Basic Web Audio API samples
HTML
146
star
13

game-asset-loader

HTML5 Filesystem, offline capable loader for web game assets.
JavaScript
109
star
14

DevTools-Lab

JavaScript
92
star
15

lightning

static site generator
Python
91
star
16

CrowdForge

Django framework for crowdsourcing complex tasks using MTurk
Python
64
star
17

screencapture-www

Adds imgur upload functionality to OS X's builtin Command - Shift - 4 screencapture tool
Shell
51
star
18

chrome-screencast

Video screencasts in Chrome
JavaScript
33
star
19

copresence-vr

WebVR copresence using WebRTC.
JavaScript
32
star
20

physical-units

A modest proposal for using real physical units for web-based UIs.
JavaScript
28
star
21

webrtc-samples

Hacking around with WebRTC
JavaScript
27
star
22

moving-music

Musical tracks on tracks
JavaScript
25
star
23

jsperfview

Charting for JSPerf
JavaScript
24
star
24

Question-Monitor-for-Stack-Exchange

Chrome extension for monitoring Stack Exchange sites such as Stack Overflow, etc.
CSS
23
star
25

Music-Visualizer-Chrome-Extension

JavaScript
21
star
26

music-of-touch

JavaScript
21
star
27

smus.com-2012

Old blog. New link below:
JavaScript
20
star
28

jshint-extension

JavaScript
20
star
29

Chrome-Media-Keys

Chrome extension to bind your keyboard's media keys to your favorite web-based music player.
JavaScript
17
star
30

mobile-web-samples

a dumping ground for random mobile web samples
JavaScript
15
star
31

sensor-fusion

Implementing sensor fusion used in WebVR polyfill
JavaScript
13
star
32

gestural-music-direction

JavaScript
12
star
33

spatial-audio

JavaScript
11
star
34

touch-laptop-experiments

Touch screen laptop experiments: responsive input and simultaneous interactions using both mouse/trackpad and touchscreen.
JavaScript
11
star
35

html5slidedown

Write HTML5 slides in markdown
JavaScript
8
star
36

jQuery-Mobile-Hacker-News

A Hacker News client written in jQuery Mobile
Java
7
star
37

smusique-extension

Chrome extension to do client side scraping from ultimate-guitar and imslp
JavaScript
7
star
38

asimov

Asimov's Chronology of Science and Discovery
JavaScript
7
star
39

web-component-samples

Playground for web components.
JavaScript
6
star
40

image-zoom

Lightroom-like image comparison view for seeing differences between compression quality levels, compression formats (JPEG, WebP) and sizes (1x, 2x).
JavaScript
6
star
41

time-sync

Playing with network and audio time synchronization
JavaScript
6
star
42

infinite-scroll

A simple infinite scrolling solution.
JavaScript
6
star
43

android-nxt

Sample code for integrating Android and Mindstorms NXT
Java
5
star
44

Chronos

Greek god of Chrome Time Tracking
JavaScript
5
star
45

smus.com

Content for smus.com
JavaScript
5
star
46

That-Trip

KML Tours in Google Earth
JavaScript
5
star
47

webplatform-tools

Tools for automating tasks on the web platform docs project.
Python
5
star
48

Radio-61

Chrome extension for thesixtyone
JavaScript
5
star
49

Running-Gestures

Prototype code for detecting pace of a runner, and then detecting when they skip
Python
4
star
50

smustalks

Repository of Talks
JavaScript
4
star
51

School-Connect

A sample jQuery Mobile application
JavaScript
4
star
52

Web-Storage-Benchmark

How much storage space is available to you if you use localStorage? WebSQL? IndexedDB? etc
JavaScript
4
star
53

humanbody.js

Java
3
star
54

smusique-uploader

A proxy server that converts and uploads PDFs to smusique.com
JavaScript
3
star
55

inequality-simulator

Simulating wealth inequality
JavaScript
3
star
56

ontonight

Weekend project: preview live music nearby to decide if you want to see the show or not.
TypeScript
3
star
57

llm4cld

JavaScript
2
star
58

asimov-gpt

Python
2
star
59

sensor-streamer

Streaming sensor data from one webpage to another using firebase.
JavaScript
2
star
60

smus.com-template

theme for the new smus.com
JavaScript
2
star
61

Chrome-Brazil

JavaScript
2
star
62

exupery

A voice-powered sketching robot. "Draw me a sheep!"
TypeScript
2
star
63

central-asia-maps

A better look at Central Asia in the middle ages. Inspired by "Thirteenth Tribe" and "Lost Enlightenment"
JavaScript
1
star
64

death-metal-english

Stay tuned
TypeScript
1
star
65

media-control-prototype

How media controls might work in Chrome
JavaScript
1
star
66

istherewind.com

App Engine application for checking the wind.
Python
1
star
67

automerge-playground

JavaScript
1
star
68

cld-tools

JavaScript
1
star