matrix-engine-wgpu 1.0.5 → 1.1.0

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 (88) 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 +5 -2
  5. package/dev.md +460 -0
  6. package/empty.js +7 -6
  7. package/examples/games/jamb/jamb.js +1127 -0
  8. package/examples/load-obj-file.js +67 -37
  9. package/examples/unlit-textures.js +26 -23
  10. package/examples.js +35 -3
  11. package/main.js +441 -43
  12. package/non-project-files/dev.txt +21 -0
  13. package/non-project-files/image1.png +0 -0
  14. package/non-project-files/image6.png +0 -0
  15. package/package.json +50 -41
  16. package/public/app.js +11409 -8893
  17. package/public/css/style.css +376 -112
  18. package/public/empty.html +1 -1
  19. package/public/empty.js +9890 -8885
  20. package/public/examples.html +10 -8
  21. package/public/examples.js +945 -203
  22. package/public/index.html +5 -7
  23. package/public/manifest copy.web +35 -0
  24. package/public/res/audios/block.mp3 +0 -0
  25. package/public/res/audios/dice1.mp3 +0 -0
  26. package/public/res/audios/dice2.mp3 +0 -0
  27. package/public/res/audios/start.mp3 +0 -0
  28. package/public/res/fonts/Accuratist.ttf +0 -0
  29. package/public/res/fonts/Closeness.ttf +0 -0
  30. package/public/res/fonts/WARGAMES.TTF +0 -0
  31. package/public/res/fonts/readme.txt +5 -0
  32. package/public/res/fonts/stormfaze.ttf +0 -0
  33. package/public/res/meshes/blender/cube.blend +0 -0
  34. package/public/res/meshes/blender/cube.blend1 +0 -0
  35. package/public/res/meshes/blender/cube.mtl +12 -0
  36. package/public/res/meshes/blender/cube.obj +46 -0
  37. package/public/res/meshes/blender/cube.png +0 -0
  38. package/public/res/meshes/blender/cubeSmartUV.blend +0 -0
  39. package/public/res/meshes/blender/cubeSmartUV.mtl +12 -0
  40. package/public/res/meshes/blender/cubeSmartUV.obj +46 -0
  41. package/public/res/meshes/blender/sphepe.blend +0 -0
  42. package/public/res/meshes/blender/sphepe.blend1 +0 -0
  43. package/public/res/meshes/blender/sphere.mtl +10 -0
  44. package/public/res/meshes/blender/sphere.obj +3402 -0
  45. package/public/res/meshes/jamb/bg.blend +0 -0
  46. package/public/res/meshes/jamb/bg.blend1 +0 -0
  47. package/public/res/meshes/jamb/bg.mtl +12 -0
  48. package/public/res/meshes/jamb/bg.obj +17 -0
  49. package/public/res/meshes/jamb/bg.png +0 -0
  50. package/public/res/meshes/jamb/dice-default.png +0 -0
  51. package/public/res/meshes/jamb/dice-mark.png +0 -0
  52. package/public/res/meshes/jamb/dice.mtl +12 -0
  53. package/public/res/meshes/jamb/dice.obj +40 -0
  54. package/public/res/meshes/jamb/dice.png +0 -0
  55. package/public/res/meshes/jamb/jamb-title.mtl +12 -0
  56. package/public/res/meshes/jamb/jamb-title.obj +26008 -0
  57. package/public/res/meshes/jamb/jamb.blend +0 -0
  58. package/public/res/meshes/jamb/jamb.blend1 +0 -0
  59. package/public/res/meshes/jamb/logo.png +0 -0
  60. package/public/res/meshes/jamb/nidzaDice.blend +0 -0
  61. package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
  62. package/public/res/meshes/jamb/pile.blend +0 -0
  63. package/public/res/meshes/jamb/simpleCube.blend +0 -0
  64. package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
  65. package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
  66. package/public/res/meshes/jamb/text.png +0 -0
  67. package/public/res/multilang/en.json +27 -0
  68. package/public/res/multilang/sr.json +27 -0
  69. package/public/test.html +636 -0
  70. package/public/three-test.js +165 -0
  71. package/public/worker.html +1 -1
  72. package/readme.md +232 -116
  73. package/src/engine/cube.js +10 -5
  74. package/src/engine/engine.js +3 -9
  75. package/src/engine/loader-obj.js +9 -6
  76. package/src/engine/matrix-class.js +240 -202
  77. package/src/engine/mesh-obj.js +605 -525
  78. package/src/engine/mesh.js +476 -0
  79. package/src/engine/raycast-test.js +93 -0
  80. package/src/engine/utils.js +129 -15
  81. package/src/multilang/lang.js +35 -0
  82. package/src/physics/matrix-ammo.js +204 -30
  83. package/src/shaders/fragment.wgsl.js +4 -2
  84. package/src/shaders/shaders.js +1 -1
  85. package/src/shaders/vertexShadow.wgsl.js +1 -1
  86. package/src/sounds/sounds.js +47 -0
  87. package/src/world.js +312 -236
  88. package/src/engine/matrix-mesh.js +0 -49
@@ -1,97 +1,304 @@
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":13}],2:[function(require,module,exports){
41
+ "use strict";
42
+
43
+ Object.defineProperty(exports, "__esModule", {
44
+ value: true
45
+ });
46
+ exports.loadJamb = 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
+ // import MatrixEngineWGPU from "./src/world.js";
52
+ // import {downloadMeshes} from './src/engine/loader-obj.js';
53
+
54
+ var loadJamb = function () {
55
+ let jamb = new _world.default({
56
+ useSingleRenderPass: true,
57
+ canvasSize: 'fullscreen',
58
+ mainCameraParams: {
59
+ type: 'arcball',
60
+ responseCoef: 1
61
+ }
62
+ }, () => {
63
+ addEventListener('AmmoReady', () => {
64
+ (0, _loaderObj.downloadMeshes)({
65
+ welcomeText: "./res/meshes/blender/piramyd.obj",
66
+ cube: "./res/meshes/blender/cube.obj"
67
+ }, onLoadObj);
68
+ });
69
+ function onLoadObj(m) {
70
+ jamb.myLoadedMeshes = m;
71
+ for (var key in m) {
72
+ console.log(`%c Loaded objs: ${key} `, _utils.LOG_MATRIX);
73
+ }
74
+ jamb.addMeshObj({
75
+ position: {
76
+ x: 0,
77
+ y: 2,
78
+ z: -15
79
+ },
80
+ rotation: {
81
+ x: 0,
82
+ y: 0,
83
+ z: 0
84
+ },
85
+ rotationSpeed: {
86
+ x: 0,
87
+ y: 0,
88
+ z: 0
89
+ },
90
+ texturesPaths: ['./res/meshes/blender/cube.png'],
91
+ name: 'CubePhysics',
92
+ mesh: m.cube,
93
+ physics: {
94
+ enabled: true,
95
+ geometry: "Cube"
96
+ }
97
+ });
98
+ jamb.addMeshObj({
99
+ position: {
100
+ x: 0,
101
+ y: 1,
102
+ z: -120
103
+ },
104
+ rotation: {
105
+ x: 0,
106
+ y: 0,
107
+ z: 0
108
+ },
109
+ rotationSpeed: {
110
+ x: 0,
111
+ y: 0,
112
+ z: 0
113
+ },
114
+ texturesPaths: ['./res/meshes/blender/cube.png'],
115
+ name: 'welcomeTextPhysics',
116
+ mesh: m.welcomeText
117
+ // physics: {
118
+ // enabled: true,
119
+ // geometry: "Sphere"
120
+ // }
121
+ });
122
+ }
123
+ });
124
+ window.app = loadObjFile;
125
+ };
126
+ exports.loadJamb = loadJamb;
11
127
 
12
- },{"./examples/load-obj-file.js":2}],2:[function(require,module,exports){
128
+ },{"../../../src/engine/loader-obj.js":9,"../../../src/engine/utils.js":13,"../../../src/world.js":19}],3:[function(require,module,exports){
13
129
  "use strict";
14
130
 
15
131
  Object.defineProperty(exports, "__esModule", {
16
132
  value: true
17
133
  });
18
- exports.application = void 0;
134
+ exports.loadObjFile = void 0;
19
135
  var _world = _interopRequireDefault(require("../src/world.js"));
20
136
  var _loaderObj = require("../src/engine/loader-obj.js");
137
+ var _utils = require("../src/engine/utils.js");
21
138
  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
- };
139
+ // import MatrixEngineWGPU from "./src/world.js";
140
+ // import {downloadMeshes} from './src/engine/loader-obj.js';
141
+
142
+ var loadObjFile = function () {
143
+ let loadObjFile = new _world.default({
144
+ useSingleRenderPass: true,
145
+ canvasSize: 'fullscreen',
146
+ mainCameraParams: {
147
+ type: 'WASD',
148
+ responseCoef: 1000
149
+ }
150
+ }, () => {
151
+ addEventListener('AmmoReady', () => {
152
+ (0, _loaderObj.downloadMeshes)({
153
+ welcomeText: "./res/meshes/blender/piramyd.obj",
154
+ armor: "./res/meshes/obj/armor.obj",
155
+ sphere: "./res/meshes/blender/sphere.obj",
156
+ cube: "./res/meshes/blender/cube.obj"
157
+ }, onLoadObj);
158
+ });
159
+ function onLoadObj(m) {
160
+ loadObjFile.myLoadedMeshes = m;
161
+ for (var key in m) {
162
+ console.log(`%c Loaded objs: ${key} `, _utils.LOG_MATRIX);
163
+ }
164
+ loadObjFile.addMeshObj({
165
+ position: {
166
+ x: 0,
167
+ y: 2,
168
+ z: -10
169
+ },
170
+ rotation: {
171
+ x: 0,
172
+ y: 0,
173
+ z: 0
174
+ },
175
+ rotationSpeed: {
176
+ x: 0,
177
+ y: 0,
178
+ z: 0
179
+ },
180
+ texturesPaths: ['./res/meshes/blender/cube.png'],
181
+ name: 'CubePhysics',
182
+ mesh: m.cube,
183
+ physics: {
184
+ enabled: true,
185
+ geometry: "Cube"
186
+ }
187
+ });
188
+ loadObjFile.addMeshObj({
189
+ position: {
190
+ x: 0,
191
+ y: 2,
192
+ z: -10
193
+ },
194
+ rotation: {
195
+ x: 0,
196
+ y: 0,
197
+ z: 0
198
+ },
199
+ rotationSpeed: {
200
+ x: 0,
201
+ y: 0,
202
+ z: 0
203
+ },
204
+ texturesPaths: ['./res/meshes/blender/cube.png'],
205
+ name: 'SpherePhysics',
206
+ mesh: m.sphere,
207
+ physics: {
208
+ enabled: true,
209
+ geometry: "Sphere"
210
+ }
211
+ });
212
+ loadObjFile.addMeshObj({
213
+ position: {
214
+ x: 0,
215
+ y: 2,
216
+ z: -10
217
+ },
218
+ rotation: {
219
+ x: 0,
220
+ y: 0,
221
+ z: 0
222
+ },
223
+ rotationSpeed: {
224
+ x: 0,
225
+ y: 0,
226
+ z: 0
227
+ },
228
+ texturesPaths: ['./res/meshes/blender/cube.png'],
229
+ name: 'CubePhysics',
230
+ mesh: m.welcomeText,
231
+ physics: {
232
+ enabled: true,
233
+ geometry: "Cube"
234
+ }
235
+ });
236
+ }
237
+ });
238
+ window.app = loadObjFile;
239
+ };
240
+ exports.loadObjFile = loadObjFile;
64
241
 
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({
242
+ },{"../src/engine/loader-obj.js":9,"../src/engine/utils.js":13,"../src/world.js":19}],4:[function(require,module,exports){
243
+ "use strict";
244
+
245
+ Object.defineProperty(exports, "__esModule", {
246
+ value: true
247
+ });
248
+ exports.unlitTextures = void 0;
249
+ var _world = _interopRequireDefault(require("../src/world.js"));
250
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
251
+ var unlitTextures = function () {
252
+ let unlitTextures = new _world.default({
253
+ useSingleRenderPass: false,
254
+ canvasSize: 'fullscreen'
255
+ }, () => {
256
+ let c = {
257
+ scale: 2,
76
258
  position: {
259
+ x: -3,
260
+ y: 0,
261
+ z: -10
262
+ },
263
+ rotation: {
77
264
  x: 0,
78
265
  y: 0,
79
- z: -5
266
+ z: 0
80
267
  },
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;
268
+ rotationSpeed: {
269
+ x: 10,
270
+ y: 0,
271
+ z: 0
272
+ },
273
+ texturesPaths: ['./res/textures/rust.jpg']
274
+ };
275
+ let o = {
276
+ scale: 2,
277
+ position: {
278
+ x: 3,
279
+ y: 0,
280
+ z: -10
281
+ },
282
+ rotation: {
283
+ x: 0,
284
+ y: 45,
285
+ z: 0
286
+ },
287
+ rotationSpeed: {
288
+ x: 0,
289
+ y: 10,
290
+ z: 0
291
+ },
292
+ texturesPaths: ['./res/textures/rust.jpg']
293
+ };
294
+ unlitTextures.addBall(c);
295
+ unlitTextures.addCube(o);
296
+ });
297
+ window.app = unlitTextures;
298
+ };
299
+ exports.unlitTextures = unlitTextures;
93
300
 
94
- },{"../src/engine/loader-obj.js":7,"../src/world.js":16}],3:[function(require,module,exports){
301
+ },{"../src/world.js":19}],5:[function(require,module,exports){
95
302
  "use strict";
96
303
 
97
304
  Object.defineProperty(exports, "__esModule", {
@@ -5438,7 +5645,7 @@ function setDefaultType(ctor) {
5438
5645
  setDefaultType$1(ctor);
5439
5646
  }
5440
5647
 
5441
- },{}],4:[function(require,module,exports){
5648
+ },{}],6:[function(require,module,exports){
5442
5649
  "use strict";
5443
5650
 
5444
5651
  Object.defineProperty(exports, "__esModule", {
@@ -5459,7 +5666,7 @@ class MEBall {
5459
5666
  this.cameras = o.cameras;
5460
5667
  this.scale = o.scale;
5461
5668
  console.log('passed : o.mainCameraParams.responseCoef ', o.mainCameraParams.responseCoef);
5462
- this.cameraParams = {
5669
+ this.mainCameraParams = {
5463
5670
  type: o.mainCameraParams.type,
5464
5671
  responseCoef: o.mainCameraParams.responseCoef
5465
5672
  }; // | WASD 'arcball' };
@@ -5693,11 +5900,11 @@ class MEBall {
5693
5900
  getTransformationMatrix(pos) {
5694
5901
  // const viewMatrix = mat4.identity();
5695
5902
  const now = Date.now();
5696
- const deltaTime = (now - this.lastFrameMS) / this.cameraParams.responseCoef;
5903
+ const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
5697
5904
  this.lastFrameMS = now;
5698
5905
 
5699
5906
  // const viewMatrix = mat4.identity(); ORI
5700
- const camera = this.cameras[this.cameraParams.type];
5907
+ const camera = this.cameras[this.mainCameraParams.type];
5701
5908
  const viewMatrix = camera.update(deltaTime, this.inputHandler());
5702
5909
  _wgpuMatrix.mat4.translate(viewMatrix, _wgpuMatrix.vec3.fromValues(pos.x, pos.y, pos.z), viewMatrix);
5703
5910
  _wgpuMatrix.mat4.rotateX(viewMatrix, Math.PI * this.rotation.getRotX(), viewMatrix);
@@ -5845,7 +6052,7 @@ class MEBall {
5845
6052
  }
5846
6053
  exports.default = MEBall;
5847
6054
 
5848
- },{"../shaders/shaders":13,"./engine":6,"./matrix-class":8,"wgpu-matrix":3}],5:[function(require,module,exports){
6055
+ },{"../shaders/shaders":16,"./engine":8,"./matrix-class":10,"wgpu-matrix":5}],7:[function(require,module,exports){
5849
6056
  "use strict";
5850
6057
 
5851
6058
  Object.defineProperty(exports, "__esModule", {
@@ -5870,7 +6077,7 @@ class MECube {
5870
6077
  this.inputHandler = (0, _engine.createInputHandler)(window, canvas);
5871
6078
  this.cameras = o.cameras;
5872
6079
  console.log('passed : o.mainCameraParams.responseCoef ', o.mainCameraParams.responseCoef);
5873
- this.cameraParams = {
6080
+ this.mainCameraParams = {
5874
6081
  type: o.mainCameraParams.type,
5875
6082
  responseCoef: o.mainCameraParams.responseCoef
5876
6083
  }; // | WASD 'arcball' };
@@ -5880,6 +6087,9 @@ class MECube {
5880
6087
  code: _shaders.UNLIT_SHADER
5881
6088
  });
5882
6089
  this.texturesPaths = [];
6090
+
6091
+ // useUVShema4x2 pass this from top !
6092
+
5883
6093
  o.texturesPaths.forEach(t => {
5884
6094
  this.texturesPaths.push(t);
5885
6095
  });
@@ -5967,8 +6177,6 @@ class MECube {
5967
6177
  });
5968
6178
  this.transform = _wgpuMatrix.mat4.create();
5969
6179
  _wgpuMatrix.mat4.identity(this.transform);
5970
-
5971
- // Create one large central planet surrounded by a large ring of asteroids
5972
6180
  this.planet = this.createGeometry({
5973
6181
  scale: this.scale,
5974
6182
  useUVShema4x2: false
@@ -6107,11 +6315,11 @@ class MECube {
6107
6315
  }
6108
6316
  getTransformationMatrix(pos) {
6109
6317
  const now = Date.now();
6110
- const deltaTime = (now - this.lastFrameMS) / this.cameraParams.responseCoef;
6318
+ const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
6111
6319
  this.lastFrameMS = now;
6112
6320
 
6113
6321
  // const viewMatrix = mat4.identity(); ORI
6114
- const camera = this.cameras[this.cameraParams.type];
6322
+ const camera = this.cameras[this.mainCameraParams.type];
6115
6323
  const viewMatrix = camera.update(deltaTime, this.inputHandler());
6116
6324
  _wgpuMatrix.mat4.translate(viewMatrix, _wgpuMatrix.vec3.fromValues(pos.x, pos.y, pos.z), viewMatrix);
6117
6325
  _wgpuMatrix.mat4.rotateX(viewMatrix, Math.PI * this.rotation.getRotX(), viewMatrix);
@@ -6254,7 +6462,7 @@ class MECube {
6254
6462
  }
6255
6463
  exports.default = MECube;
6256
6464
 
6257
- },{"../shaders/shaders":13,"./engine":6,"./matrix-class":8,"wgpu-matrix":3}],6:[function(require,module,exports){
6465
+ },{"../shaders/shaders":16,"./engine":8,"./matrix-class":10,"wgpu-matrix":5}],8:[function(require,module,exports){
6258
6466
  "use strict";
6259
6467
 
6260
6468
  Object.defineProperty(exports, "__esModule", {
@@ -6263,6 +6471,7 @@ Object.defineProperty(exports, "__esModule", {
6263
6471
  exports.WASDCamera = exports.ArcballCamera = void 0;
6264
6472
  exports.createInputHandler = createInputHandler;
6265
6473
  var _wgpuMatrix = require("wgpu-matrix");
6474
+ var _utils = require("./utils");
6266
6475
  // Note: The code in this file does not use the 'dst' output parameter of functions in the
6267
6476
  // 'wgpu-matrix' library, so produces many temporary vectors and matrices.
6268
6477
  // This is intentional, as this sample prefers readability over performance.
@@ -6385,8 +6594,6 @@ class WASDCamera extends CameraBase {
6385
6594
  set velocity(vec) {
6386
6595
  _wgpuMatrix.vec3.copy(vec, this.velocity_);
6387
6596
  }
6388
-
6389
- // Construtor
6390
6597
  constructor(options) {
6391
6598
  super();
6392
6599
  if (options && (options.position || options.target)) {
@@ -6395,7 +6602,7 @@ class WASDCamera extends CameraBase {
6395
6602
  const forward = _wgpuMatrix.vec3.normalize(_wgpuMatrix.vec3.sub(target, position));
6396
6603
  this.recalculateAngles(forward);
6397
6604
  this.position = position;
6398
- console.log('camera postion:', position);
6605
+ // console.log(`%cCamera pos: ${position}`, LOG_INFO);
6399
6606
  }
6400
6607
  }
6401
6608
 
@@ -6593,9 +6800,7 @@ function lerp(a, b, s) {
6593
6800
  return _wgpuMatrix.vec3.addScaled(a, _wgpuMatrix.vec3.sub(b, a), s);
6594
6801
  }
6595
6802
 
6596
- // IMPUT
6597
-
6598
- // // Input holds as snapshot of input state
6803
+ // Input holds as snapshot of input state
6599
6804
  // export default interface Input {
6600
6805
  // // Digital input (e.g keyboard state)
6601
6806
  // readonly digital: {
@@ -6614,10 +6819,8 @@ function lerp(a, b, s) {
6614
6819
  // readonly touching: boolean;
6615
6820
  // };
6616
6821
  // }
6617
-
6618
6822
  // InputHandler is a function that when called, returns the current Input state.
6619
6823
  // export type InputHandler = () => Input;
6620
-
6621
6824
  // createInputHandler returns an InputHandler by attaching event handlers to the window and canvas.
6622
6825
  function createInputHandler(window, canvas) {
6623
6826
  let digital = {
@@ -6717,7 +6920,7 @@ function createInputHandler(window, canvas) {
6717
6920
  };
6718
6921
  }
6719
6922
 
6720
- },{"wgpu-matrix":3}],7:[function(require,module,exports){
6923
+ },{"./utils":13,"wgpu-matrix":5}],9:[function(require,module,exports){
6721
6924
  "use strict";
6722
6925
 
6723
6926
  Object.defineProperty(exports, "__esModule", {
@@ -7181,7 +7384,7 @@ function play(nameAni) {
7181
7384
  this.animation.currentAni = this.animation.anims[this.animation.anims.active].from;
7182
7385
  }
7183
7386
 
7184
- },{}],8:[function(require,module,exports){
7387
+ },{}],10:[function(require,module,exports){
7185
7388
  "use strict";
7186
7389
 
7187
7390
  Object.defineProperty(exports, "__esModule", {
@@ -7189,14 +7392,16 @@ Object.defineProperty(exports, "__esModule", {
7189
7392
  });
7190
7393
  exports.Rotation = exports.Position = void 0;
7191
7394
  var _utils = require("./utils");
7192
- // Sub classes for matrix-wgpu
7193
7395
  /**
7194
- * @description Base class
7396
+ * @description
7397
+ * Sub classes for matrix-wgpu
7398
+ * Base class
7195
7399
  * Position { x, y, z }
7196
7400
  */
7197
7401
 
7198
7402
  class Position {
7199
7403
  constructor(x, y, z) {
7404
+ console.log('TEST TYTPOF ', x);
7200
7405
  // Not in use for nwo this is from matrix-engine project [nameUniq]
7201
7406
  this.nameUniq = null;
7202
7407
  if (typeof x == 'undefined') x = 0;
@@ -7353,13 +7558,21 @@ class Rotation {
7353
7558
  y: 0,
7354
7559
  z: 0
7355
7560
  };
7561
+ this.angle = 0;
7562
+ this.axis = {
7563
+ x: 0,
7564
+ y: 0,
7565
+ z: 0
7566
+ };
7567
+ // not in use good for exstend logic
7568
+ this.matrixRotation = null;
7356
7569
  }
7357
7570
  getRotX() {
7358
7571
  if (this.rotationSpeed.x == 0) {
7359
7572
  return (0, _utils.degToRad)(this.x);
7360
7573
  } else {
7361
7574
  this.x = this.x + this.rotationSpeed.x * 0.001;
7362
- return this.x;
7575
+ return (0, _utils.degToRad)(this.x);
7363
7576
  }
7364
7577
  }
7365
7578
  getRotY() {
@@ -7367,7 +7580,7 @@ class Rotation {
7367
7580
  return (0, _utils.degToRad)(this.y);
7368
7581
  } else {
7369
7582
  this.y = this.y + this.rotationSpeed.y * 0.001;
7370
- return this.y;
7583
+ return (0, _utils.degToRad)(this.y);
7371
7584
  }
7372
7585
  }
7373
7586
  getRotZ() {
@@ -7375,13 +7588,13 @@ class Rotation {
7375
7588
  return (0, _utils.degToRad)(this.z);
7376
7589
  } else {
7377
7590
  this.z = this.z + this.rotationSpeed.z * 0.001;
7378
- return this.z;
7591
+ return (0, _utils.degToRad)(this.z);
7379
7592
  }
7380
7593
  }
7381
7594
  }
7382
7595
  exports.Rotation = Rotation;
7383
7596
 
7384
- },{"./utils":11}],9:[function(require,module,exports){
7597
+ },{"./utils":13}],11:[function(require,module,exports){
7385
7598
  "use strict";
7386
7599
 
7387
7600
  Object.defineProperty(exports, "__esModule", {
@@ -7394,6 +7607,7 @@ var _engine = require("./engine");
7394
7607
  var _vertexShadow = require("../shaders/vertexShadow.wgsl");
7395
7608
  var _fragment = require("../shaders/fragment.wgsl");
7396
7609
  var _vertex = require("../shaders/vertex.wgsl");
7610
+ var _utils = require("./utils");
7397
7611
  class MEMeshObj {
7398
7612
  constructor(canvas, device, context, o) {
7399
7613
  this.done = false;
@@ -7404,10 +7618,10 @@ class MEMeshObj {
7404
7618
  // Mesh stuff
7405
7619
  this.mesh = o.mesh;
7406
7620
  this.mesh.uvs = this.mesh.textures;
7407
- console.log('mesh obj: ', this.mesh);
7621
+ console.log(`%c Mesh loaded: ${o.name}`, _utils.LOG_INFO);
7408
7622
  this.inputHandler = (0, _engine.createInputHandler)(window, canvas);
7409
7623
  this.cameras = o.cameras;
7410
- this.cameraParams = {
7624
+ this.mainCameraParams = {
7411
7625
  type: o.mainCameraParams.type,
7412
7626
  responseCoef: o.mainCameraParams.responseCoef
7413
7627
  };
@@ -7431,7 +7645,7 @@ class MEMeshObj {
7431
7645
  this.modelViewProjectionMatrix = _wgpuMatrix.mat4.create();
7432
7646
  // console.log('cube added texturesPaths: ', this.texturesPaths)
7433
7647
  this.loadTex0(this.texturesPaths, device).then(() => {
7434
- console.log('loaded tex buffer for mesh:', this.texture0);
7648
+ // console.log('loaded tex buffer for mesh:', this.texture0)
7435
7649
  resolve();
7436
7650
  });
7437
7651
  });
@@ -7715,23 +7929,23 @@ class MEMeshObj {
7715
7929
  // Rotates the camera around the origin based on time.
7716
7930
  this.getTransformationMatrix = pos => {
7717
7931
  const now = Date.now();
7718
- const deltaTime = (now - this.lastFrameMS) / this.cameraParams.responseCoef;
7932
+ const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
7719
7933
  this.lastFrameMS = now;
7720
-
7721
7934
  // const this.viewMatrix = mat4.identity()
7722
- const camera = this.cameras[this.cameraParams.type];
7935
+ const camera = this.cameras[this.mainCameraParams.type];
7723
7936
  this.viewMatrix = camera.update(deltaTime, this.inputHandler());
7724
7937
  _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);
7938
+ _wgpuMatrix.mat4.rotate(this.viewMatrix, _wgpuMatrix.vec3.fromValues(this.rotation.axis.x, this.rotation.axis.y, this.rotation.axis.z), (0, _utils.degToRad)(this.rotation.angle), this.viewMatrix);
7939
+ // mat4.rotateX(this.viewMatrix, this.rotation.getRotX(), this.viewMatrix);
7940
+ // mat4.rotateY(this.viewMatrix, this.rotation.getRotY(), this.viewMatrix);
7941
+ // mat4.rotateZ(this.viewMatrix, this.rotation.getRotZ(), this.viewMatrix);
7728
7942
  _wgpuMatrix.mat4.multiply(this.projectionMatrix, this.viewMatrix, this.modelViewProjectionMatrix);
7729
7943
  return this.modelViewProjectionMatrix;
7730
7944
  };
7731
7945
  this.upVector = _wgpuMatrix.vec3.fromValues(0, 1, 0);
7732
7946
  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);
7947
+ this.lightPosition = _wgpuMatrix.vec3.fromValues(0, 10, -2);
7948
+ this.lightViewMatrix = _wgpuMatrix.mat4.lookAt(this.lightPosition, this.origin, this.upVector);
7735
7949
  const lightProjectionMatrix = _wgpuMatrix.mat4.create();
7736
7950
  {
7737
7951
  const left = -80;
@@ -7742,15 +7956,15 @@ class MEMeshObj {
7742
7956
  const far = 300;
7743
7957
  _wgpuMatrix.mat4.ortho(left, right, bottom, top, near, far, lightProjectionMatrix);
7744
7958
  }
7745
- const lightViewProjMatrix = _wgpuMatrix.mat4.multiply(lightProjectionMatrix, lightViewMatrix);
7959
+ this.lightViewProjMatrix = _wgpuMatrix.mat4.multiply(lightProjectionMatrix, this.lightViewMatrix);
7746
7960
 
7747
7961
  // looks like affect on transformations for now const 0
7748
7962
  const modelMatrix = _wgpuMatrix.mat4.translation([0, 0, 0]);
7749
7963
  // The camera/light aren't moving, so write them into buffers now.
7750
7964
  {
7751
- const lightMatrixData = lightViewProjMatrix; // as Float32Array;
7965
+ const lightMatrixData = this.lightViewProjMatrix; // as Float32Array;
7752
7966
  this.device.queue.writeBuffer(this.sceneUniformBuffer, 0, lightMatrixData.buffer, lightMatrixData.byteOffset, lightMatrixData.byteLength);
7753
- const lightData = lightPosition;
7967
+ const lightData = this.lightPosition;
7754
7968
  this.device.queue.writeBuffer(this.sceneUniformBuffer, 128, lightData.buffer, lightData.byteOffset, lightData.byteLength);
7755
7969
  const modelData = modelMatrix;
7756
7970
  this.device.queue.writeBuffer(this.modelUniformBuffer, 0, modelData.buffer, modelData.byteOffset, modelData.byteLength);
@@ -7767,6 +7981,46 @@ class MEMeshObj {
7767
7981
  this.done = true;
7768
7982
  });
7769
7983
  }
7984
+ updateLightsTest = position => {
7985
+ console.log('test !');
7986
+ ////////////////////////
7987
+ this.lightPosition = _wgpuMatrix.vec3.fromValues(position[0], position[1], position[2]);
7988
+ this.lightViewMatrix = _wgpuMatrix.mat4.lookAt(this.lightPosition, this.origin, this.upVector);
7989
+ const lightProjectionMatrix = _wgpuMatrix.mat4.create();
7990
+ {
7991
+ const left = -80;
7992
+ const right = 80;
7993
+ const bottom = -80;
7994
+ const top = 80;
7995
+ const near = -200;
7996
+ const far = 300;
7997
+ _wgpuMatrix.mat4.ortho(left, right, bottom, top, near, far, lightProjectionMatrix);
7998
+ }
7999
+ this.lightViewProjMatrix = _wgpuMatrix.mat4.multiply(lightProjectionMatrix, this.lightViewMatrix);
8000
+
8001
+ // looks like affect on transformations for now const 0
8002
+ const modelMatrix = _wgpuMatrix.mat4.translation([0, 0, 0]);
8003
+ // The camera/light aren't moving, so write them into buffers now.
8004
+ {
8005
+ const lightMatrixData = this.lightViewProjMatrix; // as Float32Array;
8006
+ this.device.queue.writeBuffer(this.sceneUniformBuffer, 0, lightMatrixData.buffer, lightMatrixData.byteOffset, lightMatrixData.byteLength);
8007
+ const lightData = this.lightPosition;
8008
+ this.device.queue.writeBuffer(this.sceneUniformBuffer, 128, lightData.buffer, lightData.byteOffset, lightData.byteLength);
8009
+ const modelData = modelMatrix;
8010
+ this.device.queue.writeBuffer(this.modelUniformBuffer, 0, modelData.buffer, modelData.byteOffset, modelData.byteLength);
8011
+ }
8012
+ this.shadowPassDescriptor = {
8013
+ colorAttachments: [],
8014
+ depthStencilAttachment: {
8015
+ view: this.shadowDepthTextureView,
8016
+ depthClearValue: 1.0,
8017
+ depthLoadOp: 'clear',
8018
+ depthStoreOp: 'store'
8019
+ }
8020
+ };
8021
+
8022
+ ///////////////////////
8023
+ };
7770
8024
  async loadTex0(texturesPaths, device) {
7771
8025
  this.sampler = device.createSampler({
7772
8026
  magFilter: 'linear',
@@ -7793,35 +8047,29 @@ class MEMeshObj {
7793
8047
  const transformationMatrix = this.getTransformationMatrix(this.position);
7794
8048
  this.device.queue.writeBuffer(this.sceneUniformBuffer, 64, transformationMatrix.buffer, transformationMatrix.byteOffset, transformationMatrix.byteLength);
7795
8049
  this.renderPassDescriptor.colorAttachments[0].view = this.context.getCurrentTexture().createView();
7796
- {
7797
- const shadowPass = commandEncoder.beginRenderPass(this.shadowPassDescriptor);
7798
- shadowPass.setPipeline(this.shadowPipeline);
7799
- shadowPass.setBindGroup(0, this.sceneBindGroupForShadow);
7800
- shadowPass.setBindGroup(1, this.modelBindGroup);
7801
- shadowPass.setVertexBuffer(0, this.vertexBuffer);
7802
- shadowPass.setVertexBuffer(1, this.vertexNormalsBuffer);
7803
- shadowPass.setVertexBuffer(2, this.vertexTexCoordsBuffer);
7804
- shadowPass.setIndexBuffer(this.indexBuffer, 'uint16');
7805
- shadowPass.drawIndexed(this.indexCount);
7806
- shadowPass.end();
7807
- }
7808
- {
7809
- const renderPass = commandEncoder.beginRenderPass(this.renderPassDescriptor);
7810
- renderPass.setPipeline(this.pipeline);
7811
- renderPass.setBindGroup(0, this.sceneBindGroupForRender);
7812
- renderPass.setBindGroup(1, this.modelBindGroup);
7813
- renderPass.setVertexBuffer(0, this.vertexBuffer);
7814
- renderPass.setVertexBuffer(1, this.vertexNormalsBuffer);
7815
- renderPass.setVertexBuffer(2, this.vertexTexCoordsBuffer);
7816
- renderPass.setIndexBuffer(this.indexBuffer, 'uint16');
7817
- renderPass.drawIndexed(this.indexCount);
7818
- renderPass.end();
7819
- }
8050
+ };
8051
+ drawElements = renderPass => {
8052
+ renderPass.setBindGroup(0, this.sceneBindGroupForRender);
8053
+ renderPass.setBindGroup(1, this.modelBindGroup);
8054
+ renderPass.setVertexBuffer(0, this.vertexBuffer);
8055
+ renderPass.setVertexBuffer(1, this.vertexNormalsBuffer);
8056
+ renderPass.setVertexBuffer(2, this.vertexTexCoordsBuffer);
8057
+ renderPass.setIndexBuffer(this.indexBuffer, 'uint16');
8058
+ renderPass.drawIndexed(this.indexCount);
8059
+ };
8060
+ drawShadows = shadowPass => {
8061
+ shadowPass.setBindGroup(0, this.sceneBindGroupForShadow);
8062
+ shadowPass.setBindGroup(1, this.modelBindGroup);
8063
+ shadowPass.setVertexBuffer(0, this.vertexBuffer);
8064
+ shadowPass.setVertexBuffer(1, this.vertexNormalsBuffer);
8065
+ shadowPass.setVertexBuffer(2, this.vertexTexCoordsBuffer);
8066
+ shadowPass.setIndexBuffer(this.indexBuffer, 'uint16');
8067
+ shadowPass.drawIndexed(this.indexCount);
7820
8068
  };
7821
8069
  }
7822
8070
  exports.default = MEMeshObj;
7823
8071
 
7824
- },{"../shaders/fragment.wgsl":12,"../shaders/vertex.wgsl":14,"../shaders/vertexShadow.wgsl":15,"./engine":6,"./matrix-class":8,"wgpu-matrix":3}],10:[function(require,module,exports){
8072
+ },{"../shaders/fragment.wgsl":15,"../shaders/vertex.wgsl":17,"../shaders/vertexShadow.wgsl":18,"./engine":8,"./matrix-class":10,"./utils":13,"wgpu-matrix":5}],12:[function(require,module,exports){
7825
8073
  "use strict";
7826
8074
 
7827
8075
  Object.defineProperty(exports, "__esModule", {
@@ -7844,8 +8092,7 @@ class MEMesh {
7844
8092
  this.mesh = o.mesh;
7845
8093
  this.inputHandler = (0, _engine.createInputHandler)(window, canvas);
7846
8094
  this.cameras = o.cameras;
7847
- console.log('passed : o.mainCameraParams.responseCoef ', o.mainCameraParams.responseCoef);
7848
- this.cameraParams = {
8095
+ this.mainCameraParams = {
7849
8096
  type: o.mainCameraParams.type,
7850
8097
  responseCoef: o.mainCameraParams.responseCoef
7851
8098
  };
@@ -7856,7 +8103,7 @@ class MEMesh {
7856
8103
  });
7857
8104
  this.presentationFormat = navigator.gpu.getPreferredCanvasFormat();
7858
8105
  this.position = new _matrixClass.Position(o.position.x, o.position.y, o.position.z);
7859
- console.log('cube added on pos : ', this.position);
8106
+ // console.log('cube added on pos : ', this.position)
7860
8107
  this.rotation = new _matrixClass.Rotation(o.rotation.x, o.rotation.y, o.rotation.z);
7861
8108
  this.rotation.rotationSpeed.x = o.rotationSpeed.x;
7862
8109
  this.rotation.rotationSpeed.y = o.rotationSpeed.y;
@@ -8120,9 +8367,9 @@ class MEMesh {
8120
8367
  // Rotates the camera around the origin based on time.
8121
8368
  this.getTransformationMatrix = pos => {
8122
8369
  const now = Date.now();
8123
- const deltaTime = (now - this.lastFrameMS) / this.cameraParams.responseCoef;
8370
+ const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
8124
8371
  this.lastFrameMS = now;
8125
- const camera = this.cameras[this.cameraParams.type];
8372
+ const camera = this.cameras[this.mainCameraParams.type];
8126
8373
  this.viewMatrix = camera.update(deltaTime, this.inputHandler());
8127
8374
  _wgpuMatrix.mat4.translate(this.viewMatrix, _wgpuMatrix.vec3.fromValues(pos.x, pos.y, pos.z), this.viewMatrix);
8128
8375
  _wgpuMatrix.mat4.rotateX(this.viewMatrix, Math.PI * this.rotation.getRotX(), this.viewMatrix);
@@ -8220,14 +8467,30 @@ class MEMesh {
8220
8467
  }
8221
8468
  exports.default = MEMesh;
8222
8469
 
8223
- },{"../shaders/fragment.wgsl":12,"../shaders/vertex.wgsl":14,"../shaders/vertexShadow.wgsl":15,"./engine":6,"./loader-obj":7,"./matrix-class":8,"wgpu-matrix":3}],11:[function(require,module,exports){
8470
+ },{"../shaders/fragment.wgsl":15,"../shaders/vertex.wgsl":17,"../shaders/vertexShadow.wgsl":18,"./engine":8,"./loader-obj":9,"./matrix-class":10,"wgpu-matrix":5}],13:[function(require,module,exports){
8224
8471
  "use strict";
8225
8472
 
8226
8473
  Object.defineProperty(exports, "__esModule", {
8227
8474
  value: true
8228
8475
  });
8476
+ exports.LOG_WARN = exports.LOG_MATRIX = exports.LOG_INFO = exports.LOG_FUNNY = void 0;
8477
+ exports.ORBIT = ORBIT;
8478
+ exports.ORBIT_FROM_ARRAY = ORBIT_FROM_ARRAY;
8479
+ exports.OSCILLATOR = OSCILLATOR;
8480
+ exports.QueryString = void 0;
8481
+ exports.SWITCHER = SWITCHER;
8482
+ exports.byId = void 0;
8483
+ exports.createAppEvent = createAppEvent;
8229
8484
  exports.degToRad = degToRad;
8230
- exports.vec3 = exports.mat4 = void 0;
8485
+ exports.getAxisRot = getAxisRot;
8486
+ exports.getAxisRot2 = getAxisRot2;
8487
+ exports.getAxisRot3 = getAxisRot3;
8488
+ exports.mat4 = void 0;
8489
+ exports.quaternion_rotation_matrix = quaternion_rotation_matrix;
8490
+ exports.radToDeg = radToDeg;
8491
+ exports.randomFloatFromTo = randomFloatFromTo;
8492
+ exports.randomIntFromTo = randomIntFromTo;
8493
+ exports.vec3 = exports.scriptManager = void 0;
8231
8494
  const vec3 = exports.vec3 = {
8232
8495
  cross(a, b, dst) {
8233
8496
  dst = dst || new Float32Array(3);
@@ -8598,8 +8861,451 @@ function degToRad(degrees) {
8598
8861
  return degrees * Math.PI / 180;
8599
8862
  }
8600
8863
  ;
8864
+ function radToDeg(r) {
8865
+ var pi = Math.PI;
8866
+ return r * (180 / pi);
8867
+ }
8868
+ ;
8869
+ function createAppEvent(name, myDetails) {
8870
+ return new CustomEvent(name, {
8871
+ detail: {
8872
+ eventName: name,
8873
+ data: myDetails
8874
+ },
8875
+ bubbles: true
8876
+ });
8877
+ }
8878
+
8879
+ /**
8880
+ * @description
8881
+ * Load script in runtime.
8882
+ */
8883
+ var scriptManager = exports.scriptManager = {
8884
+ SCRIPT_ID: 0,
8885
+ LOAD: function addScript(src, id, type, parent, callback) {
8886
+ var s = document.createElement('script');
8887
+ s.onload = function () {
8888
+ // console.log('Script id loaded [src]: ' + this.src);
8889
+ if (typeof callback != 'undefined') callback();
8890
+ };
8891
+ if (typeof type !== 'undefined') {
8892
+ s.setAttribute('type', type);
8893
+ s.innerHTML = src;
8894
+ } else {
8895
+ s.setAttribute('src', src);
8896
+ }
8897
+ if (typeof id !== 'undefined') {
8898
+ s.setAttribute('id', id);
8899
+ }
8900
+ if (typeof parent !== 'undefined') {
8901
+ document.getElementById(parent).appendChild(s);
8902
+ if (typeof callback != 'undefined') callback();
8903
+ } else {
8904
+ document.body.appendChild(s);
8905
+ }
8906
+ },
8907
+ loadModule: function addScript(src, id, type, parent) {
8908
+ console.log('Script id load called ');
8909
+ var s = document.createElement('script');
8910
+ s.onload = function () {
8911
+ scriptManager.SCRIPT_ID++;
8912
+ };
8913
+ if (typeof type === 'undefined') {
8914
+ s.setAttribute('type', 'module');
8915
+ s.setAttribute('src', src);
8916
+ } else {
8917
+ s.setAttribute('type', type);
8918
+ s.innerHTML = src;
8919
+ }
8920
+ s.setAttribute('src', src);
8921
+ if (typeof id !== 'undefined') {
8922
+ s.setAttribute('id', id);
8923
+ }
8924
+ if (typeof parent !== 'undefined') {
8925
+ document.getElementById(parent).appendChild(s);
8926
+ } else {
8927
+ document.body.appendChild(s);
8928
+ }
8929
+ },
8930
+ loadGLSL: function (src) {
8931
+ return new Promise(resolve => {
8932
+ fetch(src).then(data => {
8933
+ resolve(data.text());
8934
+ });
8935
+ });
8936
+ }
8937
+ };
8601
8938
 
8602
- },{}],12:[function(require,module,exports){
8939
+ // GET PULSE VALUES IN REAL TIME
8940
+ function OSCILLATOR(min, max, step) {
8941
+ if ((typeof min === 'string' || typeof min === 'number') && (typeof max === 'string' || typeof max === 'number') && (typeof step === 'string' || typeof step === 'number')) {
8942
+ var ROOT = this;
8943
+ this.min = parseFloat(min);
8944
+ this.max = parseFloat(max);
8945
+ this.step = parseFloat(step);
8946
+ this.value_ = parseFloat(min);
8947
+ this.status = 0;
8948
+ this.on_maximum_value = function () {};
8949
+ this.on_minimum_value = function () {};
8950
+ this.UPDATE = function (STATUS_) {
8951
+ if (STATUS_ === undefined) {
8952
+ if (this.status == 0 && this.value_ < this.max) {
8953
+ this.value_ = this.value_ + this.step;
8954
+ if (this.value_ >= this.max) {
8955
+ this.value_ = this.max;
8956
+ this.status = 1;
8957
+ ROOT.on_maximum_value();
8958
+ }
8959
+ return this.value_;
8960
+ } else if (this.status == 1 && this.value_ > this.min) {
8961
+ this.value_ = this.value_ - this.step;
8962
+ if (this.value_ <= this.min) {
8963
+ this.value_ = this.min;
8964
+ this.status = 0;
8965
+ ROOT.on_minimum_value();
8966
+ }
8967
+ return this.value_;
8968
+ }
8969
+ } else {
8970
+ return this.value_;
8971
+ }
8972
+ };
8973
+ } else {
8974
+ console.log("SYS : warning for procedure 'SYS.MATH.OSCILLATOR' Desciption : Replace object with string or number, min >> " + typeof min + ' and max >>' + typeof max + ' and step >>' + typeof step + ' << must be string or number.');
8975
+ }
8976
+ }
8977
+
8978
+ // this is class not func ecma5
8979
+ function SWITCHER() {
8980
+ var ROOT = this;
8981
+ ROOT.VALUE = 1;
8982
+ ROOT.GET = function () {
8983
+ ROOT.VALUE = ROOT.VALUE * -1;
8984
+ return ROOT.VALUE;
8985
+ };
8986
+ }
8987
+ function ORBIT(cx, cy, angle, p) {
8988
+ var s = Math.sin(angle);
8989
+ var c = Math.cos(angle);
8990
+ p.x -= cx;
8991
+ p.y -= cy;
8992
+ var xnew = p.x * c - p.y * s;
8993
+ var ynew = p.x * s + p.y * c;
8994
+ p.x = xnew + cx;
8995
+ p.y = ynew + cy;
8996
+ return p;
8997
+ }
8998
+ function ORBIT_FROM_ARRAY(cx, cy, angle, p, byIndexs) {
8999
+ var s = Math.sin(angle);
9000
+ var c = Math.cos(angle);
9001
+ p[byIndexs[0]] -= cx;
9002
+ p[byIndexs[1]] -= cy;
9003
+ var xnew = p[byIndexs[0]] * c - p[byIndexs[1]] * s;
9004
+ var ynew = p[byIndexs[0]] * s + p[byIndexs[1]] * c;
9005
+ p[byIndexs[0]] = xnew + cx;
9006
+ p[byIndexs[1]] = ynew + cy;
9007
+ return p;
9008
+ }
9009
+ var byId = function (id) {
9010
+ return document.getElementById(id);
9011
+ };
9012
+ exports.byId = byId;
9013
+ function randomFloatFromTo(min, max) {
9014
+ return Math.random() * (max - min) + min;
9015
+ }
9016
+ function randomIntFromTo(min, max) {
9017
+ if (typeof min === 'object' || typeof max === 'object') {
9018
+ console.log("SYS : warning Desciption : Replace object with string , this >> " + typeof min + ' and ' + typeof min + ' << must be string or number.');
9019
+ } else if (typeof min === 'undefined' || typeof max === 'undefined') {
9020
+ console.log("SYS : warning Desciption : arguments (min, max) cant be undefined , this >> " + typeof min + ' and ' + typeof min + ' << must be string or number.');
9021
+ } else {
9022
+ return Math.floor(Math.random() * (max - min + 1) + min);
9023
+ }
9024
+ }
9025
+ var QueryString = exports.QueryString = function () {
9026
+ var query_string = {};
9027
+ var query = window.location.search.substring(1);
9028
+ var vars = query.split('&');
9029
+ for (var i = 0; i < vars.length; i++) {
9030
+ var pair = vars[i].split('=');
9031
+ if (typeof query_string[pair[0]] === 'undefined') {
9032
+ query_string[pair[0]] = decodeURIComponent(pair[1]);
9033
+ } else if (typeof query_string[pair[0]] === 'string') {
9034
+ var arr = [query_string[pair[0]], decodeURIComponent(pair[1])];
9035
+ query_string[pair[0]] = arr;
9036
+ } else {
9037
+ query_string[pair[0]].push(decodeURIComponent(pair[1]));
9038
+ }
9039
+ }
9040
+ return query_string;
9041
+ }();
9042
+ function getAxisRot(q1) {
9043
+ var x, y, z;
9044
+
9045
+ // if w>1 acos and sqrt will produce errors, this cant happen if quaternion is normalised
9046
+ if (q1.w > 1) q1.normalise();
9047
+ var angle = 2 * Math.acos(q1.w);
9048
+ // assuming quaternion normalised then w is less than 1, so term always positive.
9049
+ var s = Math.sqrt(1 - q1.w * q1.w);
9050
+ // test to avoid divide by zero, s is always positive due to sqrt
9051
+ if (s < 0.001) {
9052
+ // if s close to zero then direction of axis not important
9053
+ // if it is important that axis is normalised then replace with x=1; y=z=0;
9054
+
9055
+ x = q1.x;
9056
+ y = q1.y;
9057
+ z = q1.z;
9058
+ } else {
9059
+ x = q1.x / s; // normalise axis
9060
+ y = q1.y / s;
9061
+ z = q1.z / s;
9062
+ }
9063
+ return [radToDeg(x), radToDeg(y), radToDeg(z)];
9064
+ }
9065
+ function getAxisRot2(targetAxis, Q) {
9066
+ Q.normalize(); // if w>1 acos and sqrt will produce errors, this cant happen if quaternion is normalised
9067
+ var angle = 2 * Math.acos(Q.w());
9068
+ var s = Math.sqrt(1 - Q.w() * Q.w()); // assuming quaternion normalised then w is less than 1, so term always positive.
9069
+ if (s < 0.001) {
9070
+ // test to avoid divide by zero, s is always positive due to sqrt
9071
+ // if s close to zero then direction of axis not important
9072
+ // if it is important that axis is normalised then replace with x=1; y=z=0;
9073
+ // targetAxis.x = 1;
9074
+ // targetAxis.y = 0;
9075
+ // targetAxis.z = 0;
9076
+ targetAxis.x = Q.x();
9077
+ targetAxis.y = Q.y();
9078
+ targetAxis.z = Q.z();
9079
+ } else {
9080
+ targetAxis.x = Q.x() / s; // normalise axis
9081
+ targetAxis.y = Q.y() / s;
9082
+ targetAxis.z = Q.z() / s;
9083
+ }
9084
+ return [targetAxis, angle];
9085
+ }
9086
+ function getAxisRot3(Q) {
9087
+ var angle = Math.acos(Q.w) * 2;
9088
+ var axis = {};
9089
+ if (Math.sin(Math.acos(angle)) > 0) {
9090
+ axis.x = Q.x / Math.sin(Math.acos(angle / 2));
9091
+ axis.y = Q.y / Math.sin(Math.acos(angle / 2));
9092
+ axis.z = Q.z / Math.sin(Math.acos(angle / 2));
9093
+ } else {
9094
+ axis.x = 0;
9095
+ axis.y = 0;
9096
+ axis.z = 0;
9097
+ }
9098
+ return axis;
9099
+ }
9100
+
9101
+ // NTO TESTED
9102
+ function quaternion_rotation_matrix(Q) {
9103
+ // Covert a quaternion into a full three-dimensional rotation matrix.
9104
+
9105
+ // Input
9106
+ // :param Q: A 4 element array representing the quaternion (q0,q1,q2,q3)
9107
+
9108
+ // Output
9109
+ // :return: A 3x3 element matrix representing the full 3D rotation matrix.
9110
+ // This rotation matrix converts a point in the local reference
9111
+ // frame to a point in the global reference frame.
9112
+ // """
9113
+ // # Extract the values from Q
9114
+ var q0 = Q[0];
9115
+ var q1 = Q[1];
9116
+ var q2 = Q[2];
9117
+ var q3 = Q[3];
9118
+
9119
+ // # First row of the rotation matrix
9120
+ var r00 = 2 * (q0 * q0 + q1 * q1) - 1;
9121
+ var r01 = 2 * (q1 * q2 - q0 * q3);
9122
+ var r02 = 2 * (q1 * q3 + q0 * q2);
9123
+
9124
+ // # Second row of the rotation matrix
9125
+ var r10 = 2 * (q1 * q2 + q0 * q3);
9126
+ var r11 = 2 * (q0 * q0 + q2 * q2) - 1;
9127
+ var r12 = 2 * (q2 * q3 - q0 * q1);
9128
+
9129
+ // # Third row of the rotation matrix
9130
+ var r20 = 2 * (q1 * q3 - q0 * q2);
9131
+ var r21 = 2 * (q2 * q3 + q0 * q1);
9132
+ var r22 = 2 * (q0 * q0 + q3 * q3) - 1;
9133
+
9134
+ // # 3x3 rotation matrix
9135
+ var rot_matrix = [[r00, r01, r02], [r10, r11, r12], [r20, r21, r22]];
9136
+ return rot_matrix;
9137
+ }
9138
+
9139
+ // copnsole log graphics
9140
+ const LOG_WARN = exports.LOG_WARN = 'background: gray; color: yellow; font-size:10px';
9141
+ const LOG_INFO = exports.LOG_INFO = 'background: green; color: white; font-size:11px';
9142
+ const LOG_MATRIX = exports.LOG_MATRIX = "font-family: verdana;color: #lime; font-size:11px;text-shadow: 2px 2px 4px orangered;background: black;";
9143
+ 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;";
9144
+
9145
+ },{}],14:[function(require,module,exports){
9146
+ "use strict";
9147
+
9148
+ Object.defineProperty(exports, "__esModule", {
9149
+ value: true
9150
+ });
9151
+ exports.default = void 0;
9152
+ var _wgpuMatrix = require("wgpu-matrix");
9153
+ var _utils = require("../engine/utils");
9154
+ class MatrixAmmo {
9155
+ constructor() {
9156
+ // THIS PATH IS PATH FROM PUBLIC FINAL FOLDER
9157
+ _utils.scriptManager.LOAD("./ammojs/ammo.js", "ammojs", undefined, undefined, this.init);
9158
+ }
9159
+ init = () => {
9160
+ console.log('pre ammo');
9161
+ Ammo().then(Ammo => {
9162
+ // Physics variables
9163
+ this.dynamicsWorld = null;
9164
+ this.rigidBodies = [];
9165
+ this.Ammo = Ammo;
9166
+ this.lastUpdate = 0;
9167
+ console.log("%c Ammo core loaded.", _utils.LOG_FUNNY);
9168
+ this.initPhysics();
9169
+ // simulate async
9170
+ setTimeout(() => dispatchEvent(new CustomEvent('AmmoReady', {})), 100);
9171
+ });
9172
+ };
9173
+ initPhysics() {
9174
+ let Ammo = this.Ammo;
9175
+
9176
+ // Physics configuration
9177
+ var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration(),
9178
+ dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration),
9179
+ overlappingPairCache = new Ammo.btDbvtBroadphase(),
9180
+ solver = new Ammo.btSequentialImpulseConstraintSolver();
9181
+ this.dynamicsWorld = new Ammo.btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
9182
+ this.dynamicsWorld.setGravity(new Ammo.btVector3(0, -10, 0));
9183
+ var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(50, 0.5, 50)),
9184
+ groundTransform = new Ammo.btTransform();
9185
+ groundTransform.setIdentity();
9186
+ groundTransform.setOrigin(new Ammo.btVector3(0, -1, 0));
9187
+ var mass = 0,
9188
+ isDynamic = mass !== 0,
9189
+ localInertia = new Ammo.btVector3(0, 0, 0);
9190
+ if (isDynamic) groundShape.calculateLocalInertia(mass, localInertia);
9191
+ var myMotionState = new Ammo.btDefaultMotionState(groundTransform),
9192
+ rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, groundShape, localInertia),
9193
+ body = new Ammo.btRigidBody(rbInfo);
9194
+ this.dynamicsWorld.addRigidBody(body);
9195
+ // this.rigidBodies.push(body);
9196
+ }
9197
+ addPhysics(MEObject, pOptions) {
9198
+ if (pOptions.geometry == "Sphere") {
9199
+ this.addPhysicsSphere(MEObject, pOptions);
9200
+ } else if (pOptions.geometry == "Cube") {
9201
+ this.addPhysicsBox(MEObject, pOptions);
9202
+ }
9203
+ }
9204
+ addPhysicsSphere(MEObject, pOptions) {
9205
+ let Ammo = this.Ammo;
9206
+ var colShape = new Ammo.btSphereShape(pOptions.radius),
9207
+ startTransform = new Ammo.btTransform();
9208
+ startTransform.setIdentity();
9209
+ var mass = 1;
9210
+ var localInertia = new Ammo.btVector3(0, 0, 0);
9211
+ colShape.calculateLocalInertia(mass, localInertia);
9212
+ startTransform.setOrigin(new Ammo.btVector3(pOptions.position.x, pOptions.position.y, pOptions.position.z));
9213
+ var myMotionState = new Ammo.btDefaultMotionState(startTransform),
9214
+ rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia),
9215
+ body = new Ammo.btRigidBody(rbInfo);
9216
+ body.MEObject = MEObject;
9217
+ this.dynamicsWorld.addRigidBody(body);
9218
+ this.rigidBodies.push(body);
9219
+ return body;
9220
+ }
9221
+ addPhysicsBox(MEObject, pOptions) {
9222
+ const FLAGS = {
9223
+ CF_KINEMATIC_OBJECT: 2
9224
+ };
9225
+ let Ammo = this.Ammo;
9226
+ var colShape = new Ammo.btBoxShape(new Ammo.btVector3(1, 1, 1)),
9227
+ startTransform = new Ammo.btTransform();
9228
+ startTransform.setIdentity();
9229
+ var mass = pOptions.mass;
9230
+ var localInertia = new Ammo.btVector3(0, 0, 0);
9231
+ colShape.calculateLocalInertia(mass, localInertia);
9232
+ startTransform.setOrigin(new Ammo.btVector3(pOptions.position.x, pOptions.position.y, pOptions.position.z));
9233
+ var myMotionState = new Ammo.btDefaultMotionState(startTransform),
9234
+ rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia),
9235
+ body = new Ammo.btRigidBody(rbInfo);
9236
+ if (pOptions.mass == 0 && typeof pOptions.state == 'undefined') {
9237
+ body.setActivationState(2);
9238
+ body.setCollisionFlags(FLAGS.CF_KINEMATIC_OBJECT);
9239
+ console.log('what is pOptions.mass and state is 2 ....', pOptions.mass);
9240
+ } else {
9241
+ body.setActivationState(4);
9242
+ }
9243
+ body.MEObject = MEObject;
9244
+ this.dynamicsWorld.addRigidBody(body);
9245
+ this.rigidBodies.push(body);
9246
+ return body;
9247
+ }
9248
+ setBodyVelocity(body, x, y, z) {
9249
+ var tbv30 = new Ammo.btVector3();
9250
+ tbv30.setValue(x, y, z);
9251
+ body.setLinearVelocity(tbv30);
9252
+ }
9253
+ setKinematicTransform(body, x, y, z) {
9254
+ let pos = new Ammo.btVector3();
9255
+ let quat = new Ammo.btQuaternion();
9256
+ pos = body.getWorldTransform().getOrigin();
9257
+ let localRot = pos = body.getWorldTransform().getRotation();
9258
+ pos.setX(pos.x() + x);
9259
+ pos.setY(pos.y() + y);
9260
+ pos.setZ(pos.z() + z);
9261
+ console.log('position kinematic move : ', pos);
9262
+ console.log('position localRot : ', localRot);
9263
+
9264
+ // body.getWorldQuaternion(quat);
9265
+ // let physicsBody = kObject.userData.physicsBody;
9266
+ let physicsBody = body;
9267
+ let ms = physicsBody.getMotionState();
9268
+ if (ms) {
9269
+ var tmpTrans = new Ammo.btTransform();
9270
+ console.log('TEST pos x:', pos.x(), " y : ", pos.y(), " z:", pos.z());
9271
+ // quat.setValue(quat.x(), quat.y(), quat.z(), quat.w());
9272
+ tmpTrans.setIdentity();
9273
+ tmpTrans.setOrigin(pos);
9274
+ // tmpTrans.setRotation(quat);
9275
+ ms.setWorldTransform(tmpTrans);
9276
+ }
9277
+ console.log('body, ', body);
9278
+ }
9279
+ updatePhysics() {
9280
+ // Step world
9281
+ this.dynamicsWorld.stepSimulation(1 / 60, 10);
9282
+ // Update rigid bodies
9283
+ var trans = new Ammo.btTransform();
9284
+ this.rigidBodies.forEach(function (body) {
9285
+ if (body.getMotionState()) {
9286
+ body.getMotionState().getWorldTransform(trans);
9287
+ var _x = trans.getOrigin().x().toFixed(2);
9288
+ var _y = trans.getOrigin().y().toFixed(2);
9289
+ var _z = trans.getOrigin().z().toFixed(2);
9290
+ body.MEObject.position.setPosition(_x, _y, _z);
9291
+ var test = trans.getRotation();
9292
+ var testAxis = test.getAxis();
9293
+ test.normalize();
9294
+ body.MEObject.rotation.axis.x = testAxis.x();
9295
+ body.MEObject.rotation.axis.y = testAxis.y();
9296
+ body.MEObject.rotation.axis.z = testAxis.z();
9297
+ // var tx = radToDeg(parseFloat(test.getAngle().toFixed(2)) * testAxis.x().toFixed(2))
9298
+ // var ty = radToDeg(parseFloat(test.getAngle().toFixed(2)) * testAxis.y().toFixed(2))
9299
+ // var tz = radToDeg(parseFloat(test.getAngle().toFixed(2)) * testAxis.z().toFixed(2))
9300
+ body.MEObject.rotation.matrixRotation = (0, _utils.quaternion_rotation_matrix)(test);
9301
+ body.MEObject.rotation.angle = (0, _utils.radToDeg)(parseFloat(test.getAngle().toFixed(2)));
9302
+ }
9303
+ });
9304
+ }
9305
+ }
9306
+ exports.default = MatrixAmmo;
9307
+
9308
+ },{"../engine/utils":13,"wgpu-matrix":5}],15:[function(require,module,exports){
8603
9309
  "use strict";
8604
9310
 
8605
9311
  Object.defineProperty(exports, "__esModule", {
@@ -8655,7 +9361,7 @@ fn main(input : FragmentInput) -> @location(0) vec4f {
8655
9361
  return vec4(textureColor.rgb * lightingFactor * albedo, 1.0);
8656
9362
  }`;
8657
9363
 
8658
- },{}],13:[function(require,module,exports){
9364
+ },{}],16:[function(require,module,exports){
8659
9365
  "use strict";
8660
9366
 
8661
9367
  Object.defineProperty(exports, "__esModule", {
@@ -8713,7 +9419,7 @@ fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {
8713
9419
  return vec4f(textureColor.rgb * lightColor, textureColor.a);
8714
9420
  }`;
8715
9421
 
8716
- },{}],14:[function(require,module,exports){
9422
+ },{}],17:[function(require,module,exports){
8717
9423
  "use strict";
8718
9424
 
8719
9425
  Object.defineProperty(exports, "__esModule", {
@@ -8770,7 +9476,7 @@ fn main(
8770
9476
  }
8771
9477
  `;
8772
9478
 
8773
- },{}],15:[function(require,module,exports){
9479
+ },{}],18:[function(require,module,exports){
8774
9480
  "use strict";
8775
9481
 
8776
9482
  Object.defineProperty(exports, "__esModule", {
@@ -8798,7 +9504,7 @@ fn main(
8798
9504
  }
8799
9505
  `;
8800
9506
 
8801
- },{}],16:[function(require,module,exports){
9507
+ },{}],19:[function(require,module,exports){
8802
9508
  "use strict";
8803
9509
 
8804
9510
  Object.defineProperty(exports, "__esModule", {
@@ -8811,6 +9517,8 @@ var _cube = _interopRequireDefault(require("./engine/cube.js"));
8811
9517
  var _engine = require("./engine/engine.js");
8812
9518
  var _mesh = _interopRequireDefault(require("./engine/mesh.js"));
8813
9519
  var _meshObj = _interopRequireDefault(require("./engine/mesh-obj.js"));
9520
+ var _matrixAmmo = _interopRequireDefault(require("./physics/matrix-ammo.js"));
9521
+ var _utils = require("./engine/utils.js");
8814
9522
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8815
9523
  class MatrixEngineWGPU {
8816
9524
  mainRenderBundle = [];
@@ -8823,6 +9531,7 @@ class MatrixEngineWGPU {
8823
9531
  depthLoadOp: 'clear',
8824
9532
  depthStoreOp: 'store'
8825
9533
  };
9534
+ matrixAmmo = new _matrixAmmo.default();
8826
9535
 
8827
9536
  // The input handler
8828
9537
  constructor(options, callback) {
@@ -8830,11 +9539,22 @@ class MatrixEngineWGPU {
8830
9539
  if (typeof options == 'undefined' || typeof options == "function") {
8831
9540
  this.options = {
8832
9541
  useSingleRenderPass: true,
8833
- canvasSize: 'fullscreen'
9542
+ canvasSize: 'fullscreen',
9543
+ mainCameraParams: {
9544
+ type: 'WASD',
9545
+ responseCoef: 2000
9546
+ }
8834
9547
  };
8835
9548
  callback = options;
8836
9549
  }
9550
+ if (typeof options.mainCameraParams === 'undefined') {
9551
+ options.mainCameraParams = {
9552
+ type: 'WASD',
9553
+ responseCoef: 2000
9554
+ };
9555
+ }
8837
9556
  this.options = options;
9557
+ this.mainCameraParams = options.mainCameraParams;
8838
9558
  var canvas = document.createElement('canvas');
8839
9559
  if (this.options.canvasSize == 'fullscreen') {
8840
9560
  canvas.width = window.innerWidth;
@@ -8847,9 +9567,10 @@ class MatrixEngineWGPU {
8847
9567
 
8848
9568
  // The camera types
8849
9569
  const initialCameraPosition = _wgpuMatrix.vec3.create(0, 0, 0);
9570
+ // console.log('passed : o.mainCameraParams.responseCoef ', o.mainCameraParams.responseCoef)
8850
9571
  this.mainCameraParams = {
8851
- type: 'WASD',
8852
- responseCoef: 2000
9572
+ type: this.options.mainCameraParams.type,
9573
+ responseCoef: this.options.mainCameraParams.responseCoef
8853
9574
  };
8854
9575
  this.cameras = {
8855
9576
  arcball: new _engine.ArcballCamera({
@@ -8882,40 +9603,14 @@ class MatrixEngineWGPU {
8882
9603
  alphaMode: 'premultiplied'
8883
9604
  });
8884
9605
  if (this.options.useSingleRenderPass == true) {
8885
- this.makeDefaultRenderPassDescriptor();
8886
9606
  this.frame = this.frameSinglePass;
8887
9607
  } else {
8888
- // must be
8889
9608
  this.frame = this.framePassPerObject;
8890
9609
  }
8891
9610
  this.run(callback);
8892
9611
  };
8893
- makeDefaultRenderPassDescriptor = () => {
8894
- this.depthTexture = this.device.createTexture({
8895
- size: [this.canvas.width, this.canvas.height],
8896
- format: 'depth24plus',
8897
- usage: GPUTextureUsage.RENDER_ATTACHMENT
8898
- });
8899
- this.renderPassDescriptor = {
8900
- colorAttachments: [{
8901
- view: undefined,
8902
- clearValue: {
8903
- r: 0.0,
8904
- g: 0.0,
8905
- b: 0.0,
8906
- a: 1.0
8907
- },
8908
- loadOp: 'clear',
8909
- storeOp: 'store'
8910
- }],
8911
- depthStencilAttachment: {
8912
- view: this.depthTexture.createView(),
8913
- depthClearValue: 1.0,
8914
- depthLoadOp: 'clear',
8915
- depthStoreOp: 'store'
8916
- }
8917
- };
8918
- };
9612
+
9613
+ // Not in use for now
8919
9614
  addCube = o => {
8920
9615
  if (typeof o === 'undefined') {
8921
9616
  var o = {
@@ -8977,6 +9672,8 @@ class MatrixEngineWGPU {
8977
9672
  let myCube1 = new _cube.default(this.canvas, this.device, this.context, o);
8978
9673
  this.mainRenderBundle.push(myCube1);
8979
9674
  };
9675
+
9676
+ // Not in use for now
8980
9677
  addBall = o => {
8981
9678
  if (typeof o === 'undefined') {
8982
9679
  var o = {
@@ -9038,6 +9735,8 @@ class MatrixEngineWGPU {
9038
9735
  let myBall1 = new _ball.default(this.canvas, this.device, this.context, o);
9039
9736
  this.mainRenderBundle.push(myBall1);
9040
9737
  };
9738
+
9739
+ // Not in use for now
9041
9740
  addMesh = o => {
9042
9741
  if (typeof o.position === 'undefined') {
9043
9742
  o.position = {
@@ -9122,8 +9821,34 @@ class MatrixEngineWGPU {
9122
9821
  throw console.error('arg mesh is empty...');
9123
9822
  return;
9124
9823
  }
9125
- console.log('Mesh procedure', o);
9824
+ if (typeof o.physics === 'undefined') {
9825
+ o.physics = {
9826
+ enabled: false,
9827
+ geometry: "Sphere",
9828
+ radius: o.scale
9829
+ };
9830
+ }
9831
+ if (typeof o.physics.enabled === 'undefined') {
9832
+ o.physics.enabled = false;
9833
+ }
9834
+ if (typeof o.physics.geometry === 'undefined') {
9835
+ o.physics.geometry = "Sphere";
9836
+ }
9837
+ if (typeof o.physics.radius === 'undefined') {
9838
+ o.physics.radius = o.scale;
9839
+ }
9840
+ if (typeof o.physics.mass === 'undefined') {
9841
+ o.physics.mass = 1;
9842
+ }
9843
+
9844
+ // send same pos
9845
+ o.physics.position = o.position;
9846
+
9847
+ // console.log('Mesh procedure', o)
9126
9848
  let myMesh1 = new _meshObj.default(this.canvas, this.device, this.context, o);
9849
+ if (o.physics.enabled == true) {
9850
+ this.matrixAmmo.addPhysics(myMesh1, o.physics);
9851
+ }
9127
9852
  this.mainRenderBundle.push(myMesh1);
9128
9853
  };
9129
9854
  run(callback) {
@@ -9131,32 +9856,49 @@ class MatrixEngineWGPU {
9131
9856
  requestAnimationFrame(this.frame);
9132
9857
  }, 500);
9133
9858
  setTimeout(() => {
9134
- callback();
9859
+ callback(this);
9135
9860
  }, 20);
9136
9861
  }
9862
+ destroyProgram = () => {
9863
+ this.mainRenderBundle = undefined;
9864
+ this.canvas.remove();
9865
+ };
9137
9866
  frameSinglePass = () => {
9138
- let passEncoder;
9139
- let commandEncoder = this.device.createCommandEncoder();
9140
- if (typeof this.mainRenderBundle != 'undefined') this.mainRenderBundle.forEach((meItem, index) => {
9141
- meItem.position.update();
9142
- meItem.draw(commandEncoder);
9143
-
9144
- //
9145
- if (typeof meItem.done == 'undefined') {
9146
- this.rbContainer.push(meItem.renderBundle);
9147
- this.renderPassDescriptor.colorAttachments[0].view = this.context.getCurrentTexture().createView();
9148
- // console.log('prolazi ')
9149
- passEncoder = commandEncoder.beginRenderPass(this.renderPassDescriptor);
9150
- passEncoder.executeBundles(this.rbContainer);
9151
- passEncoder.end();
9152
- // this.device.queue.submit([commandEncoder.finish()]);
9153
- }
9154
- });
9155
- this.device.queue.submit([commandEncoder.finish()]);
9156
- requestAnimationFrame(this.frame);
9867
+ if (typeof this.mainRenderBundle == 'undefined') return;
9868
+ try {
9869
+ let shadowPass = null;
9870
+ let renderPass;
9871
+ let commandEncoder = this.device.createCommandEncoder();
9872
+ this.mainRenderBundle.forEach((meItem, index) => {
9873
+ meItem.position.update();
9874
+ });
9875
+ this.matrixAmmo.updatePhysics();
9876
+ this.mainRenderBundle.forEach((meItem, index) => {
9877
+ meItem.draw(commandEncoder);
9878
+ shadowPass = commandEncoder.beginRenderPass(meItem.shadowPassDescriptor);
9879
+ shadowPass.setPipeline(meItem.shadowPipeline);
9880
+ meItem.drawShadows(shadowPass);
9881
+ shadowPass.end();
9882
+ });
9883
+ this.mainRenderBundle.forEach((meItem, index) => {
9884
+ if (index == 0) {
9885
+ renderPass = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
9886
+ renderPass.setPipeline(meItem.pipeline);
9887
+ }
9888
+ });
9889
+ this.mainRenderBundle.forEach((meItem, index) => {
9890
+ meItem.drawElements(renderPass);
9891
+ });
9892
+ if (renderPass) renderPass.end();
9893
+ this.device.queue.submit([commandEncoder.finish()]);
9894
+ requestAnimationFrame(this.frame);
9895
+ } catch (err) {
9896
+ console.log('%cDraw func (err):' + err, _utils.LOG_WARN);
9897
+ requestAnimationFrame(this.frame);
9898
+ }
9157
9899
  };
9158
9900
  framePassPerObject = () => {
9159
- // console.log('framePassPerObject')
9901
+ console.log('framePassPerObject');
9160
9902
  let commandEncoder = this.device.createCommandEncoder();
9161
9903
  this.rbContainer = [];
9162
9904
  let passEncoder;
@@ -9177,4 +9919,4 @@ class MatrixEngineWGPU {
9177
9919
  }
9178
9920
  exports.default = MatrixEngineWGPU;
9179
9921
 
9180
- },{"./engine/ball.js":4,"./engine/cube.js":5,"./engine/engine.js":6,"./engine/mesh-obj.js":9,"./engine/mesh.js":10,"wgpu-matrix":3}]},{},[1]);
9922
+ },{"./engine/ball.js":6,"./engine/cube.js":7,"./engine/engine.js":8,"./engine/mesh-obj.js":11,"./engine/mesh.js":12,"./engine/utils.js":13,"./physics/matrix-ammo.js":14,"wgpu-matrix":5}]},{},[1]);