|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> |
| 6 | + <title>AR.js Demo</title> |
| 7 | + <script src="https://aframe.io/releases/1.4.2/aframe.min.js"></script> |
| 8 | + <script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js"></script> |
| 9 | + <style> |
| 10 | + body { |
| 11 | + margin: 0; |
| 12 | + overflow: hidden; |
| 13 | + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; |
| 14 | + } |
| 15 | + |
| 16 | + #back-button { |
| 17 | + position: fixed; |
| 18 | + top: 16px; |
| 19 | + left: 16px; |
| 20 | + z-index: 99999; |
| 21 | + background: rgba(255, 255, 255, 0.95); |
| 22 | + border: none; |
| 23 | + border-radius: 8px; |
| 24 | + padding: 10px 16px; |
| 25 | + font-size: 14px; |
| 26 | + font-weight: 500; |
| 27 | + color: #1a1a1a; |
| 28 | + cursor: pointer; |
| 29 | + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); |
| 30 | + display: flex; |
| 31 | + align-items: center; |
| 32 | + gap: 8px; |
| 33 | + transition: all 0.2s; |
| 34 | + } |
| 35 | + |
| 36 | + #back-button:hover { |
| 37 | + background: rgba(255, 255, 255, 1); |
| 38 | + transform: translateY(-1px); |
| 39 | + box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4); |
| 40 | + } |
| 41 | + |
| 42 | + #back-button:active { |
| 43 | + transform: translateY(0); |
| 44 | + } |
| 45 | + |
| 46 | + #instructions { |
| 47 | + position: fixed; |
| 48 | + top: 16px; |
| 49 | + right: 16px; |
| 50 | + z-index: 99999; |
| 51 | + background: rgba(0, 0, 0, 0.9); |
| 52 | + color: white; |
| 53 | + border-radius: 8px; |
| 54 | + padding: 12px; |
| 55 | + max-width: 200px; |
| 56 | + font-size: 11px; |
| 57 | + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); |
| 58 | + backdrop-filter: blur(10px); |
| 59 | + border: 1px solid rgba(255, 255, 255, 0.2); |
| 60 | + } |
| 61 | + |
| 62 | + #instructions h3 { |
| 63 | + margin: 0 0 8px 0; |
| 64 | + font-size: 13px; |
| 65 | + font-weight: 600; |
| 66 | + display: flex; |
| 67 | + align-items: center; |
| 68 | + gap: 6px; |
| 69 | + } |
| 70 | + |
| 71 | + #instructions ol { |
| 72 | + margin: 0; |
| 73 | + padding-left: 16px; |
| 74 | + } |
| 75 | + |
| 76 | + #instructions li { |
| 77 | + margin: 4px 0; |
| 78 | + line-height: 1.4; |
| 79 | + } |
| 80 | + |
| 81 | + #instructions a { |
| 82 | + color: #60a5fa; |
| 83 | + text-decoration: underline; |
| 84 | + } |
| 85 | + |
| 86 | + .a-canvas { |
| 87 | + position: fixed !important; |
| 88 | + top: 0 !important; |
| 89 | + left: 0 !important; |
| 90 | + width: 100% !important; |
| 91 | + height: 100% !important; |
| 92 | + } |
| 93 | + </style> |
| 94 | +</head> |
| 95 | +<body> |
| 96 | + <button id="back-button" onclick="goBack()"> |
| 97 | + <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 98 | + <path d="M19 12H5M12 19l-7-7 7-7"/> |
| 99 | + </svg> |
| 100 | + Back |
| 101 | + </button> |
| 102 | + |
| 103 | + <div id="instructions"> |
| 104 | + <h3> |
| 105 | + <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 106 | + <path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/> |
| 107 | + <circle cx="12" cy="13" r="4"/> |
| 108 | + </svg> |
| 109 | + AR Instructions |
| 110 | + </h3> |
| 111 | + <ol> |
| 112 | + <li>Allow camera access</li> |
| 113 | + <li>Print <a href="https://raw.githubusercontent.com/AR-js-org/AR.js/master/data/images/hiro.png" target="_blank">Hiro marker</a></li> |
| 114 | + <li>Point camera at marker</li> |
| 115 | + </ol> |
| 116 | + </div> |
| 117 | + |
| 118 | + <a-scene |
| 119 | + embedded |
| 120 | + arjs="sourceType: webcam; debugUIEnabled: false; detectionMode: mono_and_matrix; matrixCodeType: 3x3;" |
| 121 | + vr-mode-ui="enabled: false" |
| 122 | + renderer="logarithmicDepthBuffer: true; precision: medium;"> |
| 123 | + |
| 124 | + <a-marker preset="hiro"> |
| 125 | + <a-box |
| 126 | + position="0 0.5 0" |
| 127 | + material="color: #FF0000; opacity: 0.9;" |
| 128 | + animation="property: rotation; to: 0 360 0; loop: true; dur: 3000; easing: linear"> |
| 129 | + </a-box> |
| 130 | + <a-text |
| 131 | + value="Hello AR!" |
| 132 | + position="0 1.5 0" |
| 133 | + align="center" |
| 134 | + color="#FFFFFF" |
| 135 | + scale="2 2 2"> |
| 136 | + </a-text> |
| 137 | + </a-marker> |
| 138 | + |
| 139 | + <a-entity camera></a-entity> |
| 140 | + </a-scene> |
| 141 | + |
| 142 | + <script> |
| 143 | + function goBack() { |
| 144 | + // Stop all video streams before navigating |
| 145 | + const videos = document.querySelectorAll('video'); |
| 146 | + videos.forEach(video => { |
| 147 | + if (video.srcObject) { |
| 148 | + const stream = video.srcObject; |
| 149 | + stream.getTracks().forEach(track => track.stop()); |
| 150 | + video.srcObject = null; |
| 151 | + } |
| 152 | + }); |
| 153 | + |
| 154 | + // Get the base path from the current URL |
| 155 | + const path = window.location.pathname; |
| 156 | + const basePath = path.substring(0, path.lastIndexOf('/')); |
| 157 | + |
| 158 | + // Navigate back to home |
| 159 | + window.location.href = basePath + '/'; |
| 160 | + } |
| 161 | + |
| 162 | + // Stop camera when page is being unloaded |
| 163 | + window.addEventListener('beforeunload', () => { |
| 164 | + const videos = document.querySelectorAll('video'); |
| 165 | + videos.forEach(video => { |
| 166 | + if (video.srcObject) { |
| 167 | + const stream = video.srcObject; |
| 168 | + stream.getTracks().forEach(track => track.stop()); |
| 169 | + } |
| 170 | + }); |
| 171 | + }); |
| 172 | + </script> |
| 173 | +</body> |
| 174 | +</html> |
0 commit comments