matrix-engine-wgpu 1.0.6 → 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 (69) 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 +1127 -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/main.js +442 -48
  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 +28 -13
  16. package/public/app.js +11405 -9375
  17. package/public/css/style.css +371 -110
  18. package/public/empty.html +1 -1
  19. package/public/empty.js +9887 -9264
  20. package/public/examples.html +10 -8
  21. package/public/examples.js +553 -193
  22. package/public/index.html +3 -5
  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/meshes/jamb/bg.blend +0 -0
  29. package/public/res/meshes/jamb/bg.blend1 +0 -0
  30. package/public/res/meshes/jamb/bg.mtl +12 -0
  31. package/public/res/meshes/jamb/bg.obj +17 -0
  32. package/public/res/meshes/jamb/bg.png +0 -0
  33. package/public/res/meshes/jamb/dice-default.png +0 -0
  34. package/public/res/meshes/jamb/dice-mark.png +0 -0
  35. package/public/res/meshes/jamb/dice.mtl +12 -0
  36. package/public/res/meshes/jamb/dice.obj +40 -0
  37. package/public/res/meshes/jamb/dice.png +0 -0
  38. package/public/res/meshes/jamb/jamb-title.mtl +12 -0
  39. package/public/res/meshes/jamb/jamb-title.obj +26008 -0
  40. package/public/res/meshes/jamb/jamb.blend +0 -0
  41. package/public/res/meshes/jamb/jamb.blend1 +0 -0
  42. package/public/res/meshes/jamb/logo.png +0 -0
  43. package/public/res/meshes/jamb/nidzaDice.blend +0 -0
  44. package/public/res/meshes/jamb/nidzaDice.blend1 +0 -0
  45. package/public/res/meshes/jamb/pile.blend +0 -0
  46. package/public/res/meshes/jamb/simpleCube.blend +0 -0
  47. package/public/res/meshes/jamb/simpleCube.blend1 +0 -0
  48. package/public/res/meshes/jamb/sounds/roll1.wav +0 -0
  49. package/public/res/meshes/jamb/text.png +0 -0
  50. package/public/res/multilang/en.json +27 -0
  51. package/public/res/multilang/sr.json +27 -0
  52. package/public/test.html +636 -0
  53. package/public/three-test.js +165 -0
  54. package/public/worker.html +1 -1
  55. package/readme.md +189 -115
  56. package/src/engine/cube.js +10 -1
  57. package/src/engine/engine.js +1 -5
  58. package/src/engine/loader-obj.js +9 -6
  59. package/src/engine/matrix-class.js +237 -204
  60. package/src/engine/mesh-obj.js +605 -515
  61. package/src/engine/raycast-test.js +93 -0
  62. package/src/engine/utils.js +69 -3
  63. package/src/multilang/lang.js +35 -0
  64. package/src/physics/matrix-ammo.js +168 -15
  65. package/src/shaders/fragment.wgsl.js +4 -2
  66. package/src/shaders/shaders.js +1 -1
  67. package/src/shaders/vertexShadow.wgsl.js +1 -1
  68. package/src/sounds/sounds.js +47 -0
  69. package/src/world.js +311 -248
@@ -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
+ });
11
39
 
12
- },{"./examples/load-obj-file.js":2}],2:[function(require,module,exports){
40
+ },{"./examples/games/jamb/jamb.js":2,"./examples/load-obj-file.js":3,"./examples/unlit-textures.js":4,"./src/engine/utils.js":13}],2:[function(require,module,exports){
13
41
  "use strict";
14
42
 
15
43
  Object.defineProperty(exports, "__esModule", {
16
44
  value: true
17
45
  });
18
- exports.application = void 0;
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;
127
+
128
+ },{"../../../src/engine/loader-obj.js":9,"../../../src/engine/utils.js":13,"../../../src/world.js":19}],3:[function(require,module,exports){
129
+ "use strict";
130
+
131
+ Object.defineProperty(exports, "__esModule", {
132
+ value: true
133
+ });
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;
241
+
242
+ },{"../src/engine/loader-obj.js":9,"../src/engine/utils.js":13,"../src/world.js":19}],4:[function(require,module,exports){
243
+ "use strict";
64
244
 
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({
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":17}],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", {
@@ -5845,7 +6052,7 @@ class MEBall {
5845
6052
  }
5846
6053
  exports.default = MEBall;
5847
6054
 
5848
- },{"../shaders/shaders":14,"./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", {
@@ -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
@@ -6254,7 +6462,7 @@ class MECube {
6254
6462
  }
6255
6463
  exports.default = MECube;
6256
6464
 
6257
- },{"../shaders/shaders":14,"./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,7 +7618,7 @@ 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
7624
  this.mainCameraParams = {
@@ -7717,21 +7931,21 @@ class MEMeshObj {
7717
7931
  const now = Date.now();
7718
7932
  const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef;
7719
7933
  this.lastFrameMS = now;
7720
-
7721
7934
  // const this.viewMatrix = mat4.identity()
7722
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,18 +8047,6 @@ 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
-
7800
- // shadowPass.end();
7801
- // }
7802
- // {
7803
- // const renderPass = commandEncoder.beginRenderPass(this.renderPassDescriptor);
7804
- // renderPass.setPipeline(this.pipeline);
7805
-
7806
- // renderPass.end();
7807
- // }
7808
8050
  };
7809
8051
  drawElements = renderPass => {
7810
8052
  renderPass.setBindGroup(0, this.sceneBindGroupForRender);
@@ -7827,7 +8069,7 @@ class MEMeshObj {
7827
8069
  }
7828
8070
  exports.default = MEMeshObj;
7829
8071
 
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){
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){
7831
8073
  "use strict";
7832
8074
 
7833
8075
  Object.defineProperty(exports, "__esModule", {
@@ -8225,12 +8467,13 @@ class MEMesh {
8225
8467
  }
8226
8468
  exports.default = MEMesh;
8227
8469
 
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){
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){
8229
8471
  "use strict";
8230
8472
 
8231
8473
  Object.defineProperty(exports, "__esModule", {
8232
8474
  value: true
8233
8475
  });
8476
+ exports.LOG_WARN = exports.LOG_MATRIX = exports.LOG_INFO = exports.LOG_FUNNY = void 0;
8234
8477
  exports.ORBIT = ORBIT;
8235
8478
  exports.ORBIT_FROM_ARRAY = ORBIT_FROM_ARRAY;
8236
8479
  exports.OSCILLATOR = OSCILLATOR;
@@ -8240,6 +8483,8 @@ exports.byId = void 0;
8240
8483
  exports.createAppEvent = createAppEvent;
8241
8484
  exports.degToRad = degToRad;
8242
8485
  exports.getAxisRot = getAxisRot;
8486
+ exports.getAxisRot2 = getAxisRot2;
8487
+ exports.getAxisRot3 = getAxisRot3;
8243
8488
  exports.mat4 = void 0;
8244
8489
  exports.quaternion_rotation_matrix = quaternion_rotation_matrix;
8245
8490
  exports.radToDeg = radToDeg;
@@ -8806,6 +9051,7 @@ function getAxisRot(q1) {
8806
9051
  if (s < 0.001) {
8807
9052
  // if s close to zero then direction of axis not important
8808
9053
  // if it is important that axis is normalised then replace with x=1; y=z=0;
9054
+
8809
9055
  x = q1.x;
8810
9056
  y = q1.y;
8811
9057
  z = q1.z;
@@ -8816,6 +9062,41 @@ function getAxisRot(q1) {
8816
9062
  }
8817
9063
  return [radToDeg(x), radToDeg(y), radToDeg(z)];
8818
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
+ }
8819
9100
 
8820
9101
  // NTO TESTED
8821
9102
  function quaternion_rotation_matrix(Q) {
@@ -8855,7 +9136,13 @@ function quaternion_rotation_matrix(Q) {
8855
9136
  return rot_matrix;
8856
9137
  }
8857
9138
 
8858
- },{}],12:[function(require,module,exports){
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){
8859
9146
  "use strict";
8860
9147
 
8861
9148
  Object.defineProperty(exports, "__esModule", {
@@ -8870,16 +9157,17 @@ class MatrixAmmo {
8870
9157
  _utils.scriptManager.LOAD("./ammojs/ammo.js", "ammojs", undefined, undefined, this.init);
8871
9158
  }
8872
9159
  init = () => {
8873
- // start
9160
+ console.log('pre ammo');
8874
9161
  Ammo().then(Ammo => {
8875
9162
  // Physics variables
8876
9163
  this.dynamicsWorld = null;
8877
9164
  this.rigidBodies = [];
8878
9165
  this.Ammo = Ammo;
8879
9166
  this.lastUpdate = 0;
8880
- console.log("Ammo core loaded.");
9167
+ console.log("%c Ammo core loaded.", _utils.LOG_FUNNY);
8881
9168
  this.initPhysics();
8882
- dispatchEvent(new CustomEvent('AmmoReady', {}));
9169
+ // simulate async
9170
+ setTimeout(() => dispatchEvent(new CustomEvent('AmmoReady', {})), 100);
8883
9171
  });
8884
9172
  };
8885
9173
  initPhysics() {
@@ -8892,7 +9180,7 @@ class MatrixAmmo {
8892
9180
  solver = new Ammo.btSequentialImpulseConstraintSolver();
8893
9181
  this.dynamicsWorld = new Ammo.btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
8894
9182
  this.dynamicsWorld.setGravity(new Ammo.btVector3(0, -10, 0));
8895
- var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(50, 2, 50)),
9183
+ var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(50, 0.5, 50)),
8896
9184
  groundTransform = new Ammo.btTransform();
8897
9185
  groundTransform.setIdentity();
8898
9186
  groundTransform.setOrigin(new Ammo.btVector3(0, -1, 0));
@@ -8910,18 +9198,18 @@ class MatrixAmmo {
8910
9198
  if (pOptions.geometry == "Sphere") {
8911
9199
  this.addPhysicsSphere(MEObject, pOptions);
8912
9200
  } else if (pOptions.geometry == "Cube") {
8913
- //
9201
+ this.addPhysicsBox(MEObject, pOptions);
8914
9202
  }
8915
9203
  }
8916
9204
  addPhysicsSphere(MEObject, pOptions) {
8917
9205
  let Ammo = this.Ammo;
8918
- var colShape = new Ammo.btSphereShape(1),
9206
+ var colShape = new Ammo.btSphereShape(pOptions.radius),
8919
9207
  startTransform = new Ammo.btTransform();
8920
9208
  startTransform.setIdentity();
8921
9209
  var mass = 1;
8922
9210
  var localInertia = new Ammo.btVector3(0, 0, 0);
8923
9211
  colShape.calculateLocalInertia(mass, localInertia);
8924
- startTransform.setOrigin(new Ammo.btVector3(0, 15, -10));
9212
+ startTransform.setOrigin(new Ammo.btVector3(pOptions.position.x, pOptions.position.y, pOptions.position.z));
8925
9213
  var myMotionState = new Ammo.btDefaultMotionState(startTransform),
8926
9214
  rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia),
8927
9215
  body = new Ammo.btRigidBody(rbInfo);
@@ -8930,6 +9218,64 @@ class MatrixAmmo {
8930
9218
  this.rigidBodies.push(body);
8931
9219
  return body;
8932
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
+ }
8933
9279
  updatePhysics() {
8934
9280
  // Step world
8935
9281
  this.dynamicsWorld.stepSimulation(1 / 60, 10);
@@ -8943,29 +9289,23 @@ class MatrixAmmo {
8943
9289
  var _z = trans.getOrigin().z().toFixed(2);
8944
9290
  body.MEObject.position.setPosition(_x, _y, _z);
8945
9291
  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));
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)));
8962
9302
  }
8963
9303
  });
8964
9304
  }
8965
9305
  }
8966
9306
  exports.default = MatrixAmmo;
8967
9307
 
8968
- },{"../engine/utils":11,"wgpu-matrix":3}],13:[function(require,module,exports){
9308
+ },{"../engine/utils":13,"wgpu-matrix":5}],15:[function(require,module,exports){
8969
9309
  "use strict";
8970
9310
 
8971
9311
  Object.defineProperty(exports, "__esModule", {
@@ -9021,7 +9361,7 @@ fn main(input : FragmentInput) -> @location(0) vec4f {
9021
9361
  return vec4(textureColor.rgb * lightingFactor * albedo, 1.0);
9022
9362
  }`;
9023
9363
 
9024
- },{}],14:[function(require,module,exports){
9364
+ },{}],16:[function(require,module,exports){
9025
9365
  "use strict";
9026
9366
 
9027
9367
  Object.defineProperty(exports, "__esModule", {
@@ -9079,7 +9419,7 @@ fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {
9079
9419
  return vec4f(textureColor.rgb * lightColor, textureColor.a);
9080
9420
  }`;
9081
9421
 
9082
- },{}],15:[function(require,module,exports){
9422
+ },{}],17:[function(require,module,exports){
9083
9423
  "use strict";
9084
9424
 
9085
9425
  Object.defineProperty(exports, "__esModule", {
@@ -9136,7 +9476,7 @@ fn main(
9136
9476
  }
9137
9477
  `;
9138
9478
 
9139
- },{}],16:[function(require,module,exports){
9479
+ },{}],18:[function(require,module,exports){
9140
9480
  "use strict";
9141
9481
 
9142
9482
  Object.defineProperty(exports, "__esModule", {
@@ -9164,7 +9504,7 @@ fn main(
9164
9504
  }
9165
9505
  `;
9166
9506
 
9167
- },{}],17:[function(require,module,exports){
9507
+ },{}],19:[function(require,module,exports){
9168
9508
  "use strict";
9169
9509
 
9170
9510
  Object.defineProperty(exports, "__esModule", {
@@ -9263,40 +9603,14 @@ class MatrixEngineWGPU {
9263
9603
  alphaMode: 'premultiplied'
9264
9604
  });
9265
9605
  if (this.options.useSingleRenderPass == true) {
9266
- this.makeDefaultRenderPassDescriptor();
9267
9606
  this.frame = this.frameSinglePass;
9268
9607
  } else {
9269
- // must be
9270
9608
  this.frame = this.framePassPerObject;
9271
9609
  }
9272
9610
  this.run(callback);
9273
9611
  };
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
- };
9612
+
9613
+ // Not in use for now
9300
9614
  addCube = o => {
9301
9615
  if (typeof o === 'undefined') {
9302
9616
  var o = {
@@ -9358,6 +9672,8 @@ class MatrixEngineWGPU {
9358
9672
  let myCube1 = new _cube.default(this.canvas, this.device, this.context, o);
9359
9673
  this.mainRenderBundle.push(myCube1);
9360
9674
  };
9675
+
9676
+ // Not in use for now
9361
9677
  addBall = o => {
9362
9678
  if (typeof o === 'undefined') {
9363
9679
  var o = {
@@ -9419,6 +9735,8 @@ class MatrixEngineWGPU {
9419
9735
  let myBall1 = new _ball.default(this.canvas, this.device, this.context, o);
9420
9736
  this.mainRenderBundle.push(myBall1);
9421
9737
  };
9738
+
9739
+ // Not in use for now
9422
9740
  addMesh = o => {
9423
9741
  if (typeof o.position === 'undefined') {
9424
9742
  o.position = {
@@ -9506,7 +9824,8 @@ class MatrixEngineWGPU {
9506
9824
  if (typeof o.physics === 'undefined') {
9507
9825
  o.physics = {
9508
9826
  enabled: false,
9509
- geometry: "Sphere"
9827
+ geometry: "Sphere",
9828
+ radius: o.scale
9510
9829
  };
9511
9830
  }
9512
9831
  if (typeof o.physics.enabled === 'undefined') {
@@ -9515,6 +9834,16 @@ class MatrixEngineWGPU {
9515
9834
  if (typeof o.physics.geometry === 'undefined') {
9516
9835
  o.physics.geometry = "Sphere";
9517
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
+
9518
9847
  // console.log('Mesh procedure', o)
9519
9848
  let myMesh1 = new _meshObj.default(this.canvas, this.device, this.context, o);
9520
9849
  if (o.physics.enabled == true) {
@@ -9527,36 +9856,67 @@ class MatrixEngineWGPU {
9527
9856
  requestAnimationFrame(this.frame);
9528
9857
  }, 500);
9529
9858
  setTimeout(() => {
9530
- callback();
9859
+ callback(this);
9531
9860
  }, 20);
9532
9861
  }
9862
+ destroyProgram = () => {
9863
+ this.mainRenderBundle = undefined;
9864
+ this.canvas.remove();
9865
+ };
9533
9866
  frameSinglePass = () => {
9534
9867
  if (typeof this.mainRenderBundle == 'undefined') return;
9535
- let shadowPass = null;
9536
- let renderPass;
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
+ }
9899
+ };
9900
+ framePassPerObject = () => {
9901
+ console.log('framePassPerObject');
9537
9902
  let commandEncoder = this.device.createCommandEncoder();
9538
- this.mainRenderBundle.forEach((meItem, index) => {
9539
- meItem.position.update();
9540
- });
9903
+ this.rbContainer = [];
9904
+ let passEncoder;
9541
9905
  this.mainRenderBundle.forEach((meItem, index) => {
9542
9906
  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);
9907
+ if (meItem.renderBundle) {
9908
+ this.rbContainer.push(meItem.renderBundle);
9909
+ passEncoder = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
9910
+ passEncoder.executeBundles(this.rbContainer);
9911
+ passEncoder.end();
9912
+ } else {
9913
+ meItem.draw(commandEncoder);
9914
+ }
9554
9915
  });
9555
- renderPass.end();
9556
9916
  this.device.queue.submit([commandEncoder.finish()]);
9557
9917
  requestAnimationFrame(this.frame);
9558
9918
  };
9559
9919
  }
9560
9920
  exports.default = MatrixEngineWGPU;
9561
9921
 
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]);
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]);