Skip to content

Commit c999c2c

Browse files
authored
Merge pull request #1 from fabio914/preparing
Preparing initial version
2 parents 503db5f + 869c564 commit c999c2c

File tree

6 files changed

+807
-0
lines changed

6 files changed

+807
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
**/node_modules

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Reality Mixer JS
2+
3+
This is a small Mixed Reality Capture module for [WebXR](https://immersiveweb.dev) + [Three.js](https://threejs.org).
4+
5+
You can use this module to allow users to record your WebXR experiences in Mixed Reality.
6+
7+
Unlike the original [Reality Mixer](https://github.com/fabio914/RealityMixer) or [LIV](https://www.liv.tv), the Mixed Reality composition is happening on the browser itself. However, users will need another external application to record their browser (e.g. [OBS](https://obsproject.com)).
8+
9+
Keep in mind that this is still just a prototype and that I'm not a frontend developer. Feel free to open PRs and contribute to the project.
10+
11+
## TO-DOs
12+
13+
- Create a calibration page to allow users to calibrate the position and orientation of their camera, and to configure their chroma key (green screen).
14+
15+
- Allow the Mixed Reality Capture session to be initialized with a JSON file with a saved calibration.
16+
17+
## How to test the example
18+
19+
- Clone this repository.
20+
21+
- Run `npm ci` to download the dependencies.
22+
23+
- Run `http-server` to start the HTTP server (that can be downloaded by running `npm install -g http-server`).
24+
25+
- WebXR and `navigator.mediaDevices` require HTTPS. You could use a tool like [localtunnel](https://github.com/localtunnel/localtunnel) for testing. You can run `npm install -g localtunnel` to download it and then you can run `lt --port 8080 --subdomin 127.0.0.1` in a separate terminal.
26+
27+
- Open your browser and navigate to `https://{your HTTPS domain}/examples/webxr_vr_ballshooter.html`
28+
29+
Your browser will ask for permission to access your camera, and it'll ask for permission to use your VR headset once you click on the WebXR button.
30+
31+
You'll need to edit the code (the calibration) to set the correct position, orientation, and fov of your camera, and the correct parameters for your green screen.
32+
33+
## API
34+
35+
```javascript
36+
37+
import * as THREE from 'three';
38+
import * as MRC from 'reality-mixer';
39+
40+
let mixedRealityCapture;
41+
let scene, renderer, camera;
42+
43+
// ...
44+
45+
const cameraCalibration = new MRC.CameraCalibration(
46+
1920, // width of the video
47+
1080, // height of the video
48+
38, // vertical field of view in degrees
49+
[0, 1.5, 0], // vector with the position of the camera in scene coordinates
50+
[0, 0, 0, 1] // quaternion with the orientation of the camera
51+
);
52+
53+
const chromaKey = new MRC.ChromaKey(
54+
[0, 1, 0], // chroma key color (red, green, blue values from 0 to 1)
55+
0.25, // similarity (0 to 1)
56+
0 // smoothness (0 to 1)
57+
);
58+
59+
const calibration = new MRC.Calibration(
60+
cameraCalibration,
61+
chromaKey,
62+
4, // Delay (in number of frames) between the real camera and the virtual camera
63+
);
64+
65+
// ... Initialize your Three.js scene and renderer here ...
66+
67+
// Hide your renderer when you want to display the Mixed Reality output
68+
renderer.domElement.style.display = "none";
69+
70+
// Create a new Mixed Reality Capture session
71+
mixedRealityCapture = new MRC.MixedRealityCapture( calibration );
72+
73+
// Add the Mixed Reality Output to the document
74+
document.body.appendChild( mixedRealityCapture.domElement );
75+
76+
// ...
77+
78+
// You should call this whenever the window resizes
79+
mixedRealityCapture.onWindowResize();
80+
81+
// ...
82+
83+
// Render the Mixed Reality composition after rendering your scene
84+
85+
renderer.render( scene, camera );
86+
87+
mixedRealityCapture.render( renderer.xr, scene );
88+
89+
```

0 commit comments

Comments
 (0)