-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
81 lines (71 loc) · 3.51 KB
/
index.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Celebration • A-Frame</title>
<meta name="description" content="Celebration • A-Frame">
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js"></script>
<script
src="https://unpkg.com/[email protected]/dist/aframe-particle-system-component.min.js"></script>
<script
src="https://unpkg.com/aframe-text-geometry-component@^0.5.0/dist/aframe-text-geometry-component.min.js"></script>
</head>
<body>
<a-scene vr-mode-ui="enabled: false;" renderer="logarithmicDepthBuffer: true;"
arjs="debugUIEnabled: false; trackingMethod: best;" gesture-detector>
<a-assets>
<a-asset-item id="cake-obj"
src="https://cdn.rawgit.com/HackyRoot/A-Frame-Examples/c6a977a7/Happy_Birthday/assets/cake.obj">
</a-asset-item>
<a-asset-item id="cake-mtl"
src="https://cdn.rawgit.com/HackyRoot/A-Frame-Examples/c6a977a7/Happy_Birthday/assets/cake.mtl">
</a-asset-item>
<a-asset-item id="brush"
src="https://cdn.rawgit.com/HackyRoot/A-Frame-Examples/c6a977a7/Happy_Birthday/assets/brush.json">
</a-asset-item>
<audio id="bday"
src="https://cdn.rawgit.com/HackyRoot/A-Frame-Examples/c6a977a7/Happy_Birthday/assets/bday.mp3" preload="auto"></audio>
</a-assets>
<a-marker markerhandler id="marker" preset="kanji">
<a-obj-model src="#cake-obj" mtl="#cake-mtl" rotation="0 0 0" scale="3 1.5 3" position="0 0 0">
</a-obj-model>
<a-entity rotation="0 0 0">
<a-entity position="0 0 0" particle-system="color:#f9e154;"></a-entity>
</a-entity>
</a-marker>
<a-entity camera></a-entity>
</a-scene>
<script>
const wishText = new URLSearchParams(window.location.search).get('text') || "Happy Birthday!!";
const content = document.createElement('a-entity');
content.innerHTML = `
<a-entity position="-2 1 -3" material="color: red" scale="1 1 1"
text-geometry="value: Happy Birthday; font: #brush" sound="src:#bday; autoplay: false; loop: true;">
</a-entity>
<a-entity position="-3 -0.5 -3" material="color: #f9e154" scale="2 2 2"
text-geometry="value: ${wishText.match(/Happy Birthday (.+)!/)[1].toUpperCase()}; font: #brush;">
</a-entity>
`
document.getElementById("marker").appendChild(content)
AFRAME.registerComponent('markerhandler', {
init: function () {
this.el.sceneEl.addEventListener('markerFound', () => {
// redirect to custom URL e.g. google.com
// window.location = 'https://www.google.com/';
const entity = document.querySelector('[sound]');
console.log(entity)
entity.components.sound.playSound();
})
this.el.sceneEl.addEventListener('markerLost', () => {
// redirect to custom URL e.g. google.com
// window.location = 'https://www.google.com/';
const entity = document.querySelector('[sound]');
console.log(entity)
entity.components.sound.pauseSound();
})
}
});
</script>
</body>
</html>