melonjs 10.5.2 → 10.7.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 (67) hide show
  1. package/README.md +4 -6
  2. package/dist/melonjs.js +37470 -36394
  3. package/dist/melonjs.min.js +22 -22
  4. package/dist/melonjs.module.d.ts +606 -426
  5. package/dist/melonjs.module.js +8114 -7033
  6. package/package.json +15 -13
  7. package/src/camera/camera2d.js +11 -10
  8. package/src/game.js +5 -5
  9. package/src/geometries/ellipse.js +1 -1
  10. package/src/geometries/poly.js +1 -1
  11. package/src/geometries/rectangle.js +15 -0
  12. package/src/index.js +5 -5
  13. package/src/input/gamepad.js +12 -10
  14. package/src/input/keyboard.js +5 -3
  15. package/src/input/pointer.js +1 -1
  16. package/src/input/pointerevent.js +3 -4
  17. package/src/level/tiled/TMXLayer.js +1 -1
  18. package/src/level/tiled/TMXTileMap.js +1 -1
  19. package/src/level/tiled/TMXUtils.js +1 -1
  20. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  21. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  22. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  23. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  24. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  25. package/src/loader/loader.js +1 -1
  26. package/src/loader/loadingscreen.js +1 -1
  27. package/src/math/color.js +1 -1
  28. package/src/math/matrix2.js +2 -2
  29. package/src/math/matrix3.js +67 -66
  30. package/src/math/observable_vector2.js +1 -1
  31. package/src/math/observable_vector3.js +1 -1
  32. package/src/math/vector2.js +1 -1
  33. package/src/math/vector3.js +1 -1
  34. package/src/particles/emitter.js +120 -429
  35. package/src/particles/particle.js +51 -52
  36. package/src/particles/settings.js +310 -0
  37. package/src/physics/body.js +7 -7
  38. package/src/polyfill/console.js +7 -7
  39. package/src/polyfill/index.js +7 -0
  40. package/src/polyfill/performance.js +20 -0
  41. package/src/polyfill/requestAnimationFrame.js +10 -10
  42. package/src/renderable/colorlayer.js +1 -1
  43. package/src/renderable/container.js +11 -1
  44. package/src/renderable/imagelayer.js +3 -3
  45. package/src/renderable/nineslicesprite.js +6 -3
  46. package/src/renderable/renderable.js +18 -1
  47. package/src/renderable/sprite.js +2 -2
  48. package/src/state/state.js +13 -13
  49. package/src/system/device.js +141 -128
  50. package/src/system/event.js +10 -10
  51. package/src/system/pooling.js +150 -155
  52. package/src/system/timer.js +1 -1
  53. package/src/text/bitmaptext.js +35 -91
  54. package/src/text/text.js +82 -145
  55. package/src/text/textmetrics.js +168 -0
  56. package/src/text/textstyle.js +14 -0
  57. package/src/utils/agent.js +4 -4
  58. package/src/utils/function.js +2 -2
  59. package/src/utils/utils.js +10 -5
  60. package/src/video/canvas/canvas_renderer.js +34 -4
  61. package/src/video/renderer.js +3 -5
  62. package/src/video/texture.js +1 -1
  63. package/src/video/video.js +11 -11
  64. package/src/video/webgl/buffer/vertex.js +0 -3
  65. package/src/video/webgl/glshader.js +1 -3
  66. package/src/video/webgl/webgl_renderer.js +50 -22
  67. package/src/particles/particlecontainer.js +0 -95
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "melonjs",
3
- "version": "10.5.2",
3
+ "version": "10.7.0",
4
4
  "description": "melonJS Game Engine",
5
5
  "homepage": "http://www.melonjs.org/",
6
6
  "keywords": [
@@ -38,7 +38,8 @@
38
38
  "engines": {
39
39
  "node": ">= 12"
40
40
  },
41
- "main": "dist/melonjs.js",
41
+ "main": "dist/melonjs.module.js",
42
+ "type": "module",
42
43
  "module": "dist/melonjs.module.js",
43
44
  "files": [
44
45
  "dist/melonjs.js",
@@ -54,41 +55,42 @@
54
55
  ],
55
56
  "dependencies": {
56
57
  "@teppeis/multimaps": "^2.0.0",
58
+ "core-js": "^3.22.4",
57
59
  "earcut": "2.2.3",
58
60
  "eventemitter3": "^4.0.7",
59
61
  "howler": "2.2.3"
60
62
  },
61
63
  "devDependencies": {
62
64
  "@rollup/plugin-buble": "^0.21.3",
63
- "@rollup/plugin-commonjs": "^21.0.2",
64
- "@rollup/plugin-node-resolve": "^13.1.3",
65
+ "@rollup/plugin-commonjs": "^22.0.0",
66
+ "@rollup/plugin-node-resolve": "^13.3.0",
65
67
  "@rollup/plugin-replace": "^4.0.0",
66
68
  "@types/offscreencanvas": "^2019.6.4",
67
69
  "cheerio": "^1.0.0-rc.10",
68
70
  "del-cli": "^4.0.1",
69
- "eslint": "^8.11.0",
70
- "eslint-plugin-jsdoc": "^38.0.4",
71
- "jasmine-core": "^4.0.1",
71
+ "eslint": "^8.14.0",
72
+ "eslint-plugin-jsdoc": "^39.2.9",
73
+ "jasmine-core": "^4.1.0",
72
74
  "jsdoc": "^3.6.10",
73
- "karma": "^6.3.17",
75
+ "karma": "^6.3.19",
74
76
  "karma-chrome-launcher": "^3.1.1",
75
77
  "karma-coverage": "^2.2.0",
76
78
  "karma-html-detailed-reporter": "^2.1.0",
77
- "karma-jasmine": "^4.0.1",
79
+ "karma-jasmine": "^5.0.0",
78
80
  "karma-nyan-reporter": "0.2.5",
79
81
  "qs": "^6.10.3",
80
- "rollup": "^2.70.1",
82
+ "rollup": "^2.71.1",
81
83
  "rollup-plugin-bundle-size": "^1.0.3",
82
84
  "rollup-plugin-string": "^3.0.0",
83
- "terser": "^5.12.1",
84
- "typescript": "^4.6.2"
85
+ "terser": "^5.13.1",
86
+ "typescript": "^4.6.4"
85
87
  },
86
88
  "scripts": {
87
89
  "build": "npm run lint && rollup -c --silent",
88
90
  "dist": " npm run build && npm run minify && mkdirp dist && cp -f build/*.js dist/ && npm run types",
89
91
  "minify": "terser build/melonjs.js --compress --mangle --comments '/(?:^!|@(?:license|preserve|cc_on))/' --output build/melonjs.min.js",
90
92
  "lint": "eslint src rollup.config.js",
91
- "test": "npm run build && karma start tests/karma.conf.js",
93
+ "test": "npm run build && karma start tests/karma.conf.cjs",
92
94
  "doc": "mkdirp docs && jsdoc -c jsdoc_conf.json",
93
95
  "release": "npm run dist && npm publish --access public",
94
96
  "clean": "del-cli --force build/*.js dist/*.js dist/*.d.ts docs src/**/*.d.ts",
@@ -7,7 +7,7 @@ import Matrix3d from "./../math/matrix3.js";
7
7
  import Rect from "./../geometries/rectangle.js";
8
8
  import { renderer } from "./../video/video.js";
9
9
  import * as event from "./../system/event.js";
10
- import pool from "./../system/pooling.js";
10
+ import * as pool from "./../system/pooling.js";
11
11
  import Renderable from "./../renderable/renderable.js";
12
12
  import {clamp, toBeCloseTo} from "./../math/math.js";
13
13
  import { world } from "./../game.js";
@@ -408,7 +408,7 @@ class Camera2d extends Renderable {
408
408
 
409
409
  //publish the VIEWPORT_ONCHANGE event if necessary
410
410
  if (_x !== this.pos.x || _y !== this.pos.y) {
411
- event.emit(event.VIEWPORT_ONCHANGE, this.pos);
411
+ this.isDirty = true;
412
412
  }
413
413
  }
414
414
 
@@ -447,22 +447,22 @@ class Camera2d extends Renderable {
447
447
  if (toBeCloseTo(targetV.x, this.pos.x, 2) &&
448
448
  toBeCloseTo(targetV.y, this.pos.y, 2)) {
449
449
  this.pos.setV(targetV);
450
- return false;
450
+ return;
451
451
  } else {
452
452
  this.pos.lerp(targetV, this.damping);
453
453
  }
454
454
  } else {
455
455
  this.pos.setV(targetV);
456
456
  }
457
- return true;
457
+ this.isDirty = true;
458
458
  }
459
459
  }
460
- return false;
461
460
  }
462
461
 
463
462
  /** @ignore */
464
463
  update(dt) {
465
- var updated = this.updateTarget(dt);
464
+ // update the camera position
465
+ this.updateTarget(dt);
466
466
 
467
467
  if (this._shake.duration > 0) {
468
468
  this._shake.duration -= dt;
@@ -484,17 +484,17 @@ class Camera2d extends Renderable {
484
484
  }
485
485
  }
486
486
  // updated!
487
- updated = true;
487
+ this.isDirty = true;
488
488
  }
489
489
 
490
- if (updated === true) {
490
+ if (this.isDirty === true) {
491
491
  //publish the corresponding message
492
492
  event.emit(event.VIEWPORT_ONCHANGE, this.pos);
493
493
  }
494
494
 
495
495
  // check for fade/flash effect
496
496
  if ((this._fadeIn.tween != null) || (this._fadeOut.tween != null)) {
497
- updated = true;
497
+ this.isDirty = true;
498
498
  }
499
499
 
500
500
  if (!this.currentTransform.isIdentity()) {
@@ -503,7 +503,8 @@ class Camera2d extends Renderable {
503
503
  // reset to default
504
504
  this.invCurrentTransform.identity();
505
505
  }
506
- return updated;
506
+
507
+ return super.update(dt);
507
508
  }
508
509
 
509
510
  /**
package/src/game.js CHANGED
@@ -94,7 +94,7 @@ export let sortOn = "z";
94
94
  * @name lastUpdate
95
95
  * @memberof game
96
96
  */
97
- export let lastUpdate = window.performance.now();
97
+ export let lastUpdate = globalThis.performance.now();
98
98
 
99
99
  /**
100
100
  * Fired when a level is fully loaded and all entities instantiated. <br>
@@ -188,7 +188,7 @@ export function update(time, stage) {
188
188
  accumulatorUpdateDelta = (timer.interpolation) ? updateDelta : Math.max(updateDelta, updateAverageDelta);
189
189
 
190
190
  while (accumulator >= accumulatorUpdateDelta || timer.interpolation) {
191
- lastUpdateStart = window.performance.now();
191
+ lastUpdateStart = globalThis.performance.now();
192
192
 
193
193
  // game update event
194
194
  if (state.isPaused() !== true) {
@@ -198,7 +198,7 @@ export function update(time, stage) {
198
198
  // update all objects (and pass the elapsed time since last frame)
199
199
  isDirty = stage.update(updateDelta) || isDirty;
200
200
 
201
- lastUpdate = window.performance.now();
201
+ lastUpdate = globalThis.performance.now();
202
202
  updateAverageDelta = lastUpdate - lastUpdateStart;
203
203
 
204
204
  accumulator -= accumulatorUpdateDelta;
@@ -223,7 +223,7 @@ export function draw(stage) {
223
223
 
224
224
  if (renderer.isContextValid === true && (isDirty || isAlwaysDirty)) {
225
225
  // publish notification
226
- event.emit(event.GAME_BEFORE_DRAW, window.performance.now());
226
+ event.emit(event.GAME_BEFORE_DRAW, globalThis.performance.now());
227
227
 
228
228
  // prepare renderer to draw a new frame
229
229
  renderer.clear();
@@ -238,6 +238,6 @@ export function draw(stage) {
238
238
  renderer.flush();
239
239
 
240
240
  // publish notification
241
- event.emit(event.GAME_AFTER_DRAW, window.performance.now());
241
+ event.emit(event.GAME_AFTER_DRAW, globalThis.performance.now());
242
242
  }
243
243
  };
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../math/vector2.js";
2
- import pool from "./../system/pooling.js";
2
+ import * as pool from "./../system/pooling.js";
3
3
 
4
4
  /**
5
5
  * @classdesc
@@ -1,6 +1,6 @@
1
1
  import earcut from "earcut";
2
2
  import Vector2d from "./../math/vector2.js";
3
- import pool from "./../system/pooling.js";
3
+ import * as pool from "./../system/pooling.js";
4
4
 
5
5
  /**
6
6
  * @classdesc
@@ -172,6 +172,21 @@ class Rect extends Polygon {
172
172
  this.pos.y = value - (this.height / 2);
173
173
  }
174
174
 
175
+ /**
176
+ * center the rectangle position around the given coordinates
177
+ * @name centerOn
178
+ * @memberof Rect.prototype
179
+ * @function
180
+ * @param {number} x the x coordinate around which to center this rectangle
181
+ * @param {number} x the y coordinate around which to center this rectangle
182
+ * @returns {Rect} this rectangle
183
+ */
184
+ centerOn(x, y) {
185
+ this.centerX = x;
186
+ this.centerY = y;
187
+ return this;
188
+ }
189
+
175
190
  /**
176
191
  * resize the rectangle
177
192
  * @name resize
package/src/index.js CHANGED
@@ -1,6 +1,5 @@
1
- // ES5 polyfills
2
- import "./polyfill/console.js";
3
- import "./polyfill/requestAnimationFrame.js";
1
+ // ES5/ES6 polyfills
2
+ import "./polyfill/index.js";
4
3
 
5
4
  // utility classes
6
5
  import * as audio from "./audio/audio.js";
@@ -16,7 +15,7 @@ import { plugin, plugins } from "./plugin/plugin.js";
16
15
  import * as video from "./video/video.js";
17
16
  import save from "./system/save.js";
18
17
  import timer from "./system/timer.js";
19
- import pool from "./system/pooling.js";
18
+ import * as pool from "./system/pooling.js";
20
19
  import state from "./state/state.js";
21
20
  import level from "./level/level.js";
22
21
 
@@ -69,7 +68,8 @@ import Stage from "./state/stage.js";
69
68
  import Camera2d from "./camera/camera2d.js";
70
69
  import Container from "./renderable/container.js";
71
70
  import World from "./physics/world.js";
72
- import { ParticleEmitterSettings, ParticleEmitter } from "./particles/emitter.js";
71
+ import ParticleEmitterSettings from "./particles/settings.js";
72
+ import ParticleEmitter from "./particles/emitter.js";
73
73
  import Particle from "./particles/particle.js";
74
74
  import Entity from "./entity/entity.js";
75
75
 
@@ -265,17 +265,19 @@ var updateGamepads = function () {
265
265
  * gamepad connected callback
266
266
  * @ignore
267
267
  */
268
- window.addEventListener("gamepadconnected", function (e) {
269
- event.emit(event.GAMEPAD_CONNECTED, e.gamepad);
270
- }, false);
268
+ if (globalThis.navigator && typeof globalThis.navigator.getGamepads === "function") {
269
+ globalThis.addEventListener("gamepadconnected", function (e) {
270
+ event.emit(event.GAMEPAD_CONNECTED, e.gamepad);
271
+ }, false);
271
272
 
272
- /**
273
- * gamepad disconnected callback
274
- * @ignore
275
- */
276
- window.addEventListener("gamepaddisconnected", function (e) {
277
- event.emit(event.GAMEPAD_DISCONNECTED, e.gamepad);
278
- }, false);
273
+ /**
274
+ * gamepad disconnected callback
275
+ * @ignore
276
+ */
277
+ globalThis.addEventListener("gamepaddisconnected", function (e) {
278
+ event.emit(event.GAMEPAD_DISCONNECTED, e.gamepad);
279
+ }, false);
280
+ }
279
281
 
280
282
  /*
281
283
  * PUBLIC STUFF
@@ -319,9 +319,11 @@ export var KEY = {
319
319
  export function initKeyboardEvent() {
320
320
  // make sure the keyboard is enable
321
321
  if (keyBoardEventTarget === null && device.isMobile === false) {
322
- keyBoardEventTarget = window;
323
- keyBoardEventTarget.addEventListener("keydown", keyDownEvent, false);
324
- keyBoardEventTarget.addEventListener("keyup", keyUpEvent, false);
322
+ keyBoardEventTarget = globalThis;
323
+ if (typeof keyBoardEventTarget.addEventListener === "function") {
324
+ keyBoardEventTarget.addEventListener("keydown", keyDownEvent, false);
325
+ keyBoardEventTarget.addEventListener("keyup", keyUpEvent, false);
326
+ }
325
327
  }
326
328
  };
327
329
 
@@ -334,7 +334,7 @@ class Pointer extends Bounds {
334
334
  this.gameScreenY = this.y = tmpVec.y;
335
335
 
336
336
  // true if not originally a pointer event
337
- this.isNormalized = !device.PointerEvent || (device.PointerEvent && !(event instanceof window.PointerEvent));
337
+ this.isNormalized = !device.PointerEvent || (device.PointerEvent && !(event instanceof globalThis.PointerEvent));
338
338
 
339
339
  this.locked = locked;
340
340
  this.movementX = event.movementX || 0;
@@ -5,7 +5,7 @@ import { throttle } from "./../utils/function.js";
5
5
  import { remove } from "./../utils/array.js";
6
6
  import * as event from "./../system/event.js";
7
7
  import timer from "./../system/timer.js";
8
- import pool from "./../system/pooling.js";
8
+ import * as pool from "./../system/pooling.js";
9
9
  import device from "./../system/device.js";
10
10
  import Pointer from "./pointer.js";
11
11
  import Rect from "./../geometries/rectangle.js";
@@ -559,8 +559,8 @@ export function globalToLocal(x, y, v) {
559
559
  v = v || pool.pull("Vector2d");
560
560
  var rect = device.getElementBounds(renderer.getScreenCanvas());
561
561
  var pixelRatio = device.devicePixelRatio;
562
- x -= rect.left + (window.pageXOffset || 0);
563
- y -= rect.top + (window.pageYOffset || 0);
562
+ x -= rect.left + (globalThis.pageXOffset || 0);
563
+ y -= rect.top + (globalThis.pageYOffset || 0);
564
564
  var scale = scaleRatio;
565
565
  if (scale.x !== 1.0 || scale.y !== 1.0) {
566
566
  x /= scale.x;
@@ -783,7 +783,6 @@ export function releaseAllPointerEvents(region) {
783
783
  * @memberof input
784
784
  * @public
785
785
  * @function
786
- * @param {Function} [success] callback if the request is successful
787
786
  * @returns {boolean} return true if the request was successfully submitted
788
787
  * @example
789
788
  * // register on the pointer lock change event
@@ -1,5 +1,5 @@
1
1
  import { createCanvas } from "./../../video/video.js";
2
- import pool from "./../../system/pooling.js";
2
+ import * as pool from "./../../system/pooling.js";
3
3
  import * as TMXUtils from "./TMXUtils.js";
4
4
  import Tile from "./TMXTile.js";
5
5
  import Renderable from "./../../renderable/renderable.js";
@@ -1,4 +1,4 @@
1
- import pool from "./../../system/pooling.js";
1
+ import * as pool from "./../../system/pooling.js";
2
2
  import * as event from "./../../system/event.js";
3
3
  import { viewport } from "./../../game.js";
4
4
  import collision from "./../../physics/collision.js";
@@ -138,7 +138,7 @@ export function decodeBase64AsArray(input, bytes) {
138
138
  bytes = bytes || 1;
139
139
 
140
140
  var i, j, len;
141
- var dec = window.atob(input.replace(/[^A-Za-z0-9\+\/\=]/g, ""));
141
+ var dec = globalThis.atob(input.replace(/[^A-Za-z0-9\+\/\=]/g, ""));
142
142
  var ar = new Uint32Array(dec.length / bytes);
143
143
 
144
144
  for (i = 0, len = dec.length / bytes; i < len; i++) {
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../../../math/vector2.js";
2
- import pool from "./../../../system/pooling.js";
2
+ import * as pool from "./../../../system/pooling.js";
3
3
  import TMXRenderer from "./TMXRenderer.js";
4
4
  import TMXLayer from "./../TMXLayer.js";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../../../math/vector2.js";
2
- import pool from "./../../../system/pooling.js";
2
+ import * as pool from "./../../../system/pooling.js";
3
3
  import TMXRenderer from "./TMXRenderer.js";
4
4
  import TMXLayer from "./../TMXLayer.js";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../../../math/vector2.js";
2
- import pool from "./../../../system/pooling.js";
2
+ import * as pool from "./../../../system/pooling.js";
3
3
  import TMXRenderer from "./TMXRenderer.js";
4
4
 
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-unused-vars */
2
2
 
3
- import pool from "./../../../system/pooling.js";
3
+ import * as pool from "./../../../system/pooling.js";
4
4
  import TMXLayer from "./../TMXLayer.js";
5
5
  import Bounds from "./../../../physics/Bounds.js";
6
6
 
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../../../math/vector2.js";
2
- import pool from "./../../../system/pooling.js";
2
+ import * as pool from "./../../../system/pooling.js";
3
3
  import TMXHexagonalRenderer from "./TMXHexagonalRenderer.js";
4
4
  import { degToRad } from "./../../../math/math.js";
5
5
 
@@ -154,7 +154,7 @@ function preloadTMX(tmxData, onload, onerror) {
154
154
  case "tsx":
155
155
  // ie9 does not fully implement the responseXML
156
156
  if (device.ua.match(/msie/i) || !xmlhttp.responseXML) {
157
- if (window.DOMParser) {
157
+ if (globalThis.DOMParser) {
158
158
  // manually create the XML DOM
159
159
  result = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
160
160
  } else {
@@ -2,7 +2,7 @@ import { world, viewport } from "./../game.js";
2
2
  import { createCanvas, renderer } from "./../video/video.js";
3
3
  import * as event from "./../system/event.js";
4
4
  import {nextPowerOfTwo} from "./../math/math.js";
5
- import pool from "./../system/pooling.js";
5
+ import * as pool from "./../system/pooling.js";
6
6
  import Renderable from "./../renderable/renderable.js";
7
7
  import Stage from "./../state/stage.js";
8
8
 
package/src/math/color.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { clamp, random } from "./math.js";
2
- import pool from "./../system/pooling.js";
2
+ import * as pool from "./../system/pooling.js";
3
3
 
4
4
  // convert a give color component to it hexadecimal value
5
5
  var toHex = function (component) {
@@ -1,4 +1,4 @@
1
- import pool from "./../system/pooling.js";
1
+ import * as pool from "./../system/pooling.js";
2
2
  import Matrix3d from "./matrix3.js";
3
3
 
4
4
  /**
@@ -9,7 +9,7 @@ import Matrix3d from "./matrix3.js";
9
9
  */
10
10
  class Matrix2d {
11
11
  /**
12
- * @param {(Matrix2d|Matrix3d|...number)} args an instance of me.Matrix2d or me.Matrix3d to copy from, or individual matrix components (See {@link Matrix2d.setTransform}). If not arguments are given, the matrix will be set to Identity.
12
+ * @param {(Matrix2d|Matrix3d|...number)} args an instance of me.Matrix2d or me.Matrix3d to copy from, or individual matrix components (See {@link Matrix2d.setTransform}). If not arguments are given, the matrix will be set to Identity.
13
13
  */
14
14
  constructor(...args) {
15
15
  this.onResetEvent(...args);
@@ -1,4 +1,4 @@
1
- import pool from "./../system/pooling.js";
1
+ import * as pool from "./../system/pooling.js";
2
2
  import { EPSILON } from "./math.js";
3
3
 
4
4
  /**
@@ -475,72 +475,73 @@ class Matrix3d {
475
475
  * @returns {Matrix3d} Reference to this object for method chaining
476
476
  */
477
477
  rotate(angle, v) {
478
- var a = this.val,
479
- x = v.x,
480
- y = v.y,
481
- z = v.z;
482
-
483
- var len = Math.sqrt(x * x + y * y + z * z);
484
-
485
- var s, c, t;
486
- var a00, a01, a02, a03;
487
- var a10, a11, a12, a13;
488
- var a20, a21, a22, a23;
489
- var b00, b01, b02;
490
- var b10, b11, b12;
491
- var b20, b21, b22;
492
-
493
- if (len < EPSILON) {
494
- return null;
495
- }
496
-
497
- len = 1 / len;
498
- x *= len;
499
- y *= len;
500
- z *= len;
501
-
502
- s = Math.sin(angle);
503
- c = Math.cos(angle);
504
- t = 1 - c;
505
-
506
- a00 = a[0];
507
- a01 = a[1];
508
- a02 = a[2];
509
- a03 = a[3];
510
- a10 = a[4];
511
- a11 = a[5];
512
- a12 = a[6];
513
- a13 = a[7];
514
- a20 = a[8];
515
- a21 = a[9];
516
- a22 = a[10];
517
- a23 = a[11];
518
-
519
- // Construct the elements of the rotation matrix
520
- b00 = x * x * t + c;
521
- b01 = y * x * t + z * s;
522
- b02 = z * x * t - y * s;
523
- b10 = x * y * t - z * s;
524
- b11 = y * y * t + c;
525
- b12 = z * y * t + x * s;
526
- b20 = x * z * t + y * s;
527
- b21 = y * z * t - x * s;
528
- b22 = z * z * t + c;
529
-
530
- // Perform rotation-specific matrix multiplication
531
- a[0] = a00 * b00 + a10 * b01 + a20 * b02;
532
- a[1] = a01 * b00 + a11 * b01 + a21 * b02;
533
- a[2] = a02 * b00 + a12 * b01 + a22 * b02;
534
- a[3] = a03 * b00 + a13 * b01 + a23 * b02;
535
- a[4] = a00 * b10 + a10 * b11 + a20 * b12;
536
- a[5] = a01 * b10 + a11 * b11 + a21 * b12;
537
- a[6] = a02 * b10 + a12 * b11 + a22 * b12;
538
- a[7] = a03 * b10 + a13 * b11 + a23 * b12;
539
- a[8] = a00 * b20 + a10 * b21 + a20 * b22;
540
- a[9] = a01 * b20 + a11 * b21 + a21 * b22;
541
- a[10] = a02 * b20 + a12 * b21 + a22 * b22;
542
- a[11] = a03 * b20 + a13 * b21 + a23 * b22;
478
+ if (angle !== 0) {
479
+ var a = this.val,
480
+ x = v.x,
481
+ y = v.y,
482
+ z = v.z;
483
+
484
+ var len = Math.sqrt(x * x + y * y + z * z);
485
+
486
+ var s, c, t;
487
+ var a00, a01, a02, a03;
488
+ var a10, a11, a12, a13;
489
+ var a20, a21, a22, a23;
490
+ var b00, b01, b02;
491
+ var b10, b11, b12;
492
+ var b20, b21, b22;
493
+
494
+ if (len < EPSILON) {
495
+ return null;
496
+ }
497
+
498
+ len = 1 / len;
499
+ x *= len;
500
+ y *= len;
501
+ z *= len;
502
+
503
+ s = Math.sin(angle);
504
+ c = Math.cos(angle);
505
+ t = 1 - c;
506
+
507
+ a00 = a[0];
508
+ a01 = a[1];
509
+ a02 = a[2];
510
+ a03 = a[3];
511
+ a10 = a[4];
512
+ a11 = a[5];
513
+ a12 = a[6];
514
+ a13 = a[7];
515
+ a20 = a[8];
516
+ a21 = a[9];
517
+ a22 = a[10];
518
+ a23 = a[11];
543
519
 
520
+ // Construct the elements of the rotation matrix
521
+ b00 = x * x * t + c;
522
+ b01 = y * x * t + z * s;
523
+ b02 = z * x * t - y * s;
524
+ b10 = x * y * t - z * s;
525
+ b11 = y * y * t + c;
526
+ b12 = z * y * t + x * s;
527
+ b20 = x * z * t + y * s;
528
+ b21 = y * z * t - x * s;
529
+ b22 = z * z * t + c;
530
+
531
+ // Perform rotation-specific matrix multiplication
532
+ a[0] = a00 * b00 + a10 * b01 + a20 * b02;
533
+ a[1] = a01 * b00 + a11 * b01 + a21 * b02;
534
+ a[2] = a02 * b00 + a12 * b01 + a22 * b02;
535
+ a[3] = a03 * b00 + a13 * b01 + a23 * b02;
536
+ a[4] = a00 * b10 + a10 * b11 + a20 * b12;
537
+ a[5] = a01 * b10 + a11 * b11 + a21 * b12;
538
+ a[6] = a02 * b10 + a12 * b11 + a22 * b12;
539
+ a[7] = a03 * b10 + a13 * b11 + a23 * b12;
540
+ a[8] = a00 * b20 + a10 * b21 + a20 * b22;
541
+ a[9] = a01 * b20 + a11 * b21 + a21 * b22;
542
+ a[10] = a02 * b20 + a12 * b21 + a22 * b22;
543
+ a[11] = a03 * b20 + a13 * b21 + a23 * b22;
544
+ }
544
545
  return this;
545
546
  }
546
547
 
@@ -1,4 +1,4 @@
1
- import pool from "./../system/pooling.js";
1
+ import * as pool from "./../system/pooling.js";
2
2
  import Vector2d from "./vector2.js";
3
3
  import {clamp} from "./math.js";
4
4
 
@@ -1,6 +1,6 @@
1
1
  import Vector3d from "./vector3.js";
2
2
  import {clamp} from "./math.js";
3
- import pool from "./../system/pooling.js";
3
+ import * as pool from "./../system/pooling.js";
4
4
 
5
5
  /**
6
6
  * @classdesc
@@ -1,5 +1,5 @@
1
1
  import {clamp} from "./math.js";
2
- import pool from "./../system/pooling.js";
2
+ import * as pool from "./../system/pooling.js";
3
3
 
4
4
  /**
5
5
  * @classdesc
@@ -1,5 +1,5 @@
1
1
  import {clamp} from "./math.js";
2
- import pool from "./../system/pooling.js";
2
+ import * as pool from "./../system/pooling.js";
3
3
 
4
4
  /**
5
5
  * @classdesc