diff --git a/public/place.html b/public/place.html index cf58fbd65fec49024bc93de3a13debe430e94c26..b8be792b0d032c54217a8149a56089f927ee5daf 100644 --- a/public/place.html +++ b/public/place.html @@ -4,20 +4,18 @@ <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> - <title>Cube 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> + <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> </head> <body> <!-- Starting an immersive WebXR session requires user interaction. 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> async function activateXR() { // Add a canvas element and initialize a WebGL context that is compatible with WebXR. @@ -25,12 +23,11 @@ async function activateXR() { document.body.appendChild(canvas); const gl = canvas.getContext("webgl", {xrCompatible: true}); -const scene = new THREE.Scene(); - -const directionalLight = new THREE.DirectionalLight(0xffffff, 0.3); -directionalLight.position.set(10, 15, 10); -scene.add(directionalLight); + const scene = new THREE.Scene(); + 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. const renderer = new THREE.WebGLRenderer({ @@ -49,6 +46,9 @@ camera.matrixAutoUpdate = false; // Initialize a WebXR session using "immersive-ar". 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 // near the viewer's position at the time the session was created. @@ -60,6 +60,8 @@ const viewerSpace = await session.requestReferenceSpace('viewer'); const hitTestSource = await session.requestHitTestSource({ space: viewerSpace }); + + const loader = new THREE.GLTFLoader(); let reticle; loader.load("https://immersive-web.github.io/webxr-samples/media/gltf/reticle/reticle.gltf", function(gltf) { @@ -81,10 +83,8 @@ session.addEventListener("select", (event) => { } }); - // Create a render loop that allows us to draw on the AR view. const onXRFrame = (time, frame) => { - // Queue up the next draw request. session.requestAnimationFrame(onXRFrame); @@ -114,6 +114,7 @@ const onXRFrame = (time, frame) => { reticle.updateMatrixWorld(true); } + // Render the scene with THREE.WebGLRenderer. renderer.render(scene, camera) @@ -121,8 +122,10 @@ const onXRFrame = (time, frame) => { } session.requestAnimationFrame(onXRFrame); + + + } </script> </body> </html> -