Commit 638e2a06 authored by Esguerra Montana's avatar Esguerra Montana
Browse files

Update index.html

parent 46167b55
Pipeline #9639 passed with stage
in 7 seconds
<!doctype html>
<html> <html>
<head> <head>
<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>Hit to Place Demo</title> <title>Hit to Place Demo</title>
<!-- three.js --> <!-- three.js -->
<script src="https://unpkg.com/three@0.126.0/build/three.js"></script> <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> <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 Hit to Place 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.
...@@ -59,6 +56,9 @@ const viewerSpace = await session.requestReferenceSpace('viewer'); ...@@ -59,6 +56,9 @@ const viewerSpace = await session.requestReferenceSpace('viewer');
// Perform hit testing using the viewer as origin. // Perform hit testing using the viewer as origin.
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) {
...@@ -67,17 +67,16 @@ loader.load("https://immersive-web.github.io/webxr-samples/media/gltf/reticle/re ...@@ -67,17 +67,16 @@ loader.load("https://immersive-web.github.io/webxr-samples/media/gltf/reticle/re
scene.add(reticle); scene.add(reticle);
}) })
let fox; let chair;
loader.load("./fox/Fox.gltf", function(gltf) { loader.load("./mario/scene.gltf", function(gltf) {
fox = gltf.scene; chair = gltf.scene;
fox.scale.set(0.05, 0.05, 0.05); // Adjust the scale as needed chair.scale.set(0.5, 0.5, 0.5); // Adjust the scale as needed
}); });
session.addEventListener("select", (event) => { session.addEventListener("select", (event) => {
if (fox) { if (chair) {
const clone = fox.clone(); const clone = chair.clone();
clone.position.copy(reticle.position); clone.position.copy(reticle.position);
clone.scale.set(0.05, 0.05, 0.05); // Ensure the clone is also scaled down
scene.add(clone); scene.add(clone);
} }
}); });
...@@ -113,12 +112,17 @@ const onXRFrame = (time, frame) => { ...@@ -113,12 +112,17 @@ const onXRFrame = (time, frame) => {
reticle.updateMatrixWorld(true); reticle.updateMatrixWorld(true);
} }
// 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>
......
Markdown is supported
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