-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path5--missed-connections.html
319 lines (275 loc) · 12.8 KB
/
5--missed-connections.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<!doctype html>
<html>
<head>
<title>5 - Missed Connections</title>
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,user-scalable=no,maximum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="bower_components/aframe2/dist/aframe-v0.2.0.min.js"></script>
<script src="bower_components/aframe-layout-component/dist/aframe-layout-component.min.js"></script>
<script src="bower_components/aframe-template-component/dist/aframe-template-component.min.js"></script>
<script src="bower_components/aframe-text-component/dist/aframe-text-component.min.js"></script>
<script src="bower_components/aframe-event-set-component/dist/aframe-event-set-component.min.js"></script>
<script src="bower_components/jQuery/dist/jquery.min.js"></script>
<script src="assets/5/data/nyc-data.js"></script>
</head>
<body>
<!--
Credits
-->
<!-- Scripts that must run before Aframe initializes -->
<script type="text/javascript">
</script>
<a-scene id="main-scene" fog="type: exponential; color: #111; density:.005">
<!-- Block showing scene until these assets are loaded -->
<a-assets>
<!--
Buildings
10m/story
15m/between buildings (approx 4 12" lanes)
10m/width
135//67.5
-->
<a-mixin id="bldg" geometry="primitive: box; depth: 30; height: 30; width: 30" material="roughness: 1; color: #404045"></a-mixin>
<a-mixin id="bldg-h-sm" geometry="height: 21"></a-mixin>
<a-mixin id="bldg-h-lg" geometry="height: 60"></a-mixin>
<a-mixin id="bldg-w-lg" geometry=" width: 75"></a-mixin>
<a-mixin id="notification" geometry="radius: 20; height: 20; width: 20; depth: 20;" material="color: #4CCCE5; opacity: .8"></a-mixin>
<a-asset-item id="humanModel" src="assets/5/Models/maleCasual.dae"></a-asset-item>
<!-- <a-asset-item id="anotherHumanModel" src="assets/5/models/anotherMaleModel.dae"></a-asset-item> -->
<!-- <a-asset-item id="femaleModel" src="assets/5/models/femaleCasual.dae"></a-asset-item> -->
<a-mixin id="font" text="size: .08; height: .02" material="color: #eee"></a-mixin>
<a-mixin id="soundcube" ></a-mixin>
<!-- for testing soundcubes placement add geometry="primitive: box; height: .5; width: .5; depth: .5"></a-mixin> -->
<audio id="city-sounds" src="assets/5/audio/city-sounds.mp3"></audio>
<audio id="melancholy-piano" src="assets/5/audio/melancholy-piano.mp3"></audio>
<audio id="rain-sound" src="assets/5/audio/rain-sound.mp3"></audio>
<audio id="voices-murmur" src="assets/5/audio/voices-murmur.mp3"></audio>
<!-- <a-asset-item id="nyc" src="assets/5/manhattan+2001.obj" material="color: #111"></a-asset-item> -->
<!-- Templating engine for the humans
<script id="humans-template" type="text/x-nunjucks-template">
{% for x in range(0, 1) %}
{% for z in range(0, 1) %}
<a-entity template="src: assets/5/templates/human.template; type: handlebars"
data-position="0 0 0"
data-humanID="-1"></a-entity>
{% endfor %}
{% endfor %}
</script>
-->
<!-- Templating engine for the non-implemented notifications -->
<script id="notifications" type="text/x-nunjucks-template">
{% for x in range(-2, 2) %}
{% for z in range(-2, 2) %}
<a-entity template="src: assets/5/templates/notifications.template; type: handlebars"
data-position="{{ x * 90 }} 0 {{ z * 90 + 40}}"></a-entity>
{% endfor %}
{% endfor %}
</script>
<!-- Templating engine for the rain -->
<script id="rain-sound" type="text/x-nunjucks-template">
{% for x in range(-4, 4) %}
{% for z in range(-2, 2) %}
<a-entity template="src: assets/5/audio/piano-sound.mp3; type: handlebars" data-position="{{ x * 90 }} 0 {{ z * 90 + 40}}" autoplay="true"></a-entity>
{% endfor %}
{% endfor %}
</script>
</a-assets>
<!-- Global Settings -->
<a-sky color="#111"></a-sky>
<a-light type="ambient" color="#ccc" intensity=".1"></a-light>
<a-light type="directional" color="#ccc" position="1 1 0" intensity=".5"></a-light>
<a-image id="ground" position="0 -.025 0" height="500" width="500" rotation="90 0 0" src="assets/5/ground.png"></a-image>
<!-- Human Camera -->
<a-entity position="0 0 0" id="human-camera-position">
<a-entity position="0 1.6 1.1">
<a-camera id="human-camera" wasd-controls-enabled="true" look-controls-enabled="true" active="true">
<a-entity cursor="fuse: true; maxDistance: 5; timeout: 1500"
position="0 0 -1"
geometry="primitive: ring"
scale=".01 .01 .01"
material="color: white; shader: flat">
<!-- Animations for hovering -->
<a-animation begin="click" easing="ease-in" attribute="scale" fill="backwards" from=".005 .005 .005" to=".01 .01 .01"></a-animation>
<a-animation begin="fusing" easing="ease-in" attribute="scale" fill="forwards" from=".01 .01 .01" to=".005 .005 .005"></a-animation>
<!-- Tied the soundcubes to the camera so that they move when we move the camera -->
<a-entity mixin="soundcube" position="0 -1 0" sound="src: assets/5/audio/voices-murmur.mp3; autoplay: true; loop: true"></a-entity>
<a-entity mixin="soundcube" position="0 -4.5 0" sound="src: assets/5/audio/rain-sound.mp3; autoplay: true; loop: true; volume: .10"></a-entity>
<a-entity mixin="soundcube" position="10 -3 0" sound="src: assets/5/audio/city-sounds.mp3; autoplay: true; loop: true; volume: .40"></a-entity>
<a-entity mixin="soundcube" position="10 -3 0" sound="src: assets/5/audio/melancholy-piano.mp3; autoplay: true; loop: true; volume: .90"></a-entity>
<a-entity id="skypiano" position="0 2200 0" sound="src: assets/5/audio/melancholy-piano.mp3; autoplay: true; loop: true; volume: 2.10"></a-entity>
</a-entity>
</a-camera>
</a-entity>
</a-entity>
<!-- Topographic Camera -->
<a-entity position="0 400 0" rotation="-90 0 0">
<a-camera id="topology-camera" look-controls-enabled="true" active="false" fov="60" wasd-controls="enabled: true; acceleration: 8000; fly: true">
<a-entity cursor="fuse: true; maxDistance: 30; timeout: 500"
position="0 0 -1"
geometry="primitive: ring"
scale=".01 .01 .01"
material="color: white; shader: flat">
</a-entity>
</a-camera>
</a-entity>
<!-- Fake City (Better for not crashing mobile)-->
<a-entity id="city-container" template="src: assets/5/templates/city.template" position="22.5 0 0"></a-entity>
<!-- Real City (Better for people who like NYC more than a working mobile version)-->
<!-- <a-obj-model src="#nyc" position="-300 -1 0"></a-obj-model> -->
<!-- Humans (Code if you want to mess with the human templating engine)-->
<!-- <a-entity template="src: #humans-template" id="humans"></a-entity> -->
<!-- Notifications (Code if you want to mess with the notifications)-->
<!-- <a-entity template="src: #notifications"></a-entity> -->
</a-scene>
<script>
/*
*
* Topology mode toggle fns (only implemented for desktop)
*
*/
document.onkeydown = checkKey;
/*
Setup vars and, if the scene has not been initialized, tie the initialization to the ground
*/
var humanID = -1;
var initialized = false;
var scene = {
el: document.querySelector('a-scene'),
fog: document.querySelector('a-scene').getAttribute('fog').density
};
scene.el.addEventListener('loaded', function(){
initializeScene(humanID);
});
/*
Initialize the scene
*/
function initializeScene(humanID){
//setHumans();
console.log('initializeScene()' + humanID);
goNext(humanID);
}
var cameramode = "human";
var cameras = {
human: document.querySelector('#human-camera'),
topology: document.querySelector('#topology-camera')
}
function humanMode(){
cameramode = "human";
cameras.topology.setAttribute("active","false");
cameras.human.setAttribute("active","true");
scene.el.setAttribute("fog", "density", scene.fog);
}
function topologyMode(){
cameramode = "topology";
document.querySelector('#topology-camera').setAttribute("active","true");
document.querySelector('#human-camera').setAttribute("active","false");
scene.el.setAttribute("fog", "density", 0);
}
/*
Key checkers
*/
var textInit = false;
function checkKey(e) {
e = e || window.event;
// toggle topology mode
if(e.keyCode == '71') { // the letter g
if(cameramode == "topology"){
humanMode();
} else {
topologyMode();
}
}
// reactivate setHuman() // letter b
else if (e.keyCode == '66') {
if(textInit == false){
setHuman();
textInit = true;
}
}
}
/*
Activate a human template (text formatting, text init, add animation)
*/
function setHuman(humanID){
var $humanTextContainer = $('.human').find('#human-text-container');
var humanText = postData.posts[humanID].bodyCleaned;
console.log(humanText);
var splitBySpace = humanText.split(" ");
console.log(splitBySpace);
var lineHeight = .2;
var lineHeightRel = 0;
var textLine = 0;
while (textLine <= splitBySpace.length){
var word1 = splitBySpace[textLine];
var word2 = splitBySpace[textLine + 1];
var word3 = splitBySpace[textLine + 2];
var word4 = splitBySpace[textLine + 3];
if(word1 == undefined){
word1 = '';
}
if(word2 == undefined){
word2 = '';
}
if(word3 == undefined){
word3 = '';
}
if(word4 == undefined){
word4 = '';
}
$humanTextContainer.append('<a-entity mixin="font" text="text: ' + word1 + ' ' + word2 + ' ' + word3 + ' ' + word4 + '" position="-0.5 ' + lineHeightRel + ' 0"></a-entity>');
lineHeightRel -= lineHeight;
textLine += 4;
}
var textContainerHeight = lineHeight * (textLine / 4);
$humanTextContainer.attr('position', '0 ' + .8 + ' 0');
$humanTextContainer.append('<a-animation attribute="position" dur="90000000" fil="forwards" easing="linear" to="0 3000 .2"></a-animation>');
}
/*
Add a human template to the scene
*/
function addHumanTemplate(humanID){
var newPosition = {
x: getRandomIntInclusive(-120, 120),
z: getRandomIntInclusive(-120, 120)
}
console.log(newPosition);
$('a-scene').append('<a-entity id="nextHuman" position="' + newPosition.x + ' 0 ' + newPosition.z + '"></a-entity>');
$('a-scene #nextHuman').load('assets/5/templates/human.template', function(){
$(this).find('.human').attr('position', '0 0 0').attr('id', 'humanNo-' + humanID);
setHuman(humanID);
moveCamera(humanID, newPosition);
});
}
/*
Move the camera to a new location
*/
function moveCamera(humanID, newPosition){
var newLocation = $('#humanNo-' + humanID).attr('position');
console.log(newLocation);
$('#human-camera').attr('position', newPosition.x + ' ' + 0 + ' ' + newPosition.z);
$('#humanNo-' + humanID + ' #btnNext').on('click', function () {
console.log('moveCamera()' + humanID);
goNext(humanID);
});
}
/*
Remove a human from the scene
*/
function removeHuman(humanID){
$('#humanNo-' + humanID).parent().remove();
}
/*
Process when user wants to go the the next post
*/
function goNext(humanID){
removeHuman(humanID);
humanID = getRandomIntInclusive(1, 100);
addHumanTemplate(humanID);
}
// Thanks Mozilla
function getRandomIntInclusive(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>
</body>
</html>