Skip to content

Commit 84e563e

Browse files
committed
modified for public repo
0 parents  commit 84e563e

File tree

597 files changed

+745294
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

597 files changed

+745294
-0
lines changed

.gitignore

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

.idea/jsLibraryMappings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/bin_www.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 956 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CODING.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# How to code against the WebXR APIs
2+
3+
Working examples of this type of code can be found in the [examples directory](https://github.com/mozilla/webxr-polyfill/tree/master/examples).
4+
5+
## Session setup
6+
7+
The basic pattern is to iterate through the `XRDisplay` instances to find the one that you want to use, based on whether it's external and whether it is a pass-through display. Once you have a display, you ask it for an `XRSession` that is either for rendering a `Reality` or rendering an augmentation on top of a `Reality`.
8+
9+
let displays = null // A list of XRDisplay
10+
let display = null // The display we'll use
11+
let session = null // The XRSession we'll use
12+
let canvas = document.createElement('canvas') // The canvas into which we'll render
13+
let anchoredNodes = [] // An array of { anchorOffset: XRAnchorOffset, node: <scene node like THREE.Group> }
14+
15+
// Get displays and then request a session
16+
navigator.XR.getDisplays().then(disps => {
17+
if(disps.length == 0) {
18+
// No displays are available
19+
return
20+
}
21+
displays = disps
22+
}).catch(err => {
23+
console.error('Error getting XR displays', err)
24+
})
25+
26+
Once you have the displays, you look for one that will support the type of session that you want to start:
27+
28+
// Set up the options for the type of session we want
29+
let sessionInitOptions = {
30+
exclusive: false, // True if you want only this session to have access to the display
31+
type: 'augmentation' // do you want the session to create a 'reality' or offer an 'augmentation' on an existing `Reality`
32+
outputContext: new XRPresentationContext(canvas) // Then canvas into which we'll render
33+
}
34+
// Now test each display
35+
for(let disp of displays){
36+
if(display.supportsSession(sessionInitOptions)){
37+
display = disp
38+
break
39+
}
40+
}
41+
42+
Once you have a display and the user has chosen to start using it, you ask the display for an `XRSession` and request the first frame:
43+
44+
display.requestSession(sessionInitParamers).then(sess => {
45+
session = sess
46+
session.depthNear = 0.1
47+
session.depthFar = 1000.0
48+
49+
session.requestFrame(handleFrame)
50+
)}
51+
52+
## Per-frame rendering
53+
54+
The scene, camera, and renderer objects below are representative APIs that have equivalents in most WebGL libs like Three.js:
55+
56+
function handleFrame(frame){
57+
// Set up for the next frame
58+
session.requestFrame(frame => { handleFrame(frame) })
59+
60+
// Get the pose for the head
61+
let headCoordinateSystem = frame.getCoordinateSystem(XRCoordinateSystem.HEAD_MODEL)
62+
let headPose = frame.getDsiplayPose(frame.getCoordinateSystem(headCoordinateSystem)
63+
64+
// XXX Below we will add code here to add and manage anchors
65+
66+
// Displays can have one or more views. A magic window display has one, a headset has two (one for each eye), so iterate through each.
67+
for(const view of frame.views){
68+
69+
// Each XRView has its own projection matrix, so set the camera to use that
70+
camera.projectionMatrix = view.projectionMatrix
71+
72+
// Rotate the scene around the camera using the head pose
73+
scene.matrix = headPose.getViewMatrix(view)
74+
75+
// Set up the renderer to the XRView's viewport and then render
76+
const viewport = view.getViewport(session.baseLayer)
77+
renderer.setViewport(viewport.x, viewport.y, viewport.width, viewport.height)
78+
renderer.render(scene, camera)
79+
}
80+
}
81+
82+
## Finding and updating anchors
83+
84+
Anchors are places in space that the AR system is tracking for you. They could be a surface like a floor or table, a feature like a door knob, or just a point in space relative to the world coordinate system. When you place virtual objects in XR, you find an `XRAnchor` to attach it to, possibly with an `XRAnchorOffset` to indicate a position relative to the anchor.
85+
86+
The reason that you use anchors instead of just placing objects in a global coordinate system is that AR systems may change their relative position over time as they sense the world. A table may shift. The system may refine its estimate of the location of the floor or a wall.
87+
88+
First, let's add an anchor just floated in space a meter in front of the current head position.
89+
90+
This code uses the `XRPresentationFrame`, so it would live in the `handleFrame` method above, where the '// XXX' comment is:
91+
92+
const sceneNode = createSceneNode() // if using Three.js, could be an Object3D or a Group
93+
let anchorUID = frame.addAnchor(headCoordinateSystem, [0, 0, -1])
94+
scene.add(sceneNode) // Now the node is in the scene
95+
// Save this info for update during each frame
96+
anchoredNodes.push({
97+
anchorOffset: new XRAnchorOffset(anchor.uid),
98+
node: sceneNode
99+
})
100+
101+
Now search for an anchor on a surface like a floor or table:
102+
103+
frame.findAnchor(x, y).then(anchorOffset => {
104+
if(anchorOffset === null){
105+
// no surface was found to place the anchor
106+
return
107+
}
108+
const node = createSceneNode()
109+
// Add the node to the scene
110+
scene.add(node)
111+
// Save this info for update during each frame
112+
anchoredNodes.push({
113+
anchorOffset: anchorOffset,
114+
node: node
115+
})
116+
})
117+
118+
You now have a couple of anchored nodes save in `anchoredNodes`, so during each frame use the most recent anchor info to update the node position:
119+
120+
for(let anchoredNode of anchoredNodes){
121+
// Get the updated anchor info
122+
const anchor = frame.getAnchor(anchoredNode.anchorOffset.anchorUID)
123+
// Get the offset coordinates relative to the anchor's coordinate system
124+
let offsetTransform = anchoredNode.anchorOffset.getOffsetTransform(anchor.coordinateSystem)
125+
// Now use the offset transform to position the anchored node in the scene
126+
anchoredNode.node.matrix = offsetTransform
127+
}
128+
129+

CONTRIBUTING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Contributing to webxr-polyfill
2+
======================
3+
4+
This is an open source project and we love to receive contributions from the community. There are many ways to contribute, from writing documentation, submitting bug reports and feature requests or writing code.
5+
We would also love to hear how you are using this code and to receive contributions that make it easier to deploy and integrate.
6+
7+
Bug reports
8+
-----------
9+
10+
If you think you have found a bug, first make sure that you are testing against the [master branch](https://github.com/mozilla/webxr-polyfill) - your issue may already have been fixed. If not, search our [issues list](https://github.com/mozilla/webxr-polyfill/issues) on GitHub in the event a similar issue has already been opened.
11+
12+
It is very helpful if you can provide enough information to replicate the bug. In other words, provide a small test case which we can run to confirm your bug. It makes it easier to find the problem and resolve it.
13+
14+
Provide as much information as you can. The easier it is for us to recreate your problem, the faster we can fix it.
15+
16+
Feature requests
17+
----------------
18+
19+
If you are looking for a feature that doesn't exist currently, you are probably not alone.
20+
Open an issue on our [issues list](https://github.com/mozilla/webxr-polyfill/issues) on GitHub which describes the feature you would like to see, the value it provides, and how it should work.
21+
If you attach diagrams or mockups, it would be super nice ;-).
22+
23+
Contributing code and documentation changes
24+
-------------------------------------------
25+
26+
If you have a bugfix or new feature that you would like to contribute, please search through our issues and see if one exists, or open an issue about it first. Explain what you would like to do. It is possible someone has already begun to work on it, or that there are existing issues that you should know about before implementing the change.
27+
28+
We enjoy working with contributors to get their code accepted. There are many approaches to fixing a problem and it is important to find the best approach before writing too much code.
29+
30+
The process is described below.
31+
32+
### Fork and clone the repository
33+
34+
You will need to fork the main [repository](https://github.com/mozilla/webxr-polyfill) and clone it to your local machine. See
35+
[github help page](https://help.github.com/articles/fork-a-repo) for help.
36+
37+
Push your local changes to your forked copy of the repository and [submit a pull request](https://help.github.com/articles/using-pull-requests). In the pull request, describe what your changes do and mention the number of the issue where discussion has taken place, eg "Closes #123".
38+
39+
Then sit back and wait. There will probably be discussion about the pull request, and if any changes are needed, we would love to work with you to get your pull request merged.
Binary file not shown.

Mouse-Control-Server/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015", "react"]
3+
}

0 commit comments

Comments
 (0)