Git Product home page Git Product logo

three-vr-viewer's Introduction

THREE.js VR Viewer

Preview Image

One-liner to start THREE.js WebVR projects. This project serves as a super beginner friendly way to build WebVR experiments.

Works for WebVR enabled Chromium and Firefox Nightly.

Setup

Include the script from build/three-vr-viewer.js in your project, after THREE.js

<script type="text/javascript" src="js/three.min.js"></script>
<script type="text/javascript" src="js/three-vr-viewer.js"></script>

In your own project:

VRViewer({THREE});

That's literally it.

Please note you have to pass in an existing THREE.js.

Exposing THREE.js objects

VRViewer() returns several objects. You can destructure this object like so:

const { scene, camera, renderer, events, toggleVR, controllers, vrEffect } = VRViewer({THREE});

Now you have access to the scene, camera, etc.

The Events object can run callbacks, for example, if you want something to change every frame:

events.on( 'tick', function( dt ){
  box.rotation.x += 0.4 * dt;
});

You're also given the VR controllers, if present, as an array of controllers[]. They are, for the time being, THREE.ViveController objects so you can bind events to them like:

  controllers[0].addEventListener('triggerdown', function(){
    console.log('controller trigger pressed!');
  });

Options

VRViewer() can take several options:

  • antiAlias: (default true). Anti-aliasing. This reduces performance if on.
  • clearColor: (default 0x505050). Hexadecimal for background color.
  • emptyRoom: (default true). Creates an empty room so you're not floating in space.
  • standing: (default true). Whether or not VRControls is a standing experience.
  • loadControllers: (default true). Attempts to load controller models.
  • vrButton: (default true). Whether or not to show the "Enter VR" button.
  • pathToControllers: (default 'models/obj/vive-controller/'). Path where the Vive controller model is located. In case you need to override it.
  • controllerModelName: (default 'vr_controller_vive_1_5.obj'). Filename of the Vive controller model. In case you need to override it.
  • controllerTextureMap: (default 'onepointfive_texture.png'). Filename of the Vive controller texture map.
  • controllerSpecMap: (default 'onepointfive_spec.png'). Filename of the Vive controller specular map.

For example:

VRViewer({
  THREE,
  emptyRoom: true
});

This automatically enters VR and enables the empty room.

Installing from NPM

npm install
npm run dev

Examples

Start a web server at three-vr-viewer/example and then navigate to localhost:8000

Notes

  • The module requires that you pass in a copy of THREE.js. Meaning you should have included it with <script> tag.
  • You can also include this as an ES6 module directly by doing import create from 'VRViewer' if you're installing it from NPM.

three-vr-viewer's People

Contributors

caseyyee avatar customlogic avatar mflux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

three-vr-viewer's Issues

How to implement it with existing Three.js project

Thanks for great library. I have added in a way things are mentioned.. i get VR Button as well but i am finding it difficult to add my existing scene to VR Mode. It just shows the empty stereo effect having grid into it. Can you please provide instructions so i can use it with my existing the js project. Actually even when i run your example project the box does not seems to added there.

expose cameraL, cameraR

Would it be possible to expose cameraL & cameraR? We are working with the frustum of the camera, which is slightly different for cameraL & cameraR in comparison to the main camera.

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.