matrix-engine-wgpu 1.0.6 → 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.
Files changed (71) hide show
  1. package/.codesandbox/tasks.json +46 -0
  2. package/.devcontainer/devcontainer.json +22 -0
  3. package/.github/dependabot.yml +12 -0
  4. package/REFERENCE.md +3 -5
  5. package/dev.md +460 -0
  6. package/empty.js +7 -6
  7. package/examples/games/jamb/jamb.js +1133 -0
  8. package/examples/load-obj-file.js +65 -28
  9. package/examples/unlit-textures.js +26 -23
  10. package/examples.js +35 -3
  11. package/index.js +8 -2
  12. package/main.js +454 -48
  13. package/non-project-files/dev.txt +21 -0
  14. package/non-project-files/image1.png +0 -0
  15. package/non-project-files/image6.png +0 -0
  16. package/package.json +31 -13
  17. package/public/app.js +2234 -114
  18. package/public/css/style.css +371 -110
  19. package/public/empty.html +1 -1
  20. package/public/empty.js +9887 -9264
  21. package/public/examples.html +10 -8
  22. package/public/examples.js +2035 -247
  23. package/public/index.html +3 -5
  24. package/public/manifest copy.web +35 -0
  25. package/public/res/audios/block.mp3 +0 -0
  26. package/public/res/audios/dice1.mp3 +0 -0
  27. package/public/res/audios/dice2.mp3 +0 -0
  28. package/public/res/audios/start.mp3 +0 -0
  29. package/public/res/meshes/jamb/bg.blend +0 -0
  30. package/public/res/meshes/jamb/bg.blend1 +0 -0
  31. package/public/res/meshes/jamb/bg.mtl +12 -0
  32. package/public/res/meshes/jamb/bg.obj +17 -0
  33. package/public/res/meshes/jamb/bg.png +0 -0
  34. package/public/res/meshes/jamb/dice-default.png +0 -0
  35. package/public/res/meshes/jamb/dice-mark.png +0 -0
  36. package/public/res/meshes/jamb/dice.mtl +12 -0
  37. package/public/res/meshes/jamb/dice.obj +40 -0
  38. package/public/res/meshes/jamb/dice.png +0 -0
  39. package/public/res/meshes/jamb/jamb-title.mtl +12 -0
  40. package/public/res/meshes/jamb/jamb-title.obj +26008 -0
  41. package/public/res/meshes/jamb/jamb.blend +0 -0
  42. package/public/res/meshes/jamb/jamb.blend1 +0 -0
  43. package/public/res/meshes/jamb/logo.png +0 -0
  44. package/public/res/meshes/jamb/nidzaDice.blend +0 -0
  45. package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
  46. package/public/res/meshes/jamb/pile.blend +0 -0
  47. package/public/res/meshes/jamb/simpleCube.blend +0 -0
  48. package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
  49. package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
  50. package/public/res/meshes/jamb/text.png +0 -0
  51. package/public/res/multilang/en.json +27 -0
  52. package/public/res/multilang/sr.json +27 -0
  53. package/public/test.html +636 -0
  54. package/public/three-test.js +165 -0
  55. package/public/worker.html +1 -1
  56. package/readme.md +193 -115
  57. package/src/engine/ball.js +477 -468
  58. package/src/engine/cube.js +486 -468
  59. package/src/engine/engine.js +4 -6
  60. package/src/engine/loader-obj.js +9 -6
  61. package/src/engine/matrix-class.js +237 -204
  62. package/src/engine/mesh-obj.js +603 -515
  63. package/src/engine/raycast.js +101 -0
  64. package/src/engine/utils.js +69 -3
  65. package/src/multilang/lang.js +35 -0
  66. package/src/physics/matrix-ammo.js +168 -15
  67. package/src/shaders/fragment.wgsl.js +4 -2
  68. package/src/shaders/shaders.js +1 -1
  69. package/src/shaders/vertexShadow.wgsl.js +1 -1
  70. package/src/sounds/sounds.js +47 -0
  71. package/src/world.js +311 -248
@@ -1,97 +1,1255 @@
1
1
  (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
2
  "use strict";
3
3
 
4
+ var _jamb = require("./examples/games/jamb/jamb.js");
4
5
  var _loadObjFile = require("./examples/load-obj-file.js");
6
+ var _unlitTextures = require("./examples/unlit-textures.js");
7
+ var _utils = require("./src/engine/utils.js");
5
8
  /**
6
9
  * @examples
7
- * Just import curent example/demo
10
+ * MATRIX_ENGINE_WGPU EXAMPLE WORKSPACE
11
+ * Nikola Lukic 2024
8
12
  */
9
13
 
10
- window.app = _loadObjFile.application;
14
+ // For future
15
+ var examples = {
16
+ loadJamb: _jamb.loadJamb,
17
+ loadObjFile: _loadObjFile.loadObjFile,
18
+ unlitTextures: _unlitTextures.unlitTextures
19
+ };
20
+ (0, _utils.byId)('loadObjFile').addEventListener("click", () => {
21
+ (0, _utils.byId)('loadObjFile').setAttribute('disabled', true);
22
+ (0, _utils.byId)('unlitTextures').removeAttribute('disabled');
23
+ if (typeof app !== "undefined") app.destroyProgram();
24
+ (0, _loadObjFile.loadObjFile)();
25
+ });
26
+ (0, _utils.byId)('unlitTextures').addEventListener("click", () => {
27
+ (0, _utils.byId)('unlitTextures').setAttribute('disabled', true);
28
+ (0, _utils.byId)('loadObjFile').removeAttribute('disabled');
29
+ if (typeof app !== "undefined") app.destroyProgram();
30
+ (0, _unlitTextures.unlitTextures)();
31
+ });
32
+ (0, _utils.byId)('jamb').addEventListener("click", () => {
33
+ (0, _utils.byId)('unlitTextures').setAttribute('disabled', true);
34
+ (0, _utils.byId)('loadObjFile').setAttribute('disabled', true);
35
+ (0, _utils.byId)('jamb').removeAttribute('disabled');
36
+ if (typeof app !== "undefined") app.destroyProgram();
37
+ (0, _jamb.loadJamb)();
38
+ });
39
+
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
+ "use strict";
42
+
43
+ Object.defineProperty(exports, "__esModule", {
44
+ value: true
45
+ });
46
+ exports.myDom = exports.dices = void 0;
47
+ var _world = _interopRequireDefault(require("../../../src/world.js"));
48
+ var _loaderObj = require("../../../src/engine/loader-obj.js");
49
+ var _utils = require("../../../src/engine/utils.js");
50
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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
656
+
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
+ }
678
+ }
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;
689
+ });
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]);
696
+ }
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);
721
+ }
722
+ });
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
+ }
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`;
748
+ }
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
+ }
1077
+ };
11
1078
 
12
- },{"./examples/load-obj-file.js":2}],2:[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){
13
1080
  "use strict";
14
1081
 
15
1082
  Object.defineProperty(exports, "__esModule", {
16
1083
  value: true
17
1084
  });
18
- exports.application = void 0;
1085
+ exports.loadObjFile = void 0;
19
1086
  var _world = _interopRequireDefault(require("../src/world.js"));
20
1087
  var _loaderObj = require("../src/engine/loader-obj.js");
1088
+ var _utils = require("../src/engine/utils.js");
21
1089
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
- let application = exports.application = new _world.default({
23
- useSingleRenderPass: false,
24
- canvasSize: 'fullscreen'
25
- }, () => {
26
- let c = {
27
- scale: 1,
28
- position: {
29
- x: -2,
30
- y: 2,
31
- z: -10
32
- },
33
- rotation: {
34
- x: 0,
35
- y: 0,
36
- z: 0
37
- },
38
- rotationSpeed: {
39
- x: 0,
40
- y: 0,
41
- z: 0
42
- },
43
- texturesPaths: ['./res/textures/rust.jpg']
44
- };
45
- let o = {
46
- scale: 2,
47
- position: {
48
- x: 2,
49
- y: 0,
50
- z: -10
51
- },
52
- rotation: {
53
- x: 0,
54
- y: 45,
55
- z: 0
56
- },
57
- rotationSpeed: {
58
- x: 0,
59
- y: 0,
60
- z: 0
61
- },
62
- texturesPaths: ['./res/textures/rust.jpg']
63
- };
1090
+ // import MatrixEngineWGPU from "./src/world.js";
1091
+ // import {downloadMeshes} from './src/engine/loader-obj.js';
1092
+
1093
+ var loadObjFile = function () {
1094
+ let loadObjFile = new _world.default({
1095
+ useSingleRenderPass: true,
1096
+ canvasSize: 'fullscreen',
1097
+ mainCameraParams: {
1098
+ type: 'WASD',
1099
+ responseCoef: 1000
1100
+ }
1101
+ }, () => {
1102
+ addEventListener('AmmoReady', () => {
1103
+ (0, _loaderObj.downloadMeshes)({
1104
+ welcomeText: "./res/meshes/blender/piramyd.obj",
1105
+ armor: "./res/meshes/obj/armor.obj",
1106
+ sphere: "./res/meshes/blender/sphere.obj",
1107
+ cube: "./res/meshes/blender/cube.obj"
1108
+ }, onLoadObj);
1109
+ });
1110
+ function onLoadObj(m) {
1111
+ loadObjFile.myLoadedMeshes = m;
1112
+ for (var key in m) {
1113
+ console.log(`%c Loaded objs: ${key} `, _utils.LOG_MATRIX);
1114
+ }
1115
+ loadObjFile.addMeshObj({
1116
+ position: {
1117
+ x: 0,
1118
+ y: 2,
1119
+ z: -10
1120
+ },
1121
+ rotation: {
1122
+ x: 0,
1123
+ y: 0,
1124
+ z: 0
1125
+ },
1126
+ rotationSpeed: {
1127
+ x: 0,
1128
+ y: 0,
1129
+ z: 0
1130
+ },
1131
+ texturesPaths: ['./res/meshes/blender/cube.png'],
1132
+ name: 'CubePhysics',
1133
+ mesh: m.cube,
1134
+ physics: {
1135
+ enabled: true,
1136
+ geometry: "Cube"
1137
+ }
1138
+ });
1139
+ loadObjFile.addMeshObj({
1140
+ position: {
1141
+ x: 0,
1142
+ y: 2,
1143
+ z: -10
1144
+ },
1145
+ rotation: {
1146
+ x: 0,
1147
+ y: 0,
1148
+ z: 0
1149
+ },
1150
+ rotationSpeed: {
1151
+ x: 0,
1152
+ y: 0,
1153
+ z: 0
1154
+ },
1155
+ texturesPaths: ['./res/meshes/blender/cube.png'],
1156
+ name: 'SpherePhysics',
1157
+ mesh: m.sphere,
1158
+ physics: {
1159
+ enabled: true,
1160
+ geometry: "Sphere"
1161
+ }
1162
+ });
1163
+ loadObjFile.addMeshObj({
1164
+ position: {
1165
+ x: 0,
1166
+ y: 2,
1167
+ z: -10
1168
+ },
1169
+ rotation: {
1170
+ x: 0,
1171
+ y: 0,
1172
+ z: 0
1173
+ },
1174
+ rotationSpeed: {
1175
+ x: 0,
1176
+ y: 0,
1177
+ z: 0
1178
+ },
1179
+ texturesPaths: ['./res/meshes/blender/cube.png'],
1180
+ name: 'CubePhysics',
1181
+ mesh: m.welcomeText,
1182
+ physics: {
1183
+ enabled: true,
1184
+ geometry: "Cube"
1185
+ }
1186
+ });
1187
+ }
1188
+ });
1189
+ window.app = loadObjFile;
1190
+ };
1191
+ exports.loadObjFile = loadObjFile;
1192
+
1193
+ },{"../src/engine/loader-obj.js":9,"../src/engine/utils.js":14,"../src/world.js":22}],4:[function(require,module,exports){
1194
+ "use strict";
64
1195
 
65
- // let mesh = adaptJSON1(stanfordDragonData)
66
- // application.addBall(o)
67
- // application.addCube(c)
68
- application.addCube(o);
69
- function onLoadObj(m) {
70
- console.log('Loaded obj:', m.armor);
71
- // console.log('APP2 ', jsonPiramyd);
72
- // jsonPiramyd.vertexNormals = jsonPiramyd.normals;
73
- // jsonPiramyd.indices = jsonPiramyd.faces;
74
- // jsonPiramyd.textures = jsonPiramyd.uvs;
75
- application.addMeshObj({
1196
+ Object.defineProperty(exports, "__esModule", {
1197
+ value: true
1198
+ });
1199
+ exports.unlitTextures = void 0;
1200
+ var _world = _interopRequireDefault(require("../src/world.js"));
1201
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1202
+ var unlitTextures = function () {
1203
+ let unlitTextures = new _world.default({
1204
+ useSingleRenderPass: false,
1205
+ canvasSize: 'fullscreen'
1206
+ }, () => {
1207
+ let c = {
1208
+ scale: 2,
76
1209
  position: {
1210
+ x: -3,
1211
+ y: 0,
1212
+ z: -10
1213
+ },
1214
+ rotation: {
77
1215
  x: 0,
78
1216
  y: 0,
79
- z: -5
1217
+ z: 0
80
1218
  },
81
- texturesPaths: ['./res/meshes/obj/armor.png'],
82
- name: 'Armor',
83
- mesh: m.armor
84
- });
85
- }
86
-
87
- // downloadMeshes({armor: "./res/meshes/obj/armor.obj"}, onLoadObj)
88
- (0, _loaderObj.downloadMeshes)({
89
- armor: "./res/meshes/blender/piramyd.obj"
90
- }, onLoadObj);
91
- });
92
- window.app = application;
1219
+ rotationSpeed: {
1220
+ x: 10,
1221
+ y: 0,
1222
+ z: 0
1223
+ },
1224
+ texturesPaths: ['./res/textures/rust.jpg']
1225
+ };
1226
+ let o = {
1227
+ scale: 2,
1228
+ position: {
1229
+ x: 3,
1230
+ y: 0,
1231
+ z: -10
1232
+ },
1233
+ rotation: {
1234
+ x: 0,
1235
+ y: 0,
1236
+ z: 0
1237
+ },
1238
+ rotationSpeed: {
1239
+ x: 10,
1240
+ y: 0,
1241
+ z: 0
1242
+ },
1243
+ texturesPaths: ['./res/textures/default.png']
1244
+ };
1245
+ unlitTextures.addBall(c);
1246
+ unlitTextures.addCube(o);
1247
+ });
1248
+ window.app = unlitTextures;
1249
+ };
1250
+ exports.unlitTextures = unlitTextures;
93
1251
 
94
- },{"../src/engine/loader-obj.js":7,"../src/world.js":17}],3:[function(require,module,exports){
1252
+ },{"../src/world.js":22}],5:[function(require,module,exports){
95
1253
  "use strict";
96
1254
 
97
1255
  Object.defineProperty(exports, "__esModule", {
@@ -5438,7 +6596,7 @@ function setDefaultType(ctor) {
5438
6596
  setDefaultType$1(ctor);
5439
6597
  }
5440
6598
 
5441
- },{}],4:[function(require,module,exports){
6599
+ },{}],6:[function(require,module,exports){
5442
6600
  "use strict";
5443
6601
 
5444
6602
  Object.defineProperty(exports, "__esModule", {
@@ -5551,7 +6709,7 @@ class MEBall {
5551
6709
  asteroidCount: 15
5552
6710
  };
5553
6711
  this.loadTex0(this.texturesPaths, device).then(() => {
5554
- this.loadTex1(device).then(() => {
6712
+ this.loadTex1(this.texturesPaths, device).then(() => {
5555
6713
  this.sampler = device.createSampler({
5556
6714
  magFilter: 'linear',
5557
6715
  minFilter: 'linear'
@@ -5706,9 +6864,9 @@ class MEBall {
5706
6864
  _wgpuMatrix.mat4.multiply(this.projectionMatrix, viewMatrix, this.modelViewProjectionMatrix);
5707
6865
  return this.modelViewProjectionMatrix;
5708
6866
  }
5709
- async loadTex1(device) {
6867
+ async loadTex1(texPaths, device) {
5710
6868
  return new Promise(async resolve => {
5711
- const response = await fetch('./res/textures/tex1.jpg');
6869
+ const response = await fetch(texPaths[0]);
5712
6870
  const imageBitmap = await createImageBitmap(await response.blob());
5713
6871
  this.moonTexture = device.createTexture({
5714
6872
  size: [imageBitmap.width, imageBitmap.height, 1],
@@ -5845,7 +7003,7 @@ class MEBall {
5845
7003
  }
5846
7004
  exports.default = MEBall;
5847
7005
 
5848
- },{"../shaders/shaders":14,"./engine":6,"./matrix-class":8,"wgpu-matrix":3}],5:[function(require,module,exports){
7006
+ },{"../shaders/shaders":18,"./engine":8,"./matrix-class":10,"wgpu-matrix":5}],7:[function(require,module,exports){
5849
7007
  "use strict";
5850
7008
 
5851
7009
  Object.defineProperty(exports, "__esModule", {
@@ -5880,6 +7038,9 @@ class MECube {
5880
7038
  code: _shaders.UNLIT_SHADER
5881
7039
  });
5882
7040
  this.texturesPaths = [];
7041
+
7042
+ // useUVShema4x2 pass this from top !
7043
+
5883
7044
  o.texturesPaths.forEach(t => {
5884
7045
  this.texturesPaths.push(t);
5885
7046
  });
@@ -5960,15 +7121,13 @@ class MECube {
5960
7121
  asteroidCount: 15
5961
7122
  };
5962
7123
  this.loadTex0(this.texturesPaths, device).then(() => {
5963
- this.loadTex1(device).then(() => {
7124
+ this.loadTex1(this.texturesPaths, device).then(() => {
5964
7125
  this.sampler = device.createSampler({
5965
7126
  magFilter: 'linear',
5966
7127
  minFilter: 'linear'
5967
7128
  });
5968
7129
  this.transform = _wgpuMatrix.mat4.create();
5969
7130
  _wgpuMatrix.mat4.identity(this.transform);
5970
-
5971
- // Create one large central planet surrounded by a large ring of asteroids
5972
7131
  this.planet = this.createGeometry({
5973
7132
  scale: this.scale,
5974
7133
  useUVShema4x2: false
@@ -6105,6 +7264,13 @@ class MECube {
6105
7264
  });
6106
7265
  return bindGroup;
6107
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
+ }
6108
7274
  getTransformationMatrix(pos) {
6109
7275
  const now = Date.now();
6110
7276
  const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
@@ -6120,9 +7286,9 @@ class MECube {
6120
7286
  _wgpuMatrix.mat4.multiply(this.projectionMatrix, viewMatrix, this.modelViewProjectionMatrix);
6121
7287
  return this.modelViewProjectionMatrix;
6122
7288
  }
6123
- async loadTex1(device) {
7289
+ async loadTex1(textPath, device) {
6124
7290
  return new Promise(async resolve => {
6125
- const response = await fetch('./res/textures/tex1.jpg');
7291
+ const response = await fetch(textPath[0]);
6126
7292
  const imageBitmap = await createImageBitmap(await response.blob());
6127
7293
  this.moonTexture = device.createTexture({
6128
7294
  size: [imageBitmap.width, imageBitmap.height, 1],
@@ -6254,7 +7420,7 @@ class MECube {
6254
7420
  }
6255
7421
  exports.default = MECube;
6256
7422
 
6257
- },{"../shaders/shaders":14,"./engine":6,"./matrix-class":8,"wgpu-matrix":3}],6:[function(require,module,exports){
7423
+ },{"../shaders/shaders":18,"./engine":8,"./matrix-class":10,"wgpu-matrix":5}],8:[function(require,module,exports){
6258
7424
  "use strict";
6259
7425
 
6260
7426
  Object.defineProperty(exports, "__esModule", {
@@ -6263,6 +7429,7 @@ Object.defineProperty(exports, "__esModule", {
6263
7429
  exports.WASDCamera = exports.ArcballCamera = void 0;
6264
7430
  exports.createInputHandler = createInputHandler;
6265
7431
  var _wgpuMatrix = require("wgpu-matrix");
7432
+ var _utils = require("./utils");
6266
7433
  // Note: The code in this file does not use the 'dst' output parameter of functions in the
6267
7434
  // 'wgpu-matrix' library, so produces many temporary vectors and matrices.
6268
7435
  // This is intentional, as this sample prefers readability over performance.
@@ -6385,8 +7552,6 @@ class WASDCamera extends CameraBase {
6385
7552
  set velocity(vec) {
6386
7553
  _wgpuMatrix.vec3.copy(vec, this.velocity_);
6387
7554
  }
6388
-
6389
- // Construtor
6390
7555
  constructor(options) {
6391
7556
  super();
6392
7557
  if (options && (options.position || options.target)) {
@@ -6395,7 +7560,7 @@ class WASDCamera extends CameraBase {
6395
7560
  const forward = _wgpuMatrix.vec3.normalize(_wgpuMatrix.vec3.sub(target, position));
6396
7561
  this.recalculateAngles(forward);
6397
7562
  this.position = position;
6398
- console.log('camera postion:', position);
7563
+ // console.log(`%cCamera pos: ${position}`, LOG_INFO);
6399
7564
  }
6400
7565
  }
6401
7566
 
@@ -6426,6 +7591,8 @@ class WASDCamera extends CameraBase {
6426
7591
 
6427
7592
  // Reconstruct the camera's rotation, and store into the camera matrix.
6428
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);
6429
7596
 
6430
7597
  // Calculate the new target velocity
6431
7598
  const digital = input.digital;
@@ -6593,9 +7760,7 @@ function lerp(a, b, s) {
6593
7760
  return _wgpuMatrix.vec3.addScaled(a, _wgpuMatrix.vec3.sub(b, a), s);
6594
7761
  }
6595
7762
 
6596
- // IMPUT
6597
-
6598
- // // Input holds as snapshot of input state
7763
+ // Input holds as snapshot of input state
6599
7764
  // export default interface Input {
6600
7765
  // // Digital input (e.g keyboard state)
6601
7766
  // readonly digital: {
@@ -6614,10 +7779,8 @@ function lerp(a, b, s) {
6614
7779
  // readonly touching: boolean;
6615
7780
  // };
6616
7781
  // }
6617
-
6618
7782
  // InputHandler is a function that when called, returns the current Input state.
6619
7783
  // export type InputHandler = () => Input;
6620
-
6621
7784
  // createInputHandler returns an InputHandler by attaching event handlers to the window and canvas.
6622
7785
  function createInputHandler(window, canvas) {
6623
7786
  let digital = {
@@ -6717,7 +7880,7 @@ function createInputHandler(window, canvas) {
6717
7880
  };
6718
7881
  }
6719
7882
 
6720
- },{"wgpu-matrix":3}],7:[function(require,module,exports){
7883
+ },{"./utils":14,"wgpu-matrix":5}],9:[function(require,module,exports){
6721
7884
  "use strict";
6722
7885
 
6723
7886
  Object.defineProperty(exports, "__esModule", {
@@ -6731,6 +7894,9 @@ exports.play = play;
6731
7894
  * information can then be used later on when creating your VBOs. See
6732
7895
  * OBJ.initMeshBuffers for an example of how to use the newly created Mesh
6733
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...]
6734
7900
  * @class Mesh
6735
7901
  * @constructor
6736
7902
  *
@@ -6747,7 +7913,7 @@ class constructMesh {
6747
7913
  this.create(this.objectData, this.inputArg);
6748
7914
  };
6749
7915
  this.updateBuffers = () => {
6750
- this.inputArg.scale = 1;
7916
+ this.inputArg.scale = [0.1, 0.1, 0.1];
6751
7917
  this.create(this.objectData, this.inputArg);
6752
7918
  };
6753
7919
  }
@@ -6904,9 +8070,9 @@ class constructMesh {
6904
8070
  This same process is repeated for verts and textures.
6905
8071
  */
6906
8072
  // vertex position
6907
- unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[0]] * inputArg.scale);
6908
- unpacked.verts.push(+verts[(vertex[0] - 1) * 3 + initOrientation[1]] * inputArg.scale);
6909
- 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]);
6910
8076
 
6911
8077
  // vertex textures
6912
8078
  if (textures.length) {
@@ -6981,11 +8147,11 @@ var downloadMeshes = function (nameAndURLs, completionCallback, inputArg) {
6981
8147
  // a new object is created. this will be passed into the completionCallback
6982
8148
  if (typeof inputArg === 'undefined') {
6983
8149
  var inputArg = {
6984
- scale: 1,
8150
+ scale: [0.1, 0.1, 0.1],
6985
8151
  swap: [null]
6986
8152
  };
6987
8153
  }
6988
- if (typeof inputArg.scale === 'undefined') inputArg.scale = 0.1;
8154
+ if (typeof inputArg.scale === 'undefined') inputArg.scale = [0.1, 0.1, 0.1];
6989
8155
  if (typeof inputArg.swap === 'undefined') inputArg.swap = [null];
6990
8156
  var meshes = {};
6991
8157
 
@@ -7181,7 +8347,7 @@ function play(nameAni) {
7181
8347
  this.animation.currentAni = this.animation.anims[this.animation.anims.active].from;
7182
8348
  }
7183
8349
 
7184
- },{}],8:[function(require,module,exports){
8350
+ },{}],10:[function(require,module,exports){
7185
8351
  "use strict";
7186
8352
 
7187
8353
  Object.defineProperty(exports, "__esModule", {
@@ -7189,29 +8355,31 @@ Object.defineProperty(exports, "__esModule", {
7189
8355
  });
7190
8356
  exports.Rotation = exports.Position = void 0;
7191
8357
  var _utils = require("./utils");
7192
- // Sub classes for matrix-wgpu
7193
8358
  /**
7194
- * @description Base class
8359
+ * @description
8360
+ * Sub classes for matrix-wgpu
8361
+ * Base class
7195
8362
  * Position { x, y, z }
7196
8363
  */
7197
8364
 
7198
8365
  class Position {
7199
8366
  constructor(x, y, z) {
8367
+ // console.log('TEST TYTPOF ', x)
7200
8368
  // Not in use for nwo this is from matrix-engine project [nameUniq]
7201
8369
  this.nameUniq = null;
7202
8370
  if (typeof x == 'undefined') x = 0;
7203
8371
  if (typeof y == 'undefined') y = 0;
7204
8372
  if (typeof z == 'undefined') z = 0;
7205
- this.x = x;
7206
- this.y = y;
7207
- this.z = z;
8373
+ this.x = parseFloat(x);
8374
+ this.y = parseFloat(y);
8375
+ this.z = parseFloat(z);
7208
8376
  this.velY = 0;
7209
8377
  this.velX = 0;
7210
8378
  this.velZ = 0;
7211
8379
  this.inMove = false;
7212
- this.targetX = x;
7213
- this.targetY = y;
7214
- this.targetZ = z;
8380
+ this.targetX = parseFloat(x);
8381
+ this.targetY = parseFloat(y);
8382
+ this.targetZ = parseFloat(z);
7215
8383
  this.thrust = 0.01;
7216
8384
  return this;
7217
8385
  }
@@ -7224,36 +8392,36 @@ class Position {
7224
8392
  }
7225
8393
  translateByX(x) {
7226
8394
  this.inMove = true;
7227
- this.targetX = x;
8395
+ this.targetX = parseFloat(x);
7228
8396
  }
7229
8397
  translateByY(y) {
7230
8398
  this.inMove = true;
7231
- this.targetY = y;
8399
+ this.targetY = parseFloat(y);
7232
8400
  }
7233
8401
  translateByZ(z) {
7234
8402
  this.inMove = true;
7235
- this.targetZ = z;
8403
+ this.targetZ = parseFloat(z);
7236
8404
  }
7237
8405
  translateByXY(x, y) {
7238
8406
  this.inMove = true;
7239
- this.targetX = x;
7240
- this.targetY = y;
8407
+ this.targetX = parseFloat(x);
8408
+ this.targetY = parseFloat(y);
7241
8409
  }
7242
8410
  translateByXZ(x, z) {
7243
8411
  this.inMove = true;
7244
- this.targetX = x;
7245
- this.targetZ = z;
8412
+ this.targetX = parseFloat(x);
8413
+ this.targetZ = parseFloat(z);
7246
8414
  }
7247
8415
  translateByYZ(y, z) {
7248
8416
  this.inMove = true;
7249
- this.targetY = y;
7250
- this.targetZ = z;
8417
+ this.targetY = parseFloat(y);
8418
+ this.targetZ = parseFloat(z);
7251
8419
  }
7252
8420
  onTargetPositionReach() {}
7253
8421
  update() {
7254
- var tx = this.targetX - this.x,
7255
- ty = this.targetY - this.y,
7256
- 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),
7257
8425
  dist = Math.sqrt(tx * tx + ty * ty + tz * tz);
7258
8426
  this.velX = tx / dist * this.thrust;
7259
8427
  this.velY = ty / dist * this.thrust;
@@ -7285,7 +8453,7 @@ class Position {
7285
8453
  }
7286
8454
  }
7287
8455
  get worldLocation() {
7288
- return [this.x, this.y, this.z];
8456
+ return [parseFloat(this.x), parseFloat(this.y), parseFloat(this.z)];
7289
8457
  }
7290
8458
  SetX(newx, em) {
7291
8459
  this.x = newx;
@@ -7320,6 +8488,15 @@ class Position {
7320
8488
  // netObjId: this.nameUniq,
7321
8489
  // });
7322
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
+ }
7323
8500
  setPosition(newx, newy, newz) {
7324
8501
  this.x = newx;
7325
8502
  this.y = newy;
@@ -7353,13 +8530,38 @@ class Rotation {
7353
8530
  y: 0,
7354
8531
  z: 0
7355
8532
  };
8533
+ this.angle = 0;
8534
+ this.axis = {
8535
+ x: 0,
8536
+ y: 0,
8537
+ z: 0
8538
+ };
8539
+ // not in use good for exstend logic
8540
+ this.matrixRotation = null;
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);
7356
8558
  }
7357
8559
  getRotX() {
7358
8560
  if (this.rotationSpeed.x == 0) {
7359
8561
  return (0, _utils.degToRad)(this.x);
7360
8562
  } else {
7361
8563
  this.x = this.x + this.rotationSpeed.x * 0.001;
7362
- return this.x;
8564
+ return (0, _utils.degToRad)(this.x);
7363
8565
  }
7364
8566
  }
7365
8567
  getRotY() {
@@ -7367,7 +8569,7 @@ class Rotation {
7367
8569
  return (0, _utils.degToRad)(this.y);
7368
8570
  } else {
7369
8571
  this.y = this.y + this.rotationSpeed.y * 0.001;
7370
- return this.y;
8572
+ return (0, _utils.degToRad)(this.y);
7371
8573
  }
7372
8574
  }
7373
8575
  getRotZ() {
@@ -7375,13 +8577,13 @@ class Rotation {
7375
8577
  return (0, _utils.degToRad)(this.z);
7376
8578
  } else {
7377
8579
  this.z = this.z + this.rotationSpeed.z * 0.001;
7378
- return this.z;
8580
+ return (0, _utils.degToRad)(this.z);
7379
8581
  }
7380
8582
  }
7381
8583
  }
7382
8584
  exports.Rotation = Rotation;
7383
8585
 
7384
- },{"./utils":11}],9:[function(require,module,exports){
8586
+ },{"./utils":14}],11:[function(require,module,exports){
7385
8587
  "use strict";
7386
8588
 
7387
8589
  Object.defineProperty(exports, "__esModule", {
@@ -7394,8 +8596,19 @@ var _engine = require("./engine");
7394
8596
  var _vertexShadow = require("../shaders/vertexShadow.wgsl");
7395
8597
  var _fragment = require("../shaders/fragment.wgsl");
7396
8598
  var _vertex = require("../shaders/vertex.wgsl");
8599
+ var _utils = require("./utils");
8600
+ var _raycastTest = require("./raycast-test");
7397
8601
  class MEMeshObj {
7398
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;
7399
8612
  this.done = false;
7400
8613
  this.device = device;
7401
8614
  this.context = context;
@@ -7404,13 +8617,20 @@ class MEMeshObj {
7404
8617
  // Mesh stuff
7405
8618
  this.mesh = o.mesh;
7406
8619
  this.mesh.uvs = this.mesh.textures;
7407
- console.log('mesh obj: ', this.mesh);
8620
+ console.log(`%c Mesh loaded: ${o.name}`, _utils.LOG_FUNNY_SMALL);
7408
8621
  this.inputHandler = (0, _engine.createInputHandler)(window, canvas);
7409
8622
  this.cameras = o.cameras;
7410
8623
  this.mainCameraParams = {
7411
8624
  type: o.mainCameraParams.type,
7412
8625
  responseCoef: o.mainCameraParams.responseCoef
7413
8626
  };
8627
+
8628
+ // test raycast
8629
+ // fullscreen for now
8630
+ // window.addEventListener('mousedown', (e) => {
8631
+ // checkingProcedure(e);
8632
+ // });
8633
+ _raycastTest.touchCoordinate.enabled = true;
7414
8634
  this.lastFrameMS = 0;
7415
8635
  this.texturesPaths = [];
7416
8636
  o.texturesPaths.forEach(t => {
@@ -7717,40 +8937,42 @@ class MEMeshObj {
7717
8937
  const now = Date.now();
7718
8938
  const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
7719
8939
  this.lastFrameMS = now;
7720
-
7721
8940
  // const this.viewMatrix = mat4.identity()
7722
8941
  const camera = this.cameras[this.mainCameraParams.type];
7723
8942
  this.viewMatrix = camera.update(deltaTime, this.inputHandler());
7724
8943
  _wgpuMatrix.mat4.translate(this.viewMatrix, _wgpuMatrix.vec3.fromValues(pos.x, pos.y, pos.z), this.viewMatrix);
7725
- _wgpuMatrix.mat4.rotateX(this.viewMatrix, Math.PI * this.rotation.getRotX(), this.viewMatrix);
7726
- _wgpuMatrix.mat4.rotateY(this.viewMatrix, Math.PI * this.rotation.getRotY(), this.viewMatrix);
7727
- _wgpuMatrix.mat4.rotateZ(this.viewMatrix, Math.PI * this.rotation.getRotZ(), this.viewMatrix);
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);
8945
+
8946
+ // console.info('angle: ', this.rotation.angle, ' axis ' , this.rotation.axis.x, ' , ', this.rotation.axis.y, ' , ', this.rotation.axis.z)
7728
8947
  _wgpuMatrix.mat4.multiply(this.projectionMatrix, this.viewMatrix, this.modelViewProjectionMatrix);
7729
8948
  return this.modelViewProjectionMatrix;
7730
8949
  };
7731
8950
  this.upVector = _wgpuMatrix.vec3.fromValues(0, 1, 0);
7732
8951
  this.origin = _wgpuMatrix.vec3.fromValues(0, 0, 0);
7733
- const lightPosition = _wgpuMatrix.vec3.fromValues(50, 100, -100);
7734
- const lightViewMatrix = _wgpuMatrix.mat4.lookAt(lightPosition, this.origin, this.upVector);
8952
+ this.lightPosition = _wgpuMatrix.vec3.fromValues(0, 0, 0);
8953
+ this.lightViewMatrix = _wgpuMatrix.mat4.lookAt(this.lightPosition, this.origin, this.upVector);
7735
8954
  const lightProjectionMatrix = _wgpuMatrix.mat4.create();
8955
+ var myLMargin = 100;
7736
8956
  {
7737
- const left = -80;
7738
- const right = 80;
7739
- const bottom = -80;
7740
- const top = 80;
8957
+ const left = -myLMargin;
8958
+ const right = myLMargin;
8959
+ const bottom = -myLMargin;
8960
+ const top = myLMargin;
7741
8961
  const near = -200;
7742
8962
  const far = 300;
7743
8963
  _wgpuMatrix.mat4.ortho(left, right, bottom, top, near, far, lightProjectionMatrix);
8964
+ // test
8965
+ // mat4.ortho(right, left, top, bottom, near, far, lightProjectionMatrix);
7744
8966
  }
7745
- const lightViewProjMatrix = _wgpuMatrix.mat4.multiply(lightProjectionMatrix, lightViewMatrix);
8967
+ this.lightViewProjMatrix = _wgpuMatrix.mat4.multiply(lightProjectionMatrix, this.lightViewMatrix);
7746
8968
 
7747
8969
  // looks like affect on transformations for now const 0
7748
8970
  const modelMatrix = _wgpuMatrix.mat4.translation([0, 0, 0]);
7749
8971
  // The camera/light aren't moving, so write them into buffers now.
7750
8972
  {
7751
- const lightMatrixData = lightViewProjMatrix; // as Float32Array;
8973
+ const lightMatrixData = this.lightViewProjMatrix; // as Float32Array;
7752
8974
  this.device.queue.writeBuffer(this.sceneUniformBuffer, 0, lightMatrixData.buffer, lightMatrixData.byteOffset, lightMatrixData.byteLength);
7753
- const lightData = lightPosition;
8975
+ const lightData = this.lightPosition;
7754
8976
  this.device.queue.writeBuffer(this.sceneUniformBuffer, 128, lightData.buffer, lightData.byteOffset, lightData.byteLength);
7755
8977
  const modelData = modelMatrix;
7756
8978
  this.device.queue.writeBuffer(this.modelUniformBuffer, 0, modelData.buffer, modelData.byteOffset, modelData.byteLength);
@@ -7767,6 +8989,48 @@ class MEMeshObj {
7767
8989
  this.done = true;
7768
8990
  });
7769
8991
  }
8992
+ updateLightsTest = position => {
8993
+ console.log('Update light position.', position);
8994
+ this.lightPosition = _wgpuMatrix.vec3.fromValues(position[0], position[1], position[2]);
8995
+ this.lightViewMatrix = _wgpuMatrix.mat4.lookAt(this.lightPosition, this.origin, this.upVector);
8996
+ const lightProjectionMatrix = _wgpuMatrix.mat4.create();
8997
+ {
8998
+ const left = -80;
8999
+ const right = 80;
9000
+ const bottom = -80;
9001
+ const top = 80;
9002
+ const near = -200;
9003
+ const far = 300;
9004
+ _wgpuMatrix.mat4.ortho(left, right, bottom, top, near, far, lightProjectionMatrix);
9005
+ }
9006
+ this.lightViewProjMatrix = _wgpuMatrix.mat4.multiply(lightProjectionMatrix, this.lightViewMatrix);
9007
+
9008
+ // looks like affect on transformations for now const 0
9009
+ const modelMatrix = _wgpuMatrix.mat4.translation([0, 0, 0]);
9010
+ // The camera/light aren't moving, so write them into buffers now.
9011
+ {
9012
+ const lightMatrixData = this.lightViewProjMatrix; // as Float32Array;
9013
+ this.device.queue.writeBuffer(this.sceneUniformBuffer, 0,
9014
+ // 0 ori
9015
+ lightMatrixData.buffer, lightMatrixData.byteOffset, lightMatrixData.byteLength);
9016
+ const lightData = this.lightPosition;
9017
+ this.device.queue.writeBuffer(this.sceneUniformBuffer, 256, lightData.buffer, lightData.byteOffset, lightData.byteLength);
9018
+ const modelData = modelMatrix;
9019
+ this.device.queue.writeBuffer(this.modelUniformBuffer, 0, modelData.buffer, modelData.byteOffset, modelData.byteLength);
9020
+ }
9021
+ this.shadowPassDescriptor = {
9022
+ colorAttachments: [],
9023
+ depthStencilAttachment: {
9024
+ view: this.shadowDepthTextureView,
9025
+ depthClearValue: 1.0,
9026
+ // ori 1.0
9027
+ depthLoadOp: 'clear',
9028
+ depthStoreOp: 'store'
9029
+ }
9030
+ };
9031
+
9032
+ ///////////////////////
9033
+ };
7770
9034
  async loadTex0(texturesPaths, device) {
7771
9035
  this.sampler = device.createSampler({
7772
9036
  magFilter: 'linear',
@@ -7793,18 +9057,6 @@ class MEMeshObj {
7793
9057
  const transformationMatrix = this.getTransformationMatrix(this.position);
7794
9058
  this.device.queue.writeBuffer(this.sceneUniformBuffer, 64, transformationMatrix.buffer, transformationMatrix.byteOffset, transformationMatrix.byteLength);
7795
9059
  this.renderPassDescriptor.colorAttachments[0].view = this.context.getCurrentTexture().createView();
7796
- // {
7797
- // const shadowPass = commandEncoder.beginRenderPass(this.shadowPassDescriptor);
7798
- // shadowPass.setPipeline(this.shadowPipeline);
7799
-
7800
- // shadowPass.end();
7801
- // }
7802
- // {
7803
- // const renderPass = commandEncoder.beginRenderPass(this.renderPassDescriptor);
7804
- // renderPass.setPipeline(this.pipeline);
7805
-
7806
- // renderPass.end();
7807
- // }
7808
9060
  };
7809
9061
  drawElements = renderPass => {
7810
9062
  renderPass.setBindGroup(0, this.sceneBindGroupForRender);
@@ -7814,6 +9066,12 @@ class MEMeshObj {
7814
9066
  renderPass.setVertexBuffer(2, this.vertexTexCoordsBuffer);
7815
9067
  renderPass.setIndexBuffer(this.indexBuffer, 'uint16');
7816
9068
  renderPass.drawIndexed(this.indexCount);
9069
+
9070
+ // test ray
9071
+
9072
+ // try{ OLD
9073
+ // if(this.raycast.enabled == true) checkingRay(this)
9074
+ // } catch(e) {}
7817
9075
  };
7818
9076
  drawShadows = shadowPass => {
7819
9077
  shadowPass.setBindGroup(0, this.sceneBindGroupForShadow);
@@ -7827,7 +9085,7 @@ class MEMeshObj {
7827
9085
  }
7828
9086
  exports.default = MEMeshObj;
7829
9087
 
7830
- },{"../shaders/fragment.wgsl":13,"../shaders/vertex.wgsl":15,"../shaders/vertexShadow.wgsl":16,"./engine":6,"./matrix-class":8,"wgpu-matrix":3}],10:[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){
7831
9089
  "use strict";
7832
9090
 
7833
9091
  Object.defineProperty(exports, "__esModule", {
@@ -8225,27 +9483,133 @@ class MEMesh {
8225
9483
  }
8226
9484
  exports.default = MEMesh;
8227
9485
 
8228
- },{"../shaders/fragment.wgsl":13,"../shaders/vertex.wgsl":15,"../shaders/vertexShadow.wgsl":16,"./engine":6,"./loader-obj":7,"./matrix-class":8,"wgpu-matrix":3}],11:[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){
8229
9590
  "use strict";
8230
9591
 
8231
9592
  Object.defineProperty(exports, "__esModule", {
8232
9593
  value: true
8233
9594
  });
9595
+ exports.LOG_WARN = exports.LOG_MATRIX = exports.LOG_INFO = exports.LOG_FUNNY_SMALL = exports.LOG_FUNNY = void 0;
8234
9596
  exports.ORBIT = ORBIT;
8235
9597
  exports.ORBIT_FROM_ARRAY = ORBIT_FROM_ARRAY;
8236
9598
  exports.OSCILLATOR = OSCILLATOR;
8237
- exports.QueryString = void 0;
8238
9599
  exports.SWITCHER = SWITCHER;
8239
9600
  exports.byId = void 0;
8240
9601
  exports.createAppEvent = createAppEvent;
8241
9602
  exports.degToRad = degToRad;
9603
+ exports.genName = genName;
8242
9604
  exports.getAxisRot = getAxisRot;
8243
- exports.mat4 = void 0;
9605
+ exports.getAxisRot2 = getAxisRot2;
9606
+ exports.getAxisRot3 = getAxisRot3;
9607
+ exports.mb = exports.mat4 = void 0;
8244
9608
  exports.quaternion_rotation_matrix = quaternion_rotation_matrix;
8245
9609
  exports.radToDeg = radToDeg;
8246
9610
  exports.randomFloatFromTo = randomFloatFromTo;
8247
9611
  exports.randomIntFromTo = randomIntFromTo;
8248
- exports.vec3 = exports.scriptManager = void 0;
9612
+ exports.vec3 = exports.urlQuery = exports.scriptManager = void 0;
8249
9613
  const vec3 = exports.vec3 = {
8250
9614
  cross(a, b, dst) {
8251
9615
  dst = dst || new Float32Array(3);
@@ -8777,7 +10141,7 @@ function randomIntFromTo(min, max) {
8777
10141
  return Math.floor(Math.random() * (max - min + 1) + min);
8778
10142
  }
8779
10143
  }
8780
- var QueryString = exports.QueryString = function () {
10144
+ var urlQuery = exports.urlQuery = function () {
8781
10145
  var query_string = {};
8782
10146
  var query = window.location.search.substring(1);
8783
10147
  var vars = query.split('&');
@@ -8806,6 +10170,7 @@ function getAxisRot(q1) {
8806
10170
  if (s < 0.001) {
8807
10171
  // if s close to zero then direction of axis not important
8808
10172
  // if it is important that axis is normalised then replace with x=1; y=z=0;
10173
+
8809
10174
  x = q1.x;
8810
10175
  y = q1.y;
8811
10176
  z = q1.z;
@@ -8816,6 +10181,41 @@ function getAxisRot(q1) {
8816
10181
  }
8817
10182
  return [radToDeg(x), radToDeg(y), radToDeg(z)];
8818
10183
  }
10184
+ function getAxisRot2(targetAxis, Q) {
10185
+ Q.normalize(); // if w>1 acos and sqrt will produce errors, this cant happen if quaternion is normalised
10186
+ var angle = 2 * Math.acos(Q.w());
10187
+ var s = Math.sqrt(1 - Q.w() * Q.w()); // assuming quaternion normalised then w is less than 1, so term always positive.
10188
+ if (s < 0.001) {
10189
+ // test to avoid divide by zero, s is always positive due to sqrt
10190
+ // if s close to zero then direction of axis not important
10191
+ // if it is important that axis is normalised then replace with x=1; y=z=0;
10192
+ // targetAxis.x = 1;
10193
+ // targetAxis.y = 0;
10194
+ // targetAxis.z = 0;
10195
+ targetAxis.x = Q.x();
10196
+ targetAxis.y = Q.y();
10197
+ targetAxis.z = Q.z();
10198
+ } else {
10199
+ targetAxis.x = Q.x() / s; // normalise axis
10200
+ targetAxis.y = Q.y() / s;
10201
+ targetAxis.z = Q.z() / s;
10202
+ }
10203
+ return [targetAxis, angle];
10204
+ }
10205
+ function getAxisRot3(Q) {
10206
+ var angle = Math.acos(Q.w) * 2;
10207
+ var axis = {};
10208
+ if (Math.sin(Math.acos(angle)) > 0) {
10209
+ axis.x = Q.x / Math.sin(Math.acos(angle / 2));
10210
+ axis.y = Q.y / Math.sin(Math.acos(angle / 2));
10211
+ axis.z = Q.z / Math.sin(Math.acos(angle / 2));
10212
+ } else {
10213
+ axis.x = 0;
10214
+ axis.y = 0;
10215
+ axis.z = 0;
10216
+ }
10217
+ return axis;
10218
+ }
8819
10219
 
8820
10220
  // NTO TESTED
8821
10221
  function quaternion_rotation_matrix(Q) {
@@ -8855,36 +10255,150 @@ function quaternion_rotation_matrix(Q) {
8855
10255
  return rot_matrix;
8856
10256
  }
8857
10257
 
8858
- },{}],12:[function(require,module,exports){
10258
+ // copnsole log graphics
10259
+ const LOG_WARN = exports.LOG_WARN = 'background: gray; color: yellow; font-size:10px';
10260
+ const LOG_INFO = exports.LOG_INFO = 'background: green; color: white; font-size:11px';
10261
+ const LOG_MATRIX = exports.LOG_MATRIX = "font-family: stormfaze;color: #lime; font-size:11px;text-shadow: 2px 2px 4px orangered;background: black;";
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;
10368
+
10369
+ },{"../engine/utils":14}],16:[function(require,module,exports){
8859
10370
  "use strict";
8860
10371
 
8861
10372
  Object.defineProperty(exports, "__esModule", {
8862
10373
  value: true
8863
10374
  });
8864
10375
  exports.default = void 0;
8865
- var _wgpuMatrix = require("wgpu-matrix");
8866
10376
  var _utils = require("../engine/utils");
10377
+ // import {vec3} from "wgpu-matrix";
10378
+
8867
10379
  class MatrixAmmo {
8868
10380
  constructor() {
8869
10381
  // THIS PATH IS PATH FROM PUBLIC FINAL FOLDER
8870
10382
  _utils.scriptManager.LOAD("./ammojs/ammo.js", "ammojs", undefined, undefined, this.init);
10383
+ this.lastRoll = '';
10384
+ this.presentScore = '';
8871
10385
  }
8872
10386
  init = () => {
8873
- // start
10387
+ // console.log('pre ammo')
8874
10388
  Ammo().then(Ammo => {
8875
10389
  // Physics variables
8876
10390
  this.dynamicsWorld = null;
8877
10391
  this.rigidBodies = [];
8878
10392
  this.Ammo = Ammo;
8879
10393
  this.lastUpdate = 0;
8880
- console.log("Ammo core loaded.");
10394
+ console.log("%c Ammo core loaded.", _utils.LOG_FUNNY);
8881
10395
  this.initPhysics();
8882
- dispatchEvent(new CustomEvent('AmmoReady', {}));
10396
+ // simulate async
10397
+ setTimeout(() => dispatchEvent(new CustomEvent('AmmoReady', {})), 100);
8883
10398
  });
8884
10399
  };
8885
10400
  initPhysics() {
8886
10401
  let Ammo = this.Ammo;
8887
-
8888
10402
  // Physics configuration
8889
10403
  var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration(),
8890
10404
  dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration),
@@ -8892,10 +10406,10 @@ class MatrixAmmo {
8892
10406
  solver = new Ammo.btSequentialImpulseConstraintSolver();
8893
10407
  this.dynamicsWorld = new Ammo.btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
8894
10408
  this.dynamicsWorld.setGravity(new Ammo.btVector3(0, -10, 0));
8895
- var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(50, 2, 50)),
10409
+ var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(70, 1, 70)),
8896
10410
  groundTransform = new Ammo.btTransform();
8897
10411
  groundTransform.setIdentity();
8898
- groundTransform.setOrigin(new Ammo.btVector3(0, -1, 0));
10412
+ groundTransform.setOrigin(new Ammo.btVector3(0, -4.45, 0));
8899
10413
  var mass = 0,
8900
10414
  isDynamic = mass !== 0,
8901
10415
  localInertia = new Ammo.btVector3(0, 0, 0);
@@ -8903,25 +10417,29 @@ class MatrixAmmo {
8903
10417
  var myMotionState = new Ammo.btDefaultMotionState(groundTransform),
8904
10418
  rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, groundShape, localInertia),
8905
10419
  body = new Ammo.btRigidBody(rbInfo);
10420
+ body.name = 'ground';
10421
+ this.ground = body;
8906
10422
  this.dynamicsWorld.addRigidBody(body);
8907
10423
  // this.rigidBodies.push(body);
10424
+ // add collide event
10425
+ this.detectCollision();
8908
10426
  }
8909
10427
  addPhysics(MEObject, pOptions) {
8910
10428
  if (pOptions.geometry == "Sphere") {
8911
10429
  this.addPhysicsSphere(MEObject, pOptions);
8912
10430
  } else if (pOptions.geometry == "Cube") {
8913
- //
10431
+ this.addPhysicsBox(MEObject, pOptions);
8914
10432
  }
8915
10433
  }
8916
10434
  addPhysicsSphere(MEObject, pOptions) {
8917
10435
  let Ammo = this.Ammo;
8918
- var colShape = new Ammo.btSphereShape(1),
10436
+ var colShape = new Ammo.btSphereShape(pOptions.radius),
8919
10437
  startTransform = new Ammo.btTransform();
8920
10438
  startTransform.setIdentity();
8921
10439
  var mass = 1;
8922
10440
  var localInertia = new Ammo.btVector3(0, 0, 0);
8923
10441
  colShape.calculateLocalInertia(mass, localInertia);
8924
- startTransform.setOrigin(new Ammo.btVector3(0, 15, -10));
10442
+ startTransform.setOrigin(new Ammo.btVector3(pOptions.position.x, pOptions.position.y, pOptions.position.z));
8925
10443
  var myMotionState = new Ammo.btDefaultMotionState(startTransform),
8926
10444
  rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia),
8927
10445
  body = new Ammo.btRigidBody(rbInfo);
@@ -8930,6 +10448,168 @@ class MatrixAmmo {
8930
10448
  this.rigidBodies.push(body);
8931
10449
  return body;
8932
10450
  }
10451
+ addPhysicsBox(MEObject, pOptions) {
10452
+ const FLAGS = {
10453
+ TEST_NIDZA: 3,
10454
+ CF_KINEMATIC_OBJECT: 2
10455
+ };
10456
+ let Ammo = this.Ammo;
10457
+ // improve this - scale by comp
10458
+ var colShape = new Ammo.btBoxShape(new Ammo.btVector3(pOptions.scale[0], pOptions.scale[1], pOptions.scale[2])),
10459
+ startTransform = new Ammo.btTransform();
10460
+ startTransform.setIdentity();
10461
+ var mass = pOptions.mass;
10462
+ var localInertia = new Ammo.btVector3(0, 0, 0);
10463
+ colShape.calculateLocalInertia(mass, localInertia);
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
+
10475
+ var myMotionState = new Ammo.btDefaultMotionState(startTransform),
10476
+ rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia),
10477
+ body = new Ammo.btRigidBody(rbInfo);
10478
+ if (pOptions.mass == 0 && typeof pOptions.state == 'undefined' && typeof pOptions.collide == 'undefined') {
10479
+ body.setActivationState(2);
10480
+ body.setCollisionFlags(FLAGS.CF_KINEMATIC_OBJECT);
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);
10486
+ } else {
10487
+ body.setActivationState(4);
10488
+ }
10489
+ // console.log('what is name.', pOptions.name)
10490
+ body.name = pOptions.name;
10491
+ body.MEObject = MEObject;
10492
+ this.dynamicsWorld.addRigidBody(body);
10493
+ this.rigidBodies.push(body);
10494
+ return body;
10495
+ }
10496
+ setBodyVelocity(body, x, y, z) {
10497
+ var tbv30 = new Ammo.btVector3();
10498
+ tbv30.setValue(x, y, z);
10499
+ body.setLinearVelocity(tbv30);
10500
+ }
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
+ }
10511
+ let pos = new Ammo.btVector3();
10512
+ // let quat = new Ammo.btQuaternion();
10513
+ pos = body.getWorldTransform().getOrigin();
10514
+ let localRot = body.getWorldTransform().getRotation();
10515
+ // console.log('pre pos x:', pos.x(), " y : ", pos.y(), " z:", pos.z())
10516
+ pos.setX(pos.x() + x);
10517
+ pos.setY(pos.y() + y);
10518
+ pos.setZ(pos.z() + z);
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);
10524
+ let physicsBody = body;
10525
+ let ms = physicsBody.getMotionState();
10526
+ if (ms) {
10527
+ var tmpTrans = new Ammo.btTransform();
10528
+
10529
+ // quat.setValue(quat.x(), quat.y(), quat.z(), quat.w());
10530
+ tmpTrans.setIdentity();
10531
+ tmpTrans.setOrigin(pos);
10532
+ tmpTrans.setRotation(localRot);
10533
+ ms.setWorldTransform(tmpTrans);
10534
+ }
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
+ }
10612
+ }
8933
10613
  updatePhysics() {
8934
10614
  // Step world
8935
10615
  this.dynamicsWorld.stepSimulation(1 / 60, 10);
@@ -8943,29 +10623,22 @@ class MatrixAmmo {
8943
10623
  var _z = trans.getOrigin().z().toFixed(2);
8944
10624
  body.MEObject.position.setPosition(_x, _y, _z);
8945
10625
  var test = trans.getRotation();
8946
- // var testAxis = test.getAxis();
8947
- // var testAngle = test.getAngle()
8948
- // testAxis.x()
8949
- // console.log("world axis X = " + testAxis.x());
8950
- console.log("world axis X = " + test.x());
8951
- console.log("world axis Y = " + test.y());
8952
- console.log("world axis Z = " + test.z());
8953
- console.log("world axis W = " + test.w());
8954
- var bug = (0, _utils.getAxisRot)({
8955
- x: test.x(),
8956
- y: test.y(),
8957
- z: test.z(),
8958
- w: test.w()
8959
- });
8960
- console.log('bug:', bug);
8961
- // transform.setRotation(new Ammo.btQuaternion(quat.x, quat.y, quat.z, quat.w));
10626
+ var testAxis = test.getAxis();
10627
+ test.normalize();
10628
+ body.MEObject.rotation.axis.x = testAxis.x();
10629
+ body.MEObject.rotation.axis.y = testAxis.y();
10630
+ body.MEObject.rotation.axis.z = testAxis.z();
10631
+ body.MEObject.rotation.matrixRotation = (0, _utils.quaternion_rotation_matrix)(test);
10632
+ body.MEObject.rotation.angle = (0, _utils.radToDeg)(parseFloat(test.getAngle().toFixed(2)));
8962
10633
  }
8963
10634
  });
10635
+ // collision detect
10636
+ this.detectCollision();
8964
10637
  }
8965
10638
  }
8966
10639
  exports.default = MatrixAmmo;
8967
10640
 
8968
- },{"../engine/utils":11,"wgpu-matrix":3}],13:[function(require,module,exports){
10641
+ },{"../engine/utils":14}],17:[function(require,module,exports){
8969
10642
  "use strict";
8970
10643
 
8971
10644
  Object.defineProperty(exports, "__esModule", {
@@ -8994,7 +10667,7 @@ struct FragmentInput {
8994
10667
  }
8995
10668
 
8996
10669
  const albedo = vec3f(0.9);
8997
- const ambientFactor = 0.2;
10670
+ const ambientFactor = 0.7;
8998
10671
 
8999
10672
  @fragment
9000
10673
  fn main(input : FragmentInput) -> @location(0) vec4f {
@@ -9013,15 +10686,17 @@ fn main(input : FragmentInput) -> @location(0) vec4f {
9013
10686
  }
9014
10687
  }
9015
10688
  visibility /= 9.0;
9016
-
9017
10689
  let lambertFactor = max(dot(normalize(scene.lightPos - input.fragPos), normalize(input.fragNorm)), 0.0);
9018
10690
  let lightingFactor = min(ambientFactor + visibility * lambertFactor, 1.0);
9019
10691
  let textureColor = textureSample(meshTexture, meshSampler, input.uv);
9020
10692
 
9021
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);
9022
10697
  }`;
9023
10698
 
9024
- },{}],14:[function(require,module,exports){
10699
+ },{}],18:[function(require,module,exports){
9025
10700
  "use strict";
9026
10701
 
9027
10702
  Object.defineProperty(exports, "__esModule", {
@@ -9065,7 +10740,7 @@ fn vertexMain(input: VertexInput) -> VertexOutput {
9065
10740
  @group(1) @binding(2) var meshTexture: texture_2d<f32>;
9066
10741
 
9067
10742
  // Static directional lighting
9068
- const lightDir = vec3f(1, 1, 1);
10743
+ const lightDir = vec3f(0, 1, 0);
9069
10744
  const dirColor = vec3(1);
9070
10745
  const ambientColor = vec3f(0.05);
9071
10746
 
@@ -9079,7 +10754,7 @@ fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {
9079
10754
  return vec4f(textureColor.rgb * lightColor, textureColor.a);
9080
10755
  }`;
9081
10756
 
9082
- },{}],15:[function(require,module,exports){
10757
+ },{}],19:[function(require,module,exports){
9083
10758
  "use strict";
9084
10759
 
9085
10760
  Object.defineProperty(exports, "__esModule", {
@@ -9136,7 +10811,7 @@ fn main(
9136
10811
  }
9137
10812
  `;
9138
10813
 
9139
- },{}],16:[function(require,module,exports){
10814
+ },{}],20:[function(require,module,exports){
9140
10815
  "use strict";
9141
10816
 
9142
10817
  Object.defineProperty(exports, "__esModule", {
@@ -9160,11 +10835,61 @@ struct Model {
9160
10835
  fn main(
9161
10836
  @location(0) position: vec3f
9162
10837
  ) -> @builtin(position) vec4f {
9163
- return scene.lightViewProjMatrix * model.modelMatrix * vec4(position, 1.0);
10838
+ return scene.lightViewProjMatrix * model.modelMatrix * vec4(position, 1);
9164
10839
  }
9165
10840
  `;
9166
10841
 
9167
- },{}],17:[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){
9168
10893
  "use strict";
9169
10894
 
9170
10895
  Object.defineProperty(exports, "__esModule", {
@@ -9179,6 +10904,8 @@ var _mesh = _interopRequireDefault(require("./engine/mesh.js"));
9179
10904
  var _meshObj = _interopRequireDefault(require("./engine/mesh-obj.js"));
9180
10905
  var _matrixAmmo = _interopRequireDefault(require("./physics/matrix-ammo.js"));
9181
10906
  var _utils = require("./engine/utils.js");
10907
+ var _lang = require("./multilang/lang.js");
10908
+ var _sounds = require("./sounds/sounds.js");
9182
10909
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9183
10910
  class MatrixEngineWGPU {
9184
10911
  mainRenderBundle = [];
@@ -9192,6 +10919,7 @@ class MatrixEngineWGPU {
9192
10919
  depthStoreOp: 'store'
9193
10920
  };
9194
10921
  matrixAmmo = new _matrixAmmo.default();
10922
+ matrixSounds = new _sounds.MatrixSounds();
9195
10923
 
9196
10924
  // The input handler
9197
10925
  constructor(options, callback) {
@@ -9240,6 +10968,18 @@ class MatrixEngineWGPU {
9240
10968
  position: initialCameraPosition
9241
10969
  })
9242
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
+ }
9243
10983
  this.init({
9244
10984
  canvas,
9245
10985
  callback
@@ -9251,7 +10991,17 @@ class MatrixEngineWGPU {
9251
10991
  }) => {
9252
10992
  this.canvas = canvas;
9253
10993
  this.adapter = await navigator.gpu.requestAdapter();
9254
- 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
+
9255
11005
  this.context = canvas.getContext('webgpu');
9256
11006
  const devicePixelRatio = window.devicePixelRatio;
9257
11007
  canvas.width = canvas.clientWidth * devicePixelRatio;
@@ -9263,40 +11013,14 @@ class MatrixEngineWGPU {
9263
11013
  alphaMode: 'premultiplied'
9264
11014
  });
9265
11015
  if (this.options.useSingleRenderPass == true) {
9266
- this.makeDefaultRenderPassDescriptor();
9267
11016
  this.frame = this.frameSinglePass;
9268
11017
  } else {
9269
- // must be
9270
11018
  this.frame = this.framePassPerObject;
9271
11019
  }
9272
11020
  this.run(callback);
9273
11021
  };
9274
- makeDefaultRenderPassDescriptor = () => {
9275
- this.depthTexture = this.device.createTexture({
9276
- size: [this.canvas.width, this.canvas.height],
9277
- format: 'depth24plus',
9278
- usage: GPUTextureUsage.RENDER_ATTACHMENT
9279
- });
9280
- this.renderPassDescriptor = {
9281
- colorAttachments: [{
9282
- view: undefined,
9283
- clearValue: {
9284
- r: 0.0,
9285
- g: 0.0,
9286
- b: 0.0,
9287
- a: 1.0
9288
- },
9289
- loadOp: 'clear',
9290
- storeOp: 'store'
9291
- }],
9292
- depthStencilAttachment: {
9293
- view: this.depthTexture.createView(),
9294
- depthClearValue: 1.0,
9295
- depthLoadOp: 'clear',
9296
- depthStoreOp: 'store'
9297
- }
9298
- };
9299
- };
11022
+
11023
+ // Not in use for now
9300
11024
  addCube = o => {
9301
11025
  if (typeof o === 'undefined') {
9302
11026
  var o = {
@@ -9358,6 +11082,8 @@ class MatrixEngineWGPU {
9358
11082
  let myCube1 = new _cube.default(this.canvas, this.device, this.context, o);
9359
11083
  this.mainRenderBundle.push(myCube1);
9360
11084
  };
11085
+
11086
+ // Not in use for now
9361
11087
  addBall = o => {
9362
11088
  if (typeof o === 'undefined') {
9363
11089
  var o = {
@@ -9419,6 +11145,8 @@ class MatrixEngineWGPU {
9419
11145
  let myBall1 = new _ball.default(this.canvas, this.device, this.context, o);
9420
11146
  this.mainRenderBundle.push(myBall1);
9421
11147
  };
11148
+
11149
+ // Not in use for now
9422
11150
  addMesh = o => {
9423
11151
  if (typeof o.position === 'undefined') {
9424
11152
  o.position = {
@@ -9464,6 +11192,9 @@ class MatrixEngineWGPU {
9464
11192
  this.mainRenderBundle.push(myMesh1);
9465
11193
  };
9466
11194
  addMeshObj = o => {
11195
+ if (typeof o.name === 'undefined') {
11196
+ o.name = (0, _utils.genName)(9);
11197
+ }
9467
11198
  if (typeof o.position === 'undefined') {
9468
11199
  o.position = {
9469
11200
  x: 0,
@@ -9492,30 +11223,56 @@ class MatrixEngineWGPU {
9492
11223
  o.mainCameraParams = this.mainCameraParams;
9493
11224
  }
9494
11225
  if (typeof o.scale === 'undefined') {
9495
- o.scale = 1;
11226
+ o.scale = [1, 1, 1];
11227
+ }
11228
+ if (typeof o.raycast === 'undefined') {
11229
+ o.raycast = {
11230
+ enabled: false
11231
+ };
9496
11232
  }
9497
11233
  o.entityArgPass = this.entityArgPass;
9498
11234
  o.cameras = this.cameras;
9499
- if (typeof o.name === 'undefined') {
9500
- o.name = 'random' + Math.random();
9501
- }
11235
+ // if(typeof o.name === 'undefined') {o.name = 'random' + Math.random();}
9502
11236
  if (typeof o.mesh === 'undefined') {
11237
+ _utils.mb.error('arg mesh is empty for ', o.name);
9503
11238
  throw console.error('arg mesh is empty...');
9504
11239
  return;
9505
11240
  }
9506
11241
  if (typeof o.physics === 'undefined') {
9507
11242
  o.physics = {
9508
- enabled: false,
9509
- geometry: "Sphere"
11243
+ scale: [1, 1, 1],
11244
+ enabled: true,
11245
+ geometry: "Sphere",
11246
+ radius: o.scale,
11247
+ name: o.name,
11248
+ rotation: o.rotation
9510
11249
  };
9511
11250
  }
9512
11251
  if (typeof o.physics.enabled === 'undefined') {
9513
- o.physics.enabled = false;
11252
+ o.physics.enabled = true;
9514
11253
  }
9515
11254
  if (typeof o.physics.geometry === 'undefined') {
9516
11255
  o.physics.geometry = "Sphere";
9517
11256
  }
9518
- // console.log('Mesh procedure', o)
11257
+ if (typeof o.physics.radius === 'undefined') {
11258
+ o.physics.radius = o.scale;
11259
+ }
11260
+ if (typeof o.physics.mass === 'undefined') {
11261
+ o.physics.mass = 1;
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
+ }
11272
+
11273
+ // send same pos
11274
+ o.physics.position = o.position;
11275
+ // console.log('Mesh procedure', o)
9519
11276
  let myMesh1 = new _meshObj.default(this.canvas, this.device, this.context, o);
9520
11277
  if (o.physics.enabled == true) {
9521
11278
  this.matrixAmmo.addPhysics(myMesh1, o.physics);
@@ -9527,36 +11284,67 @@ class MatrixEngineWGPU {
9527
11284
  requestAnimationFrame(this.frame);
9528
11285
  }, 500);
9529
11286
  setTimeout(() => {
9530
- callback();
11287
+ callback(this);
9531
11288
  }, 20);
9532
11289
  }
11290
+ destroyProgram = () => {
11291
+ this.mainRenderBundle = undefined;
11292
+ this.canvas.remove();
11293
+ };
9533
11294
  frameSinglePass = () => {
9534
11295
  if (typeof this.mainRenderBundle == 'undefined') return;
9535
- let shadowPass = null;
9536
- let renderPass;
11296
+ try {
11297
+ let shadowPass = null;
11298
+ let renderPass;
11299
+ let commandEncoder = this.device.createCommandEncoder();
11300
+ this.mainRenderBundle.forEach((meItem, index) => {
11301
+ meItem.position.update();
11302
+ });
11303
+ this.matrixAmmo.updatePhysics();
11304
+ this.mainRenderBundle.forEach((meItem, index) => {
11305
+ meItem.draw(commandEncoder);
11306
+ shadowPass = commandEncoder.beginRenderPass(meItem.shadowPassDescriptor);
11307
+ shadowPass.setPipeline(meItem.shadowPipeline);
11308
+ meItem.drawShadows(shadowPass);
11309
+ shadowPass.end();
11310
+ });
11311
+ this.mainRenderBundle.forEach((meItem, index) => {
11312
+ if (index == 0) {
11313
+ renderPass = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
11314
+ renderPass.setPipeline(meItem.pipeline);
11315
+ }
11316
+ });
11317
+ this.mainRenderBundle.forEach((meItem, index) => {
11318
+ meItem.drawElements(renderPass);
11319
+ });
11320
+ if (renderPass) renderPass.end();
11321
+ this.device.queue.submit([commandEncoder.finish()]);
11322
+ requestAnimationFrame(this.frame);
11323
+ } catch (err) {
11324
+ console.log('%cDraw func (err):' + err, _utils.LOG_WARN);
11325
+ requestAnimationFrame(this.frame);
11326
+ }
11327
+ };
11328
+ framePassPerObject = () => {
11329
+ // console.log('framePassPerObject')
9537
11330
  let commandEncoder = this.device.createCommandEncoder();
9538
- this.mainRenderBundle.forEach((meItem, index) => {
9539
- meItem.position.update();
9540
- });
11331
+ this.rbContainer = [];
11332
+ let passEncoder;
9541
11333
  this.mainRenderBundle.forEach((meItem, index) => {
9542
11334
  meItem.draw(commandEncoder);
9543
- shadowPass = commandEncoder.beginRenderPass(meItem.shadowPassDescriptor);
9544
- shadowPass.setPipeline(meItem.shadowPipeline);
9545
- meItem.drawShadows(shadowPass);
9546
- shadowPass.end();
9547
- });
9548
- this.mainRenderBundle.forEach((meItem, index) => {
9549
- if (index == 0) renderPass = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
9550
- if (index == 1) renderPass.setPipeline(meItem.pipeline);
9551
- });
9552
- this.mainRenderBundle.forEach((meItem, index) => {
9553
- meItem.drawElements(renderPass);
11335
+ if (meItem.renderBundle) {
11336
+ this.rbContainer.push(meItem.renderBundle);
11337
+ passEncoder = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
11338
+ passEncoder.executeBundles(this.rbContainer);
11339
+ passEncoder.end();
11340
+ } else {
11341
+ meItem.draw(commandEncoder);
11342
+ }
9554
11343
  });
9555
- renderPass.end();
9556
11344
  this.device.queue.submit([commandEncoder.finish()]);
9557
11345
  requestAnimationFrame(this.frame);
9558
11346
  };
9559
11347
  }
9560
11348
  exports.default = MatrixEngineWGPU;
9561
11349
 
9562
- },{"./engine/ball.js":4,"./engine/cube.js":5,"./engine/engine.js":6,"./engine/mesh-obj.js":9,"./engine/mesh.js":10,"./engine/utils.js":11,"./physics/matrix-ammo.js":12,"wgpu-matrix":3}]},{},[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]);