From adc5f179f929a187d834f392de22951bfc8d64fd Mon Sep 17 00:00:00 2001
From: Percen <21pesi1bif@hft-stuttgart.de>
Date: Mon, 9 Dec 2024 13:38:02 +0000
Subject: [PATCH] Update public/index.html

---
 public/index.html | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/public/index.html b/public/index.html
index ee35392..5287b27 100644
--- a/public/index.html
+++ b/public/index.html
@@ -8,6 +8,7 @@
 
   <!-- 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>
 
@@ -72,6 +73,33 @@ session.updateRenderState({
 // near the viewer's position at the time the session was created.
 const referenceSpace = await session.requestReferenceSpace('local');
 
+// A 'local' reference space has a native origin that is located
+// near the viewer's position at the time the session was created.
+const referenceSpace = await session.requestReferenceSpace('local');
+
+// Create another XRReferenceSpace that has the viewer as the origin.
+const viewerSpace = await session.requestReferenceSpace('viewer');
+// Perform hit testing using the viewer as origin.
+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) {
+  reticle = gltf.scene;
+  reticle.visible = false;
+  scene.add(reticle);
+})
+
+let flower;
+loader.load("https://immersive-web.github.io/webxr-samples/media/gltf/sunflower/sunflower.gltf", function(gltf) {
+  flower = gltf.scene;
+});
+
+// Create a render loop that allows us to draw on the AR view.
+const onXRFrame = (time, frame) => {
+
+
 // Create a render loop that allows us to draw on the AR view.
 const onXRFrame = (time, frame) => {
   // Queue up the next draw request.
@@ -94,6 +122,16 @@ const onXRFrame = (time, frame) => {
     camera.matrix.fromArray(view.transform.matrix)
     camera.projectionMatrix.fromArray(view.projectionMatrix);
     camera.updateMatrixWorld(true);
+    
+
+const hitTestResults = frame.getHitTestResults(hitTestSource);
+if (hitTestResults.length > 0 && reticle) {
+  const hitPose = hitTestResults[0].getPose(referenceSpace);
+  reticle.visible = true;
+  reticle.position.set(hitPose.transform.position.x, hitPose.transform.position.y, hitPose.transform.position.z)
+  reticle.updateMatrixWorld(true);
+}
+
 
     // Render the scene with THREE.WebGLRenderer.
     renderer.render(scene, camera)
-- 
GitLab