matrix-engine-wgpu 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,95 +37,1046 @@ var examples = {
37
37
  (0, _jamb.loadJamb)();
38
38
  });
39
39
 
40
- },{"./examples/games/jamb/jamb.js":2,"./examples/load-obj-file.js":3,"./examples/unlit-textures.js":4,"./src/engine/utils.js":13}],2:[function(require,module,exports){
40
+ },{"./examples/games/jamb/jamb.js":2,"./examples/load-obj-file.js":3,"./examples/unlit-textures.js":4,"./src/engine/utils.js":14}],2:[function(require,module,exports){
41
41
  "use strict";
42
42
 
43
43
  Object.defineProperty(exports, "__esModule", {
44
44
  value: true
45
45
  });
46
- exports.loadJamb = void 0;
46
+ exports.myDom = exports.dices = void 0;
47
47
  var _world = _interopRequireDefault(require("../../../src/world.js"));
48
48
  var _loaderObj = require("../../../src/engine/loader-obj.js");
49
49
  var _utils = require("../../../src/engine/utils.js");
50
50
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51
- // import MatrixEngineWGPU from "./src/world.js";
52
- // import {downloadMeshes} from './src/engine/loader-obj.js';
51
+ let dices = exports.dices = {
52
+ C: 0,
53
+ STATUS: 'FREE_TO_PLAY',
54
+ STATUS_H2: 'WAIT',
55
+ STATUS_H3: 'WAIT',
56
+ R: {},
57
+ SAVED_DICES: {},
58
+ pickDice: dice => {
59
+ (void 0).SAVED_DICES[dice] = (void 0).R[dice];
60
+ },
61
+ checkAll: function () {
62
+ this.C++;
63
+ if (typeof this.R.CubePhysics1 != 'undefined' && typeof this.R.CubePhysics2 != 'undefined' && typeof this.R.CubePhysics3 != 'undefined' && typeof this.R.CubePhysics4 != 'undefined' && typeof this.R.CubePhysics5 != 'undefined' && typeof this.R.CubePhysics6 != 'undefined' && this.C > 1200) {
64
+ dispatchEvent(new CustomEvent('all-done', {
65
+ detail: {}
66
+ }));
67
+ this.C = 0;
68
+ }
69
+ },
70
+ validatePass: function () {
71
+ if (dices.STATUS == "IN_PLAY" || dices.STATUS == "FREE_TO_PLAY") {
72
+ // console.log('%cBLOCK', LOG_FUNNY)
73
+ if (dices.STATUS == "IN_PLAY") _utils.mb.error(`STATUS IS ${dices.STATUS}, please wait for results...`);
74
+ if (dices.STATUS == "FREE_TO_PLAY") _utils.mb.error(`STATUS IS ${dices.STATUS}, you need to roll dice first.`);
75
+ app.matrixSounds.play('block');
76
+ return false;
77
+ } else {
78
+ return true;
79
+ }
80
+ }
81
+ };
82
+ let myDom = exports.myDom = {
83
+ state: {
84
+ rowDown: []
85
+ },
86
+ memoNumberRow: [],
87
+ hideSettings: function () {
88
+ (0, _utils.byId)('blocker').style.display = 'none';
89
+ (0, _utils.byId)('messageBox').style.display = 'none';
90
+ },
91
+ createMenu: function () {
92
+ var root = document.createElement('div');
93
+ root.id = 'hud';
94
+ root.style.position = 'absolute';
95
+ root.style.right = '10%';
96
+ root.style.top = '10%';
97
+ var help = document.createElement('div');
98
+ help.id = 'HELP';
99
+ help.classList.add('btn2');
100
+ help.innerHTML = `<span data-label="help"></span>`;
101
+ var settings = document.createElement('div');
102
+ settings.id = 'settings';
103
+ settings.classList.add('btn2');
104
+ settings.innerHTML = `<span data-label="settings"></span>`;
105
+ settings.addEventListener('click', () => {
106
+ (0, _utils.byId)('messageBox').innerHTML = `
107
+ <div>
108
+ <span data-label="settings"></span>
109
+ <div>
110
+
111
+ <div>
112
+ <span data-label="sounds"></span>
113
+
114
+ <label class="switch">
115
+ <input type="checkbox">
116
+ <span class="sliderSwitch round"></span>
117
+ </label>
118
+
119
+ </div>
120
+
121
+ <div>
122
+ <button class="btn2" onclick="app.myDom.hideSettings()">
123
+ <span data-label="hide"></span>
124
+ </button>
125
+ </div>
126
+
127
+ </div>
128
+ </div>
129
+ `;
130
+ (0, _utils.byId)('blocker').style.display = 'flex';
131
+ (0, _utils.byId)('messageBox').style.display = 'flex';
132
+ dispatchEvent(new CustomEvent('updateLang', {}));
133
+ });
134
+ var roll = document.createElement('div');
135
+ roll.id = 'hud-roll';
136
+ roll.classList.add('btn');
137
+ roll.innerHTML = `<span data-label="roll"></span>`;
138
+ roll.addEventListener('click', () => {
139
+ app.ROLL();
140
+ });
141
+ var separator = document.createElement('div');
142
+ separator.innerHTML = `=======`;
143
+ root.append(settings);
144
+ root.append(help);
145
+ root.append(separator);
146
+ root.append(roll);
147
+ document.body.appendChild(root);
148
+
149
+ // global access
150
+ // app.label.update()
151
+ dispatchEvent(new CustomEvent('updateLang', {}));
152
+ },
153
+ createBlocker: function () {
154
+ var root = document.createElement('div');
155
+ root.id = 'blocker';
156
+ var messageBox = document.createElement('div');
157
+ messageBox.id = 'messageBox';
158
+
159
+ // console.log('TEST', app.label.get)
160
+ messageBox.innerHTML = `
161
+ <span data-label="welcomeMsg"></span>
162
+ <a href="https://github.com/zlatnaspirala/matrix-engine-wgpu">zlatnaspirala/matrix-engine-wgpu</a><br><br>
163
+ <button class="btn" ><span style="font-size:30px;margin:15px;padding:10px" data-label="startGame"></span></button> <br>
164
+ <div><span data-label="changeLang"></span></div>
165
+ <button class="btn" onclick="
166
+ app.label.loadMultilang('en').then(r => {
167
+ app.label.get = r;
168
+ app.label.update()
169
+ });
170
+ " ><span data-label="english"></span></button>
171
+ <button class="btn" onclick="app.label.loadMultilang('sr').then(r => {
172
+ app.label.get = r
173
+ app.label.update() })" ><span data-label="serbian"></span></button>
174
+ `;
175
+ let initialMsgBoxEvent = function () {
176
+ console.log('click on msgbox');
177
+ (0, _utils.byId)('messageBox').innerHTML = ``;
178
+ (0, _utils.byId)('blocker').style.display = 'none';
179
+ myDom.createMenu();
180
+ messageBox.removeEventListener('click', initialMsgBoxEvent);
181
+ };
182
+ messageBox.addEventListener('click', initialMsgBoxEvent);
183
+ root.append(messageBox);
184
+ document.body.appendChild(root);
185
+ app.label.update();
186
+ },
187
+ createJamb: function () {
188
+ var root = document.createElement('div');
189
+ root.id = 'jambTable';
190
+ root.style.position = 'absolute';
191
+ root.style.display = 'flex';
192
+ root.style.top = '10px';
193
+ root.style.left = '10px';
194
+ root.style.width = '200px';
195
+ root.style.background = '#7d7d7d8c';
196
+ var rowHeader = document.createElement('div');
197
+ rowHeader.id = 'rowHeader';
198
+ rowHeader.style.top = '10px';
199
+ rowHeader.style.left = '10px';
200
+ rowHeader.style.width = '200px';
201
+ rowHeader.innerHTML = '<span data-label="cornerText"></span><span id="user-points">0</span>';
202
+ root.appendChild(rowHeader);
203
+ rowHeader.classList.add('myTheme1');
204
+ var rowDown = document.createElement('div');
205
+ rowDown.id = 'rowDown';
206
+ rowDown.style.top = '10px';
207
+ rowDown.style.left = '10px';
208
+ rowDown.style.width = '200px';
209
+ rowDown.innerHTML = '↓';
210
+ rowDown.classList.add('myTheme1');
211
+ root.appendChild(rowDown);
212
+ var rowFree = document.createElement('div');
213
+ rowFree.id = 'rowFree';
214
+ rowFree.style.top = '10px';
215
+ rowFree.style.left = '10px';
216
+ rowFree.style.width = '200px';
217
+ rowFree.innerHTML = '↕';
218
+ rowFree.classList.add('myTheme1');
219
+ root.appendChild(rowFree);
220
+ var rowUp = document.createElement('div');
221
+ rowUp.id = 'rowUp';
222
+ rowUp.style.top = '10px';
223
+ rowUp.style.left = '10px';
224
+ rowUp.style.width = '200px';
225
+ rowUp.innerHTML = '↑';
226
+ rowUp.classList.add('myTheme1');
227
+ root.appendChild(rowUp);
228
+ var rowHand = document.createElement('div');
229
+ rowHand.id = 'rowHand';
230
+ rowHand.style.top = '10px';
231
+ rowHand.style.left = '10px';
232
+ rowHand.style.width = '200px';
233
+ rowHand.innerHTML = '<span data-label="hand"></span>';
234
+ rowHand.classList.add('myTheme1');
235
+ root.appendChild(rowHand);
236
+
237
+ // INJECT TABLE HEADER ROW
238
+ this.createLeftHeaderRow(rowHeader);
239
+ this.createRowDown(rowDown);
240
+ this.createRowFree(rowFree);
241
+ this.createRow(rowUp);
242
+ this.createRow(rowHand);
243
+ document.body.appendChild(root);
244
+ // console.log('JambTable added.')
245
+ },
246
+ createLeftHeaderRow: function (myRoot) {
247
+ for (var x = 1; x < 7; x++) {
248
+ var rowNumber = document.createElement('div');
249
+ rowNumber.id = 'rowNumber' + x;
250
+ rowNumber.style.top = '10px';
251
+ rowNumber.style.left = '10px';
252
+ rowNumber.style.width = 'auto';
253
+ rowNumber.style.background = '#7d7d7d8c';
254
+ rowNumber.innerHTML = `<span>${x}</span>`;
255
+ myRoot.appendChild(rowNumber);
256
+ }
257
+ var rowNumberSum = document.createElement('div');
258
+ rowNumberSum.id = 'H_rowNumberSum';
259
+ rowNumberSum.style.width = 'auto';
260
+ rowNumberSum.style.background = '#7d7d7d8c';
261
+ rowNumberSum.innerHTML = `Σ`;
262
+ myRoot.appendChild(rowNumberSum);
263
+ var rowMax = document.createElement('div');
264
+ rowMax.id = 'H_rowMax';
265
+ rowMax.style.width = 'auto';
266
+ rowMax.style.background = '#7d7d7d8c';
267
+ rowMax.innerHTML = `<span data-label="MAX"></span>`;
268
+ myRoot.appendChild(rowMax);
269
+ var rowMin = document.createElement('div');
270
+ rowMin.id = 'H_rowMax';
271
+ rowMin.style.width = 'auto';
272
+ rowMin.style.background = '#7d7d7d8c';
273
+ rowMin.innerHTML = `<span data-label="MIN"></span>`;
274
+ myRoot.appendChild(rowMin);
275
+ var rowMaxMinSum = document.createElement('div');
276
+ rowMaxMinSum.id = 'H_rowMaxMinSum';
277
+ rowMaxMinSum.style.width = 'auto';
278
+ rowMaxMinSum.style.background = '#7d7d7d8c';
279
+ rowMaxMinSum.innerHTML = `Σ`;
280
+ myRoot.appendChild(rowMaxMinSum);
281
+ var largeStraight = document.createElement('div');
282
+ largeStraight.id = 'H_largeStraight';
283
+ largeStraight.style.width = 'auto';
284
+ largeStraight.style.background = '#7d7d7d8c';
285
+ largeStraight.innerHTML = `<span data-label="straight"></span>`;
286
+ myRoot.appendChild(largeStraight);
287
+ var threeOfAKind = document.createElement('div');
288
+ threeOfAKind.id = 'H_threeOfAKind';
289
+ threeOfAKind.style.width = 'auto';
290
+ threeOfAKind.style.background = '#7d7d7d8c';
291
+ threeOfAKind.innerHTML = `<span data-label="threeOf"></span>`;
292
+ myRoot.appendChild(threeOfAKind);
293
+ var fullHouse = document.createElement('div');
294
+ fullHouse.id = 'H_fullHouse';
295
+ fullHouse.style.width = 'auto';
296
+ fullHouse.style.background = '#7d7d7d8c';
297
+ fullHouse.innerHTML = `<span data-label="fullhouse"></span>`;
298
+ myRoot.appendChild(fullHouse);
299
+ var poker = document.createElement('div');
300
+ poker.id = 'H_poker';
301
+ poker.style.width = 'auto';
302
+ poker.style.background = '#7d7d7d8c';
303
+ poker.innerHTML = `<span data-label="poker"></span>`;
304
+ myRoot.appendChild(poker);
305
+ var jamb = document.createElement('div');
306
+ jamb.id = 'H_jamb';
307
+ jamb.style.width = 'auto';
308
+ jamb.style.background = '#7d7d7d8c';
309
+ jamb.innerHTML = `<span data-label="jamb"></span>`;
310
+ myRoot.appendChild(jamb);
311
+ var rowSum = document.createElement('div');
312
+ rowSum.id = 'H_rowSum';
313
+ rowSum.style.width = 'auto';
314
+ rowSum.style.background = '#7d7d7d8c';
315
+ rowSum.innerHTML = `Σ`;
316
+ myRoot.appendChild(rowSum);
317
+ var rowSumFINAL = document.createElement('div');
318
+ rowSumFINAL.id = 'H_rowSumFINAL';
319
+ rowSumFINAL.style.width = 'auto';
320
+ rowSumFINAL.style.background = '#7d7d7d8c';
321
+ rowSumFINAL.innerHTML = `<spam data-label="final"></span>`;
322
+ myRoot.appendChild(rowSumFINAL);
323
+ },
324
+ createRow: function (myRoot) {
325
+ for (var x = 1; x < 7; x++) {
326
+ var rowNumber = document.createElement('div');
327
+ rowNumber.id = 'rowNumber' + x;
328
+ rowNumber.style.top = '10px';
329
+ rowNumber.style.left = '10px';
330
+ rowNumber.style.width = 'auto';
331
+ rowNumber.style.background = '#7d7d7d8c';
332
+ rowNumber.innerHTML = `-`;
333
+ rowNumber.addEventListener('click', () => {
334
+ console.log('LOG THIS ', this);
335
+ // works
336
+ // rowDown
337
+ if (this.state.rowDown.length == 0) {
338
+ console.log('it is no play yet in this row ', this);
339
+ }
340
+ });
341
+ myRoot.appendChild(rowNumber);
342
+ }
343
+ var rowNumberSum = document.createElement('div');
344
+ rowNumberSum.id = 'rowNumberSum';
345
+ rowNumberSum.style.width = 'auto';
346
+ rowNumberSum.style.background = '#7d7d7d8c';
347
+ rowNumberSum.innerHTML = `-`;
348
+ myRoot.appendChild(rowNumberSum);
349
+ var rowMax = document.createElement('div');
350
+ rowMax.id = 'rowMax';
351
+ rowMax.style.width = 'auto';
352
+ rowMax.style.background = '#7d7d7d8c';
353
+ rowMax.innerHTML = `-`;
354
+ myRoot.appendChild(rowMax);
355
+ var rowMin = document.createElement('div');
356
+ rowMin.id = 'rowMax';
357
+ rowMin.style.width = 'auto';
358
+ rowMin.style.background = '#7d7d7d8c';
359
+ rowMin.innerHTML = `-`;
360
+ myRoot.appendChild(rowMin);
361
+ var rowMaxMinSum = document.createElement('div');
362
+ rowMaxMinSum.id = 'rowMaxMinSum';
363
+ rowMaxMinSum.style.width = 'auto';
364
+ rowMaxMinSum.style.background = '#7d7d7d8c';
365
+ rowMaxMinSum.innerHTML = `-`;
366
+ myRoot.appendChild(rowMaxMinSum);
367
+ var largeStraight = document.createElement('div');
368
+ largeStraight.id = 'largeStraight';
369
+ largeStraight.style.width = 'auto';
370
+ largeStraight.style.background = '#7d7d7d8c';
371
+ largeStraight.innerHTML = `-`;
372
+ myRoot.appendChild(largeStraight);
373
+ var threeOfAKind = document.createElement('div');
374
+ threeOfAKind.id = 'down_threeOfAKind';
375
+ threeOfAKind.style.width = 'auto';
376
+ threeOfAKind.style.background = '#7d7d7d8c';
377
+ threeOfAKind.innerHTML = `-`;
378
+ myRoot.appendChild(threeOfAKind);
379
+ var fullHouse = document.createElement('div');
380
+ fullHouse.id = 'fullHouse';
381
+ fullHouse.style.width = 'auto';
382
+ fullHouse.style.background = '#7d7d7d8c';
383
+ fullHouse.innerHTML = `-`;
384
+ myRoot.appendChild(fullHouse);
385
+ var poker = document.createElement('div');
386
+ poker.id = 'poker';
387
+ poker.style.width = 'auto';
388
+ poker.style.background = '#7d7d7d8c';
389
+ poker.innerHTML = `-`;
390
+ myRoot.appendChild(poker);
391
+ var jamb = document.createElement('div');
392
+ jamb.id = 'jamb';
393
+ jamb.style.width = 'auto';
394
+ jamb.style.background = '#7d7d7d8c';
395
+ jamb.innerHTML = `-`;
396
+ myRoot.appendChild(jamb);
397
+ var rowSum = document.createElement('div');
398
+ rowSum.id = 'rowSum';
399
+ rowSum.style.width = 'auto';
400
+ rowSum.style.background = '#7d7d7d8c';
401
+ rowSum.innerHTML = `-`;
402
+ myRoot.appendChild(rowSum);
403
+ },
404
+ createRowFree: function (myRoot) {
405
+ for (var x = 1; x < 7; x++) {
406
+ var rowNumber = document.createElement('div');
407
+ rowNumber.id = 'free-rowNumber' + x;
408
+ rowNumber.style.top = '10px';
409
+ rowNumber.style.left = '10px';
410
+ rowNumber.style.width = 'auto';
411
+ rowNumber.style.background = '#7d7d7d8c';
412
+ rowNumber.innerHTML = `-`;
413
+ rowNumber.addEventListener('click', e => {
414
+ if (dices.validatePass() == false) return;
415
+ var getName = e.target.id;
416
+ getName = getName.replace('free-rowNumber', '');
417
+ var count23456 = 0;
418
+ for (let key in dices.R) {
419
+ if (parseInt(dices.R[key]) == parseInt(getName)) {
420
+ count23456++;
421
+ }
422
+ }
423
+ this.state.rowDown.push(count23456 * parseInt(getName));
424
+ e.target.innerHTML = count23456 * parseInt(getName);
425
+ if (parseInt(getName) == 6) {
426
+ myDom.calcFreeNumbers();
427
+ }
428
+ dices.STATUS = "FREE_TO_PLAY";
429
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
430
+ });
431
+ myRoot.appendChild(rowNumber);
432
+ }
433
+ var rowNumberSum = document.createElement('div');
434
+ rowNumberSum.id = 'free-rowNumberSum';
435
+ rowNumberSum.style.width = 'auto';
436
+ rowNumberSum.style.background = '#7d7d7d8c';
437
+ rowNumberSum.innerHTML = `-`;
438
+ myRoot.appendChild(rowNumberSum);
439
+ var rowMax = document.createElement('div');
440
+ rowMax.id = 'free-rowMax';
441
+ rowMax.style.width = 'auto';
442
+ rowMax.style.background = '#7d7d7d8c';
443
+ rowMax.innerHTML = `-`;
444
+ rowMax.addEventListener("click", this.calcFreeRowMax);
445
+ myRoot.appendChild(rowMax);
446
+ var rowMin = document.createElement('div');
447
+ rowMin.id = 'free-rowMin';
448
+ rowMin.style.width = 'auto';
449
+ rowMin.style.background = '#7d7d7d8c';
450
+ rowMin.innerHTML = `-`;
451
+ rowMin.addEventListener('click', this.calcFreeRowMin);
452
+ myRoot.appendChild(rowMin);
453
+ var rowMaxMinSum = document.createElement('div');
454
+ rowMaxMinSum.id = 'free-rowMaxMinSum';
455
+ rowMaxMinSum.style.width = 'auto';
456
+ rowMaxMinSum.style.background = '#7d7d7d8c';
457
+ rowMaxMinSum.innerHTML = `-`;
458
+ myRoot.appendChild(rowMaxMinSum);
459
+ var largeStraight = document.createElement('div');
460
+ largeStraight.id = 'free-largeStraight';
461
+ largeStraight.style.width = 'auto';
462
+ largeStraight.style.background = '#7d7d7d8c';
463
+ largeStraight.innerHTML = `-`;
464
+ largeStraight.addEventListener('click', this.attachFreeKenta);
465
+ myRoot.appendChild(largeStraight);
466
+ var threeOfAKind = document.createElement('div');
467
+ threeOfAKind.id = 'free-threeOfAKind';
468
+ threeOfAKind.style.width = 'auto';
469
+ threeOfAKind.style.background = '#7d7d7d8c';
470
+ threeOfAKind.innerHTML = `-`;
471
+ threeOfAKind.addEventListener('click', this.attachFreeTrilling);
472
+ myRoot.appendChild(threeOfAKind);
473
+ var fullHouse = document.createElement('div');
474
+ fullHouse.id = 'free-fullHouse';
475
+ fullHouse.style.width = 'auto';
476
+ fullHouse.style.background = '#7d7d7d8c';
477
+ fullHouse.innerHTML = `-`;
478
+ fullHouse.addEventListener('click', this.attachFreeFullHouse);
479
+ myRoot.appendChild(fullHouse);
480
+ var poker = document.createElement('div');
481
+ poker.id = 'free-poker';
482
+ poker.style.width = 'auto';
483
+ poker.style.background = '#7d7d7d8c';
484
+ poker.innerHTML = `-`;
485
+ poker.addEventListener('click', this.attachFreePoker);
486
+ myRoot.appendChild(poker);
487
+ var jamb = document.createElement('div');
488
+ jamb.id = 'free-jamb';
489
+ jamb.style.width = 'auto';
490
+ jamb.style.background = '#7d7d7d8c';
491
+ jamb.innerHTML = `-`;
492
+ jamb.addEventListener('click', this.attachFreeJamb);
493
+ myRoot.appendChild(jamb);
494
+ var rowSum = document.createElement('div');
495
+ rowSum.id = 'free-rowSum';
496
+ rowSum.style.width = 'auto';
497
+ rowSum.style.background = '#7d7d7d8c';
498
+ rowSum.innerHTML = `-`;
499
+ myRoot.appendChild(rowSum);
500
+ },
501
+ createRowDown: function (myRoot) {
502
+ for (var x = 1; x < 7; x++) {
503
+ var rowNumber = document.createElement('div');
504
+ rowNumber.id = 'down-rowNumber' + x;
505
+ rowNumber.style.top = '10px';
506
+ rowNumber.style.left = '10px';
507
+ rowNumber.style.width = 'auto';
508
+ rowNumber.style.background = '#7d7d7d8c';
509
+ rowNumber.innerHTML = `-`;
510
+ this.memoNumberRow.push(rowNumber);
511
+ // initial
512
+ if (x == 1) {
513
+ rowNumber.classList.add('canPlay');
514
+ }
515
+ rowNumber.addEventListener('click', e => {
516
+ if (dices.validatePass() == false) return;
517
+ var getName = e.target.id;
518
+ getName = getName.replace('down-rowNumber', '');
519
+ if (this.state.rowDown.length == 0) {
520
+ console.log('LOG ', getName);
521
+ if (parseInt(getName) == 1) {
522
+ var count1 = 0;
523
+ for (let key in dices.R) {
524
+ if (parseInt(dices.R[key]) == 1) {
525
+ console.log('yeap', dices.R);
526
+ count1++;
527
+ }
528
+ }
529
+ this.state.rowDown.push(count1);
530
+ e.target.innerHTML = count1;
531
+ e.target.classList.remove('canPlay');
532
+ this.memoNumberRow[1].classList.add('canPlay');
533
+ dices.STATUS = "FREE_TO_PLAY";
534
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
535
+ } else {
536
+ console.log('BLOCK');
537
+ }
538
+ } else {
539
+ if (this.state.rowDown.length > 0) {
540
+ if (parseInt(getName) == this.state.rowDown.length + 1) {
541
+ console.log('moze za ', parseInt(getName));
542
+ var count23456 = 0;
543
+ for (let key in dices.R) {
544
+ if (parseInt(dices.R[key]) == parseInt(getName)) {
545
+ console.log('yeap', dices.R);
546
+ count23456++;
547
+ }
548
+ }
549
+ this.state.rowDown.push(count23456 * parseInt(getName));
550
+ //
551
+ e.target.innerHTML = count23456 * parseInt(getName);
552
+ if (parseInt(getName) == 6) {
553
+ // calc sum
554
+ console.log('calc sum for numb ~ ');
555
+ // this.state.rowDown.length + 1
556
+ myDom.calcDownNumbers();
557
+ e.target.classList.remove('canPlay');
558
+ this.rowMax.classList.add('canPlay');
559
+ } else {
560
+ e.target.classList.remove('canPlay');
561
+ this.memoNumberRow[parseInt(getName)].classList.add('canPlay');
562
+ }
563
+ dices.STATUS = "FREE_TO_PLAY";
564
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
565
+ } else {
566
+ console.log('BLOCK');
567
+ }
568
+ }
569
+ }
570
+ });
571
+ myRoot.appendChild(rowNumber);
572
+ }
573
+ var rowNumberSum = document.createElement('div');
574
+ rowNumberSum.id = 'down-rowNumberSum';
575
+ rowNumberSum.style.width = 'auto';
576
+ rowNumberSum.style.background = '#7d7d7d8c';
577
+ rowNumberSum.innerHTML = `-`;
578
+ myRoot.appendChild(rowNumberSum);
579
+ var rowMax = document.createElement('div');
580
+ rowMax.id = 'down-rowMax';
581
+ rowMax.style.width = 'auto';
582
+ rowMax.style.background = '#7d7d7d8c';
583
+ rowMax.innerHTML = `-`;
584
+ myRoot.appendChild(rowMax);
585
+ this.rowMax = rowMax;
586
+ // this.rowMax.addEventListener("click", (e) => {
587
+ // e.target.classList.remove('canPlay')
588
+ // this.rowMin.classList.add('canPlay')
589
+ // })
590
+
591
+ var rowMin = document.createElement('div');
592
+ rowMin.id = 'down-rowMin';
593
+ rowMin.style.width = 'auto';
594
+ rowMin.style.background = '#7d7d7d8c';
595
+ rowMin.innerHTML = `-`;
596
+ this.rowMin = rowMin;
597
+ myRoot.appendChild(rowMin);
598
+ this.rowMin = rowMin;
599
+ var rowMaxMinSum = document.createElement('div');
600
+ rowMaxMinSum.id = 'down-rowMaxMinSum';
601
+ rowMaxMinSum.style.width = 'auto';
602
+ rowMaxMinSum.style.background = '#7d7d7d8c';
603
+ rowMaxMinSum.innerHTML = `-`;
604
+ myRoot.appendChild(rowMaxMinSum);
605
+ var largeStraight = document.createElement('div');
606
+ largeStraight.id = 'down-largeStraight';
607
+ largeStraight.style.width = 'auto';
608
+ largeStraight.style.background = '#7d7d7d8c';
609
+ largeStraight.innerHTML = `-`;
610
+ myRoot.appendChild(largeStraight);
611
+ var threeOfAKind = document.createElement('div');
612
+ threeOfAKind.id = 'down-threeOfAKind';
613
+ threeOfAKind.style.width = 'auto';
614
+ threeOfAKind.style.background = '#7d7d7d8c';
615
+ threeOfAKind.innerHTML = `-`;
616
+ myRoot.appendChild(threeOfAKind);
617
+ var fullHouse = document.createElement('div');
618
+ fullHouse.id = 'down-fullHouse';
619
+ fullHouse.style.width = 'auto';
620
+ fullHouse.style.background = '#7d7d7d8c';
621
+ fullHouse.innerHTML = `-`;
622
+ myRoot.appendChild(fullHouse);
623
+ var poker = document.createElement('div');
624
+ poker.id = 'down-poker';
625
+ poker.style.width = 'auto';
626
+ poker.style.background = '#7d7d7d8c';
627
+ poker.innerHTML = `-`;
628
+ myRoot.appendChild(poker);
629
+ var jamb = document.createElement('div');
630
+ jamb.id = 'down-jamb';
631
+ jamb.style.width = 'auto';
632
+ jamb.style.background = '#7d7d7d8c';
633
+ jamb.innerHTML = `-`;
634
+ myRoot.appendChild(jamb);
635
+ var rowSum = document.createElement('div');
636
+ rowSum.id = 'down-rowSum';
637
+ rowSum.style.width = 'auto';
638
+ rowSum.style.background = '#7d7d7d8c';
639
+ rowSum.innerHTML = `-`;
640
+ myRoot.appendChild(rowSum);
641
+ },
642
+ calcDownNumbers: function () {
643
+ var s = 0;
644
+ this.state.rowDown.forEach(i => {
645
+ console.log(parseFloat(i));
646
+ s += parseFloat(i);
647
+ });
648
+ (0, _utils.byId)('down-rowNumberSum').style.background = 'rgb(113 0 0 / 55%)';
649
+ (0, _utils.byId)('down-rowNumberSum').innerHTML = s;
650
+ // console.log('this.rowMax also set free to plat status', this.rowMax)
651
+ dices.STATUS = "FREE_TO_PLAY";
652
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
653
+ this.rowMax.addEventListener("click", this.calcDownRowMax);
654
+ },
655
+ // free row start
53
656
 
54
- var loadJamb = function () {
55
- let jamb = new _world.default({
56
- useSingleRenderPass: true,
57
- canvasSize: 'fullscreen',
58
- mainCameraParams: {
59
- type: 'arcball',
60
- responseCoef: 1
657
+ calcFreeNumbers: function () {
658
+ var s = 0;
659
+ this.state.rowDown.forEach(i => {
660
+ console.log(parseFloat(i));
661
+ s += parseFloat(i);
662
+ });
663
+ (0, _utils.byId)('free-rowNumberSum').style.background = 'rgb(113 0 0 / 55%)';
664
+ (0, _utils.byId)('free-rowNumberSum').innerHTML = s;
665
+ // console.log('this.rowMax also set free to plat status', this.rowMax)
666
+ dices.STATUS = "FREE_TO_PLAY";
667
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
668
+ (0, _utils.byId)('free-rowMax').addEventListener("click", this.calc);
669
+ },
670
+ calcFreeRowMax: e => {
671
+ if (dices.validatePass() == false) return;
672
+ var test = 0;
673
+ let keyLessNum = Object.keys(dices.R).reduce((key, v) => dices.R[v] < dices.R[key] ? v : key);
674
+ for (var key in dices.R) {
675
+ if (key != keyLessNum) {
676
+ test += parseFloat(dices.R[key]);
677
+ }
61
678
  }
62
- }, () => {
63
- addEventListener('AmmoReady', () => {
64
- (0, _loaderObj.downloadMeshes)({
65
- welcomeText: "./res/meshes/blender/piramyd.obj",
66
- cube: "./res/meshes/blender/cube.obj"
67
- }, onLoadObj);
679
+ e.target.innerHTML = test;
680
+ // now attach next event.
681
+ dices.STATUS = "FREE_TO_PLAY";
682
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
683
+ (0, _utils.byId)('free-rowMax').removeEventListener("click", (void 0).calcFreeRowMax);
684
+ },
685
+ calcFreeRowMin: () => {
686
+ if (dices.validatePass() == false) return;
687
+ var maxTestKey = Object.keys(dices.R).reduce(function (a, b) {
688
+ return dices.R[a] > dices.R[b] ? a : b;
68
689
  });
69
- function onLoadObj(m) {
70
- jamb.myLoadedMeshes = m;
71
- for (var key in m) {
72
- console.log(`%c Loaded objs: ${key} `, _utils.LOG_MATRIX);
690
+ var test = 0;
691
+ for (var key in dices.R) {
692
+ if (key != maxTestKey) {
693
+ test += parseFloat(dices.R[key]);
694
+ } else {
695
+ console.log('not calc dice ', dices.R[key]);
73
696
  }
74
- jamb.addMeshObj({
75
- position: {
76
- x: 0,
77
- y: 2,
78
- z: -15
79
- },
80
- rotation: {
81
- x: 0,
82
- y: 0,
83
- z: 0
84
- },
85
- rotationSpeed: {
86
- x: 0,
87
- y: 0,
88
- z: 0
89
- },
90
- texturesPaths: ['./res/meshes/blender/cube.png'],
91
- name: 'CubePhysics',
92
- mesh: m.cube,
93
- physics: {
94
- enabled: true,
95
- geometry: "Cube"
697
+ }
698
+ (0, _utils.byId)('free-rowMin').innerHTML = test;
699
+ (0, _utils.byId)('free-rowMin').removeEventListener('click', (void 0).calcFreeRowMin);
700
+ // calc max min dont forget rules for bonus +30
701
+ var SUMMINMAX = parseFloat((0, _utils.byId)('free-rowMax').innerHTML) - parseFloat((0, _utils.byId)('free-rowMin').innerHTML);
702
+ (0, _utils.byId)('free-rowMaxMinSum').innerHTML = SUMMINMAX;
703
+ myDom.incrasePoints(SUMMINMAX);
704
+ dices.STATUS = "FREE_TO_PLAY";
705
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
706
+ },
707
+ attachFreeKenta: function () {
708
+ if (dices.validatePass() == false) return;
709
+ console.log('Test free kenta :', dices.R);
710
+ var result = app.myDom.checkForDuplicate()[0];
711
+ var testArray = app.myDom.checkForDuplicate()[1];
712
+ console.log('TEST duplik: ' + result);
713
+ if (result.length == 2) {
714
+ console.log('TEST duplik less 3 : ' + result);
715
+ var locPrevent = false;
716
+ testArray.forEach((item, index, array) => {
717
+ if (result[0].value == item.value && locPrevent == false) {
718
+ console.log('detect by value item.value', item.value);
719
+ locPrevent = true;
720
+ array.splice(index, 1);
96
721
  }
97
722
  });
98
- jamb.addMeshObj({
99
- position: {
100
- x: 0,
101
- y: 1,
102
- z: -120
103
- },
104
- rotation: {
105
- x: 0,
106
- y: 0,
107
- z: 0
108
- },
109
- rotationSpeed: {
110
- x: 0,
111
- y: 0,
112
- z: 0
113
- },
114
- texturesPaths: ['./res/meshes/blender/cube.png'],
115
- name: 'welcomeTextPhysics',
116
- mesh: m.welcomeText
117
- // physics: {
118
- // enabled: true,
119
- // geometry: "Sphere"
120
- // }
723
+ // if we catch 1 and 6 in same stack then it is not possible for kenta...
724
+ var test1 = false,
725
+ test6 = false;
726
+ testArray.forEach((item, index, array) => {
727
+ if (item.value == 1) {
728
+ test1 = true;
729
+ } else if (item.value == 6) {
730
+ test6 = true;
731
+ }
121
732
  });
733
+ if (test1 == true && test6 == true) {
734
+ (0, _utils.byId)('free-largeStraight').innerHTML = `0`;
735
+ } else if (test1 == true) {
736
+ (0, _utils.byId)('free-largeStraight').innerHTML = 15 + 50;
737
+ myDom.incrasePoints(15 + 50);
738
+ } else if (test6 == true) {
739
+ (0, _utils.byId)('free-largeStraight').innerHTML = 20 + 50;
740
+ myDom.incrasePoints(20 + 50);
741
+ }
742
+ } else if (result < 2) {
743
+ (0, _utils.byId)('free-largeStraight').innerHTML = 66;
744
+ myDom.incrasePoints(66);
745
+ } else {
746
+ // zero value
747
+ (0, _utils.byId)('free-largeStraight').innerHTML = `0`;
122
748
  }
123
- });
124
- window.app = loadObjFile;
749
+ (0, _utils.byId)('free-largeStraight').removeEventListener('click', this.attachFreeKenta);
750
+ dices.STATUS = "FREE_TO_PLAY";
751
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
752
+ },
753
+ attachFreeTrilling: function () {
754
+ if (dices.validatePass() == false) return;
755
+ var result = app.myDom.checkForDuplicate()[0];
756
+ // var testArray = app.myDom.checkForDuplicate()[1];
757
+ // console.log('DUPLICATE FOR TRILING ', result);
758
+ if (result.length > 2) {
759
+ var testWin = 0;
760
+ var TEST = app.myDom.checkForAllDuplicate();
761
+ console.log('DUPLICATE FOR TRILING TEST ', TEST);
762
+ for (var key in TEST) {
763
+ if (TEST[key] > 2) {
764
+ // win
765
+ var getDiceID = parseInt(key.replace('value__', ''));
766
+ testWin = getDiceID * 3;
767
+ }
768
+ }
769
+ console.log('DUPLICATE FOR TRILING 30 + TEST ', testWin);
770
+ if (testWin > 0) {
771
+ (0, _utils.byId)('free-threeOfAKind').innerHTML = 20 + testWin;
772
+ myDom.incrasePoints(20 + testWin);
773
+ }
774
+ } else {
775
+ (0, _utils.byId)('free-threeOfAKind').innerHTML = 0;
776
+ }
777
+ (0, _utils.byId)('free-threeOfAKind').removeEventListener('click', this.attachFreeTrilling);
778
+ dices.STATUS = "FREE_TO_PLAY";
779
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
780
+ },
781
+ attachFreeFullHouse: function () {
782
+ if (dices.validatePass() == false) return;
783
+ var TEST = app.myDom.checkForAllDuplicate();
784
+ // console.log('DUPLICATE FOR FULL HOUSE 30 + TEST ');
785
+ var win = 0;
786
+ var testPair = false;
787
+ var testTrilling = false;
788
+ var testWinPair = 0;
789
+ var testWinTrilling = 0;
790
+ for (var key in TEST) {
791
+ if (TEST[key] == 2) {
792
+ // win
793
+ var getDiceID = parseInt(key.replace('value__', ''));
794
+ testWinPair = getDiceID * 2;
795
+ testPair = true;
796
+ } else if (TEST[key] == 3) {
797
+ var getDiceID = parseInt(key.replace('value__', ''));
798
+ testWinTrilling = getDiceID * 3;
799
+ testTrilling = true;
800
+ }
801
+ }
802
+ if (testPair == true && testTrilling == true) {
803
+ win = testWinPair + testWinTrilling;
804
+ (0, _utils.byId)('free-fullHouse').innerHTML = win + 30;
805
+ myDom.incrasePoints(win + 30);
806
+ } else {
807
+ (0, _utils.byId)('free-fullHouse').innerHTML = 0;
808
+ }
809
+ (0, _utils.byId)('free-fullHouse').removeEventListener('click', this.attachFreeFullHouse);
810
+ dices.STATUS = "FREE_TO_PLAY";
811
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
812
+ },
813
+ attachFreePoker: function () {
814
+ if (dices.validatePass() == false) return;
815
+ var TEST = app.myDom.checkForAllDuplicate();
816
+ // console.log('DUPLICATE FOR poker 40 + TEST ');
817
+ for (var key in TEST) {
818
+ if (TEST[key] == 4 || TEST[key] > 4) {
819
+ var getDiceID = parseInt(key.replace('value__', ''));
820
+ var win = getDiceID * 4;
821
+ (0, _utils.byId)('free-poker').innerHTML = win + 40;
822
+ myDom.incrasePoints(win + 40);
823
+ }
824
+ }
825
+ (0, _utils.byId)('free-poker').removeEventListener('click', this.attachFreePoker);
826
+ dices.STATUS = "FREE_TO_PLAY";
827
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
828
+ },
829
+ attachFreeJamb: function () {
830
+ if (dices.validatePass() == false) return;
831
+ // console.log('<GAMEPLAY><FREE ROW IS FEELED>')
832
+ var TEST = app.myDom.checkForAllDuplicate();
833
+ for (var key in TEST) {
834
+ if (TEST[key] == 5 || TEST[key] > 5) {
835
+ // win
836
+ var getDiceID = parseInt(key.replace('value__', ''));
837
+ var win = getDiceID * 5;
838
+ (0, _utils.byId)('free-poker').innerHTML = win + 50;
839
+ myDom.incrasePoints(win + 50);
840
+ }
841
+ }
842
+ (0, _utils.byId)('free-jamb').removeEventListener('click', this.attachFreeJamb);
843
+ dices.STATUS = "FREE_TO_PLAY";
844
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
845
+ },
846
+ // end of free row
847
+
848
+ calcDownRowMax: e => {
849
+ if (dices.validatePass() == false) return;
850
+ e.target.classList.remove('canPlay');
851
+ (void 0).rowMin.classList.add('canPlay');
852
+ var test = 0;
853
+ let keyLessNum = Object.keys(dices.R).reduce((key, v) => dices.R[v] < dices.R[key] ? v : key);
854
+ // console.log('FIND MIN DICE TO REMOVE FROM SUM ', keyLessNum);
855
+ for (var key in dices.R) {
856
+ if (key != keyLessNum) {
857
+ test += parseFloat(dices.R[key]);
858
+ }
859
+ }
860
+ e.target.innerHTML = test;
861
+ // now attach next event.
862
+ dices.STATUS = "FREE_TO_PLAY";
863
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
864
+ (void 0).rowMax.removeEventListener("click", (void 0).calcDownRowMax);
865
+ (0, _utils.byId)('down-rowMin').addEventListener('click', (void 0).calcDownRowMin);
866
+ },
867
+ incrasePoints: function (arg) {
868
+ (0, _utils.byId)('user-points').innerHTML = parseInt((0, _utils.byId)('user-points').innerHTML) + parseInt(arg);
869
+ },
870
+ calcDownRowMin: () => {
871
+ if (dices.validatePass() == false) return;
872
+ (void 0).rowMin.classList.remove('canPlay');
873
+ console.log('MIN ENABLED');
874
+ var maxTestKey = Object.keys(dices.R).reduce(function (a, b) {
875
+ return dices.R[a] > dices.R[b] ? a : b;
876
+ });
877
+ var test = 0;
878
+ for (var key in dices.R) {
879
+ if (key != maxTestKey) {
880
+ test += parseFloat(dices.R[key]);
881
+ } else {
882
+ console.log('not calc dice ', dices.R[key]);
883
+ }
884
+ }
885
+ (void 0).rowMin.innerHTML = test;
886
+ (0, _utils.byId)('down-rowMin').removeEventListener('click', (void 0).calcDownRowMin);
887
+ // calc max min dont forget rules for bonus +30
888
+ var SUMMINMAX = parseFloat((void 0).rowMax.innerHTML) - parseFloat((void 0).rowMin.innerHTML);
889
+ (0, _utils.byId)('down-rowMaxMinSum').innerHTML = SUMMINMAX;
890
+ myDom.incrasePoints(SUMMINMAX);
891
+ dices.STATUS = "FREE_TO_PLAY";
892
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
893
+ (0, _utils.byId)('down-largeStraight').classList.add('canPlay');
894
+ (0, _utils.byId)('down-largeStraight').addEventListener('click', (void 0).attachKenta);
895
+ },
896
+ checkForDuplicate: function () {
897
+ var testArray = [];
898
+ for (var key in dices.R) {
899
+ var gen = {
900
+ myId: key,
901
+ value: dices.R[key]
902
+ };
903
+ testArray.push(gen);
904
+ }
905
+ var result = Object.values(testArray.reduce((c, v) => {
906
+ let k = v.value;
907
+ c[k] = c[k] || [];
908
+ c[k].push(v);
909
+ return c;
910
+ }, {})).reduce((c, v) => v.length > 1 ? c.concat(v) : c, []);
911
+ return [result, testArray];
912
+ },
913
+ checkForAllDuplicate: function () {
914
+ var testArray = [];
915
+ for (var key in dices.R) {
916
+ var gen = {
917
+ myId: key,
918
+ value: dices.R[key]
919
+ };
920
+ testArray.push(gen);
921
+ }
922
+ // console.log('testArray ', testArray)
923
+ var result = Object.values(testArray.reduce((c, v) => {
924
+ let k = v.value;
925
+ c[k] = c[k] || [];
926
+ c[k].push(v);
927
+ return c;
928
+ }, {})).reduce((c, v) => v.length > 1 ? c.concat(v) : c, []);
929
+ var discret = {};
930
+ result.forEach((item, index, array) => {
931
+ if (typeof discret['value__' + item.value] === 'undefined') {
932
+ discret['value__' + item.value] = 1;
933
+ } else {
934
+ discret['value__' + item.value] += 1;
935
+ }
936
+ });
937
+ return discret;
938
+ },
939
+ attachKenta: function () {
940
+ console.log('Test kenta ', dices.R);
941
+ (0, _utils.byId)('down-largeStraight').classList.remove('canPlay');
942
+ var result = app.myDom.checkForDuplicate()[0];
943
+ var testArray = app.myDom.checkForDuplicate()[1];
944
+ // console.log('TEST duplik: ' + result);
945
+ if (result.length == 2) {
946
+ console.log('TEST duplik less 3 : ' + result);
947
+ var locPrevent = false;
948
+ testArray.forEach((item, index, array) => {
949
+ if (result[0].value == item.value && locPrevent == false) {
950
+ console.log('detect by value item.value', item.value);
951
+ locPrevent = true;
952
+ array.splice(index, 1);
953
+ }
954
+ });
955
+ // if we catch 1 and 6 in same stack then it is not possible for kenta...
956
+ var test1 = false,
957
+ test6 = false;
958
+ testArray.forEach((item, index, array) => {
959
+ if (item.value == 1) {
960
+ test1 = true;
961
+ } else if (item.value == 6) {
962
+ test6 = true;
963
+ }
964
+ });
965
+ if (test1 == true && test6 == true) {
966
+ (0, _utils.byId)('down-largeStraight').innerHTML = `0`;
967
+ } else if (test1 == true) {
968
+ (0, _utils.byId)('down-largeStraight').innerHTML = 15 + 50;
969
+ myDom.incrasePoints(15 + 50);
970
+ } else if (test6 == true) {
971
+ (0, _utils.byId)('down-largeStraight').innerHTML = 20 + 50;
972
+ myDom.incrasePoints(20 + 50);
973
+ }
974
+ } else if (result < 2) {
975
+ (0, _utils.byId)('down-largeStraight').innerHTML = 66;
976
+ myDom.incrasePoints(66);
977
+ } else {
978
+ // zero value
979
+ (0, _utils.byId)('down-largeStraight').innerHTML = `0`;
980
+ }
981
+ (0, _utils.byId)('down-threeOfAKind').addEventListener('click', this.attachDownTrilling);
982
+ (0, _utils.byId)('down-largeStraight').removeEventListener('click', this.attachKenta);
983
+ dices.STATUS = "FREE_TO_PLAY";
984
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
985
+ },
986
+ attachDownTrilling: function () {
987
+ var result = app.myDom.checkForDuplicate()[0];
988
+ // var testArray = app.myDom.checkForDuplicate()[1];
989
+ // console.log('DUPLICATE FOR TRILING ', result);
990
+ if (result.length > 2) {
991
+ var testWin = 0;
992
+ var TEST = app.myDom.checkForAllDuplicate();
993
+ console.log('DUPLICATE FOR TRILING TEST ', TEST);
994
+ for (var key in TEST) {
995
+ if (TEST[key] > 2) {
996
+ // win
997
+ var getDiceID = parseInt(key.replace('value__', ''));
998
+ testWin = getDiceID * 3;
999
+ }
1000
+ }
1001
+ console.log('DUPLICATE FOR TRILING 30 + TEST ', testWin);
1002
+ (0, _utils.byId)('down-threeOfAKind').innerHTML = 20 + testWin;
1003
+ myDom.incrasePoints(20 + testWin);
1004
+ } else {
1005
+ (0, _utils.byId)('down-threeOfAKind').innerHTML = 0;
1006
+ }
1007
+ (0, _utils.byId)('down-threeOfAKind').removeEventListener('click', this.attachDownTrilling);
1008
+ (0, _utils.byId)('down-fullHouse').addEventListener('click', this.attachDownFullHouse);
1009
+ dices.STATUS = "FREE_TO_PLAY";
1010
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
1011
+ },
1012
+ attachDownFullHouse: function () {
1013
+ var TEST = app.myDom.checkForAllDuplicate();
1014
+ // console.log('DUPLICATE FOR FULL HOUSE 30 + TEST ');
1015
+ var win = 0;
1016
+ var testPair = false;
1017
+ var testTrilling = false;
1018
+ var testWinPair = 0;
1019
+ var testWinTrilling = 0;
1020
+ for (var key in TEST) {
1021
+ if (TEST[key] == 2) {
1022
+ // win
1023
+ var getDiceID = parseInt(key.replace('value__', ''));
1024
+ testWinPair = getDiceID * 2;
1025
+ testPair = true;
1026
+ } else if (TEST[key] == 3) {
1027
+ var getDiceID = parseInt(key.replace('value__', ''));
1028
+ testWinTrilling = getDiceID * 3;
1029
+ testTrilling = true;
1030
+ }
1031
+ }
1032
+ if (testPair == true && testTrilling == true) {
1033
+ win = testWinPair + testWinTrilling;
1034
+ (0, _utils.byId)('down-fullHouse').innerHTML = win + 30;
1035
+ myDom.incrasePoints(win + 30);
1036
+ } else {
1037
+ (0, _utils.byId)('down-fullHouse').innerHTML = 0;
1038
+ }
1039
+ (0, _utils.byId)('down-poker').addEventListener('click', this.attachDownPoker);
1040
+ (0, _utils.byId)('down-fullHouse').removeEventListener('click', this.attachDownFullHouse);
1041
+ dices.STATUS = "FREE_TO_PLAY";
1042
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
1043
+ },
1044
+ attachDownPoker: function () {
1045
+ var TEST = app.myDom.checkForAllDuplicate();
1046
+ // console.log('DUPLICATE FOR poker 40 + TEST ');
1047
+ for (var key in TEST) {
1048
+ if (TEST[key] == 4 || TEST[key] > 4) {
1049
+ // win
1050
+ var getDiceID = parseInt(key.replace('value__', ''));
1051
+ var win = getDiceID * 4;
1052
+ (0, _utils.byId)('down-poker').innerHTML = win + 40;
1053
+ myDom.incrasePoints(win + 40);
1054
+ }
1055
+ }
1056
+ (0, _utils.byId)('down-poker').removeEventListener('click', this.attachDownPoker);
1057
+ (0, _utils.byId)('down-jamb').addEventListener('click', this.attachDownJamb);
1058
+ dices.STATUS = "FREE_TO_PLAY";
1059
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
1060
+ },
1061
+ attachDownJamb: function () {
1062
+ (0, _utils.byId)('down-jamb').removeEventListener('click', this.attachDownJamb);
1063
+ console.log('<GAMEPLAY><DOWN ROW IS FEELED>');
1064
+ var TEST = app.myDom.checkForAllDuplicate();
1065
+ for (var key in TEST) {
1066
+ if (TEST[key] == 5 || TEST[key] > 5) {
1067
+ // win
1068
+ var getDiceID = parseInt(key.replace('value__', ''));
1069
+ var win = getDiceID * 5;
1070
+ (0, _utils.byId)('down-poker').innerHTML = win + 50;
1071
+ myDom.incrasePoints(win + 50);
1072
+ }
1073
+ }
1074
+ dices.STATUS = "FREE_TO_PLAY";
1075
+ dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
1076
+ }
125
1077
  };
126
- exports.loadJamb = loadJamb;
127
1078
 
128
- },{"../../../src/engine/loader-obj.js":9,"../../../src/engine/utils.js":13,"../../../src/world.js":19}],3:[function(require,module,exports){
1079
+ },{"../../../src/engine/loader-obj.js":9,"../../../src/engine/utils.js":14,"../../../src/world.js":22}],3:[function(require,module,exports){
129
1080
  "use strict";
130
1081
 
131
1082
  Object.defineProperty(exports, "__esModule", {
@@ -239,7 +1190,7 @@ var loadObjFile = function () {
239
1190
  };
240
1191
  exports.loadObjFile = loadObjFile;
241
1192
 
242
- },{"../src/engine/loader-obj.js":9,"../src/engine/utils.js":13,"../src/world.js":19}],4:[function(require,module,exports){
1193
+ },{"../src/engine/loader-obj.js":9,"../src/engine/utils.js":14,"../src/world.js":22}],4:[function(require,module,exports){
243
1194
  "use strict";
244
1195
 
245
1196
  Object.defineProperty(exports, "__esModule", {
@@ -281,15 +1232,15 @@ var unlitTextures = function () {
281
1232
  },
282
1233
  rotation: {
283
1234
  x: 0,
284
- y: 45,
1235
+ y: 0,
285
1236
  z: 0
286
1237
  },
287
1238
  rotationSpeed: {
288
- x: 0,
289
- y: 10,
1239
+ x: 10,
1240
+ y: 0,
290
1241
  z: 0
291
1242
  },
292
- texturesPaths: ['./res/textures/rust.jpg']
1243
+ texturesPaths: ['./res/textures/default.png']
293
1244
  };
294
1245
  unlitTextures.addBall(c);
295
1246
  unlitTextures.addCube(o);
@@ -298,7 +1249,7 @@ var unlitTextures = function () {
298
1249
  };
299
1250
  exports.unlitTextures = unlitTextures;
300
1251
 
301
- },{"../src/world.js":19}],5:[function(require,module,exports){
1252
+ },{"../src/world.js":22}],5:[function(require,module,exports){
302
1253
  "use strict";
303
1254
 
304
1255
  Object.defineProperty(exports, "__esModule", {
@@ -5758,7 +6709,7 @@ class MEBall {
5758
6709
  asteroidCount: 15
5759
6710
  };
5760
6711
  this.loadTex0(this.texturesPaths, device).then(() => {
5761
- this.loadTex1(device).then(() => {
6712
+ this.loadTex1(this.texturesPaths, device).then(() => {
5762
6713
  this.sampler = device.createSampler({
5763
6714
  magFilter: 'linear',
5764
6715
  minFilter: 'linear'
@@ -5913,9 +6864,9 @@ class MEBall {
5913
6864
  _wgpuMatrix.mat4.multiply(this.projectionMatrix, viewMatrix, this.modelViewProjectionMatrix);
5914
6865
  return this.modelViewProjectionMatrix;
5915
6866
  }
5916
- async loadTex1(device) {
6867
+ async loadTex1(texPaths, device) {
5917
6868
  return new Promise(async resolve => {
5918
- const response = await fetch('./res/textures/tex1.jpg');
6869
+ const response = await fetch(texPaths[0]);
5919
6870
  const imageBitmap = await createImageBitmap(await response.blob());
5920
6871
  this.moonTexture = device.createTexture({
5921
6872
  size: [imageBitmap.width, imageBitmap.height, 1],
@@ -6052,7 +7003,7 @@ class MEBall {
6052
7003
  }
6053
7004
  exports.default = MEBall;
6054
7005
 
6055
- },{"../shaders/shaders":16,"./engine":8,"./matrix-class":10,"wgpu-matrix":5}],7:[function(require,module,exports){
7006
+ },{"../shaders/shaders":18,"./engine":8,"./matrix-class":10,"wgpu-matrix":5}],7:[function(require,module,exports){
6056
7007
  "use strict";
6057
7008
 
6058
7009
  Object.defineProperty(exports, "__esModule", {
@@ -6170,7 +7121,7 @@ class MECube {
6170
7121
  asteroidCount: 15
6171
7122
  };
6172
7123
  this.loadTex0(this.texturesPaths, device).then(() => {
6173
- this.loadTex1(device).then(() => {
7124
+ this.loadTex1(this.texturesPaths, device).then(() => {
6174
7125
  this.sampler = device.createSampler({
6175
7126
  magFilter: 'linear',
6176
7127
  minFilter: 'linear'
@@ -6313,6 +7264,13 @@ class MECube {
6313
7264
  });
6314
7265
  return bindGroup;
6315
7266
  }
7267
+
7268
+ // TEST
7269
+ getViewMatrix() {
7270
+ const camera = this.cameras[this.mainCameraParams.type];
7271
+ const viewMatrix = camera.update(deltaTime, this.inputHandler());
7272
+ return viewMatrix;
7273
+ }
6316
7274
  getTransformationMatrix(pos) {
6317
7275
  const now = Date.now();
6318
7276
  const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
@@ -6328,9 +7286,9 @@ class MECube {
6328
7286
  _wgpuMatrix.mat4.multiply(this.projectionMatrix, viewMatrix, this.modelViewProjectionMatrix);
6329
7287
  return this.modelViewProjectionMatrix;
6330
7288
  }
6331
- async loadTex1(device) {
7289
+ async loadTex1(textPath, device) {
6332
7290
  return new Promise(async resolve => {
6333
- const response = await fetch('./res/textures/tex1.jpg');
7291
+ const response = await fetch(textPath[0]);
6334
7292
  const imageBitmap = await createImageBitmap(await response.blob());
6335
7293
  this.moonTexture = device.createTexture({
6336
7294
  size: [imageBitmap.width, imageBitmap.height, 1],
@@ -6462,7 +7420,7 @@ class MECube {
6462
7420
  }
6463
7421
  exports.default = MECube;
6464
7422
 
6465
- },{"../shaders/shaders":16,"./engine":8,"./matrix-class":10,"wgpu-matrix":5}],8:[function(require,module,exports){
7423
+ },{"../shaders/shaders":18,"./engine":8,"./matrix-class":10,"wgpu-matrix":5}],8:[function(require,module,exports){
6466
7424
  "use strict";
6467
7425
 
6468
7426
  Object.defineProperty(exports, "__esModule", {
@@ -6633,6 +7591,8 @@ class WASDCamera extends CameraBase {
6633
7591
 
6634
7592
  // Reconstruct the camera's rotation, and store into the camera matrix.
6635
7593
  super.matrix = _wgpuMatrix.mat4.rotateX(_wgpuMatrix.mat4.rotationY(this.yaw), this.pitch);
7594
+ // super.matrix = mat4.rotateX(mat4.rotationY(this.yaw), -this.pitch);
7595
+ // super.matrix = mat4.rotateY(mat4.rotateX(this.pitch), this.yaw);
6636
7596
 
6637
7597
  // Calculate the new target velocity
6638
7598
  const digital = input.digital;
@@ -6920,7 +7880,7 @@ function createInputHandler(window, canvas) {
6920
7880
  };
6921
7881
  }
6922
7882
 
6923
- },{"./utils":13,"wgpu-matrix":5}],9:[function(require,module,exports){
7883
+ },{"./utils":14,"wgpu-matrix":5}],9:[function(require,module,exports){
6924
7884
  "use strict";
6925
7885
 
6926
7886
  Object.defineProperty(exports, "__esModule", {
@@ -6934,6 +7894,9 @@ exports.play = play;
6934
7894
  * information can then be used later on when creating your VBOs. See
6935
7895
  * OBJ.initMeshBuffers for an example of how to use the newly created Mesh
6936
7896
  *
7897
+ * Nidza Note:
7898
+ * There is difference from me source obj loader and me-wgpu obj loader
7899
+ * Here we need scele in comp x,y,z because we use also primitive [cube, sphere etc...]
6937
7900
  * @class Mesh
6938
7901
  * @constructor
6939
7902
  *
@@ -6950,7 +7913,7 @@ class constructMesh {
6950
7913
  this.create(this.objectData, this.inputArg);
6951
7914
  };
6952
7915
  this.updateBuffers = () => {
6953
- this.inputArg.scale = 1;
7916
+ this.inputArg.scale = [0.1, 0.1, 0.1];
6954
7917
  this.create(this.objectData, this.inputArg);
6955
7918
  };
6956
7919
  }
@@ -7107,9 +8070,9 @@ class constructMesh {
7107
8070
  This same process is repeated for verts and textures.
7108
8071
  */
7109
8072
  // vertex position
7110
- unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[0]] * inputArg.scale);
7111
- unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[1]] * inputArg.scale);
7112
- unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[2]] * inputArg.scale);
8073
+ unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[0]] * inputArg.scale[0]);
8074
+ unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[1]] * inputArg.scale[1]);
8075
+ unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[2]] * inputArg.scale[2]);
7113
8076
 
7114
8077
  // vertex textures
7115
8078
  if (textures.length) {
@@ -7184,11 +8147,11 @@ var downloadMeshes = function (nameAndURLs, completionCallback, inputArg) {
7184
8147
  // a new object is created. this will be passed into the completionCallback
7185
8148
  if (typeof inputArg === 'undefined') {
7186
8149
  var inputArg = {
7187
- scale: 1,
8150
+ scale: [0.1, 0.1, 0.1],
7188
8151
  swap: [null]
7189
8152
  };
7190
8153
  }
7191
- if (typeof inputArg.scale === 'undefined') inputArg.scale = 0.1;
8154
+ if (typeof inputArg.scale === 'undefined') inputArg.scale = [0.1, 0.1, 0.1];
7192
8155
  if (typeof inputArg.swap === 'undefined') inputArg.swap = [null];
7193
8156
  var meshes = {};
7194
8157
 
@@ -7401,22 +8364,22 @@ var _utils = require("./utils");
7401
8364
 
7402
8365
  class Position {
7403
8366
  constructor(x, y, z) {
7404
- console.log('TEST TYTPOF ', x);
8367
+ // console.log('TEST TYTPOF ', x)
7405
8368
  // Not in use for nwo this is from matrix-engine project [nameUniq]
7406
8369
  this.nameUniq = null;
7407
8370
  if (typeof x == 'undefined') x = 0;
7408
8371
  if (typeof y == 'undefined') y = 0;
7409
8372
  if (typeof z == 'undefined') z = 0;
7410
- this.x = x;
7411
- this.y = y;
7412
- this.z = z;
8373
+ this.x = parseFloat(x);
8374
+ this.y = parseFloat(y);
8375
+ this.z = parseFloat(z);
7413
8376
  this.velY = 0;
7414
8377
  this.velX = 0;
7415
8378
  this.velZ = 0;
7416
8379
  this.inMove = false;
7417
- this.targetX = x;
7418
- this.targetY = y;
7419
- this.targetZ = z;
8380
+ this.targetX = parseFloat(x);
8381
+ this.targetY = parseFloat(y);
8382
+ this.targetZ = parseFloat(z);
7420
8383
  this.thrust = 0.01;
7421
8384
  return this;
7422
8385
  }
@@ -7429,36 +8392,36 @@ class Position {
7429
8392
  }
7430
8393
  translateByX(x) {
7431
8394
  this.inMove = true;
7432
- this.targetX = x;
8395
+ this.targetX = parseFloat(x);
7433
8396
  }
7434
8397
  translateByY(y) {
7435
8398
  this.inMove = true;
7436
- this.targetY = y;
8399
+ this.targetY = parseFloat(y);
7437
8400
  }
7438
8401
  translateByZ(z) {
7439
8402
  this.inMove = true;
7440
- this.targetZ = z;
8403
+ this.targetZ = parseFloat(z);
7441
8404
  }
7442
8405
  translateByXY(x, y) {
7443
8406
  this.inMove = true;
7444
- this.targetX = x;
7445
- this.targetY = y;
8407
+ this.targetX = parseFloat(x);
8408
+ this.targetY = parseFloat(y);
7446
8409
  }
7447
8410
  translateByXZ(x, z) {
7448
8411
  this.inMove = true;
7449
- this.targetX = x;
7450
- this.targetZ = z;
8412
+ this.targetX = parseFloat(x);
8413
+ this.targetZ = parseFloat(z);
7451
8414
  }
7452
8415
  translateByYZ(y, z) {
7453
8416
  this.inMove = true;
7454
- this.targetY = y;
7455
- this.targetZ = z;
8417
+ this.targetY = parseFloat(y);
8418
+ this.targetZ = parseFloat(z);
7456
8419
  }
7457
8420
  onTargetPositionReach() {}
7458
8421
  update() {
7459
- var tx = this.targetX - this.x,
7460
- ty = this.targetY - this.y,
7461
- tz = this.targetZ - this.z,
8422
+ var tx = parseFloat(this.targetX) - parseFloat(this.x),
8423
+ ty = parseFloat(this.targetY) - parseFloat(this.y),
8424
+ tz = parseFloat(this.targetZ) - parseFloat(this.z),
7462
8425
  dist = Math.sqrt(tx * tx + ty * ty + tz * tz);
7463
8426
  this.velX = tx / dist * this.thrust;
7464
8427
  this.velY = ty / dist * this.thrust;
@@ -7490,7 +8453,7 @@ class Position {
7490
8453
  }
7491
8454
  }
7492
8455
  get worldLocation() {
7493
- return [this.x, this.y, this.z];
8456
+ return [parseFloat(this.x), parseFloat(this.y), parseFloat(this.z)];
7494
8457
  }
7495
8458
  SetX(newx, em) {
7496
8459
  this.x = newx;
@@ -7525,6 +8488,15 @@ class Position {
7525
8488
  // netObjId: this.nameUniq,
7526
8489
  // });
7527
8490
  }
8491
+ get X() {
8492
+ return parseFloat(this.x);
8493
+ }
8494
+ get Y() {
8495
+ return parseFloat(this.y);
8496
+ }
8497
+ get Z() {
8498
+ return parseFloat(this.z);
8499
+ }
7528
8500
  setPosition(newx, newy, newz) {
7529
8501
  this.x = newx;
7530
8502
  this.y = newy;
@@ -7567,6 +8539,23 @@ class Rotation {
7567
8539
  // not in use good for exstend logic
7568
8540
  this.matrixRotation = null;
7569
8541
  }
8542
+ toDegree() {
8543
+ /*
8544
+ heading = atan2(y * sin(angle)- x * z * (1 - cos(angle)) , 1 - (y2 + z2 ) * (1 - cos(angle)))
8545
+ attitude = asin(x * y * (1 - cos(angle)) + z * sin(angle))
8546
+ bank = atan2(x * sin(angle)-y * z * (1 - cos(angle)) , 1 - (x2 + z2) * (1 - cos(angle)))
8547
+ */
8548
+ return [(0, _utils.radToDeg)(this.axis.x), (0, _utils.radToDeg)(this.axis.y), (0, _utils.radToDeg)(this.axis.z)];
8549
+ }
8550
+ toDegreeX() {
8551
+ return Math.cos((0, _utils.radToDeg)(this.axis.x) / 2);
8552
+ }
8553
+ toDegreeY() {
8554
+ return Math.cos((0, _utils.radToDeg)(this.axis.z) / 2);
8555
+ }
8556
+ toDegreeZ() {
8557
+ return Math.cos((0, _utils.radToDeg)(this.axis.y) / 2);
8558
+ }
7570
8559
  getRotX() {
7571
8560
  if (this.rotationSpeed.x == 0) {
7572
8561
  return (0, _utils.degToRad)(this.x);
@@ -7594,7 +8583,7 @@ class Rotation {
7594
8583
  }
7595
8584
  exports.Rotation = Rotation;
7596
8585
 
7597
- },{"./utils":13}],11:[function(require,module,exports){
8586
+ },{"./utils":14}],11:[function(require,module,exports){
7598
8587
  "use strict";
7599
8588
 
7600
8589
  Object.defineProperty(exports, "__esModule", {
@@ -7608,8 +8597,18 @@ var _vertexShadow = require("../shaders/vertexShadow.wgsl");
7608
8597
  var _fragment = require("../shaders/fragment.wgsl");
7609
8598
  var _vertex = require("../shaders/vertex.wgsl");
7610
8599
  var _utils = require("./utils");
8600
+ var _raycastTest = require("./raycast-test");
7611
8601
  class MEMeshObj {
7612
8602
  constructor(canvas, device, context, o) {
8603
+ if (typeof o.name === 'undefined') o.name = (0, _utils.genName)(9);
8604
+ if (typeof o.raycast === 'undefined') {
8605
+ this.raycast = {
8606
+ enabled: false
8607
+ };
8608
+ } else {
8609
+ this.raycast = o.raycast;
8610
+ }
8611
+ this.name = o.name;
7613
8612
  this.done = false;
7614
8613
  this.device = device;
7615
8614
  this.context = context;
@@ -7618,13 +8617,20 @@ class MEMeshObj {
7618
8617
  // Mesh stuff
7619
8618
  this.mesh = o.mesh;
7620
8619
  this.mesh.uvs = this.mesh.textures;
7621
- console.log(`%c Mesh loaded: ${o.name}`, _utils.LOG_INFO);
8620
+ console.log(`%c Mesh loaded: ${o.name}`, _utils.LOG_FUNNY_SMALL);
7622
8621
  this.inputHandler = (0, _engine.createInputHandler)(window, canvas);
7623
8622
  this.cameras = o.cameras;
7624
8623
  this.mainCameraParams = {
7625
8624
  type: o.mainCameraParams.type,
7626
8625
  responseCoef: o.mainCameraParams.responseCoef
7627
8626
  };
8627
+
8628
+ // test raycast
8629
+ // fullscreen for now
8630
+ // window.addEventListener('mousedown', (e) => {
8631
+ // checkingProcedure(e);
8632
+ // });
8633
+ _raycastTest.touchCoordinate.enabled = true;
7628
8634
  this.lastFrameMS = 0;
7629
8635
  this.texturesPaths = [];
7630
8636
  o.texturesPaths.forEach(t => {
@@ -7936,25 +8942,27 @@ class MEMeshObj {
7936
8942
  this.viewMatrix = camera.update(deltaTime, this.inputHandler());
7937
8943
  _wgpuMatrix.mat4.translate(this.viewMatrix, _wgpuMatrix.vec3.fromValues(pos.x, pos.y, pos.z), this.viewMatrix);
7938
8944
  _wgpuMatrix.mat4.rotate(this.viewMatrix, _wgpuMatrix.vec3.fromValues(this.rotation.axis.x, this.rotation.axis.y, this.rotation.axis.z), (0, _utils.degToRad)(this.rotation.angle), this.viewMatrix);
7939
- // mat4.rotateX(this.viewMatrix, this.rotation.getRotX(), this.viewMatrix);
7940
- // mat4.rotateY(this.viewMatrix, this.rotation.getRotY(), this.viewMatrix);
7941
- // mat4.rotateZ(this.viewMatrix, this.rotation.getRotZ(), this.viewMatrix);
8945
+
8946
+ // console.info('angle: ', this.rotation.angle, ' axis ' , this.rotation.axis.x, ' , ', this.rotation.axis.y, ' , ', this.rotation.axis.z)
7942
8947
  _wgpuMatrix.mat4.multiply(this.projectionMatrix, this.viewMatrix, this.modelViewProjectionMatrix);
7943
8948
  return this.modelViewProjectionMatrix;
7944
8949
  };
7945
8950
  this.upVector = _wgpuMatrix.vec3.fromValues(0, 1, 0);
7946
8951
  this.origin = _wgpuMatrix.vec3.fromValues(0, 0, 0);
7947
- this.lightPosition = _wgpuMatrix.vec3.fromValues(0, 10, -2);
8952
+ this.lightPosition = _wgpuMatrix.vec3.fromValues(0, 0, 0);
7948
8953
  this.lightViewMatrix = _wgpuMatrix.mat4.lookAt(this.lightPosition, this.origin, this.upVector);
7949
8954
  const lightProjectionMatrix = _wgpuMatrix.mat4.create();
8955
+ var myLMargin = 100;
7950
8956
  {
7951
- const left = -80;
7952
- const right = 80;
7953
- const bottom = -80;
7954
- const top = 80;
8957
+ const left = -myLMargin;
8958
+ const right = myLMargin;
8959
+ const bottom = -myLMargin;
8960
+ const top = myLMargin;
7955
8961
  const near = -200;
7956
8962
  const far = 300;
7957
8963
  _wgpuMatrix.mat4.ortho(left, right, bottom, top, near, far, lightProjectionMatrix);
8964
+ // test
8965
+ // mat4.ortho(right, left, top, bottom, near, far, lightProjectionMatrix);
7958
8966
  }
7959
8967
  this.lightViewProjMatrix = _wgpuMatrix.mat4.multiply(lightProjectionMatrix, this.lightViewMatrix);
7960
8968
 
@@ -7982,8 +8990,7 @@ class MEMeshObj {
7982
8990
  });
7983
8991
  }
7984
8992
  updateLightsTest = position => {
7985
- console.log('test !');
7986
- ////////////////////////
8993
+ console.log('Update light position.', position);
7987
8994
  this.lightPosition = _wgpuMatrix.vec3.fromValues(position[0], position[1], position[2]);
7988
8995
  this.lightViewMatrix = _wgpuMatrix.mat4.lookAt(this.lightPosition, this.origin, this.upVector);
7989
8996
  const lightProjectionMatrix = _wgpuMatrix.mat4.create();
@@ -8003,9 +9010,11 @@ class MEMeshObj {
8003
9010
  // The camera/light aren't moving, so write them into buffers now.
8004
9011
  {
8005
9012
  const lightMatrixData = this.lightViewProjMatrix; // as Float32Array;
8006
- this.device.queue.writeBuffer(this.sceneUniformBuffer, 0, lightMatrixData.buffer, lightMatrixData.byteOffset, lightMatrixData.byteLength);
9013
+ this.device.queue.writeBuffer(this.sceneUniformBuffer, 0,
9014
+ // 0 ori
9015
+ lightMatrixData.buffer, lightMatrixData.byteOffset, lightMatrixData.byteLength);
8007
9016
  const lightData = this.lightPosition;
8008
- this.device.queue.writeBuffer(this.sceneUniformBuffer, 128, lightData.buffer, lightData.byteOffset, lightData.byteLength);
9017
+ this.device.queue.writeBuffer(this.sceneUniformBuffer, 256, lightData.buffer, lightData.byteOffset, lightData.byteLength);
8009
9018
  const modelData = modelMatrix;
8010
9019
  this.device.queue.writeBuffer(this.modelUniformBuffer, 0, modelData.buffer, modelData.byteOffset, modelData.byteLength);
8011
9020
  }
@@ -8014,6 +9023,7 @@ class MEMeshObj {
8014
9023
  depthStencilAttachment: {
8015
9024
  view: this.shadowDepthTextureView,
8016
9025
  depthClearValue: 1.0,
9026
+ // ori 1.0
8017
9027
  depthLoadOp: 'clear',
8018
9028
  depthStoreOp: 'store'
8019
9029
  }
@@ -8056,6 +9066,12 @@ class MEMeshObj {
8056
9066
  renderPass.setVertexBuffer(2, this.vertexTexCoordsBuffer);
8057
9067
  renderPass.setIndexBuffer(this.indexBuffer, 'uint16');
8058
9068
  renderPass.drawIndexed(this.indexCount);
9069
+
9070
+ // test ray
9071
+
9072
+ // try{ OLD
9073
+ // if(this.raycast.enabled == true) checkingRay(this)
9074
+ // } catch(e) {}
8059
9075
  };
8060
9076
  drawShadows = shadowPass => {
8061
9077
  shadowPass.setBindGroup(0, this.sceneBindGroupForShadow);
@@ -8069,7 +9085,7 @@ class MEMeshObj {
8069
9085
  }
8070
9086
  exports.default = MEMeshObj;
8071
9087
 
8072
- },{"../shaders/fragment.wgsl":15,"../shaders/vertex.wgsl":17,"../shaders/vertexShadow.wgsl":18,"./engine":8,"./matrix-class":10,"./utils":13,"wgpu-matrix":5}],12:[function(require,module,exports){
9088
+ },{"../shaders/fragment.wgsl":17,"../shaders/vertex.wgsl":19,"../shaders/vertexShadow.wgsl":20,"./engine":8,"./matrix-class":10,"./raycast-test":13,"./utils":14,"wgpu-matrix":5}],12:[function(require,module,exports){
8073
9089
  "use strict";
8074
9090
 
8075
9091
  Object.defineProperty(exports, "__esModule", {
@@ -8467,30 +9483,133 @@ class MEMesh {
8467
9483
  }
8468
9484
  exports.default = MEMesh;
8469
9485
 
8470
- },{"../shaders/fragment.wgsl":15,"../shaders/vertex.wgsl":17,"../shaders/vertexShadow.wgsl":18,"./engine":8,"./loader-obj":9,"./matrix-class":10,"wgpu-matrix":5}],13:[function(require,module,exports){
9486
+ },{"../shaders/fragment.wgsl":17,"../shaders/vertex.wgsl":19,"../shaders/vertexShadow.wgsl":20,"./engine":8,"./loader-obj":9,"./matrix-class":10,"wgpu-matrix":5}],13:[function(require,module,exports){
9487
+ "use strict";
9488
+
9489
+ Object.defineProperty(exports, "__esModule", {
9490
+ value: true
9491
+ });
9492
+ exports.addRaycastListener = addRaycastListener;
9493
+ exports.getRayFromMouse = getRayFromMouse;
9494
+ exports.rayIntersectsSphere = rayIntersectsSphere;
9495
+ exports.touchCoordinate = void 0;
9496
+ var _wgpuMatrix = require("wgpu-matrix");
9497
+ /**
9498
+ * @author Nikola Lukic
9499
+ * @email zlatnaspirala@gmail.com
9500
+ * @site https://maximumroulette.com
9501
+ * @Licence GPL v3
9502
+ * @credits chatgpt used for this script adaptation.
9503
+ * @Note matrix-engine-wgpu adaptation test
9504
+ * default for now:
9505
+ * app.cameras['WASD']
9506
+ * Only tested for WASD type of camera.
9507
+ * app is global - will be fixed in future
9508
+ */
9509
+
9510
+ let rayHitEvent;
9511
+ let touchCoordinate = exports.touchCoordinate = {
9512
+ enabled: false,
9513
+ x: 0,
9514
+ y: 0,
9515
+ stopOnFirstDetectedHit: false
9516
+ };
9517
+ function multiplyMatrixVector(matrix, vector) {
9518
+ return _wgpuMatrix.vec4.transformMat4(vector, matrix);
9519
+ }
9520
+ function getRayFromMouse(event, canvas, camera) {
9521
+ const rect = canvas.getBoundingClientRect();
9522
+ let x = (event.clientX - rect.left) / rect.width * 2 - 1;
9523
+ let y = (event.clientY - rect.top) / rect.height * 2 - 1;
9524
+ // simple invert
9525
+ x = -x;
9526
+ y = -y;
9527
+ const fov = Math.PI / 4;
9528
+ const aspect = canvas.width / canvas.height;
9529
+ const near = 0.1;
9530
+ const far = 1000;
9531
+ camera.projectionMatrix = _wgpuMatrix.mat4.perspective(2 * Math.PI / 5, aspect, 1, 1000.0);
9532
+ const invProjection = _wgpuMatrix.mat4.inverse(camera.projectionMatrix);
9533
+
9534
+ // const correctedView = mat4.clone(camera.view_);
9535
+ // correctedView[2] *= -1;
9536
+ // correctedView[6] *= -1;
9537
+ // correctedView[10] *= -1;
9538
+ // const invView = mat4.inverse(correctedView);
9539
+
9540
+ const invView = _wgpuMatrix.mat4.inverse(camera.view);
9541
+ const ndc = [x, y, 1, 1];
9542
+ let worldPos = multiplyMatrixVector(invProjection, ndc);
9543
+ worldPos = multiplyMatrixVector(invView, worldPos);
9544
+ let world;
9545
+ if (worldPos[3] !== 0) {
9546
+ world = [worldPos[0] / worldPos[3], worldPos[2] / worldPos[3], worldPos[1] / worldPos[3]];
9547
+ } else {
9548
+ console.log("[raycaster]special case 0.");
9549
+ world = [worldPos[0], worldPos[1], worldPos[2]];
9550
+ }
9551
+ const rayOrigin = [camera.position[0], camera.position[1], camera.position[2]];
9552
+ const rayDirection = _wgpuMatrix.vec3.normalize(_wgpuMatrix.vec3.subtract(world, rayOrigin));
9553
+ return {
9554
+ rayOrigin,
9555
+ rayDirection
9556
+ };
9557
+ }
9558
+ function rayIntersectsSphere(rayOrigin, rayDirection, sphereCenter, sphereRadius) {
9559
+ const pos = [sphereCenter.x, sphereCenter.z, sphereCenter.y];
9560
+ const oc = _wgpuMatrix.vec3.subtract(rayOrigin, pos);
9561
+ const a = _wgpuMatrix.vec3.dot(rayDirection, rayDirection);
9562
+ const b = 2.0 * _wgpuMatrix.vec3.dot(oc, rayDirection);
9563
+ const c = _wgpuMatrix.vec3.dot(oc, oc) - sphereRadius * sphereRadius;
9564
+ const discriminant = b * b - 4 * a * c;
9565
+ return discriminant > 0;
9566
+ }
9567
+ function addRaycastListener() {
9568
+ window.addEventListener('click', event => {
9569
+ let canvas = document.getElementsByTagName('canvas')[0];
9570
+ let camera = app.cameras.WASD;
9571
+ const {
9572
+ rayOrigin,
9573
+ rayDirection
9574
+ } = getRayFromMouse(event, canvas, camera);
9575
+ for (const object of app.mainRenderBundle) {
9576
+ if (rayIntersectsSphere(rayOrigin, rayDirection, object.position, 2)) {
9577
+ // console.log('Object clicked:', object.name);
9578
+ // Just like in matrix-engine webGL version "ray.hit.event"
9579
+ dispatchEvent(new CustomEvent('ray.hit.event', {
9580
+ detail: {
9581
+ hitObject: object
9582
+ }
9583
+ }));
9584
+ }
9585
+ }
9586
+ });
9587
+ }
9588
+
9589
+ },{"wgpu-matrix":5}],14:[function(require,module,exports){
8471
9590
  "use strict";
8472
9591
 
8473
9592
  Object.defineProperty(exports, "__esModule", {
8474
9593
  value: true
8475
9594
  });
8476
- exports.LOG_WARN = exports.LOG_MATRIX = exports.LOG_INFO = exports.LOG_FUNNY = void 0;
9595
+ exports.LOG_WARN = exports.LOG_MATRIX = exports.LOG_INFO = exports.LOG_FUNNY_SMALL = exports.LOG_FUNNY = void 0;
8477
9596
  exports.ORBIT = ORBIT;
8478
9597
  exports.ORBIT_FROM_ARRAY = ORBIT_FROM_ARRAY;
8479
9598
  exports.OSCILLATOR = OSCILLATOR;
8480
- exports.QueryString = void 0;
8481
9599
  exports.SWITCHER = SWITCHER;
8482
9600
  exports.byId = void 0;
8483
9601
  exports.createAppEvent = createAppEvent;
8484
9602
  exports.degToRad = degToRad;
9603
+ exports.genName = genName;
8485
9604
  exports.getAxisRot = getAxisRot;
8486
9605
  exports.getAxisRot2 = getAxisRot2;
8487
9606
  exports.getAxisRot3 = getAxisRot3;
8488
- exports.mat4 = void 0;
9607
+ exports.mb = exports.mat4 = void 0;
8489
9608
  exports.quaternion_rotation_matrix = quaternion_rotation_matrix;
8490
9609
  exports.radToDeg = radToDeg;
8491
9610
  exports.randomFloatFromTo = randomFloatFromTo;
8492
9611
  exports.randomIntFromTo = randomIntFromTo;
8493
- exports.vec3 = exports.scriptManager = void 0;
9612
+ exports.vec3 = exports.urlQuery = exports.scriptManager = void 0;
8494
9613
  const vec3 = exports.vec3 = {
8495
9614
  cross(a, b, dst) {
8496
9615
  dst = dst || new Float32Array(3);
@@ -9022,7 +10141,7 @@ function randomIntFromTo(min, max) {
9022
10141
  return Math.floor(Math.random() * (max - min + 1) + min);
9023
10142
  }
9024
10143
  }
9025
- var QueryString = exports.QueryString = function () {
10144
+ var urlQuery = exports.urlQuery = function () {
9026
10145
  var query_string = {};
9027
10146
  var query = window.location.search.substring(1);
9028
10147
  var vars = query.split('&');
@@ -9139,25 +10258,133 @@ function quaternion_rotation_matrix(Q) {
9139
10258
  // copnsole log graphics
9140
10259
  const LOG_WARN = exports.LOG_WARN = 'background: gray; color: yellow; font-size:10px';
9141
10260
  const LOG_INFO = exports.LOG_INFO = 'background: green; color: white; font-size:11px';
9142
- const LOG_MATRIX = exports.LOG_MATRIX = "font-family: verdana;color: #lime; font-size:11px;text-shadow: 2px 2px 4px orangered;background: black;";
10261
+ const LOG_MATRIX = exports.LOG_MATRIX = "font-family: stormfaze;color: #lime; font-size:11px;text-shadow: 2px 2px 4px orangered;background: black;";
9143
10262
  const LOG_FUNNY = exports.LOG_FUNNY = "font-family: stormfaze;color: #f1f033; font-size:14px;text-shadow: 2px 2px 4px #f335f4, 4px 4px 4px #d64444, 2px 2px 4px #c160a6, 6px 2px 0px #123de3;background: black;";
10263
+ const LOG_FUNNY_SMALL = exports.LOG_FUNNY_SMALL = "font-family: stormfaze;color: #f1f033; font-size:10px;text-shadow: 2px 2px 4px #f335f4, 4px 4px 4px #d64444, 1px 1px 2px #c160a6, 3px 1px 0px #123de3;background: black;";
10264
+ function genName(length) {
10265
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
10266
+ let result = "";
10267
+ for (let i = 0; i < length; i++) {
10268
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
10269
+ }
10270
+ return result;
10271
+ }
10272
+ let mb = exports.mb = {
10273
+ root: () => byId('msgBox'),
10274
+ pContent: () => byId('not-content'),
10275
+ copy: function () {
10276
+ navigator.clipboard.writeText(mb.root().children[0].innerText);
10277
+ },
10278
+ c: 0,
10279
+ ic: 0,
10280
+ t: {},
10281
+ setContent: function (content, t) {
10282
+ var iMsg = document.createElement('div');
10283
+ iMsg.innerHTML = content;
10284
+ iMsg.id = `msgbox-loc-${mb.c}`;
10285
+ mb.root().appendChild(iMsg);
10286
+ iMsg.classList.add('animate1');
10287
+ if (t == 'ok') {
10288
+ iMsg.style = 'font-family: stormfaze;color:white;padding:7px;margin:2px';
10289
+ } else {
10290
+ iMsg.style = 'font-family: stormfaze;color:white;padding:7px;margin:2px';
10291
+ }
10292
+ },
10293
+ kill: function () {
10294
+ mb.root().remove();
10295
+ },
10296
+ show: function (content, t) {
10297
+ mb.setContent(content, t);
10298
+ mb.root().style.display = "block";
10299
+ var loc2 = mb.c;
10300
+ setTimeout(function () {
10301
+ byId(`msgbox-loc-${loc2}`).classList.remove("fadeInDown");
10302
+ byId(`msgbox-loc-${loc2}`).classList.add("fadeOut");
10303
+ setTimeout(function () {
10304
+ byId(`msgbox-loc-${loc2}`).style.display = "none";
10305
+ byId(`msgbox-loc-${loc2}`).classList.remove("fadeOut");
10306
+ byId(`msgbox-loc-${loc2}`).remove();
10307
+ mb.ic++;
10308
+ if (mb.c == mb.ic) {
10309
+ mb.root().style.display = 'none';
10310
+ }
10311
+ }, 1000);
10312
+ }, 3000);
10313
+ mb.c++;
10314
+ },
10315
+ error: function (content) {
10316
+ mb.root().classList.remove("success");
10317
+ mb.root().classList.add("error");
10318
+ mb.root().classList.add("fadeInDown");
10319
+ mb.show(content, 'err');
10320
+ },
10321
+ success: function (content) {
10322
+ mb.root().classList.remove("error");
10323
+ mb.root().classList.add("success");
10324
+ mb.root().classList.add("fadeInDown");
10325
+ mb.show(content, 'ok');
10326
+ }
10327
+ };
10328
+
10329
+ },{}],15:[function(require,module,exports){
10330
+ "use strict";
10331
+
10332
+ Object.defineProperty(exports, "__esModule", {
10333
+ value: true
10334
+ });
10335
+ exports.MultiLang = void 0;
10336
+ var _utils = require("../engine/utils");
10337
+ class MultiLang {
10338
+ constructor() {
10339
+ addEventListener('updateLang', () => {
10340
+ console.log('Multilang updated.');
10341
+ this.update();
10342
+ });
10343
+ }
10344
+ update = function () {
10345
+ var allTranDoms = document.querySelectorAll('[data-label]');
10346
+ allTranDoms.forEach(i => {
10347
+ i.innerHTML = this.get[i.getAttribute('data-label')];
10348
+ });
10349
+ };
10350
+ loadMultilang = async function (lang = 'en') {
10351
+ lang = 'res/multilang/' + lang + '.json';
10352
+ console.info(`%cMultilang: ${lang}`, _utils.LOG_MATRIX);
10353
+ try {
10354
+ const r = await fetch(lang, {
10355
+ headers: {
10356
+ 'Accept': 'application/json',
10357
+ 'Content-Type': 'application/json'
10358
+ }
10359
+ });
10360
+ return await r.json();
10361
+ } catch (err) {
10362
+ console.warn('Not possible to access multilang json asset! Err => ', err);
10363
+ return {};
10364
+ }
10365
+ };
10366
+ }
10367
+ exports.MultiLang = MultiLang;
9144
10368
 
9145
- },{}],14:[function(require,module,exports){
10369
+ },{"../engine/utils":14}],16:[function(require,module,exports){
9146
10370
  "use strict";
9147
10371
 
9148
10372
  Object.defineProperty(exports, "__esModule", {
9149
10373
  value: true
9150
10374
  });
9151
10375
  exports.default = void 0;
9152
- var _wgpuMatrix = require("wgpu-matrix");
9153
10376
  var _utils = require("../engine/utils");
10377
+ // import {vec3} from "wgpu-matrix";
10378
+
9154
10379
  class MatrixAmmo {
9155
10380
  constructor() {
9156
10381
  // THIS PATH IS PATH FROM PUBLIC FINAL FOLDER
9157
10382
  _utils.scriptManager.LOAD("./ammojs/ammo.js", "ammojs", undefined, undefined, this.init);
10383
+ this.lastRoll = '';
10384
+ this.presentScore = '';
9158
10385
  }
9159
10386
  init = () => {
9160
- console.log('pre ammo');
10387
+ // console.log('pre ammo')
9161
10388
  Ammo().then(Ammo => {
9162
10389
  // Physics variables
9163
10390
  this.dynamicsWorld = null;
@@ -9172,7 +10399,6 @@ class MatrixAmmo {
9172
10399
  };
9173
10400
  initPhysics() {
9174
10401
  let Ammo = this.Ammo;
9175
-
9176
10402
  // Physics configuration
9177
10403
  var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration(),
9178
10404
  dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration),
@@ -9180,10 +10406,10 @@ class MatrixAmmo {
9180
10406
  solver = new Ammo.btSequentialImpulseConstraintSolver();
9181
10407
  this.dynamicsWorld = new Ammo.btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
9182
10408
  this.dynamicsWorld.setGravity(new Ammo.btVector3(0, -10, 0));
9183
- var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(50, 0.5, 50)),
10409
+ var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(70, 1, 70)),
9184
10410
  groundTransform = new Ammo.btTransform();
9185
10411
  groundTransform.setIdentity();
9186
- groundTransform.setOrigin(new Ammo.btVector3(0, -1, 0));
10412
+ groundTransform.setOrigin(new Ammo.btVector3(0, -4.45, 0));
9187
10413
  var mass = 0,
9188
10414
  isDynamic = mass !== 0,
9189
10415
  localInertia = new Ammo.btVector3(0, 0, 0);
@@ -9191,8 +10417,12 @@ class MatrixAmmo {
9191
10417
  var myMotionState = new Ammo.btDefaultMotionState(groundTransform),
9192
10418
  rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, groundShape, localInertia),
9193
10419
  body = new Ammo.btRigidBody(rbInfo);
10420
+ body.name = 'ground';
10421
+ this.ground = body;
9194
10422
  this.dynamicsWorld.addRigidBody(body);
9195
10423
  // this.rigidBodies.push(body);
10424
+ // add collide event
10425
+ this.detectCollision();
9196
10426
  }
9197
10427
  addPhysics(MEObject, pOptions) {
9198
10428
  if (pOptions.geometry == "Sphere") {
@@ -9220,26 +10450,44 @@ class MatrixAmmo {
9220
10450
  }
9221
10451
  addPhysicsBox(MEObject, pOptions) {
9222
10452
  const FLAGS = {
10453
+ TEST_NIDZA: 3,
9223
10454
  CF_KINEMATIC_OBJECT: 2
9224
10455
  };
9225
10456
  let Ammo = this.Ammo;
9226
- var colShape = new Ammo.btBoxShape(new Ammo.btVector3(1, 1, 1)),
10457
+ // improve this - scale by comp
10458
+ var colShape = new Ammo.btBoxShape(new Ammo.btVector3(pOptions.scale[0], pOptions.scale[1], pOptions.scale[2])),
9227
10459
  startTransform = new Ammo.btTransform();
9228
10460
  startTransform.setIdentity();
9229
10461
  var mass = pOptions.mass;
9230
10462
  var localInertia = new Ammo.btVector3(0, 0, 0);
9231
10463
  colShape.calculateLocalInertia(mass, localInertia);
9232
10464
  startTransform.setOrigin(new Ammo.btVector3(pOptions.position.x, pOptions.position.y, pOptions.position.z));
10465
+ //rotation
10466
+ // console.log('startTransform.setRotation', startTransform.setRotation)
10467
+ var t = startTransform.getRotation();
10468
+ t.setX((0, _utils.degToRad)(pOptions.rotation.x));
10469
+ t.setY((0, _utils.degToRad)(pOptions.rotation.y));
10470
+ t.setZ((0, _utils.degToRad)(pOptions.rotation.z));
10471
+ startTransform.setRotation(t);
10472
+
10473
+ // startTransform.setRotation(pOptions.rotation.x, pOptions.rotation.y, pOptions.rotation.z);
10474
+
9233
10475
  var myMotionState = new Ammo.btDefaultMotionState(startTransform),
9234
10476
  rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia),
9235
10477
  body = new Ammo.btRigidBody(rbInfo);
9236
- if (pOptions.mass == 0 && typeof pOptions.state == 'undefined') {
10478
+ if (pOptions.mass == 0 && typeof pOptions.state == 'undefined' && typeof pOptions.collide == 'undefined') {
9237
10479
  body.setActivationState(2);
9238
10480
  body.setCollisionFlags(FLAGS.CF_KINEMATIC_OBJECT);
9239
- console.log('what is pOptions.mass and state is 2 ....', pOptions.mass);
10481
+ // console.log('what is pOptions.mass and state is 2 ....', pOptions.mass)
10482
+ } else if (typeof pOptions.collide != 'undefined' && pOptions.collide == false) {
10483
+ // idea not work for now - eliminate collide effect
10484
+ body.setActivationState(4);
10485
+ body.setCollisionFlags(FLAGS.TEST_NIDZA);
9240
10486
  } else {
9241
10487
  body.setActivationState(4);
9242
10488
  }
10489
+ // console.log('what is name.', pOptions.name)
10490
+ body.name = pOptions.name;
9243
10491
  body.MEObject = MEObject;
9244
10492
  this.dynamicsWorld.addRigidBody(body);
9245
10493
  this.rigidBodies.push(body);
@@ -9250,31 +10498,117 @@ class MatrixAmmo {
9250
10498
  tbv30.setValue(x, y, z);
9251
10499
  body.setLinearVelocity(tbv30);
9252
10500
  }
9253
- setKinematicTransform(body, x, y, z) {
10501
+ setKinematicTransform(body, x, y, z, rx, ry, rz) {
10502
+ if (typeof rx == 'undefined') {
10503
+ var rx = 0;
10504
+ }
10505
+ if (typeof ry == 'undefined') {
10506
+ var ry = 0;
10507
+ }
10508
+ if (typeof rz == 'undefined') {
10509
+ var rz = 0;
10510
+ }
9254
10511
  let pos = new Ammo.btVector3();
9255
- let quat = new Ammo.btQuaternion();
10512
+ // let quat = new Ammo.btQuaternion();
9256
10513
  pos = body.getWorldTransform().getOrigin();
9257
- let localRot = pos = body.getWorldTransform().getRotation();
10514
+ let localRot = body.getWorldTransform().getRotation();
10515
+ // console.log('pre pos x:', pos.x(), " y : ", pos.y(), " z:", pos.z())
9258
10516
  pos.setX(pos.x() + x);
9259
10517
  pos.setY(pos.y() + y);
9260
10518
  pos.setZ(pos.z() + z);
9261
- console.log('position kinematic move : ', pos);
9262
- console.log('position localRot : ', localRot);
9263
-
9264
- // body.getWorldQuaternion(quat);
9265
- // let physicsBody = kObject.userData.physicsBody;
10519
+ // console.log('position kinematic move : ', pos)
10520
+ // console.log('position localRot : ', localRot)
10521
+ localRot.setX(rx);
10522
+ localRot.setY(ry);
10523
+ localRot.setZ(rz);
9266
10524
  let physicsBody = body;
9267
10525
  let ms = physicsBody.getMotionState();
9268
10526
  if (ms) {
9269
10527
  var tmpTrans = new Ammo.btTransform();
9270
- console.log('TEST pos x:', pos.x(), " y : ", pos.y(), " z:", pos.z());
10528
+
9271
10529
  // quat.setValue(quat.x(), quat.y(), quat.z(), quat.w());
9272
10530
  tmpTrans.setIdentity();
9273
10531
  tmpTrans.setOrigin(pos);
9274
- // tmpTrans.setRotation(quat);
10532
+ tmpTrans.setRotation(localRot);
9275
10533
  ms.setWorldTransform(tmpTrans);
9276
10534
  }
9277
- console.log('body, ', body);
10535
+ // console.log('body, ', body)
10536
+ }
10537
+ getBodyByName(name) {
10538
+ var b = null;
10539
+ this.rigidBodies.forEach((item, index, array) => {
10540
+ if (item.name == name) {
10541
+ b = array[index];
10542
+ }
10543
+ });
10544
+ return b;
10545
+ }
10546
+ getNameByBody(body) {
10547
+ var b = null;
10548
+ this.rigidBodies.forEach((item, index, array) => {
10549
+ if (item.kB == body.kB) {
10550
+ b = array[index].name;
10551
+ }
10552
+ });
10553
+ return b;
10554
+ }
10555
+ detectCollision() {
10556
+ console.log('override this');
10557
+ return;
10558
+ this.lastRoll = '';
10559
+ this.presentScore = '';
10560
+ let dispatcher = this.dynamicsWorld.getDispatcher();
10561
+ let numManifolds = dispatcher.getNumManifolds();
10562
+ for (let i = 0; i < numManifolds; i++) {
10563
+ let contactManifold = dispatcher.getManifoldByIndexInternal(i);
10564
+ // let numContacts = contactManifold.getNumContacts();
10565
+ // this.rigidBodies.forEach((item) => {
10566
+ // if(item.kB == contactManifold.getBody0().kB) {
10567
+ // // console.log('Detected body0 =', item.name)
10568
+ // }
10569
+ // if(item.kB == contactManifold.getBody1().kB) {
10570
+ // // console.log('Detected body1 =', item.name)
10571
+ // }
10572
+ // })
10573
+
10574
+ if (this.ground.kB == contactManifold.getBody0().kB && this.getNameByBody(contactManifold.getBody1()) == 'CubePhysics1') {
10575
+ // console.log(this.ground ,'GROUND IS IN CONTACT WHO IS BODY1 ', contactManifold.getBody1())
10576
+ // console.log('GROUND IS IN CONTACT WHO IS BODY1 getNameByBody ', this.getNameByBody(contactManifold.getBody1()))
10577
+ // CHECK ROTATION
10578
+ var testR = contactManifold.getBody1().getWorldTransform().getRotation();
10579
+ if (Math.abs(testR.y()) < 0.00001) {
10580
+ this.lastRoll += " 4 +";
10581
+ this.presentScore += 4;
10582
+ dispatchEvent(new CustomEvent('dice-1', {}));
10583
+ }
10584
+ if (Math.abs(testR.x()) < 0.00001) {
10585
+ this.lastRoll += " 3 +";
10586
+ this.presentScore += 3;
10587
+ dispatchEvent(new CustomEvent('dice-4', {}));
10588
+ }
10589
+ if (testR.x().toString().substring(0, 5) == testR.y().toString().substring(1, 6)) {
10590
+ this.lastRoll += " 2 +";
10591
+ this.presentScore += 2;
10592
+ dispatchEvent(new CustomEvent('dice-6', {}));
10593
+ }
10594
+ if (testR.x().toString().substring(0, 5) == testR.y().toString().substring(0, 5)) {
10595
+ this.lastRoll += " 1 +";
10596
+ this.presentScore += 1;
10597
+ dispatchEvent(new CustomEvent('dice-2', {}));
10598
+ }
10599
+ if (testR.z().toString().substring(0, 5) == testR.y().toString().substring(1, 6)) {
10600
+ this.lastRoll += " 6 +";
10601
+ this.presentScore += 6;
10602
+ dispatchEvent(new CustomEvent('dice-5', {}));
10603
+ }
10604
+ if (testR.z().toString().substring(0, 5) == testR.y().toString().substring(0, 5)) {
10605
+ this.lastRoll += " 5 +";
10606
+ this.presentScore += 5;
10607
+ dispatchEvent(new CustomEvent('dice-3', {}));
10608
+ }
10609
+ console.log('this.lastRoll = ', this.lastRoll, ' presentScore = ', this.presentScore);
10610
+ }
10611
+ }
9278
10612
  }
9279
10613
  updatePhysics() {
9280
10614
  // Step world
@@ -9294,18 +10628,17 @@ class MatrixAmmo {
9294
10628
  body.MEObject.rotation.axis.x = testAxis.x();
9295
10629
  body.MEObject.rotation.axis.y = testAxis.y();
9296
10630
  body.MEObject.rotation.axis.z = testAxis.z();
9297
- // var tx = radToDeg(parseFloat(test.getAngle().toFixed(2)) * testAxis.x().toFixed(2))
9298
- // var ty = radToDeg(parseFloat(test.getAngle().toFixed(2)) * testAxis.y().toFixed(2))
9299
- // var tz = radToDeg(parseFloat(test.getAngle().toFixed(2)) * testAxis.z().toFixed(2))
9300
10631
  body.MEObject.rotation.matrixRotation = (0, _utils.quaternion_rotation_matrix)(test);
9301
10632
  body.MEObject.rotation.angle = (0, _utils.radToDeg)(parseFloat(test.getAngle().toFixed(2)));
9302
10633
  }
9303
10634
  });
10635
+ // collision detect
10636
+ this.detectCollision();
9304
10637
  }
9305
10638
  }
9306
10639
  exports.default = MatrixAmmo;
9307
10640
 
9308
- },{"../engine/utils":13,"wgpu-matrix":5}],15:[function(require,module,exports){
10641
+ },{"../engine/utils":14}],17:[function(require,module,exports){
9309
10642
  "use strict";
9310
10643
 
9311
10644
  Object.defineProperty(exports, "__esModule", {
@@ -9334,7 +10667,7 @@ struct FragmentInput {
9334
10667
  }
9335
10668
 
9336
10669
  const albedo = vec3f(0.9);
9337
- const ambientFactor = 0.2;
10670
+ const ambientFactor = 0.7;
9338
10671
 
9339
10672
  @fragment
9340
10673
  fn main(input : FragmentInput) -> @location(0) vec4f {
@@ -9353,15 +10686,17 @@ fn main(input : FragmentInput) -> @location(0) vec4f {
9353
10686
  }
9354
10687
  }
9355
10688
  visibility /= 9.0;
9356
-
9357
10689
  let lambertFactor = max(dot(normalize(scene.lightPos - input.fragPos), normalize(input.fragNorm)), 0.0);
9358
10690
  let lightingFactor = min(ambientFactor + visibility * lambertFactor, 1.0);
9359
10691
  let textureColor = textureSample(meshTexture, meshSampler, input.uv);
9360
10692
 
9361
10693
  return vec4(textureColor.rgb * lightingFactor * albedo, 1.0);
10694
+ // return vec4f(input.fragNorm * 0.5 + 0.5, 1)
10695
+ // return vec4f(input.uv, 0, 1)
10696
+ // return vec4(textureColor.rgb , 0.5);
9362
10697
  }`;
9363
10698
 
9364
- },{}],16:[function(require,module,exports){
10699
+ },{}],18:[function(require,module,exports){
9365
10700
  "use strict";
9366
10701
 
9367
10702
  Object.defineProperty(exports, "__esModule", {
@@ -9405,7 +10740,7 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
9405
10740
  @group(1) @binding(2) var meshTexture: texture_2d<f32>;
9406
10741
 
9407
10742
  // Static directional lighting
9408
- const lightDir = vec3f(1, 1, 1);
10743
+ const lightDir = vec3f(0, 1, 0);
9409
10744
  const dirColor = vec3(1);
9410
10745
  const ambientColor = vec3f(0.05);
9411
10746
 
@@ -9419,7 +10754,7 @@ fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {
9419
10754
  return vec4f(textureColor.rgb * lightColor, textureColor.a);
9420
10755
  }`;
9421
10756
 
9422
- },{}],17:[function(require,module,exports){
10757
+ },{}],19:[function(require,module,exports){
9423
10758
  "use strict";
9424
10759
 
9425
10760
  Object.defineProperty(exports, "__esModule", {
@@ -9476,7 +10811,7 @@ fn main(
9476
10811
  }
9477
10812
  `;
9478
10813
 
9479
- },{}],18:[function(require,module,exports){
10814
+ },{}],20:[function(require,module,exports){
9480
10815
  "use strict";
9481
10816
 
9482
10817
  Object.defineProperty(exports, "__esModule", {
@@ -9500,11 +10835,61 @@ struct Model {
9500
10835
  fn main(
9501
10836
  @location(0) position: vec3f
9502
10837
  ) -> @builtin(position) vec4f {
9503
- return scene.lightViewProjMatrix * model.modelMatrix * vec4(position, 1.0);
10838
+ return scene.lightViewProjMatrix * model.modelMatrix * vec4(position, 1);
9504
10839
  }
9505
10840
  `;
9506
10841
 
9507
- },{}],19:[function(require,module,exports){
10842
+ },{}],21:[function(require,module,exports){
10843
+ "use strict";
10844
+
10845
+ Object.defineProperty(exports, "__esModule", {
10846
+ value: true
10847
+ });
10848
+ exports.MatrixSounds = void 0;
10849
+ class MatrixSounds {
10850
+ constructor() {
10851
+ this.volume = 0.5;
10852
+ this.audios = {};
10853
+ }
10854
+ createClones(c, name, path) {
10855
+ for (var x = 1; x < c; x++) {
10856
+ let a = new Audio(path);
10857
+ a.id = name + x;
10858
+ a.volume = this.volume;
10859
+ this.audios[name + x] = a;
10860
+ document.body.append(a);
10861
+ }
10862
+ }
10863
+ createAudio(name, path, useClones) {
10864
+ let a = new Audio(path);
10865
+ a.id = name;
10866
+ a.volume = this.volume;
10867
+ this.audios[name] = a;
10868
+ document.body.append(a);
10869
+ if (typeof useClones !== 'undefined') {
10870
+ this.createClones(useClones, name, path);
10871
+ }
10872
+ }
10873
+ play(name) {
10874
+ if (this.audios[name].paused == true) {
10875
+ this.audios[name].play();
10876
+ } else {
10877
+ this.tryClone(name);
10878
+ }
10879
+ }
10880
+ tryClone(name) {
10881
+ var cc = 1;
10882
+ try {
10883
+ while (this.audios[name + cc].paused == false) {
10884
+ cc++;
10885
+ }
10886
+ if (this.audios[name + cc]) this.audios[name + cc].play();
10887
+ } catch (err) {}
10888
+ }
10889
+ }
10890
+ exports.MatrixSounds = MatrixSounds;
10891
+
10892
+ },{}],22:[function(require,module,exports){
9508
10893
  "use strict";
9509
10894
 
9510
10895
  Object.defineProperty(exports, "__esModule", {
@@ -9519,6 +10904,8 @@ var _mesh = _interopRequireDefault(require("./engine/mesh.js"));
9519
10904
  var _meshObj = _interopRequireDefault(require("./engine/mesh-obj.js"));
9520
10905
  var _matrixAmmo = _interopRequireDefault(require("./physics/matrix-ammo.js"));
9521
10906
  var _utils = require("./engine/utils.js");
10907
+ var _lang = require("./multilang/lang.js");
10908
+ var _sounds = require("./sounds/sounds.js");
9522
10909
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9523
10910
  class MatrixEngineWGPU {
9524
10911
  mainRenderBundle = [];
@@ -9532,6 +10919,7 @@ class MatrixEngineWGPU {
9532
10919
  depthStoreOp: 'store'
9533
10920
  };
9534
10921
  matrixAmmo = new _matrixAmmo.default();
10922
+ matrixSounds = new _sounds.MatrixSounds();
9535
10923
 
9536
10924
  // The input handler
9537
10925
  constructor(options, callback) {
@@ -9580,6 +10968,18 @@ class MatrixEngineWGPU {
9580
10968
  position: initialCameraPosition
9581
10969
  })
9582
10970
  };
10971
+
10972
+ //
10973
+ this.label = new _lang.MultiLang();
10974
+ if (_utils.urlQuery.lang != null) {
10975
+ this.label.loadMultilang(_utils.urlQuery.lang).then(r => {
10976
+ this.label.get = r;
10977
+ });
10978
+ } else {
10979
+ this.label.loadMultilang().then(r => {
10980
+ this.label.get = r;
10981
+ });
10982
+ }
9583
10983
  this.init({
9584
10984
  canvas,
9585
10985
  callback
@@ -9591,7 +10991,17 @@ class MatrixEngineWGPU {
9591
10991
  }) => {
9592
10992
  this.canvas = canvas;
9593
10993
  this.adapter = await navigator.gpu.requestAdapter();
9594
- this.device = await this.adapter.requestDevice();
10994
+ this.device = await this.adapter.requestDevice({
10995
+ extensions: ["ray_tracing"]
10996
+ });
10997
+
10998
+ // Maybe works in ssl with webworkers...
10999
+ // const adapterInfo = await this.adapter.requestAdapterInfo();
11000
+ // var test = this.adapter.features()
11001
+ // console.log(adapterInfo.vendor);
11002
+ // console.log('test' + test);
11003
+ // console.log("FEATURES : " + this.adapter.features)
11004
+
9595
11005
  this.context = canvas.getContext('webgpu');
9596
11006
  const devicePixelRatio = window.devicePixelRatio;
9597
11007
  canvas.width = canvas.clientWidth * devicePixelRatio;
@@ -9782,6 +11192,9 @@ class MatrixEngineWGPU {
9782
11192
  this.mainRenderBundle.push(myMesh1);
9783
11193
  };
9784
11194
  addMeshObj = o => {
11195
+ if (typeof o.name === 'undefined') {
11196
+ o.name = (0, _utils.genName)(9);
11197
+ }
9785
11198
  if (typeof o.position === 'undefined') {
9786
11199
  o.position = {
9787
11200
  x: 0,
@@ -9810,26 +11223,33 @@ class MatrixEngineWGPU {
9810
11223
  o.mainCameraParams = this.mainCameraParams;
9811
11224
  }
9812
11225
  if (typeof o.scale === 'undefined') {
9813
- o.scale = 1;
11226
+ o.scale = [1, 1, 1];
11227
+ }
11228
+ if (typeof o.raycast === 'undefined') {
11229
+ o.raycast = {
11230
+ enabled: false
11231
+ };
9814
11232
  }
9815
11233
  o.entityArgPass = this.entityArgPass;
9816
11234
  o.cameras = this.cameras;
9817
- if (typeof o.name === 'undefined') {
9818
- o.name = 'random' + Math.random();
9819
- }
11235
+ // if(typeof o.name === 'undefined') {o.name = 'random' + Math.random();}
9820
11236
  if (typeof o.mesh === 'undefined') {
11237
+ _utils.mb.error('arg mesh is empty for ', o.name);
9821
11238
  throw console.error('arg mesh is empty...');
9822
11239
  return;
9823
11240
  }
9824
11241
  if (typeof o.physics === 'undefined') {
9825
11242
  o.physics = {
9826
- enabled: false,
11243
+ scale: [1, 1, 1],
11244
+ enabled: true,
9827
11245
  geometry: "Sphere",
9828
- radius: o.scale
11246
+ radius: o.scale,
11247
+ name: o.name,
11248
+ rotation: o.rotation
9829
11249
  };
9830
11250
  }
9831
11251
  if (typeof o.physics.enabled === 'undefined') {
9832
- o.physics.enabled = false;
11252
+ o.physics.enabled = true;
9833
11253
  }
9834
11254
  if (typeof o.physics.geometry === 'undefined') {
9835
11255
  o.physics.geometry = "Sphere";
@@ -9840,11 +11260,19 @@ class MatrixEngineWGPU {
9840
11260
  if (typeof o.physics.mass === 'undefined') {
9841
11261
  o.physics.mass = 1;
9842
11262
  }
11263
+ if (typeof o.physics.name === 'undefined') {
11264
+ o.physics.name = o.name;
11265
+ }
11266
+ if (typeof o.physics.scale === 'undefined') {
11267
+ o.physics.scale = o.scale;
11268
+ }
11269
+ if (typeof o.physics.rotation === 'undefined') {
11270
+ o.physics.rotation = o.rotation;
11271
+ }
9843
11272
 
9844
11273
  // send same pos
9845
11274
  o.physics.position = o.position;
9846
-
9847
- // console.log('Mesh procedure', o)
11275
+ // console.log('Mesh procedure', o)
9848
11276
  let myMesh1 = new _meshObj.default(this.canvas, this.device, this.context, o);
9849
11277
  if (o.physics.enabled == true) {
9850
11278
  this.matrixAmmo.addPhysics(myMesh1, o.physics);
@@ -9898,7 +11326,7 @@ class MatrixEngineWGPU {
9898
11326
  }
9899
11327
  };
9900
11328
  framePassPerObject = () => {
9901
- console.log('framePassPerObject');
11329
+ // console.log('framePassPerObject')
9902
11330
  let commandEncoder = this.device.createCommandEncoder();
9903
11331
  this.rbContainer = [];
9904
11332
  let passEncoder;
@@ -9919,4 +11347,4 @@ class MatrixEngineWGPU {
9919
11347
  }
9920
11348
  exports.default = MatrixEngineWGPU;
9921
11349
 
9922
- },{"./engine/ball.js":6,"./engine/cube.js":7,"./engine/engine.js":8,"./engine/mesh-obj.js":11,"./engine/mesh.js":12,"./engine/utils.js":13,"./physics/matrix-ammo.js":14,"wgpu-matrix":5}]},{},[1]);
11350
+ },{"./engine/ball.js":6,"./engine/cube.js":7,"./engine/engine.js":8,"./engine/mesh-obj.js":11,"./engine/mesh.js":12,"./engine/utils.js":14,"./multilang/lang.js":15,"./physics/matrix-ammo.js":16,"./sounds/sounds.js":21,"wgpu-matrix":5}]},{},[1]);