{"id":15146694,"url":"https://github.com/stspanho/aframe-hit-test","last_synced_at":"2025-10-24T01:31:05.775Z","repository":{"id":63558277,"uuid":"247535546","full_name":"stspanho/aframe-hit-test","owner":"stspanho","description":"A-Frame hit-testing example","archived":false,"fork":false,"pushed_at":"2021-10-25T09:44:43.000Z","size":8763,"stargazers_count":51,"open_issues_count":0,"forks_count":21,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-30T22:17:01.558Z","etag":null,"topics":["a-frame","android","augmented-reality","threejs","webxr"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stspanho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-15T19:21:03.000Z","updated_at":"2024-11-22T18:17:17.000Z","dependencies_parsed_at":"2022-11-21T09:01:55.941Z","dependency_job_id":null,"html_url":"https://github.com/stspanho/aframe-hit-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stspanho%2Faframe-hit-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stspanho%2Faframe-hit-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stspanho%2Faframe-hit-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stspanho%2Faframe-hit-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stspanho","download_url":"https://codeload.github.com/stspanho/aframe-hit-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237901410,"owners_count":19384384,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["a-frame","android","augmented-reality","threejs","webxr"],"created_at":"2024-09-26T12:03:53.675Z","updated_at":"2025-10-24T01:30:55.960Z","avatar_url":"https://github.com/stspanho.png","language":"HTML","readme":"# Update\n\nIt has been added by default in A-Frame. Check https://medium.com/samsung-internet-dev/use-new-augmented-reality-features-with-just-a-few-lines-of-code-with-webxr-and-aframe-c6f3f5789345\n\n# WebXR hit-testing example\n\nIn this example I've used the Spinosaurus example by Klaus Weidner (https://glitch.com/edit/undefined#!/xr-spinosaurus)\nand implemented a hit-testing component for A-Frame.\n\nThe component uses the new WebXR hit-testing feature. You can test this with an Android phone and a Chrome (Beta) v81+ browser.\n\nYou can read more about this feature here: https://immersive-web.github.io/hit-test/\n\n![](example.gif)\n\n(Note the example is without shadows, because I have some flickering issues.)\n\n## The component\n\n```\nAFRAME.registerComponent('ar-hit-test', {\n\t\t\tinit: function () {\n\t\t\t\tthis.xrHitTestSource = null;\n\t\t\t\tthis.viewerSpace = null;\n\t\t\t\tthis.refSpace = null;\n\n\t\t\t\tthis.el.sceneEl.renderer.xr.addEventListener('sessionend', (ev) =\u003e {\n\t\t\t\t\tthis.viewerSpace = null;\n\t\t\t\t\tthis.refSpace = null;\n\t\t\t\t\tthis.xrHitTestSource = null;\n\t\t\t\t});\n\t\t\t\tthis.el.sceneEl.renderer.xr.addEventListener('sessionstart', (ev) =\u003e {\n\t\t\t\t\tlet session = this.el.sceneEl.renderer.xr.getSession();\n\n\t\t\t\t\tlet element = this.el;\n\t\t\t\t\tsession.addEventListener('select', function () {\n\t\t\t\t\t\tlet position = element.getAttribute('position');\n\n\t\t\t\t\t\tdocument.getElementById('dino').setAttribute('position', position);\n\t\t\t\t\t\tdocument.getElementById('light').setAttribute('position', {\n\t\t\t\t\t\t\tx: (position.x - 2),\n\t\t\t\t\t\t\ty: (position.y + 4),\n\t\t\t\t\t\t\tz: (position.z + 2)\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\tsession.requestReferenceSpace('viewer').then((space) =\u003e {\n\t\t\t\t\t\tthis.viewerSpace = space;\n\t\t\t\t\t\tsession.requestHitTestSource({space: this.viewerSpace})\n\t\t\t\t\t\t\t\t.then((hitTestSource) =\u003e {\n\t\t\t\t\t\t\t\t\tthis.xrHitTestSource = hitTestSource;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\tsession.requestReferenceSpace('local-floor').then((space) =\u003e {\n\t\t\t\t\t\tthis.refSpace = space;\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\ttick: function () {\n\t\t\t\tif (this.el.sceneEl.is('ar-mode')) {\n\t\t\t\t\tif (!this.viewerSpace) return;\n\n\t\t\t\t\tlet frame = this.el.sceneEl.frame;\n\t\t\t\t\tlet xrViewerPose = frame.getViewerPose(this.refSpace);\n\n\t\t\t\t\tif (this.xrHitTestSource \u0026\u0026 xrViewerPose) {\n\t\t\t\t\t\tlet hitTestResults = frame.getHitTestResults(this.xrHitTestSource);\n\t\t\t\t\t\tif (hitTestResults.length \u003e 0) {\n\t\t\t\t\t\t\tlet pose = hitTestResults[0].getPose(this.refSpace);\n\n\t\t\t\t\t\t\tlet inputMat = new THREE.Matrix4();\n\t\t\t\t\t\t\tinputMat.fromArray(pose.transform.matrix);\n\n\t\t\t\t\t\t\tlet position = new THREE.Vector3();\n\t\t\t\t\t\t\tposition.setFromMatrixPosition(inputMat);\n\t\t\t\t\t\t\tthis.el.setAttribute('position', position);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstspanho%2Faframe-hit-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstspanho%2Faframe-hit-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstspanho%2Faframe-hit-test/lists"}