Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
be19e7b
Steps to enable developer mode
schezfaz Jul 11, 2021
3ce2eaf
Steps for ADB setup
schezfaz Jul 11, 2021
c4131fa
Flags to be enabled in the oculus browser
schezfaz Jul 11, 2021
c3e03f2
docs: steps to run the application within the oculus browser
schezfaz Jul 11, 2021
caefbfe
docs: Steps for reverse port forwarding
schezfaz Jul 11, 2021
7d9e7c3
docs: flags, insecure origins
schezfaz Jul 11, 2021
e1f0ab3
docs: debugging content in the oculus browser
schezfaz Jul 11, 2021
a1cab84
docs: Added Table of Content
schezfaz Jul 11, 2021
d6ea0d3
docs: formatting fixes
schezfaz Jul 11, 2021
c3a3fb1
docs: typo fix
schezfaz Jul 12, 2021
0253005
docs: removed oculus browser flags section
schezfaz Jul 13, 2021
12a50df
Merge PR#3 from MLH-Fellowship/docs-oculus-dev-env
schezfaz Jul 13, 2021
a2618e2
created new route for hand-model-sample
schezfaz Jul 14, 2021
91e2788
created new route for hand-model-sample
schezfaz Jul 14, 2021
718f381
Create Project-Setup.md
awanshrestha Jul 15, 2021
92adf81
added awan's code - sphere scene
schezfaz Jul 15, 2021
3969333
re-adjusted sphere position
schezfaz Jul 15, 2021
404b9d1
added hand models
schezfaz Jul 15, 2021
775a593
integrated hand models
schezfaz Jul 16, 2021
e0455ac
Merge pull request #9 from MLH-Fellowship/docs-oculus-dev-env
schezfaz Jul 23, 2021
aec9b96
Timestamp detection of pinchstart & pinchend for both hands
schezfaz Jul 24, 2021
db0f69f
attempt: add pixel dynamically when drawFlag is true
schezfaz Jul 26, 2021
cf3f1dd
Adds sphere on pinch
awanshrestha Jul 26, 2021
404ebbd
dynamically create sphere at index tip position onPinchStart
schezfaz Jul 26, 2021
6414897
Makes sphere small
awanshrestha Jul 26, 2021
9f6ae05
Added dynamic spheres for the Left Hand
schezfaz Jul 26, 2021
5cf60a9
grabbing spheres in the scene: sort of
schezfaz Jul 29, 2021
f582689
pinch + grab gesture
schezfaz Aug 2, 2021
6bf482b
Updated README.md
schezfaz Aug 2, 2021
1db3ef4
restructured document architecture
schezfaz Aug 2, 2021
f2def88
Updated README.md
schezfaz Aug 2, 2021
1ce43d3
Merge pull request #10 from MLH-Fellowship/restructure
schezfaz Aug 3, 2021
2e3fd17
Adds simple pinch
awanshrestha Aug 5, 2021
17d4793
Merge branch 'hand-model-sample' of https://github.com/MLH-Fellowship…
awanshrestha Aug 5, 2021
6bae7a9
Hand: Drawing + Grabbing Examples
schezfaz Aug 5, 2021
cc528ce
WebXR sandbox space for getPose
schezfaz Aug 5, 2021
5ff9e9a
Merge branch 'master' of https://github.com/MLH-Fellowship/webxr-laye…
schezfaz Aug 5, 2021
0c86749
Draw + Erase Example Using WebXR Hand-Input API
schezfaz Aug 9, 2021
a6c25ae
increased threshold for erase
schezfaz Aug 9, 2021
b9cbdc8
Adds simple hands and restructure folders
awanshrestha Aug 11, 2021
c8b1d32
Restructures the Pinch code
awanshrestha Aug 11, 2021
b10877c
Solves Dragging Disappearance Issue
awanshrestha Aug 11, 2021
a5b476f
Adds double detection feature
awanshrestha Aug 11, 2021
0ade0b3
Adds object size change feature
awanshrestha Aug 12, 2021
cc1770b
Adds Thanos Snap Feature
awanshrestha Aug 12, 2021
07d0796
Solves Thanos Snap Issue
awanshrestha Aug 12, 2021
933aaf7
segratated spring/summer cards
schezfaz Aug 12, 2021
c63fda9
cleaned up grabbing example code
schezfaz Aug 12, 2021
41ecc70
Detect Spiderman signature hand pose
schezfaz Aug 12, 2021
46e1e48
Detect the spiderman pose
schezfaz Aug 12, 2021
7b41841
restructured examples
schezfaz Aug 17, 2021
178d3bc
restructured examples
schezfaz Aug 17, 2021
8211a99
tweaked styles and feel
schezfaz Aug 17, 2021
08e51ee
Spiderman stuffses
schezfaz Aug 19, 2021
c86c9aa
Solves Grab issue
awanshrestha Aug 24, 2021
3d5ecc1
Adds Touch Color Feature
awanshrestha Aug 24, 2021
89a94a9
Spider man web removes after pose ends
awanshrestha Aug 24, 2021
53cdaa4
Merge pull request #11 from MLH-Fellowship/hand-model-sample
awanshrestha Aug 24, 2021
5788a96
rephrased sample description
schezfaz Aug 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# WebXR Layers Sample
<!--
[Documentation](https://github.com/und3fined-v01d/webxr-layers/tree/docs) | [Application](https://webxr-layers.netlify.app) -->

This repository is an amalgamation of WebXR samples created using the [WebXR API](https://www.w3.org/TR/webxrlayers-1/#intro), with [Three.js](https://threejs.org/) as the primary 3D rendering library as part of the [MLH Fellowship](https://fellowship.mlh.io/).

## Getting Started
- [Project Setup - Local Machine ](./docs/Project-Setup.md) : Since WebXR only works over secure HTTPS connections, we would require a few initial configurations such as an OpenSSL certificate to get the project up and running on the local machime

- [Project Setup - Oculus Browser](./docs/Oculus-Dev-Setup.md): Detailed steps leading upto a complete developer and debugging setup within the Oculus Browser

## Samples Overview
This [application](https://webxr-layers.netlify.app/) contains samples that belong to two broad categories:

- [Creaing and Interacting with Video Layers in an XR Environment]()
- Hand Gestures and Interactions with Three.js Objects


## Contributors
| MLH Fellowship Cohort | Contributors |
| ------------- | ------------- |
| [Spring 2021](https://developers.facebook.com/blog/post/2021/03/31/facebook-open-source-introduces-mlh-fellowship-class-spring-2021/) | [Soham Parekh](https://github.com/und3fined-v01d), [Teoh Zhixiang](https://github.com/zhixiangteoh) |
| Summer 2021 | [Schezeen Fazulbhoy](https://github.com/schezfaz), [Awan Shrestha ](https://github.com/awanshrestha) |

[Documentation](https://github.com/und3fined-v01d/webxr-layers/tree/docs) | [Application](https://webxr-layers.netlify.app)
210 changes: 210 additions & 0 deletions apps/changeColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@

import * as THREE from 'three';
import { VRButton } from 'three/examples/jsm/webxr/VRButton';
import { BoxLineGeometry } from 'three/examples/jsm/geometries/BoxLineGeometry';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import { XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
import { XRHandModelFactory } from 'three/examples/jsm/webxr/XRHandModelFactory.js';

const tmpVector1 = new THREE.Vector3();
const tmpVector2 = new THREE.Vector3();

let App = class App {
constructor() {
const container = document.createElement('div');
document.body.appendChild(container);

let controllerRight, controllerLeft;
let controllerRightGrip, controllerLeftGrip;

this.drawFlag = false;

/*Creating Camera, Scene and Renderer */
this.camera = this.createCamera();
this.scene = this.createScene();
this.renderer = this.createRenderer();
container.appendChild(this.renderer.domElement);

this.controls = new OrbitControls(this.camera, container);
this.controls.target.set(0, 1.6, 0);
this.controls.update();

/*Initialising controllerModelFactory and handModelFactory from Three.js */
const controllerModelFactory = new XRControllerModelFactory();
const handModelFactory = new XRHandModelFactory().setPath(
"/hand-models"
);;

/* Setting up Right Hand from POV */
controllerRight = this.renderer.xr.getController(0);
this.scene.add(controllerRight);
controllerRightGrip = this.renderer.xr.getControllerGrip(0);
controllerRightGrip.add(controllerModelFactory.createControllerModel(controllerRightGrip));
this.scene.add(controllerRightGrip);

this.rightHand = this.renderer.xr.getHand(0);
this.rightHand.add(handModelFactory.createHandModel(this.rightHand));
this.scene.add(this.rightHand);

/* Setting up Left Hand from POV */
controllerLeft = this.renderer.xr.getController(1);
this.scene.add(controllerLeft);
controllerLeftGrip = this.renderer.xr.getControllerGrip(1);
controllerLeftGrip.add(controllerModelFactory.createControllerModel(controllerLeftGrip));
this.scene.add(controllerLeftGrip);

this.leftHand = this.renderer.xr.getHand(1);
this.leftHand.add(handModelFactory.createHandModel(this.leftHand));
this.scene.add(this.leftHand);

this.session;
this.renderer.xr.addEventListener("sessionstart", (event) => {
this.session = this.renderer.xr.getSession();

});
this.renderer.xr.addEventListener("sessionend", (event) => {
this.session = null;
});

this.addLight();

const geometry = new THREE.SphereBufferGeometry(0.4, 30, 30);
const material = new THREE.MeshStandardMaterial({ color: 0xfdffbf });

this.sphere = new THREE.Mesh(geometry, material);
this.sphere.position.set(0, 0.6, -0.45);

this.scene.add(this.sphere)

const room = new THREE.LineSegments(
new BoxLineGeometry(6, 6, 6, 10, 10, 10),
new THREE.LineBasicMaterial({
color: "#151515",
})
);

room.geometry.translate(0, 3, 0);

this.scene.add(room);

this.setupVR();

this.renderer.setAnimationLoop(this.render.bind(this));
window.addEventListener('resize', this.resize.bind(this));

}

getHandVisibilityStatus() {
// if (this.session) {
// for (let i = 0; i < this.session.inputSources.length; i++) {
// if (this.session.inputSources[i].hand) {
// let wrist = this.session.inputSources[i].hand.get("wrist");
// if (!wrist) {
// return;
// }
// // let wristPose = getJointPose(wrist, this.renderer.referenceSpace);
// }
// }
// }
if (this.session) {
for (const inputSource of this.session.inputSources) {
if (inputSource.hand) {
let name = inputSource.handedness;
let theHand;
if (name === 'right'){
theHand = this.rightHand;
let indexTip = theHand.joints['index-finger-tip'];
this.checkTouch(indexTip, name)
} else {
theHand = this.leftHand;
let indexTip = theHand.joints['index-finger-tip'];
this.checkTouch(indexTip, name)
}
}
}
}
}
checkTouch( indexTip, hand) {
// let diffX = Math.abs(indexTip.position.x - thumbTip.position.x)
// let diffY = Math.abs(indexTip.position.y - thumbTip.position.y)
// let diffZ = Math.abs(indexTip.position.z - thumbTip.position.z)
// if (diffX!=0 || diffY!=0 || diffZ!=0){// When hands are not seen, the diffs initialize at zeroes. Stops once hands are seen.
// if (diffX < 0.02 && diffY < 0.02 && diffZ < 0.02) {
// console.log(diffX, diffY, diffZ)
// console.log(hand + "PINCHING")
// let geometryPinch = new THREE.SphereBufferGeometry(0.01, 30, 30);
// let materialPinch = new THREE.MeshStandardMaterial({ color: 0xfdffbf });

// let spherePinch = new THREE.Mesh(geometryPinch, materialPinch);
// spherePinch.position.set(indexTip.position.x, indexTip.position.y, indexTip.position.z);
// this.scene.add(spherePinch);
// }
// }

const distance = indexTip.getWorldPosition(tmpVector1).distanceTo(this.sphere.getWorldPosition(tmpVector2));
if (distance < this.sphere.geometry.boundingSphere.radius * this.sphere.scale.x) {

console.log('Touch')
if(hand == 'right'){
this.sphere.material.color.setHex( 0x00ffaa );
}
if(hand == 'left'){
this.sphere.material.color.setHex( 0xb983de );
}


}

}

resize() {
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
}
render() {
this.renderer.render(this.scene, this.camera);
this.getHandVisibilityStatus();
}

createCamera() {
const camera = new THREE.PerspectiveCamera(
50,
window.innerWidth / window.innerHeight,
0.1,
100
);

camera.position.set(0, 1.6, 3);
return camera;
}

createScene() {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x808080);
return scene;
}

createRenderer() {
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.xr.enabled = true;
return renderer;
}

addLight() {
const ambient = new THREE.HemisphereLight(0x606060, 0x404040);
this.scene.add(ambient);
const light = new THREE.DirectionalLight(0xffffff);
light.position.set(1, 1, 1).normalize();
this.scene.add(light);
}
setupVR() {
this.renderer.xr.enabled = true;
document.body.appendChild(VRButton.createButton(this.renderer));
}
}

export default App;
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BoxLineGeometry } from "three/examples/jsm/geometries/BoxLineGeometry";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { XRControllerModelFactory } from "three/examples/jsm/webxr/XRControllerModelFactory";

import { WebGLRenderer } from "../util/WebGLRenderer";
import { VRButton } from "../util/webxr/VRButton";
import { WebGLRenderer } from "../../util/WebGLRenderer";
import { VRButton } from "../../util/webxr/VRButton";

class App {
constructor() {
Expand Down
Loading