Commit c82824d6 authored by Riegel's avatar Riegel
Browse files

Update public/place.html

parent d30a8316
Pipeline #7744 passed with stage
in 5 seconds
...@@ -4,20 +4,18 @@ ...@@ -4,20 +4,18 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" <meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Cube Demo</title> <title>Hit to Place Demo</title>
<!-- three.js -->
<script src="https://unpkg.com/three@0.126.0/build/three.js"></script>
<script src="https://unpkg.com/three@0.126.0/examples/js/loaders/GLTFLoader.js"></script>
<!-- three.js -->
<script src="https://unpkg.com/three@0.126.0/build/three.js"></script>
<script src="https://unpkg.com/three@0.126.0/examples/js/loaders/GLTFLoader.js"></script>
</head> </head>
<body> <body>
<!-- Starting an immersive WebXR session requires user interaction. <!-- Starting an immersive WebXR session requires user interaction.
We start this one with a simple button. --> We start this one with a simple button. -->
<button onclick="activateXR()">Start placing Demo</button> <button onclick="activateXR()">Start Hit to Place Demo</button>
<script> <script>
async function activateXR() { async function activateXR() {
// Add a canvas element and initialize a WebGL context that is compatible with WebXR. // Add a canvas element and initialize a WebGL context that is compatible with WebXR.
...@@ -25,12 +23,11 @@ async function activateXR() { ...@@ -25,12 +23,11 @@ async function activateXR() {
document.body.appendChild(canvas); document.body.appendChild(canvas);
const gl = canvas.getContext("webgl", {xrCompatible: true}); const gl = canvas.getContext("webgl", {xrCompatible: true});
const scene = new THREE.Scene(); const scene = new THREE.Scene();
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.3);
directionalLight.position.set(10, 15, 10);
scene.add(directionalLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.0);
directionalLight.position.set(10, 15, 10);
scene.add(directionalLight);
// Set up the WebGLRenderer, which handles rendering to the session's base layer. // Set up the WebGLRenderer, which handles rendering to the session's base layer.
const renderer = new THREE.WebGLRenderer({ const renderer = new THREE.WebGLRenderer({
...@@ -49,6 +46,9 @@ camera.matrixAutoUpdate = false; ...@@ -49,6 +46,9 @@ camera.matrixAutoUpdate = false;
// Initialize a WebXR session using "immersive-ar". // Initialize a WebXR session using "immersive-ar".
const session = await navigator.xr.requestSession("immersive-ar", {requiredFeatures: ['hit-test']}); const session = await navigator.xr.requestSession("immersive-ar", {requiredFeatures: ['hit-test']});
session.updateRenderState({
baseLayer: new XRWebGLLayer(session, gl)
});
// A 'local' reference space has a native origin that is located // A 'local' reference space has a native origin that is located
// near the viewer's position at the time the session was created. // near the viewer's position at the time the session was created.
...@@ -60,6 +60,8 @@ const viewerSpace = await session.requestReferenceSpace('viewer'); ...@@ -60,6 +60,8 @@ const viewerSpace = await session.requestReferenceSpace('viewer');
const hitTestSource = await session.requestHitTestSource({ space: viewerSpace }); const hitTestSource = await session.requestHitTestSource({ space: viewerSpace });
const loader = new THREE.GLTFLoader(); const loader = new THREE.GLTFLoader();
let reticle; let reticle;
loader.load("https://immersive-web.github.io/webxr-samples/media/gltf/reticle/reticle.gltf", function(gltf) { loader.load("https://immersive-web.github.io/webxr-samples/media/gltf/reticle/reticle.gltf", function(gltf) {
...@@ -81,10 +83,8 @@ session.addEventListener("select", (event) => { ...@@ -81,10 +83,8 @@ session.addEventListener("select", (event) => {
} }
}); });
// Create a render loop that allows us to draw on the AR view. // Create a render loop that allows us to draw on the AR view.
const onXRFrame = (time, frame) => { const onXRFrame = (time, frame) => {
// Queue up the next draw request. // Queue up the next draw request.
session.requestAnimationFrame(onXRFrame); session.requestAnimationFrame(onXRFrame);
...@@ -115,14 +115,17 @@ const onXRFrame = (time, frame) => { ...@@ -115,14 +115,17 @@ const onXRFrame = (time, frame) => {
} }
// Render the scene with THREE.WebGLRenderer. // Render the scene with THREE.WebGLRenderer.
renderer.render(scene, camera) renderer.render(scene, camera)
} }
} }
session.requestAnimationFrame(onXRFrame); session.requestAnimationFrame(onXRFrame);
} }
</script> </script>
</body> </body>
</html> </html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment