-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: AR support #397
Draft
mariobuikhuizen
wants to merge
13
commits into
widgetti:master
Choose a base branch
from
mariobuikhuizen:feat_ar_2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP: AR support #397
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dad53f7
WIP: AR support
mariobuikhuizen cac0166
add pythreejs dependecy with updated threejs version
mariobuikhuizen 17c1bd5
fix: no image
mariobuikhuizen 41d684d
fix: don't use render_continuous
mariobuikhuizen 3057275
fix: better directional light defaults
maartenbreddels 29e6dcc
feat: background-opacity in style, used for ar style
maartenbreddels 7bd0d43
use hittest to place box in scene
maartenbreddels 336c623
render to screen in AR mode and ignore update calls
maartenbreddels 1f35631
fix: add lights to rootObject such that they track the AR placement
maartenbreddels 9ea176d
refactor: use template for button and untangle ar code
mariobuikhuizen 0747ec1
fix: set renderloop to null and add missing space
mariobuikhuizen 55aceab
better centering of box
maartenbreddels 5a67b47
add server module
maartenbreddels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,76 @@ | ||
{ | ||
"light": { | ||
"background-color": "white", | ||
"axes": { | ||
"color": "black" | ||
} | ||
}, | ||
"dark": { | ||
"background-color": "#000001", | ||
"axes": { | ||
"color": "white", | ||
"label": { | ||
"color": "white" | ||
}, | ||
"ticklabel": { | ||
"color": "white" | ||
} | ||
} | ||
}, | ||
"demo": { | ||
"background-color": "white", | ||
"box": { | ||
"color": "pink", | ||
"visible": true | ||
}, | ||
"axes": { | ||
"z": { | ||
"color": "#00f", | ||
"ticklabel": { | ||
"color": "#0f0" | ||
}, | ||
"label": { | ||
"color": "#f00" | ||
} | ||
}, | ||
"ticklabel": { | ||
"color": "black" | ||
}, | ||
"label": { | ||
"color": "black" | ||
}, | ||
"color": "black", | ||
"visible": true, | ||
"x": { | ||
"color": "#f00", | ||
"ticklabel": { | ||
"color": "#00f" | ||
}, | ||
"label": { | ||
"color": "#0f0" | ||
}, | ||
"ticklabel": { | ||
"color": "#00f" | ||
} | ||
}, | ||
"y": { | ||
"color": "#0f0", | ||
"ticklabel": { | ||
"color": "#f00" | ||
}, | ||
"label": { | ||
"color": "#00f" | ||
}, | ||
"ticklabel": { | ||
"color": "#f00" | ||
} | ||
}, | ||
"color": "black", | ||
"visible": true | ||
"z": { | ||
"color": "#00f", | ||
"label": { | ||
"color": "#f00" | ||
}, | ||
"ticklabel": { | ||
"color": "#0f0" | ||
} | ||
} | ||
} | ||
}, | ||
"dark": { | ||
"background-color": "black", | ||
"nobox": { | ||
"box": { | ||
"visible": true | ||
"visible": false | ||
}, | ||
"axes": { | ||
"color": "white", | ||
"ticklabel": { | ||
"color": "white" | ||
}, | ||
"visible": true, | ||
"label": { | ||
"color": "white" | ||
} | ||
"visible": true | ||
} | ||
}, | ||
"light": { | ||
"background-color": "white", | ||
"ar": { | ||
"background-color": "#000001", | ||
"background-opacity": 0, | ||
"box": { | ||
"visible": true | ||
"visible": false | ||
}, | ||
"axes": { | ||
"color": "black", | ||
"ticklabel": { | ||
"color": "black" | ||
}, | ||
"visible": true, | ||
"label": { | ||
"color": "black" | ||
} | ||
"visible": false | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
export const closeOverlay = document.createElement("div"); | ||
closeOverlay.style.display = "none"; | ||
document.body.appendChild(closeOverlay); | ||
|
||
let onClose = () => console.log("onClose not set"); | ||
|
||
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); | ||
svg.setAttribute("width", 38); | ||
svg.setAttribute("height", 38); | ||
svg.style.position = "absolute"; | ||
svg.style.right = "20px"; | ||
svg.style.top = "20px"; | ||
svg.addEventListener("click", () => onClose()); | ||
closeOverlay.appendChild(svg); | ||
|
||
const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); | ||
path.setAttribute("d", "M 12,12 L 28,28 M 28,12 12,28"); | ||
path.setAttribute("stroke", "#fff"); | ||
path.setAttribute("stroke-width", 2); | ||
svg.appendChild(path); | ||
|
||
function setOnClose(fn) { | ||
onClose = fn; | ||
} | ||
|
||
function showCloseOverlay(value) { | ||
closeOverlay.style.display = value ? "" : "none"; | ||
} | ||
|
||
let lastXrTransform = null; | ||
let lastWidth = null; | ||
let lastHeight = null; | ||
|
||
export function createController(renderer, scene, onSelect) { | ||
const arController = renderer.xr.getController(0); | ||
arController.addEventListener("select", () => onSelect(lastXrTransform)); | ||
scene.add(arController); | ||
return arController; | ||
} | ||
|
||
export async function start(renderer, renderFn, onStop) { | ||
if (renderer.xr.getSession() !== null) { | ||
return; | ||
} | ||
renderer.xr.enabled = true; | ||
|
||
const sessionInit = { | ||
optionalFeatures: ["dom-overlay", "hit-test"], | ||
domOverlay: { root: closeOverlay } | ||
}; | ||
|
||
showCloseOverlay(true); | ||
|
||
const session = await navigator.xr.requestSession("immersive-ar", sessionInit); | ||
renderer.xr.setReferenceSpaceType("local"); | ||
renderer.xr.setSession(session); | ||
const { x, y } = renderer.getSize(); | ||
lastWidth = x; | ||
lastHeight = y; | ||
renderer.setSize(window.innerWidth, window.innerHeight); | ||
|
||
lastXrTransform = null; | ||
|
||
renderer.setAnimationLoop( | ||
await extractHitTransform( | ||
renderer, | ||
renderFn, | ||
(xrTransform) => { lastXrTransform = xrTransform; })); | ||
|
||
setOnClose(onStop); | ||
} | ||
|
||
export function stop(renderer) { | ||
if (renderer.xr.getSession() === null) { | ||
return; | ||
} | ||
renderer.xr.getSession().end(); | ||
renderer.xr.setSession(null); | ||
lastXrTransform = null; | ||
showCloseOverlay(false); | ||
renderer.setAnimationLoop(() => null); | ||
renderer.setSize(lastWidth, lastHeight); | ||
} | ||
|
||
async function extractHitTransform(renderer, renderFn, onXrTransformChange) { | ||
const session = renderer.xr.getSession(); | ||
const referenceSpace = await session.requestReferenceSpace("viewer"); | ||
const hitTestSource = await session.requestHitTestSource({ space: referenceSpace }); | ||
|
||
return (time, frame) => { | ||
if (frame) { | ||
// based on https://threejs.org/examples/webxr_ar_hittest.html | ||
const referenceSpace = renderer.xr.getReferenceSpace(); | ||
|
||
if (hitTestSource) { | ||
const hitTestResults = frame.getHitTestResults(hitTestSource); | ||
if (hitTestResults.length) { | ||
const hit = hitTestResults[0]; | ||
const pose = hit.getPose(referenceSpace); | ||
onXrTransformChange(pose.transform); | ||
} | ||
} | ||
} | ||
renderFn(time, frame); | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise we still render continuous after stopping.