-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.html
executable file
·529 lines (448 loc) · 28.4 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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>aframe.city</title>
<meta name="description" content="A-Frame City Builder">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="apple-touch-icon-152x152.png" />
<link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" />
<meta name="application-name" content="aframe.city"/>
<meta name="msapplication-TileColor" content="#000000" />
<meta name="msapplication-TileImage" content="mstile-144x144.png" />
<!-- using aframe master until next stable -->
<!-- <script src="https://rawgit.com/aframevr/aframe/master/dist/aframe-master.js"></script> -->
<script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
<!-- jquery for city builder app components -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- this was a build script but webpack was too annoying so not used for now -->
<script src="lib/dist/aframe-city-builder.js"></script>
<!-- for desktop menu overlay -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
<!-- components used -->
<!-- <script src="https://rawgit.com/fernandojsg/aframe-teleport-controls/master/dist/aframe-teleport-controls.min.js"></script> -->
<script src="https://rawgit.com/kfarr/aframe-teleport-controls/master/dist/aframe-teleport-controls.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-controller-cursor-component.min.js"></script>
<script src="https://rawgit.com/kfarr/aframe-select-bar-component/master/dist/aframe-select-bar-component.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.7.3/firebase.js"></script>
<script src="https://rawgit.com/konsumer/randopeep/gh-pages/randopeep.js"></script>
<!-- anonymous tracking using amplitude.com, see https://github.com/kfarr/aframe-city-builder/issues/19 -->
<script type="text/javascript">
(function(e,t){var n=e.amplitude||{_q:[],_iq:{}};var r=t.createElement("script");r.type="text/javascript";
r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-3.4.0-min.gz.js";
r.onload=function(){e.amplitude.runQueuedFunctions()};var i=t.getElementsByTagName("script")[0];
i.parentNode.insertBefore(r,i);function s(e,t){e.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
return this}}var o=function(){this._q=[];return this};var a=["add","append","clearAll","prepend","set","setOnce","unset"];
for(var u=0;u<a.length;u++){s(o,a[u])}n.Identify=o;var c=function(){this._q=[];return this;
};var p=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"];
for(var l=0;l<p.length;l++){s(c,p[l])}n.Revenue=c;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","logEventWithTimestamp","logEventWithGroups"];
function v(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
}}for(var n=0;n<d.length;n++){t(d[n])}}v(n);n.getInstance=function(e){e=(!e||e.length===0?"$default_instance":e).toLowerCase();
if(!n._iq.hasOwnProperty(e)){n._iq[e]={_q:[]};v(n._iq[e])}return n._iq[e]};e.amplitude=n;
})(window,document);
amplitude.getInstance().init("33201f4a9c574462a955bc71d76ba945");
amplitude.getInstance().logEvent('Loaded Amplitude', {'location': window.location.href});
</script>
<!-- <script src="https://rawgit.com/bryik/aframe-bmfont-text-component/master/dist/aframe-bmfont-text-component.min.js"></script>
<script src="https://rawgit.com/ngokevin/kframe/master/components/text/dist/aframe-text-component.min.js"></script> -->
<!-- <script src="https://rawgit.com/ngokevin/aframe-animation-component/master/dist/aframe-animation-component.js"></script>
<script src="https://rawgit.com/kfarr/aframe-gridhelper/master/dist/aframe-gridhelper-component.min.js"></script> -->
<!-- <script src="lib/skyGradient.js"></script>
<script src="lib/ground.js"></script>
<script src="lib/aframe-select-bar.js"></script>
<script src="lib/builder-controls.js"></script> -->
<style>
.intro-overlay {
z-index: 1;
position: absolute;
top: 20px;
left: 20px;
max-width: 700px;
box-sizing: border-box;
padding: 1.5em;
color: #FFF;
background: rgba(0, 0, 0, 0.75);
font-family: Source Sans Pro, Helvetica Neue, Helvetica, Arial, sans-serif;
}
.menu-overlay {
z-index: 99999;
position: fixed;
top: 20px;
right: 20px;
box-sizing: border-box;
padding: 1.5em;
width: 60px;
height: 60px;
padding-bottom: 0px;
background: rgba(0, 0, 0, 0.5) url(./assets/images/hamburger-white.png) center no-repeat;
background-size: 40px 40px;
font-family: Source Sans Pro, Helvetica Neue, Helvetica, Arial, sans-serif;
}
.menu-overlay:hover {
background: rgba(0, 0, 0, 0.2) url(./assets/images/hamburger-white.png) center no-repeat;
background-size: 40px 40px;
}
</style>
</head>
<body>
<a-scene id="my-scene" antialias="true" >
<a-assets>
<!-- scene items -->
<a-asset-item id="table-obj" src="assets/environment/table.obj"></a-asset-item>
<a-asset-item id="table-mtl" src="assets/environment/table.mtl"></a-asset-item>
<a-asset-item id="env_arrow" src="assets/environment/env_arrow.obj"></a-asset-item>
<!-- geometric city builder text -->
<img id="chrome" src="assets/environment/env_map_chrome.jpg">
<a-asset-item id="exoBlackRegular" src="assets/environment/env_exo_black_regular.js"></a-asset-item>
<a-asset-item id="exoBoldItalic" src="assets/environment/env_exo_bold_italic.js"></a-asset-item>
<a-mixin id="avatar"
geometry="primitive: box; depth: 0.3; height: 0.3; width: 0.3"
material="color: #222"></a-mixin>
<a-mixin id="eye" geometry="primitive: circle; radius: 0.08"
material="shader: flat; side: double"></a-mixin>
<a-mixin id="eyePupil" geometry="primitive: circle; radius: 0.02"
material="shader: flat; side: double; color: #222"></a-mixin>
</a-assets>
<!-- Player -->
<!-- <a-entity id="cameraWrapper" position="0.05 0.41 0.34" rotation="-43.5 0.80 0"> -->
<a-entity id="cameraWrapper" position="-1.06 1.31 1.82" rotation="-12.834254610930437 -16.844959176846217 0">
<a-entity id="camera" camera look-controls wasd-controls="fly: true"></a-entity>
</a-entity>
<!-- Left Hand -->
<a-entity id="leftController" action-controls="menuID: menuActions" wasd-controls oculus-touch-controls="hand: left" vive-controls="hand: left" windows-motion-controls="hand: left; model: false">
<a-entity id="menuActions" select-bar="controllerID: leftController" scale="0.7 0.7 0.7" position="0 0.05 0.08" rotation="-85 0 0">
<optgroup label="Actions" value="actions">
<option value="teleport" src="assets/environment/icon_teleport.png" selected>Teleport</option>
<option value="erase" src="assets/environment/icon_erase.png">Erase</option>
<option value="saveAs" src="assets/environment/icon_saveAs.png">Save As</option>
<option value="save" src="assets/environment/icon_save.png">Save (Overwrite)</option>
<option value="new" src="assets/environment/icon_new.png">New</option>
<option value="exit" src="assets/environment/icon_exit.png">Exit VR</option>
<option value="undo" src="assets/environment/icon_undo.png">Undo</option>
</optgroup>
</a-entity>
</a-entity>
<!-- Right Hand -->
<a-entity builder-controls="menuId: menuObjects" id="rightController" oculus-touch-controls="hand: right" vive-controls="hand: right" windows-motion-controls="hand: right; model: false">
<a-entity id="rightItem" file="kfarr_bases_valencia" objectGroup="kfarr_bases" objectId="0" obj-model="obj: url(assets/obj/kfarr_bases_valencia.obj); mtl: url(assets/obj/kfarr_bases_valencia.mtl)" rotation="-56.8 0 0" scale="0.004 0.004 0.004" position="0 -0.08 -0.09"></a-entity>
<a-entity id="rightArm" mixins="arm"></a-entity>
<a-entity select-bar id="menuObjects" scale="0.7 0.7 0.7" position="0 0.05 0.08" rotation="-85 0 0">
<optgroup label="Bases" value="kfarr_bases">
<option value="kfarr_bases_valencia" src="assets/preview/kfarr_bases_valencia.jpg" selected>Valencia Street</option>
<option value="kfarr_bases_valencia_dashed" src="assets/preview/kfarr_bases_valencia_dashed.jpg">Valencia Dashed</option>
<option value="kfarr_bases_valencia_tram" src="assets/preview/kfarr_bases_valencia_tram.jpg">Valencia w/Tram</option>
<option value="kfarr_bases_valencia_intersection" src="assets/preview/kfarr_bases_valencia_intersection.jpg">Valencia Intersection</option>
<option value="kfarr_bases_valencia_intersection_tram" src="assets/preview/kfarr_bases_valencia_intersection_tram.jpg">Valencia Tram Intrsctn</option>
<option value="kfarr_bases_valencia_tram2" src="assets/preview/kfarr_bases_valencia_tram2.jpg">Valencia w/Tram v2</option>
<option value="kfarr_bases_valencia_store-1-11-12" src="assets/preview/kfarr_bases_valencia_store-1-11-12.jpg">Lot Mix 1, 11, 12</option>
<option value="kfarr_bases_valencia_store-1-3" src="assets/preview/kfarr_bases_valencia_store-1-3.jpg">Lot Mix 1, 3</option>
<option value="kfarr_bases_valencia_store-5-lot" src="assets/preview/kfarr_bases_valencia_store-5-lot.jpg">Lot Mix 5, empty</option>
<option value="kfarr_bases_valencia_lot" src="assets/preview/kfarr_bases_valencia_lot.jpg">Lot Empty</option>
<option value="kfarr_bases_valencia_store-8-11-13" src="assets/preview/kfarr_bases_valencia_store-8-11-13.jpg">Lot Mix 8, 11, 13</option>
<option value="base_street1" src="assets/preview/base_street1.jpg">Basic Street</option>
<option value="base_grass1" src="assets/preview/base_grass1.jpg">Grass Lot</option>
<option value="base_crossstreet" src="assets/preview/base_crossstreet.jpg">Basic Intersection</option>
</optgroup>
</a-entity>
</a-entity>
<!-- City -->
<a-entity id="city"></a-entity>
<!-- Table and Grid -->
<a-entity id="tableGrid" position="0.25 0.5 0.25" gridhelper="size:10; divisions:20">
<a-box id="tableTop" position="0.12 -0.01 -1.02" width="3" height="0.1" depth="2" color="#09620b" material="color:#09620b" geometry="primitive:box;width:3;height:0.1;depth:2" scale="0.9 0.19999999999999996 0.78"></a-box>
<a-entity id="tableBase" scale="0.015 0.015 0.015" position="0.18 -0.02 -1" rotation="0 0 0" obj-model="obj:#table-obj;mtl:#table-mtl"></a-entity>
</a-entity>
<!-- Floor -->
<a-entity id="floor" color="#603a2b" material="color:#603a2b" geometry="primitive: circle; radius: 2.5" position="0 0 0" rotation="-90 0 0" ></a-entity>
<a-entity position="-3 1 -6" rotation="5 0 0">
<!-- City Builder Geometric Text Title adapted from Ada Rose's https://aframe.io/examples/showcase/hello-metaverse/ -->
<!-- <a-entity position="-0.5 0.5 -0.5" scale="0.6 1.2 1" text="text:CITY BUILDER;font:#exoBlackRegular;bevelEnabled:true;bevelSize:0.1;bevelThickness:0.1;curveSegments:1;size:1.5;height:0.5" material="color:white;metalness:0.9;roughness:0.05;sphericalEnvMap:#chrome"></a-entity>
<a-entity position="-1 2.15 0.3" text="text:A-Frame; font:#exoBoldItalic;style:italic;size:0.8;weight:bold;height:0;" material="shader:flat;color:white;" rotation="0 0 0" scale="1 1 1" visible="true"></a-entity>
<a-entity position="-1 2.15 0.3" text="text:A-Frame;font:#exoBoldItalic;style:italic;size:0.8;weight:bold;height:0;bevelEnabled:true;bevelSize:0.04;bevelThickness:0.04;curveSegments:1" material="shader:flat;color:white;transparent:true;opacity:0.4"></a-entity> -->
<!-- logo replacement when geometric text broke upon aframe 0.4.0 release -->
<!-- <a-plane position="3.5 1 -0.5" scale="5 1 0" src="assets/images/aframecity.png" material="opacity:0.6"></a-plane> -->
<!-- using new text component for appname and cityname -->
<a-entity
id="title"
position="3.5 1 -0.5"
geometry="primitive: plane; width: 4; height: 1.4"
material="color: black; opacity: 0.6"
text__appname="color: yellow; align: center; font: exo2bold; wrap-count: 12; z-offset: 0.01; baseline: bottom;
value: aframe.city"
text__cityname="color: white; align: center; font: exo2semibold; wrap-count: 24; z-offset: 0.01; baseline: top;
value: #NewCity"
></a-entity>
</a-entity>
<!-- Environment -->
<a-entity id="sky"
geometry="primitive: sphere; radius: 65;"
material="shader: skyGradient; colorTop: #353449; colorBottom: #BC483E; side: back"></a-entity>
<a-entity ground></a-entity>
<a-entity light="color: white; intensity: 0.5" position="-5 5 15"></a-entity>
<a-entity light="color: white; intensity: 0.5; type: ambient;"></a-entity>
</a-scene>
<!-- dialog box overlay for desktop users -->
<div id="dialog" class="img-rounded intro-overlay">
<!-- <p><a onclick="hide()" class="btn btn-danger pull-right">x</a></p> -->
<h4><strong>A-Frame City Builder</strong></h4>
<p>This app lets you create a virtual city in 8-bit "pixel" style using the HTC Vive or Oculus Rift VR headset and tracked hand controllers. You will also need a <a href="https://webvr.info/">WebVR compatible browser</a>.</p>
<p><a href="https://github.com/mikelovesrobots/mmmm">"Mini Mike's Metro Mini"</a> objects are CC License, <a href="https://github.com/kfarr/aframe-city-builder">codebase is MIT License</a>. <a href="https://github.com/kfarr/aframe-city-builder/issues/19">Anonymous usage data collected using Amplitude</a>.</p>
<h5>CONTROLS - Supports both Oculus Touch and Vive Controls</h5>
<p>Place objects with <code>trigger</code> and undo the last placement by squeezing a <code>grip</code> button. Switch objects by pressing <code>right</code> or <code>left</code> on touchpad or thumbstick. Press <code>up</code> or <code>down</code> to switch object groups.
<h5>LOAD and SAVE:</h5>
<p><div class="input-group">
<input id="fileInput" type="text" class="form-control" onfocus="this.select();" placeholder="Enter JSON URL" value="example-aframe-city.json">
<span class="input-group-btn">
<button onclick="loadFileButton()" class="btn btn-info" type="button">Load JSON URL</button>
</span>
</div></p>
<p><div class="input-group">
<input id="jsonInput" type="text" class="form-control" placeholder="Paste JSON String Here">
<span class="input-group-btn">
<button onclick="loadButton()" class="btn btn-info" type="button">Load JSON String</button>
</span>
</div></p>
<p><a onclick="downloadButton()" class="btn btn-info">Download City Layout as JSON ▼</a></p>
<p><a onclick="saveButton()" class="btn btn-info">Save City Layout to Firebase 💾</a></p>
<p><a onclick="hide()" class="btn btn-success pull-right">Close</a></p>
</div>
<a onclick="show()"><div class="menu-overlay btn btn-outline-secondary"></div></a>
<script type="text/javascript">
var enteredVR = false;
document.querySelector('a-scene').addEventListener('enter-vr', function () {
console.log("ENTERED VR");
console.log(enteredVR);
if (!enteredVR) {
document.getElementById('cameraWrapper').setAttribute("position", "0 0 0");
document.getElementById('cameraWrapper').setAttribute("rotation", "0 0 0");
enteredVR = true;
};
amplitude.getInstance().logEvent('Enter VR');
}); // works the first time, but then makes things wonky the 2nd time
document.querySelector('a-scene').addEventListener('exit-vr', function () {
console.log("EXIT VR");
// document.getElementById('cameraWrapper').setAttribute("position", "-1.06 1.31 1.82"); // position="-1.06 1.31 1.82"
// document.getElementById('cameraWrapper').setAttribute("rotation", "-12.834254610930437 -16.844959176846217 0");
amplitude.getInstance().logEvent('Exit VR');
}); // works the first time
</script>
<script type="text/javascript">
document.querySelector('a-scene').addEventListener('loaded', function () {
amplitude.getInstance().logEvent('Loaded A-Frame Scene');
})
</script>
<script type="text/javascript">
// Initialize Firebase
var config = {
apiKey: "AIzaSyBcPajwJo7PyqEjQ70GuvQyIXGOE8xW7Cs",
authDomain: "test-b0c62.firebaseapp.com",
databaseURL: "https://test-b0c62.firebaseio.com",
storageBucket: "test-b0c62.appspot.com",
messagingSenderId: "832504680709"
};
firebase.initializeApp(config);
// Get a reference to the database service
var database = firebase.database();
function writeCityData(cityName, cityJSON) {
if(((typeof cityName != "undefined") && (typeof cityName.valueOf() == "string")) && (cityName.length > 0)) {
firebase.database().ref('cities/' + cityName).set({
cityJSON: cityJSON
});
} else {
console.log("invalid city name: " + cityName);
}
};
function saveButton(overwrite = false) {
var cityNode = $("#city")[0];
var cityJSON = [];
// fetch each city object and add into json
$('#city').children().each(function () {
var thisWorldRotationX = this.object3D.rotation.x / (Math.PI / 180);
var thisWorldRotationY = this.object3D.rotation.y / (Math.PI / 180);
var thisWorldRotationZ = this.object3D.rotation.z / (Math.PI / 180);
var thisEulerRotationString = thisWorldRotationX + ' ' + thisWorldRotationY + ' ' + thisWorldRotationZ;
var childJSON = {
id: this.id,
file: this.getAttribute('file'),
position: this.object3D.position.x + ' ' + this.object3D.position.y + ' ' + this.object3D.position.z,
rotation: thisEulerRotationString,
scale: this.object3D.scale.x + ' ' + this.object3D.scale.y + ' ' + this.object3D.scale.z
};
cityJSON.push(childJSON);
});
var jsonData = JSON.stringify(cityJSON);
function slugify(text) {
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
randomCityName = randopeep.address.city();
// randomCityNameSlug = slugify(randomCityName);
cityNameCamel = randomCityName.replace(/\s+/g, '');
console.log(randomCityName);
console.log(cityNameCamel);
if (overwrite && location.hash.substring(1)) { // very lazy way to make save
cityNameCamel = location.hash.substring(1);
}
writeCityData(cityNameCamel, cityJSON);
window.location.hash = '#' + cityNameCamel;
document.getElementById("title").setAttribute("text__cityname", "value", "#" + cityNameCamel);
document.title = "aframe.city#" + cityNameCamel;
var ampEventProperties = {
'name': cityNameCamel
// 'size': 20 // how many objects in city? (first get rid of jquery above)
// 'hash': 'value' // hash of serialized json of city - just an idea to weed out duplicate cities with different names
};
// amplitude.getInstance().logEvent('EVENT_TYPE', eventProperties);
if (overwrite) {
amplitude.getInstance().logEvent('Save', ampEventProperties);
} else {
amplitude.getInstance().logEvent('Save As', ampEventProperties);
};
}
function hide() {
$("#dialog").removeClass('intro-overlay');
}
function loadTest() {
// test a user going through the menu options a bunch
for (g = 0; g < 5; g++) {
for (i = 0; i < 20; i++) {
setTimeout(function(){document.getElementById("menu").emit("onOptionNext")}, 500);
}
setTimeout(function(){document.getElementById("menu").emit("onOptgroupNext")}, 500);
}
}
function loadCityData(cityNameCamel) {
console.log("trying to load city:" + cityNameCamel);
// Erase exiting city (if any)
var cityEl = document.getElementById("city");
while (cityEl.firstChild) {
cityEl.removeChild(cityEl.firstChild);
}
firebase.database().ref('cities/' + cityNameCamel).once('value').then(function(snapshot) {
var cityJSON = snapshot.val().cityJSON;
console.log(cityJSON);
toDOM(cityJSON);
document.getElementById("title").setAttribute("text__cityname", "value", "#" + cityNameCamel)
document.title = "aframe.city#" + cityNameCamel;
amplitude.getInstance().logEvent('Loaded City', {'name': cityNameCamel});
});
}
// on load - load the city -- TODO - this should be on a city loader component on the scene entity instead
setTimeout(function(){
// IS THERE A HASH?
var cityName = location.hash.substring(1);
console.log("hash check: " + cityName);
if (cityName) {
loadCityData(cityName);
};
}, 1500);
function downloadButton() {
var cityNode = $("#city")[0];
var cityJSON = [];
// fetch each city object and add into json
$('#city').children().each(function () {
var thisWorldRotationX = this.object3D.rotation.x / (Math.PI / 180);
var thisWorldRotationY = this.object3D.rotation.y / (Math.PI / 180);
var thisWorldRotationZ = this.object3D.rotation.z / (Math.PI / 180);
var thisEulerRotationString = thisWorldRotationX + ' ' + thisWorldRotationY + ' ' + thisWorldRotationZ;
var childJSON = {
id: this.id,
file: this.getAttribute('file'),
position: this.object3D.position.x + ' ' + this.object3D.position.y + ' ' + this.object3D.position.z,
rotation: thisEulerRotationString,
scale: this.object3D.scale.x + ' ' + this.object3D.scale.y + ' ' + this.object3D.scale.z
};
cityJSON.push(childJSON);
});
var jsonData = JSON.stringify(cityJSON);
function download(text, name, type) {
var a = document.createElement("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
a.click();
}
download(jsonData, 'my-aframe-city.json', 'text/plain');
}
function appendObject(id, file, scale, position, rotation, scale) {
console.log(position);
$('<a-entity />', {
id: id,
class: 'city object children',
position: position, // doesn't seem to do anything
scale: scale,
rotation: rotation,
file: file,
"obj-model": "obj: url(assets/obj/" + file + ".obj); mtl: url(assets/obj/" + file + ".mtl)",
// src: '#' + file + '-obj',
// mtl: '#' + file + '-mtl',
appendTo : $('#city')
});
document.getElementById(id).setAttribute("position", position); // workaround - this does set position
}
function toDOM(jsonInput) {
// this assumes it is being run first -- it will start placing objects with id 0 and set objectcount to the number of loaded objects
for(var i = 0; i < jsonInput.length; i++) {
var obj = jsonInput[i];
console.log("Adding entity #" + obj.id);
appendObject(obj.id, obj.file, obj.scale, obj.position, obj.rotation, obj.scale)
}
objectCount = i;
console.log("objectCount:" + objectCount);
}
function loadFileButton() {
$.getJSON($("#fileInput")[0].value, function(json) {
toDOM(json);
});
}
function loadButton() {
console.log("load button clicked");
function isJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
jsonInput = $("#jsonInput")[0].value;
console.log(jsonInput);
if (isJsonString(jsonInput)) {
toDOM(JSON.parse(jsonInput));
} else {
console.log("oops not valid json");
}
}
function locationHashChanged() {
// check if valid hash
// if yes, then clear old city // load new city with that hash
var cityName = location.hash.substring(1);
console.log("hash changed to: " + cityName);
if (cityName) {
loadCityData(cityName);
};
}
window.onhashchange = locationHashChanged;
function show() {
$("#dialog").toggleClass('intro-overlay');
}
if (screen.width <= 699) {
$("#dialog").removeClass('intro-overlay');
}
</script>
<!--githubcorner-->
<a href="https://github.com/kfarr/aframe-city-builder" class="github-corner">
<svg width="80" height="80" viewBox="0 0 250 250" style="fill: #111; color: #EFEFEF; position: fixed; bottom: 0; border: 0; left: 0; transform: rotate(180deg); opacity: 0.8">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
</svg>
</a>
<style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}
</style>
</body>
</html>