forked from fractastical/metalambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
807 lines (612 loc) · 24.6 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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<!-- Babylon.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js"></script>
<script src="https://assets.babylonjs.com/generated/Assets.js"></script>
<script src="https://preview.babylonjs.com/ammo.js"></script>
<script src="https://preview.babylonjs.com/cannon.js"></script>
<script src="https://preview.babylonjs.com/Oimo.js"></script>
<script src="https://preview.babylonjs.com/earcut.min.js"></script>
<script src="https://preview.babylonjs.com/babylon.js"></script>
<script src="https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.min.js"></script>
<script src="https://preview.babylonjs.com/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js"></script>
<script src="https://preview.babylonjs.com/postProcessesLibrary/babylonjs.postProcess.min.js"></script>
<script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.js"></script>
<script src="https://preview.babylonjs.com/serializers/babylonjs.serializers.min.js"></script>
<script src="https://preview.babylonjs.com/gui/babylon.gui.min.js"></script>
<script src="https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js"></script>
<script src="https://unpkg.com/codeflask/build/codeflask.min.js"></script>
<style>
html, body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#renderCanvas {
width: 100%;
height: 100%;
touch-action: none;
}
.header {
padding: 20px;
height: 140px;
text-align: center;
background: #1abc9c;
color: white;
font-size: 30px;
}
#inputs {
width: 400px;
height: 800px;
border-radius: 3px;
top: 0%;
position: fixed;
box-shadow: 0 2px 2px 0 rgba(#000, .14), 0 1px 5px 0 rgba(#000, .12), 0 3px 1px -2px rgba(#000, .2);
}
#controlpanel {
position:absolute;
left: 233px;
top: 428px;
width: 229px;
height:143px;
}
#codeArea {
width: 400px;
height: 800px;
border-radius: 3px;
top: 0%;
position: fixed;
box-shadow: 0 2px 2px 0 rgba(#000, .14), 0 1px 5px 0 rgba(#000, .12), 0 3px 1px -2px rgba(#000, .2);
}
#codeArea2 {
width: 500px;
height: 1000px;
border-radius: 3px;
top: 0%;
position: fixed;
box-shadow: 0 2px 2px 0 rgba(#000, .14), 0 1px 5px 0 rgba(#000, .12), 0 3px 1px -2px rgba(#000, .2);
right: 0%;
}
.profile {
right: 30px;
position: fixed;
}
.leftbottom {
left: 5px;
bottom: 5px;
width: 444px;
position: fixed;
}
.rightbottom {
right: 0;
bottom: 0;
position: fixed;
}
.codeflask {
width: 400px
height: 83%
border-radius: 3px
}
&::before, .codeflask__lines
background: #FFF
.codeflask__textarea
</style>
</head>
<title>MetaLambda</title>
</head>
<body>
<div id="inputs">
<h2>Game of MetaLife 0.33</h2>
Address:<BR/>
<input id="address" type="text" size="45" ></input><BR/><BR/>
<table style="font-size:60%">
<tr>
<th>Name</th>
<th>xFreq</th>
<th>yFreq</th>
<th>zFreq</th>
<th>color</th>
<th>split</th>
<th>mutate</th>
</tr>
<tr>
<td>Lifeform 1</td>
<td><input id="xFreq" type="text" value="10" size="3"></input>
</td>
<td> <input id="yFreq" type="text" value="10" size="3"></input>
</td>
<td><input id="zFreq" type="text" value="10" size="3"></input>
</td>
<td> <input id="color" type="text" value="10" size="5"></input>
</input>
</td>
<td> <input id="splitFreq" type="text" value="10" size="4"></input>
</input>
</td>
<td> <input id="mutation" type="text" value="10" size="4"></input><BR/>
</input>
</td>
</tr>
<tr>
<td>Lifeform 2</td>
<td><input id="xFreq2" type="text" value="10" size="3"></input>
</td>
<td> <input id="yFreq2" type="text" value="10" size="3"></input>
</td>
<td><input id="zFreq2" type="text" value="10" size="3"></input>
</td>
<td> <input id="color2" type="text" value="10" size="5"></input>
</input>
</td>
<td> <input id="splitFreq2" type="text" value="10" size="4"></input>
</input>
</td>
<td> <input id="mutation2" type="text" value="10" size="4"></input><BR/>
</input>
</td>
</tr>
</table>
<div style="width:200px;padding-top:10px;padding-left:10px">
<!--This is an interactive 3d MetaLife simulator. Use "w" "a" "s" "d" and the mouse cursor to navigate.<BR/>-->
The first three parameters determine the frequency of movement in the x,y,z coordinate space. The last two determine the frequency that it reproduces and the strength of mutation each time it splits.<BR/>
All of the code in the right panel can be changed for more specialised effects.
<BR/><BR/><img src="./img/nav.png" width="180px"/>
</div>
</div>
<!--<div id="codeArea" class="codeflask">
if(ca.xFreq > 100)
current_x += 1;
if(ca.yFreq > 100)
current_y += 1;
if(ca.zFreq > 100)
current_z += 1;
if(numberofComputationalStepsCompleted % ca.splitFreq == 0)
{
var splitCA = mutate(ca);
}
</div>-->
<div class="leftbottom">
Joel Dietz <a href="https://connection.mit.edu/joel-dietz" target="_blank">MIT</a> | <a href="cryptoapollo.io" target="_blank">ART</a> | <a href="https://youtu.be/HhNnnKV-h_Q" target="_blank">Ted Talk</a> |
<a href="http://metametaverse.io" target="_blank">MMV</a><BR/>
<a href="https://joel-dietz.gitbook.io/metalife/" target="_blank"> Documentation @ Gitbook</a><BR/>
<!--<input id="test" type="button" value="run 1000 steps" onclick="runMetaStep(1000);"></input>-->
</div>
<div id="codeArea2" class="codeflask">
if (ca.xFreq > 100) {
if ((numberofComputationalStepsCompleted % 100) < (ca.xFreq % 100))
current_x += 1;
} else if (ca.xFreq <= 100)
if ((numberofComputationalStepsCompleted % 100) < (ca.xFreq))
current_x -= 1;
if (ca.yFreq > 100) {
if ((numberofComputationalStepsCompleted % 100) < (ca.yFreq % 100))
current_y += 1;
} else if (ca.yFreq <= 100)
if ((numberofComputationalStepsCompleted % 100) < (ca.yFreq))
current_y -= 1;
if (ca.zFreq > 100) {
if ((numberofComputationalStepsCompleted % 100) < (ca.zFreq % 100))
current_z += 1;
} else if (ca.zFreq <= 100)
if ((numberofComputationalStepsCompleted % 100) < (ca.zFreq))
current_z -= 1;
if (numberofComputationalStepsCompleted != 0 && numberofComputationalStepsCompleted % ca.splitFreq == 0) {
if (allActiveCAs.length < 12) {
var splitCA = mutate(ca, ca.mutation);
allActiveCAs.push(splitCA);
}
}
</div>
<!-- <div class="rightbottom">
<input id="xFreq2" type="text" value="10" size="5"></input>
<input id="yFreq2" type="text" value="10" size="5"></input>
<input id="zFreq2" type="text" value="10" size="5"></input>
<input id="color2" type="text" value="10" size="5"></input>
<input id="splitFreq2" type="text" value="10" size="5"></input>
<input id="mutation2" type="text" value="10" size="5"></input>
</div>-->
<div class="profile">
</div>
<div style="position: relative;">
<canvas id="layer1" width="300px" height="300px"
style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
<!--<canvas id="layer2" width="140" height="140"
style="position: absolute; left: 233px; top: 198px; z-index: 1;"></canvas>-->
<canvas id="layer2" width="229" height="229"
style="position: absolute; left: 233px; top: 198px; z-index: 1;"></canvas>
<canvas id="layer3" width="60" height="60"
style="position: absolute; left: 433px; top: 198px;"></canvas>
</div>
<div id="controlpanel">
<div id="stats" style="padding:5px">
</div>
<input type="button" onclick="metaLifeExport()" value="Save to blockchain" />
<input type="button" onclick="reset()" value="Restart" />
</div>
<script src="./index.js"></script>
<script src="./metalambda.js"></script>
<script>
function metaLifeExport() {
alert("Beginning export");
engine.stopRenderLoop();
BABYLON.GLTF2Export.GLTFAsync(scene, "metalife").then((gltf) => {
gltf.downloadFiles();
});
}
var canvas = document.getElementById("layer2");
var startRenderLoop = function(engine, canvas) {
engine.runRenderLoop(function() {
if (sceneToRender && sceneToRender.activeCamera) {
sceneToRender.render();
}
});
}
var engine = null;
var scene = null;
var playingField = null;
var skySphere = null;
var sceneToRender = null;
var raySeedStrength = 10;
var ship1xDir = .3;
var ship1yDir = 1;
var ship1zDir = .9;
var ray2SeedStrength = 10;
var ship2xDir = -1;
var ship2yDir = -.3;
var ship2zDir = -.8;
// var parse = require('codeflask');
// import CodeFlask from 'codeflask';
var createDefaultEngine = function() {
return new BABYLON.Engine(canvas, true, {
/* preserveDrawingBuffer: true,
stencil: true,
disableWebGL2Support: false */
});
};
var createScene = function() {
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
scene.clearColor = BABYLON.Color3.Black();
// This creates and positions a free camera (non-mesh)
// var camera = new BABYLON.ArcRotateCamera("camera1", Math.PI / 1, 6 * Math.PI / 12, 150, new BABYLON.Vector3(0, 1, 0), scene);
// var rot_state = {x:camera.alpha , y:camera.beta};
// // This targets the camera to scene origin
// camera.setTarget(BABYLON.Vector3.Zero());
var camera = new BABYLON.FlyCamera("FlyCamera", new BABYLON.Vector3(50, 50, -100), scene);
// camera.angularSensibilityX = 1;
// camera.angularSensibilityY = 1;
// This attaches the camera to the canvas
camera.attachControl(canvas, true);
// chose
function setupPlayingField() {
var defaultGridMaterial = new BABYLON.GridMaterial("default", scene);
defaultGridMaterial.majorUnitFrequency = 5;
defaultGridMaterial.gridRatio = 0.5;
var defaultGridMaterial2 = new BABYLON.GridMaterial("ca2", scene);
defaultGridMaterial2.majorUnitFrequency = 4;
defaultGridMaterial2.gridRatio = 0.4;
// defaultGridMaterial2.lineColor = BABYLON.Color3(0.72, 0, 0);
playingField = BABYLON.MeshBuilder.CreateBox("box", {
size: startingSize
}, scene);
playingField.material = defaultGridMaterial;
playingField.position.x = 50;
playingField.position.y = 50;
playingField.position.z = 50;
defaultGridMaterial.alpha = 0.2;
defaultGridMaterial.opacity = 0.6;
var skyMaterial = new BABYLON.GridMaterial("skyMaterial", scene);
skyMaterial.majorUnitFrequency = 6;
skyMaterial.minorUnitVisibility = 0.43;
skyMaterial.gridRatio = 0.5;
skyMaterial.mainColor = new BABYLON.Color3(0, 0.05, 0.2);
skyMaterial.lineColor = new BABYLON.Color3(0, 1.0, 1.0);
skyMaterial.backFaceCulling = false;
skySphere = BABYLON.Mesh.CreateSphere("skySphere", 300, 450, scene);
skySphere.material = skyMaterial;
}
function createEnergy() {
var cube = BABYLON.MeshBuilder.CreateBox("box", {
size: 1
}, scene);
cube.material = new BABYLON.StandardMaterial("matBallon", scene);
cube.material.emissiveColor = new BABYLON.Color3(1, 1, 1);
cube.material.alpha = 0.33;
cube.position.y = Math.floor(Math.random() * startingSize) + 1;
cube.position.x = Math.floor(Math.random() * startingSize) + 1;
cube.position.z = Math.floor(Math.random() * startingSize) + 1;
cube.energy = 10;
var cubeIndex = cube.position.y + cube.position.x + cube.position.z;
cubeList.push(cube);
sortedCubeList[cubeIndex] = cube;
}
var ca1 = BABYLON.Mesh.CreateSphere("balloon1", 10, 2.0, scene);
ca1.material = new BABYLON.StandardMaterial("matBallon", scene);
ca1.material.emissiveColor = new BABYLON.Color3.FromHexString("#" + colora + colorb + colorc);
ca1.position = new BABYLON.Vector3((Math.random() * startingSize), (Math.random() * startingSize), (Math.random() * startingSize));
ca1.energy = startingEnergyEnergy;
ca1.seed = (Math.random() * 100);
ca1.color = "#" + colora + colorb + colorc;
ca1.xFreq = xFreq;
ca1.yFreq = yFreq;
ca1.zFreq = zFreq;
ca1.splitFreq = splitFreq;
ca1.mutation = mutation;
allActiveCAs.push(ca1);
var ca2 = BABYLON.Mesh.CreateSphere("balloon1", 10, 2.0, scene);
ca2.material = new BABYLON.StandardMaterial("matBallon", scene);
ca2.material.emissiveColor = new BABYLON.Color3.FromHexString("#" + colora2 + colorb2 + colorc2);
ca2.position = new BABYLON.Vector3((Math.random() * startingSize), (Math.random() * startingSize), (Math.random() * startingSize));
ca2.energy = startingEnergyEnergy;
ca2.seed = (Math.random() * 100);
ca2.color = "#" + colora2 + colorb2 + colorc2;
ca2.xFreq = xFreq2;
ca2.yFreq = yFreq2;
ca2.zFreq = zFreq2;
ca2.splitFreq = splitFreq2;
ca2.mutation = mutation2;
/* console.log(ca2.color); */
allActiveCAs.push(ca2);
/*
for (let i=1;i < 3;i++)
{
var newCA = BABYLON.Mesh.CreateSphere("balloon1", 10, 2.0, scene);
newCA.material = new BABYLON.StandardMaterial("matBallon", scene);
newCA.material.emissiveColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
newCA.position = new BABYLON.Vector3((Math.random()*startingSize), (Math.random()*startingSize), (Math.random()*startingSize));
newCA.energy = startingEnergyEnergy;
newCA.seed = (Math.random()*100);
newCA.xFreq = (Math.random()*200);
newCA.yFreq = (Math.random()*200);
newCA.zFreq = (Math.random()*200);
allActiveCAs.push(newCA);
}
*/
function buyCA() {
var newCA = BABYLON.Mesh.CreateSphere("balloon1", 10, 2.0, scene);
newCA.material = new BABYLON.StandardMaterial("matBallon", scene);
newCA.material.emissiveColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());
newCA.position = new BABYLON.Vector3((Math.random() * startingSize), (Math.random() * startingSize), (Math.random() * startingSize));
newCA.energy = startingEnergyEnergy;
newCA.seed = (Math.random() * startingSize);
allActiveCAs.push(newCA);
}
setupPlayingField();
for (let i = 0; i < startingNumberOfCubes; i++)
createEnergy();
// createCAs();
// when button is pressed, run one computational step
// GUI
var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
var compstepbutton = BABYLON.GUI.Button.CreateSimpleButton("csb1", numberOfComputationalStepsPerGame + " remaining");
compstepbutton.width = "150px"
compstepbutton.height = "40px";
compstepbutton.color = "black";
compstepbutton.top = -320;
compstepbutton.left = -170;
compstepbutton.cornerRadius = 20;
compstepbutton.background = "white";
compstepbutton.onPointerUpObservable.add(function() {
BABYLON.GLTF2Export.GLTFAsync(scene, "fileName").then((gltf) => {
gltf.downloadFiles();
});
});
advancedTexture.addControl(compstepbutton);
var ship1;
var ship2;
var modei = 0;
var modes = ["Default Mode", "Combat Mode"]
var activeMode = "";
var modeswitchbutton = BABYLON.GUI.Button.CreateSimpleButton("msb1", "Default mode");
modeswitchbutton.width = "150px"
modeswitchbutton.height = "40px";
modeswitchbutton.color = "black";
modeswitchbutton.top = -320;
modeswitchbutton.left = 170;
modeswitchbutton.cornerRadius = 20;
modeswitchbutton.background = "white";
modeswitchbutton.onPointerUpObservable.add(function() {
modei++;
if (modei >= modes.length)
modei = 0;
activeMode = modes[modei];
modeswitchbutton.textBlock.text = activeMode;
if (modei == 1) {
BABYLON.SceneLoader.ImportMesh("", "/", "UFO.glb", scene, function(newMeshes, particleSystems, skeletons) {
ship1 = newMeshes[0];
ship1.rotation.y = Math.PI / 2;
ship1.position = new BABYLON.Vector3(1, 1, 1);
// scene.beginAnimation(skeletons[0], 0, 100, true, 1.0);
// scene.createDefaultCamera(1,1,1);
});
BABYLON.SceneLoader.ImportMesh("", "/", "igspaceship2.glb", scene, function(newMeshes, particleSystems, skeletons) {
ship2 = newMeshes[0];
ship2.rotation.y = Math.PI / 2;
ship2.position = new BABYLON.Vector3(startingSize, startingSize, startingSize);
// scene.beginAnimation(skeletons[0], 0, 100, true, 1.0);
// scene.createDefaultCamera(1,1,1);
});
//
// BABYLON.SceneLoader.Append("", "Intergalactic_Spaceships_Version_2.glb", scene, function (scene) {
// // Create a default arc rotate camera and light.
// scene.createDefaultCameraOrLight(true, true, true);
//
// // The default camera looks at the back of the asset.
// // Rotate the camera by 180 degrees to the front of the asset.
// scene.activeCamera.alpha += Math.PI;
// });
}
});
advancedTexture.addControl(modeswitchbutton);
var buyCAButton = BABYLON.GUI.Button.CreateSimpleButton("but1", "Create MetaLife");
buyCAButton.width = "150px"
buyCAButton.height = "40px";
buyCAButton.color = "white";
buyCAButton.top = -200;
buyCAButton.left = 1;
buyCAButton.cornerRadius = 20;
buyCAButton.background = "green";
buyCAButton.onPointerUpObservable.add(function() {
if (team1points > 9) {
buyCA();
team1points -= 5;
ca1lbutton.textBlock.text = team1points + " points";
}
});
advancedTexture.addControl(buyCAButton);
var team1points = 10;
var team2points = 0;
var ca1lbutton = BABYLON.GUI.Button.CreateSimpleButton("t1p", team1points + " energy");
ca1lbutton.width = "150px"
ca1lbutton.height = "40px";
ca1lbutton.color = "white";
ca1lbutton.top = -240;
ca1lbutton.left = -170;
ca1lbutton.cornerRadius = 20;
ca1lbutton.background = "blue";
ca1lbutton.onPointerUpObservable.add(function() {
buyCA();
});
advancedTexture.addControl(ca1lbutton);
var ca2lbutton = BABYLON.GUI.Button.CreateSimpleButton("t1p", team1points + " energy");
/* var ca2lbutton = BABYLON.GUI.Button.CreateSimpleButton("t2p", team2points + " points");
ca2lbutton.width = "150px"
ca2lbutton.height = "40px";
ca2lbutton.color = "white";
ca2lbutton.top = -240;
ca2lbutton.left = 170;
ca2lbutton.cornerRadius = 20;
ca2lbutton.background = "red";
advancedTexture.addControl(ca2lbutton);
*/
function vecToLocal(vector, mesh) {
var m = mesh.getWorldMatrix();
var v = BABYLON.Vector3.TransformCoordinates(vector, m);
return v;
}
var raySeedStrength = 10;
var ship1xDir = .3;
var ship1yDir = 1;
var ship1zDir = .9;
var ray2SeedStrength = 10;
var ship2xDir = -1;
var ship2yDir = -.3;
var ship2zDir = -.8;
function castRay() {
var origin = ship1.position;
var microseed = Math.random() * raySeedStrength;
var forward = new BABYLON.Vector3(-7 + microseed, 4 + microseed, 2 + microseed);
forward = vecToLocal(forward, ship1);
var direction = forward.subtract(origin);
direction = BABYLON.Vector3.Normalize(direction);
var length = 33;
var ray = new BABYLON.Ray(origin, direction, length);
var rayHelper = new BABYLON.RayHelper(ray);
var localMeshDirection = new BABYLON.Vector3(0, 0, 1);
var localMeshOrigin = new BABYLON.Vector3(0, 0, .4);
var length = 33;
// rayHelper.attachToMesh(ship1, origin, direction, length);
rayHelper.show(scene);
var hits = scene.multiPickWithRay(ray);
if (hits) {
console.log("hits:" + hits.length);
for (var i = 0; i < hits.length; i++) {
if (hits[i] != playingField && hits[i] != skySphere); {
hits[i].pickedMesh.dispose();
/* hits[i].pickedMesh.scaling.y -= 0.1;
hits[i].pickedMesh.alpha = .05; */
team1points += 1;
ca1lbutton.textBlock.text = team1points + " points";
}
}
}
}
function castRay2() {
var origin = ship2.position;
var microseed = Math.random() * ray2SeedStrength;
var forward = new BABYLON.Vector3(7 - microseed, -4 - microseed, -2 - microseed);
forward = vecToLocal(forward, ship2);
var direction = forward.subtract(origin);
direction = BABYLON.Vector3.Normalize(direction);
var length = 33;
var ray = new BABYLON.Ray(origin, direction, length);
var rayHelper = new BABYLON.RayHelper(ray);
var localMeshDirection = new BABYLON.Vector3(0, 0, 1);
var localMeshOrigin = new BABYLON.Vector3(0, 0, .4);
var length = 33;
// rayHelper.attachToMesh(ship2, origin, direction, length);
rayHelper.show(scene);
var hits = scene.multiPickWithRay(ray);
if (hits) {
console.log("hits:" + hits.length);
for (var i = 0; i < hits.length; i++) {
if (hits[i] != playingField); {
hits[i].pickedMesh.dispose();
team2points += 1;
ca2lbutton.textBlock.text = team2points + " points";
}
}
}
}
var metaEnergyCount = 0;
setTimeout(() => {
console.log("World!");
}, 50000);
scene.beforeRender = () => {
metaEnergyCount++;
if (numberofComputationalStepsCompleted <= 1000)
runOneStep();
};
// scene.registerBeforeRender(function () {
// castRay();
// });
engine.runRenderLoop(function() {
camera.alpha += 0.003;
});
return scene;
};
window.initFunction = async function() {
var asyncEngineCreation = async function() {
try {
return createDefaultEngine();
} catch (e) {
console.log("the available createEngine function failed. Creating the default engine instead");
return createDefaultEngine();
}
}
window.engine = await asyncEngineCreation();
if (!engine) throw 'engine should not be null.';
startRenderLoop(engine, canvas);
window.scene = createScene();
};
initFunction().then(() => {
sceneToRender = scene
});
// Resize
window.addEventListener("resize", function() {
engine.resize();
});
/* const code1 = new CodeFlask('#codeArea', {
language: 'js',
lineNumbers: true
}) */
const code2 = new CodeFlask('#codeArea2', {
language: 'js',
lineNumbers: true
})
function reset() {
createScene();
/* window.scene = createScene(); */
}
</script>
</body>
</html>