|
1 | 1 | <html> |
2 | 2 | <head> |
3 | 3 | <title>A-Frame Cubemap Component - Fade</title> |
4 | | - <script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script> |
| 4 | + <script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script> |
5 | 5 | <script src="/index.js"></script> |
6 | 6 | </head> |
7 | 7 | <body> |
8 | 8 | <a-scene stats> |
| 9 | + <a-entity |
| 10 | + id="skybox" |
| 11 | + cubemap="folder: /examples/assets/Yokohama3/" |
| 12 | + ></a-entity> |
9 | 13 | <a-sphere |
10 | 14 | id="sphere" |
11 | 15 | radius="4000" |
|
14 | 18 | animation__fadeOut="property: material.opacity; from: 0.0; to: 1.0; startEvents: fadeOut" |
15 | 19 | > |
16 | 20 | </a-sphere> |
17 | | - <a-entity id="skybox" cubemap="folder: /examples/assets/Yokohama3/"></a-entity> |
18 | 21 | </a-scene> |
19 | 22 |
|
20 | 23 | <script> |
|
23 | 26 | sphere = document.querySelector("#sphere"), |
24 | 27 | cubemapPath = "folder: /examples/assets/Yokohama3/"; |
25 | 28 |
|
26 | | - function toggleBackground() { |
27 | | - cubemapPath = |
28 | | - cubemapPath === "folder: /examples/assets/Yokohama3/" |
29 | | - ? "folder: /examples/assets/GoldenGateBridge2/" |
30 | | - : "folder: /examples/assets/Yokohama3/"; |
| 29 | + // When the fadeout animation completes, swap the cubemap and fade in. |
| 30 | + sphere.addEventListener("animationcomplete", function (event) { |
| 31 | + if (event.detail.name === "animation__fadeout") { |
| 32 | + skybox.setAttribute("cubemap", cubemapPath); |
| 33 | + sphere.emit("fadeIn"); |
| 34 | + } |
| 35 | + }); |
31 | 36 |
|
32 | | - sphere.emit("fadeOut"); |
33 | | - sphere.addEventListener("animationcomplete", function (event) { |
34 | | - if (event.detail.name === "animation__fadeout") { |
35 | | - skybox.setAttribute("cubemap", cubemapPath); |
36 | | - sphere.emit("fadeIn"); |
37 | | - } |
38 | | - }); |
| 37 | + function run() { |
| 38 | + // fade in first cubemap |
| 39 | + sphere.emit("fadeIn"); |
| 40 | + |
| 41 | + // swap cubemap every 5 seconds |
| 42 | + setInterval(() => { |
| 43 | + sphere.emit("fadeOut"); |
| 44 | + |
| 45 | + // Swap |
| 46 | + cubemapPath = |
| 47 | + cubemapPath === "folder: /examples/assets/Yokohama3/" |
| 48 | + ? "folder: /examples/assets/GoldenGateBridge2/" |
| 49 | + : "folder: /examples/assets/Yokohama3/"; |
| 50 | + }, 5000); |
39 | 51 | } |
40 | 52 |
|
41 | 53 | if (scene.hasLoaded) { |
42 | 54 | run(); |
43 | 55 | } else { |
44 | 56 | scene.addEventListener("loaded", run); |
45 | 57 | } |
46 | | - |
47 | | - function run() { |
48 | | - // Cubemap has loaded, so fade in. |
49 | | - sphere.emit("fadeIn"); |
50 | | - |
51 | | - // Toggle the background. |
52 | | - toggleBackground(); |
53 | | - |
54 | | - // Toggle the background back and forth every 5 seconds. |
55 | | - skybox.addEventListener("cubemapLoaded", () => { |
56 | | - setTimeout(toggleBackground, 5000); |
57 | | - }); |
58 | | - } |
59 | 58 | </script> |
60 | 59 | </body> |
61 | 60 | </html> |
0 commit comments