GithubHelp home page GithubHelp logo

smarthug / teleport Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 0.0 301.81 MB

A WebXR teleport for three.js

Home Page: https://www.youtube.com/watch?v=ut48erRros4&t=9s

License: MIT License

HTML 9.57% CSS 2.77% JavaScript 87.66%
three webxr controls teleport spatial-controls camera-controls vr webvr

teleport's Introduction

three-spatial-controls

Open in Visual Studio Code

alt text

A WebXR camera control for three.js

NPM JavaScript Style Guide

Install

npm install three-spatial-controls

Demo

How To Use

  • press Select button (Trigger button) to teleport
  • press right/left Squeeze button (Grab button) to increase/decrease teleport distance
  • use right or left joystick to decide player's direction after a teleport

Video

https://www.youtube.com/watch?v=ut48erRros4&t=9s

Usage

import * as THREE from 'three'
import SpatialControls from 'three-spatial-controls'

let scene, camera, renderer
let spatialControls

function Init() {
  // three.js setup
  scene = new THREE.Scene()
  renderer.xr.enabled = true
  camera = new THREE.PerspectiveCamera(
    75,
    window.innerWidth / window.innerHeight,
    0.1,
    10000
  )

  // this will be the player
  let cameraRig = new THREE.Group()
  scene.add(cameraRig)

  let controller0 = renderer.xr.getController(0)
  let controller1 = renderer.xr.getController(1)

  cameraRig.add(camera)
  cameraRig.add(controller0)
  cameraRig.add(controller1)

  spatialControls = new SpatialControls(
    renderer,
    cameraRig,
    controller0,
    controller1,
    // optional config 
    {
      destMarker: destMarker,             // indicator of teleport destination ,THREE.Object3D
      rightHanded: true,                  // righthanded or lefthanded
      playerHandHelper: playerHandHelper, // helper obj for player hand, THREE.Object3D
      destHandHelper: destHandHelper,     // helper obj for destination hand, THREE.Object3D
      multiplyScalar: 1                   // teleport distance
    }
  )
}

function Animate() {
  spatialControls.update()

  renderer.render(scene, camera)
}

License

MIT © smarthug

teleport's People

Contributors

smarthug avatar

Stargazers

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

Watchers

 avatar  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.