1-Cube.html 1.75 KB
Newer Older
Faizi's avatar
Faizi committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>AR.js Example</title>
  <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
  <script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.7.6/aframe/build/aframe-ar.js"></script>
  <style>
    body {
      font-family: Arial, sans-serif;
      text-align: center;
      background-color: #f4f4f4;
      margin: 0;
      padding: 0;
    }
    .button {
      background-color: #003366;
      color: white;
      padding: 15px 25px;
      margin: 10px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-size: 16px;
    }
    .button:hover {
      background-color: #0055aa;
    }
    .hidden {
      display: none;
    }
  </style>
</head>
<body>
  <button class="button" onclick="activateXR()">Start AR Scene</button>
  <button class="button" onclick="captureScene()">Capture Scene</button>
  
  <a-scene embedded arjs class="hidden">
    <a-marker preset="hiro">
      <a-box position="0 0.5 0" material="color: red" animation="property: rotation; to: 360 360 360; loop: true; dur: 10000"></a-box>
    </a-marker>
    <a-entity camera></a-entity>
  </a-scene>

  <script>
    function activateXR() {
      const scene = document.querySelector("a-scene");
      scene.classList.remove("hidden");
    }

    function captureScene() {
      const canvas = document.querySelector("canvas");
      if (canvas) {
        const dataURL = canvas.toDataURL("image/png");
        const link = document.createElement("a");
        link.href = dataURL;
        link.download = "AR_Scene.png";
        link.click();
      } else {
        alert("No AR scene to capture!");
      }
    }
  </script>
</body>
</html>