1.1.69 • Published 2 years ago

vrb v1.1.69

Weekly downloads
282
License
-
Repository
github
Last release
2 years ago

vrb

npm version

vrb (ˈvɚb , ˌvi ɑr ˈbi), v.: to verb VR; to virtually really be.

Simple three.js-based web VR module. Supports positional audio and VR controllers.

Opens in an orthographic view of the scene. Click a toggle to enter in and out of a perspective VR mode.

install

npm i vrb

usage

import vrb from 'vrb'
import {Scene} from 'three'

const scene = new Scene()
const viewer = document.createElement('div')
const onReady = () => {
	// do whatever you want once the VR device is ready
}
const onNoVr = () => {
	// do whatever you want once it is determined that your system does not support VR
}


const vrb = vrb({ scene, viewer, onReady, onNoVr })

const toggle = document.createElement('div')
toggle.onclick = vrb.toggleVr

options

onAnimate

Hook that will be called each render frame. Use to update your scene.

Example usage:

const onAnimate = () => {
    clouds.drift()
    song.nextNote()
}

vrb({ scene, toggle, viewer, onAnimate })

onControllerConnected

Hook that will be called each time a controller connects, with the controller as the argument. Use e.g. to add a mesh to the controller and attach event listeners.

Example usage:

const onControllerConnected = controller => {
    controller.add(new BoxGeometry(0.5))
    controller.addEventListener('thumbpad press began', handleThumbpadPress)
}

vrb({ scene, viewer, onControllerConnected })

camerasConfig

Override default camera configuration with this object.

{
    ORTHOGRAPHIC_FRUSTUM_TOP,
    ORTHOGRAPHIC_FRUSTUM_BOTTOM,
    ORTHOGRAPHIC_FRUSTUM_LEFT,
    ORTHOGRAPHIC_FRUSTUM_RIGHT,
    ORTHOGRAPHIC_FRUSTUM_NEAR,
    ORTHOGRAPHIC_FRUSTUM_FAR,
    PERSPECTIVE_ASPECT_RATIO,
    PERSPECTIVE_FOV,
    PERSPECTIVE_FRUSTUM_FAR,
    PERSPECTIVE_FRUSTUM_NEAR,
    INITIAL_ORTHOGRAPHIC_POSITION,
    INITIAL_ORTHOGRAPHIC_TARGET,
    INITIAL_PERSPECTIVE_POSITION,
    INITIAL_PERSPECTIVE_TARGET,
}

methods & properties

.player

This is a meshless three.js Object3D which has the perspective camera and any controllers added to it. That way you can translate the player around independently of the three.js VRControls to go beyond room scale VR. Note: if you want to know the position of the user's head, you'll have to look at both player.position and cameras.perspectiveCamera.position, as it will be the sum of the two.

#getIsPresenting

Wrapper for renderer.vr.getDevice().isPresenting.

#createSpatialOscillator

Wrapper for three.js AudioListener context #createOscillator.

#createPositionalSound

Provides a configured three.js PositionalAudio.

#setBackgroundColor

Wrapper for three.js WebGLRenderer#setClearColor.

#changeOnAnimate

If it is necessary to change your onAnimate function after building your vrb, use this. Pass it a function that will get called with the current onAnimate and return what you want it to be afterwards.

vrb.changeOnAnimate(oldAnimate => createModifiedAnimate(oldAnimate))

#changeOnControllerConnected

If it is necessary to change your onControllerConnected function after building your vrb, use this. Pass it a function that will get called with the current onControllerConnected and return what you want it to be afterwards.

vrb.onControllerConnected(oldOnControllerConnected => createModifiedOnControllerConnected(oldOnControllerConnected))

1.1.69

2 years ago

1.1.68

2 years ago

1.1.67

2 years ago

1.1.66

2 years ago

1.1.64

4 years ago

1.1.62

4 years ago

1.1.61

4 years ago

1.1.60

4 years ago

1.1.59

4 years ago

1.1.57

4 years ago

1.1.56

5 years ago

1.1.55

5 years ago

1.1.53

5 years ago

1.1.52

5 years ago

1.1.51

5 years ago

1.1.50

5 years ago

1.1.49

5 years ago

1.1.48

5 years ago

1.1.47

5 years ago

1.1.46

5 years ago

1.1.45

5 years ago

1.1.44

5 years ago

1.1.43

5 years ago

1.1.42

5 years ago

1.1.41

5 years ago

1.1.40

5 years ago

1.1.39

5 years ago

1.1.38

5 years ago

1.1.37

5 years ago

1.1.36

5 years ago

1.1.35

5 years ago

1.1.34

5 years ago

1.1.33

5 years ago

1.1.32

5 years ago

1.1.31

5 years ago

1.1.30

5 years ago

1.1.29

5 years ago

1.1.28

5 years ago

1.1.27

5 years ago

1.1.26

5 years ago

1.1.25

5 years ago

1.1.24

5 years ago

1.1.23

5 years ago

1.1.22

5 years ago

1.1.21

5 years ago

1.1.20

5 years ago

1.1.19

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago