-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
263 lines (256 loc) · 9.82 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<html>
<!--
TODO:
- optimize page loading
- custom pattern
- overlay loading screen
- Help button for instructions
- toggle button :check:
- animation for text
- text itself
- Chestnuts Roasting
- chest animation
- flame animations
- nut animation
- name displayed
- desktop vs mobile display
- unlockable masks unique to cards
-->
<head>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/MaesterChestnut/AR.js/mergeBranch/aframe/build/aframe-ar.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/v4.1.2/dist/aframe-extras.min.js"></script>
<style>
/*#overlay-wrapper {
height: 500px;
width: 500px;
background-color: gray;
opacity: .5;
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: -500px;
}*/
#interactive-wrapper {
height: 70px;
width: 70px;
background-color: skyblue;
border-radius: 50%;
border: 3px solid black;
bottom: 10px;
right: 10px;
position: absolute;
text-align: -webkit-center;
z-index: 5;
font-size: 40px;
line-height: 60px;
}
#arjsDebugUIContainer {
display: none;
}
</style>
</head>
<body>
<div id='overlay-wrapper'>
<div id='text-wrapper'>
<div id='title-wrapper'>
</div>
<div id='instruction-wrapper'>
</div>
<div id='interactive-wrapper'>
?
</div>
</div>
</div>
<!--div id=''-->
<a-scene embedded vr-mode-ui='enabled: false'
arjs='sourceType: webcam'>
<a-assets id="critical-assets">
<!--a-asset-item id="hollow" src="gltfModels/hollow_mask/scene.gltf"></a-asset-item-->
<!--audio id="appear" src="appear.wav" preload="auto"></audio-->
<a-asset-item id="chest-asset" src="gltfModels/treasure_chest/scene.gltf"></a-asset-item>
<a-asset-item id="spell-asset" src="gltfModels/spell/scene.gltf"></a-asset-item>
</a-assets>
<a-assets timeout="10" id="inner-assets">
<a-asset-item id="tentacle-asset" src="gltfModels/tentacle/scene.gltf"></a-asset-item>
<a-asset-item id="snitch-asset" src="gltfModels/snitch/scene.gltf"></a-asset-item>
<a-asset-item id="r2-asset" src="gltfModels/r2/scene.gltf"></a-asset-item>
<a-asset-item id="shenron-asset" src="gltfModels/shenron/scene.gltf"></a-asset-item>
<!--a-asset-item id="flame-asset" src="gltfModels/small_fire/scene.gltf"></a-asset-item-->
</a-assets>
<!--a-marker-camera preset='custom' type='pattern' url="https://s3.amazonaws.com/aws-website-chestnutmeansbusiness-l2ucx/panther-pattern.patt"></a-marker-camera-->
<a-marker preset='hiro' registerevents emitevents='true'>
<a-entity animation-mixer id="spell" rotation="90" scale=".01 .01 1"
position="0 0 0" gltf-model="#spell-asset">
<a-animation id='spell-appear' attribute="scale"
begin="spell-appear" to=".1 .1 1" dur="6000">
</a-animation>
</a-entity>
<a-entity anim-control animation-mixer="clip: static pose" id="chest"
position="0 0 0" gltf-model="#chest-asset" scale=".001 .001 .001">
<a-animation id="chest-appear" attribute="scale"
to=".008 .008 .008" dur="4000" begin="chest-appear">
</a-animation>
<!--a-animation id="chest-sink" attribute="position" to="0 -4 0" dur="4000"
begin="chest-away">
</a-animation>
<a-animation attribute="visible" dur="4000" to="false" begin="chest-away"></a-animation-->
</a-entity>
</a-marker>
<a-camera-static/>
</a-scene>
<script>
var assets = document.querySelectorAll('a-assets');
assets.forEach((asset) => {
asset.addEventListener('loaded', () => {
console.log('Assets Loaded: ', asset);
})
});
var scene = document.querySelector('a-scene');
let params = (new URL(document.location)).searchParams;
if(params.get('stats') === "true") {
scene.setAttribute('stats', true);
}
var instructionMenu = document.querySelector('#instruction-wrapper');
document.querySelector('#interactive-wrapper').addEventListener('click', () => {
if (instructionMenu.className.indexOf('open') >= 0) {
instructionMenu.classList.replace('open', 'close');
} else {
instructionMenu.classList.add('open');
instructionMenu.classList.remove('close');
}
});
</script>
<script>
AFRAME.registerComponent('registerevents', {
init: function() {
var marker = this.el;
var spellEntity = document.getElementById('spell');
var spellAnimation = document.querySelector('#spell-appear');
var chestAnimation = document.querySelector('#chest-appear');
//var chest = document.querySelector('#chest');
var animStatus = false;
//var sound = document.querySelector('[sound]');
// Make the element emit events when found and when lost.
marker.setAttribute('emitevents', 'true');
marker.addEventListener('markerFound', () => {
if(!animStatus){
spellAnimation.emit('spell-appear');
}
});
spellAnimation.addEventListener('animationend', () => {
animStatus = true;
chestAnimation.emit("chest-appear");
});
marker.addEventListener('markerLost', function() {
//if ends mid appearance - scratch sound
});
}
});
</script>
<script>
var chestAnimation = document.querySelector('#chest');
var modelMap = {
'dragon': {
//'gltf-model': 'url(gltfModels/shenron/scene.gltf)',
'gltf-model': '#shenron-asset',
'scale': '.1 .1 .1',
'animation-mixer': true
},
'tentacle': {
//'gltf-model': 'url(gltfModels/tentacle/scene.gltf)',
'gltf-model': '#tentacle-asset',
'scale': '.1 .5 .1',
'animation-mixer': true
},
'gold': {
//'gltf-model': 'url(gltfModels/snitch/scene.gltf)',
'gltf-model': '#snitch-asset',
'scale': '.001 .001 .001',
'animation-mixer': true
},
'R2': {
//'gltf-model': 'url(gltfModels/r2/scene.gltf)',
'gltf-model': '#r2-asset',
'scale': '.1 .1 .1',
'animation-mixer': true
}
};
var modelVoice;
var chestCommands = {
'opensasame': () => {
//summon random model
chest.setAttribute('animation-mixer', "clip: *; loop: pingpong; repetitions: 1");
modelVoice = modelMap['tentacle'];
},
'dragon arise': () => {
chest.setAttribute('animation-mixer', "clip: *; loop: pingpong; repetitions: 1");
modelVoice = modelMap['shrenron'];
},
'open (up)': () => {
chest.setAttribute('animation-mixer', "clip: *; loop: pingpong; repetitions: 1");
modelVoice = modelMap['goblin'];
},
'let the games begin': () => {
chest.setAttribute('animation-mixer', "clip: *; loop: pingpong; repetitions: 1");
modelVoice = modelMap['gold'];
},
'I\'ve gotta bad feeling about this': () => {
chest.setAttribute('animation-mixer', "clip: *; loop: pingpong; repetitions: 1");
modelVoice = modelMap['R2'];
},
'show me *tag': (tag) => {
chest.setAttribute('animation-mixer', "clip: *; loop: pingpong; repetitions: 1");
console.log('Summoning ', tag);
modelVoice = modelMap[tag];
},
'another one': () => {
chest.setAttribute('animation-mixer', "clip: static pose; loop: pingpong; repetitions: 1");
console.log('Resetting');
let summoned = document.querySelectorAll('.summonedEntity');
if (summoned) {
summoned.forEach( (elem) => {
elem.setAttribute('position', {x: 0, y: 1, z: 9999});
});
}
}/*,
'chestnuts roasting': () => {
console.log('chestnut recog');
chestAnimation.emit('chest-away');
}*/
};
AFRAME.registerComponent('anim-control', {
init: function() {
var chestAnimation = document.querySelector('#chest-appear');
var chest = document.querySelector('#chest');
var sceneEl = document.querySelector('a-marker');
//trigger chest opening
chestAnimation.addEventListener('animationend', () => {
if (annyang) {
annyang.addCommands(chestCommands);
annyang.start();
} else {
chest.setAttribute('animation-mixer', "clip: *; loop: pingpong; repetitions: 1");
}
});
chest.addEventListener('animation-loop', (action) => {
action.detail.action.clampWhenFinished = true;
});
chest.addEventListener('animation-finished', () => {
var el = document.createElement('a-entity');
//select modelmap; need to handle if chest isn't open
var model = modelVoice ? modelVoice : modelMap['tentacle'];
for (var key in model) {
console.log('Key: ', key, ' prop: ', model[key]);
el.setAttribute(key, model[key]);
}
el.setAttribute('class', 'summonedEntity');
el.setAttribute('position', {x: 0, y: 1, z: 0});
sceneEl.append(el);
});
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/2.6.0/annyang.min.js"></script>
</body>
</html>