melonjs 14.4.0 → 14.5.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.
- package/README.md +11 -55
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +1 -1
- package/dist/melonjs.mjs/application/header.js +1 -1
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +4 -4
- package/dist/melonjs.mjs/camera/camera2d.js +1 -1
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +43 -9
- package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +18 -42
- package/dist/melonjs.mjs/geometries/point.js +1 -6
- package/dist/melonjs.mjs/geometries/poly.js +2 -5
- package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +8 -6
- package/dist/melonjs.mjs/input/gamepad.js +10 -16
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +1 -1
- package/dist/melonjs.mjs/input/pointer.js +1 -1
- package/dist/melonjs.mjs/input/pointerevent.js +2 -16
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +1 -1
- package/dist/melonjs.mjs/level/level.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +24 -0
- package/dist/melonjs.mjs/loader/loader.js +331 -716
- package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +281 -0
- package/dist/melonjs.mjs/loader/settings.js +91 -0
- package/dist/melonjs.mjs/math/color.js +1 -1
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +7 -9
- package/dist/melonjs.mjs/math/matrix3.js +18 -21
- package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
- package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
- package/dist/melonjs.mjs/math/vector2.js +3 -3
- package/dist/melonjs.mjs/math/vector3.js +3 -4
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +3 -3
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +18 -14
- package/dist/melonjs.mjs/physics/bounds.js +18 -70
- package/dist/melonjs.mjs/physics/collision.js +1 -1
- package/dist/melonjs.mjs/physics/detector.js +1 -1
- package/dist/melonjs.mjs/physics/quadtree.js +1 -1
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +1 -1
- package/dist/melonjs.mjs/physics/world.js +1 -1
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +1 -1
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +25 -19
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
- package/dist/melonjs.mjs/renderable/light2d.js +1 -1
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
- package/dist/melonjs.mjs/renderable/renderable.js +126 -105
- package/dist/melonjs.mjs/renderable/sprite.js +33 -54
- package/dist/melonjs.mjs/renderable/trigger.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
- package/dist/melonjs.mjs/state/stage.js +1 -1
- package/dist/melonjs.mjs/state/state.js +2 -2
- package/dist/melonjs.mjs/system/device.js +1 -1
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +8 -18
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
- package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +1 -1
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +1 -1
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +1 -1
- package/dist/melonjs.mjs/utils/string.js +2 -2
- package/dist/melonjs.mjs/utils/utils.js +2 -4
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +1 -1
- package/dist/melonjs.mjs/video/renderer.js +1 -1
- package/dist/melonjs.mjs/video/texture/atlas.js +10 -9
- package/dist/melonjs.mjs/video/texture/cache.js +3 -3
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
- package/{src/video/webgl → dist/melonjs.mjs/video/webgl/compositors}/webgl_compositor.js +28 -205
- package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +2 -2
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +2 -2
- package/dist/melonjs.module.js +17844 -17809
- package/dist/types/entity/entity.d.ts +2 -2
- package/dist/types/geometries/path2d.d.ts +5 -31
- package/dist/types/geometries/point.d.ts +2 -7
- package/dist/types/geometries/poly.d.ts +0 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/loader/cache.d.ts +7 -0
- package/dist/types/loader/loader.d.ts +166 -181
- package/dist/types/loader/parser.d.ts +41 -0
- package/dist/types/loader/settings.d.ts +57 -0
- package/dist/types/particles/emitter.d.ts +4 -4
- package/dist/types/physics/bounds.d.ts +29 -84
- package/dist/types/renderable/container.d.ts +0 -11
- package/dist/types/renderable/renderable.d.ts +37 -31
- package/dist/types/renderable/sprite.d.ts +3 -3
- package/dist/types/state/state.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +2 -2
- package/dist/types/video/renderer.d.ts +1 -1
- package/dist/types/video/webgl/compositors/compositor.d.ts +101 -0
- package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
- package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
- package/dist/types/video/webgl/webgl_renderer.d.ts +1 -1
- package/package.json +16 -15
- package/src/audio/audio.js +3 -3
- package/src/entity/entity.js +42 -8
- package/src/geometries/ellipse.js +1 -2
- package/src/geometries/path2d.js +17 -41
- package/src/geometries/point.js +0 -5
- package/src/geometries/poly.js +1 -4
- package/src/geometries/rectangle.js +12 -8
- package/src/index.js +2 -2
- package/src/input/gamepad.js +9 -15
- package/src/input/pointerevent.js +1 -15
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXLayer.js +0 -7
- package/src/level/tiled/TMXTileMap.js +7 -3
- package/src/level/tiled/TMXTileset.js +4 -4
- package/src/loader/cache.js +16 -0
- package/src/loader/loader.js +339 -711
- package/src/loader/loadingscreen.js +3 -3
- package/src/loader/parser.js +279 -0
- package/src/loader/settings.js +85 -0
- package/src/math/matrix2.js +6 -8
- package/src/math/matrix3.js +17 -20
- package/src/math/observable_vector2.js +2 -2
- package/src/math/observable_vector3.js +2 -3
- package/src/math/vector2.js +2 -2
- package/src/math/vector3.js +2 -3
- package/src/particles/emitter.js +2 -2
- package/src/physics/body.js +17 -13
- package/src/physics/bounds.js +17 -69
- package/src/renderable/container.js +24 -18
- package/src/renderable/imagelayer.js +6 -0
- package/src/renderable/renderable.js +125 -104
- package/src/renderable/sprite.js +32 -53
- package/src/state/state.js +1 -1
- package/src/system/pooling.js +7 -17
- package/src/text/bitmaptext.js +65 -7
- package/src/utils/string.js +1 -1
- package/src/utils/utils.js +1 -3
- package/src/video/texture/atlas.js +9 -8
- package/src/video/texture/cache.js +2 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/compositors/compositor.js +227 -0
- package/src/video/webgl/compositors/webgl_compositor.js +300 -0
- package/src/video/webgl/webgl_renderer.js +1 -1
package/src/text/bitmaptext.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Color from "./../math/color.js";
|
|
2
2
|
import pool from "./../system/pooling.js";
|
|
3
|
-
import
|
|
3
|
+
import { getImage, getBinary } from "./../loader/loader.js";
|
|
4
4
|
import Renderable from "./../renderable/renderable.js";
|
|
5
5
|
import TextMetrics from "./textmetrics.js";
|
|
6
6
|
|
|
@@ -95,7 +95,7 @@ import TextMetrics from "./textmetrics.js";
|
|
|
95
95
|
* font image
|
|
96
96
|
* @private
|
|
97
97
|
*/
|
|
98
|
-
this.fontImage = (typeof settings.font === "object") ? settings.font :
|
|
98
|
+
this.fontImage = (typeof settings.font === "object") ? settings.font : getImage(settings.font);
|
|
99
99
|
|
|
100
100
|
if (typeof settings.fontData !== "string") {
|
|
101
101
|
/**
|
|
@@ -103,11 +103,11 @@ import TextMetrics from "./textmetrics.js";
|
|
|
103
103
|
* @private
|
|
104
104
|
*/
|
|
105
105
|
// use settings.font to retreive the data from the loader
|
|
106
|
-
this.fontData = pool.pull("BitmapTextData",
|
|
106
|
+
this.fontData = pool.pull("BitmapTextData", getBinary(settings.font));
|
|
107
107
|
} else {
|
|
108
108
|
this.fontData = pool.pull("BitmapTextData",
|
|
109
109
|
// if starting/includes "info face" the whole data string was passed as parameter
|
|
110
|
-
(settings.fontData.includes("info face")) ? settings.fontData :
|
|
110
|
+
(settings.fontData.includes("info face")) ? settings.fontData : getBinary(settings.fontData)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -176,11 +176,70 @@ import TextMetrics from "./textmetrics.js";
|
|
|
176
176
|
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
this.
|
|
179
|
+
this.updateBounds();
|
|
180
180
|
|
|
181
181
|
return this;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* update the bounding box for this Bitmap Text.
|
|
186
|
+
* @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
|
|
187
|
+
* @returns {Bounds} this Bitmap Text bounding box Rectangle object
|
|
188
|
+
*/
|
|
189
|
+
updateBounds(absolute = true) {
|
|
190
|
+
var bounds = this.getBounds();
|
|
191
|
+
|
|
192
|
+
bounds.clear();
|
|
193
|
+
|
|
194
|
+
if (typeof this.metrics !== "undefined") {
|
|
195
|
+
var ax, ay;
|
|
196
|
+
|
|
197
|
+
bounds.addBounds(this.metrics.measureText(this._text));
|
|
198
|
+
|
|
199
|
+
switch (this.textAlign) {
|
|
200
|
+
case "right":
|
|
201
|
+
ax = this.metrics.width * 1.0;
|
|
202
|
+
break;
|
|
203
|
+
|
|
204
|
+
case "center":
|
|
205
|
+
ax = this.metrics.width * 0.5;
|
|
206
|
+
break;
|
|
207
|
+
|
|
208
|
+
default :
|
|
209
|
+
ax = this.metrics.width * 0.0;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// adjust y pos based on alignment value
|
|
214
|
+
switch (this.textBaseline) {
|
|
215
|
+
case "middle":
|
|
216
|
+
ay = this.metrics.height * 0.5;
|
|
217
|
+
break;
|
|
218
|
+
|
|
219
|
+
case "ideographic":
|
|
220
|
+
case "alphabetic":
|
|
221
|
+
case "bottom":
|
|
222
|
+
ay = this.metrics.height * 1.0;
|
|
223
|
+
break;
|
|
224
|
+
|
|
225
|
+
default :
|
|
226
|
+
ay = this.metrics.height * 0.0;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// translate the bounds accordingly
|
|
231
|
+
bounds.translate(ax, ay);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (absolute === true) {
|
|
235
|
+
if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
|
|
236
|
+
bounds.translate(this.ancestor.getAbsolutePosition());
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return bounds;
|
|
241
|
+
}
|
|
242
|
+
|
|
184
243
|
/**
|
|
185
244
|
* defines the color used to tint the bitmap text
|
|
186
245
|
* @public
|
|
@@ -207,9 +266,8 @@ import TextMetrics from "./textmetrics.js";
|
|
|
207
266
|
resize(scale) {
|
|
208
267
|
this.fontScale.set(scale, scale);
|
|
209
268
|
|
|
210
|
-
this.
|
|
269
|
+
this.updateBounds();
|
|
211
270
|
|
|
212
|
-
// clear the cache text to recalculate bounds
|
|
213
271
|
this.isDirty = true;
|
|
214
272
|
|
|
215
273
|
return this;
|
package/src/utils/string.js
CHANGED
package/src/utils/utils.js
CHANGED
|
@@ -99,9 +99,7 @@ var utils = {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// parse the url
|
|
102
|
-
url.slice(1).split("&").filter((value) => {
|
|
103
|
-
return (value !== "");
|
|
104
|
-
}).forEach((value) => {
|
|
102
|
+
url.slice(1).split("&").filter((value) => value !== "").forEach((value) => {
|
|
105
103
|
var kv = value.split("=");
|
|
106
104
|
var k = kv.shift();
|
|
107
105
|
var v = kv.join("=");
|
|
@@ -4,7 +4,7 @@ import TextureCache from "./../texture/cache.js";
|
|
|
4
4
|
import Sprite from "./../../renderable/sprite.js";
|
|
5
5
|
import { renderer } from "./../video.js";
|
|
6
6
|
import pool from "./../../system/pooling.js";
|
|
7
|
-
import
|
|
7
|
+
import { getImage } from "./../../loader/loader.js";
|
|
8
8
|
import { ETA } from "./../../math/math.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -98,7 +98,7 @@ export class TextureAtlas {
|
|
|
98
98
|
// set the texture
|
|
99
99
|
if (typeof(src) === "undefined") {
|
|
100
100
|
// get the texture name from the atlas meta data
|
|
101
|
-
var image =
|
|
101
|
+
var image = getImage(atlas.meta.image);
|
|
102
102
|
if (!image) {
|
|
103
103
|
throw new Error(
|
|
104
104
|
"Atlas texture '" + image + "' not found"
|
|
@@ -106,7 +106,7 @@ export class TextureAtlas {
|
|
|
106
106
|
}
|
|
107
107
|
this.sources.set(atlas.meta.image, image);
|
|
108
108
|
} else {
|
|
109
|
-
this.sources.set(atlas.meta.image || "default", typeof src === "string" ?
|
|
109
|
+
this.sources.set(atlas.meta.image || "default", typeof src === "string" ? getImage(src) : src);
|
|
110
110
|
}
|
|
111
111
|
this.repeat = "no-repeat";
|
|
112
112
|
}
|
|
@@ -120,13 +120,13 @@ export class TextureAtlas {
|
|
|
120
120
|
}
|
|
121
121
|
this.format = "ShoeBox";
|
|
122
122
|
this.repeat = "no-repeat";
|
|
123
|
-
this.sources.set("default", typeof src === "string" ?
|
|
123
|
+
this.sources.set("default", typeof src === "string" ? getImage(src) : src);
|
|
124
124
|
}
|
|
125
125
|
// Internal texture atlas
|
|
126
126
|
else if (atlas.meta.app.includes("melonJS")) {
|
|
127
127
|
this.format = "melonJS";
|
|
128
128
|
this.repeat = atlas.meta.repeat || "no-repeat";
|
|
129
|
-
this.sources.set("default", typeof src === "string" ?
|
|
129
|
+
this.sources.set("default", typeof src === "string" ? getImage(src) : src);
|
|
130
130
|
}
|
|
131
131
|
// initialize the atlas
|
|
132
132
|
this.atlases.set(atlas.meta.image || "default", this.parse(atlas));
|
|
@@ -140,7 +140,7 @@ export class TextureAtlas {
|
|
|
140
140
|
|
|
141
141
|
if (typeof(src) !== "undefined") {
|
|
142
142
|
// overwrite if specified
|
|
143
|
-
atlas.image = typeof src === "string" ?
|
|
143
|
+
atlas.image = typeof src === "string" ? getImage(src) : src;
|
|
144
144
|
}
|
|
145
145
|
// initialize the atlas
|
|
146
146
|
this.atlases.set("default", this.parseFromSpriteSheet(atlas));
|
|
@@ -346,12 +346,13 @@ export class TextureAtlas {
|
|
|
346
346
|
region = this.getAtlas(atlas)[name];
|
|
347
347
|
} else {
|
|
348
348
|
// look for the given region in each existing atlas
|
|
349
|
-
this.atlases.
|
|
349
|
+
for (let atlas of this.atlases.values()) {
|
|
350
350
|
if (typeof atlas[name] !== "undefined") {
|
|
351
351
|
// there should be only one
|
|
352
352
|
region = atlas[name];
|
|
353
|
+
break;
|
|
353
354
|
}
|
|
354
|
-
}
|
|
355
|
+
}
|
|
355
356
|
}
|
|
356
357
|
return region;
|
|
357
358
|
}
|
|
@@ -56,8 +56,8 @@ class TextureCache {
|
|
|
56
56
|
} else {
|
|
57
57
|
// manage cases where a specific atlas is specified
|
|
58
58
|
this.cache.forEach((value, key) => {
|
|
59
|
-
var _atlas = value.getAtlas();
|
|
60
|
-
if (key === image && _atlas
|
|
59
|
+
var _atlas = value.getAtlas()[0];
|
|
60
|
+
if (key === image && _atlas.width === atlas.framewidth && _atlas.height === atlas.frameheight) {
|
|
61
61
|
entry = value;
|
|
62
62
|
}
|
|
63
63
|
});
|
package/src/video/video.js
CHANGED
|
@@ -87,7 +87,7 @@ export function init(width, height, options) {
|
|
|
87
87
|
// initialize the default game Application with the given options
|
|
88
88
|
game.init(width, height, options);
|
|
89
89
|
} catch (e) {
|
|
90
|
-
console(e.message);
|
|
90
|
+
console.log(e.message);
|
|
91
91
|
// me.video.init() historically returns false if failing at creating/using a HTML5 canvas
|
|
92
92
|
return false;
|
|
93
93
|
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as event from "../../../system/event.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @classdesc
|
|
6
|
+
* A base Compositor object.
|
|
7
|
+
*/
|
|
8
|
+
export default class Compositor {
|
|
9
|
+
/**
|
|
10
|
+
* @param {WebGLRenderer} renderer - the current WebGL renderer session
|
|
11
|
+
*/
|
|
12
|
+
constructor (renderer) {
|
|
13
|
+
this.init(renderer);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the compositor
|
|
18
|
+
* @ignore
|
|
19
|
+
*/
|
|
20
|
+
init (renderer) {
|
|
21
|
+
// local reference
|
|
22
|
+
var gl = renderer.gl;
|
|
23
|
+
|
|
24
|
+
// the associated renderer
|
|
25
|
+
this.renderer = renderer;
|
|
26
|
+
|
|
27
|
+
// WebGL context
|
|
28
|
+
this.gl = renderer.gl;
|
|
29
|
+
|
|
30
|
+
// Global fill color
|
|
31
|
+
this.color = renderer.currentColor;
|
|
32
|
+
|
|
33
|
+
// Global transformation matrix
|
|
34
|
+
this.viewMatrix = renderer.currentTransform;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* a reference to the active WebGL shader
|
|
38
|
+
* @type {GLShader}
|
|
39
|
+
*/
|
|
40
|
+
this.activeShader = null;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
|
|
44
|
+
* @type {number}
|
|
45
|
+
* @default gl.TRIANGLES
|
|
46
|
+
*/
|
|
47
|
+
this.mode = gl.TRIANGLES;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* an array of vertex attribute properties
|
|
51
|
+
* @see WebGLCompositor.addAttribute
|
|
52
|
+
* @type {Array}
|
|
53
|
+
*/
|
|
54
|
+
this.attributes = [];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* the size of a single vertex in bytes
|
|
58
|
+
* (will automatically be calculated as attributes definitions are added)
|
|
59
|
+
* @see WebGLCompositor.addAttribute
|
|
60
|
+
* @type {number}
|
|
61
|
+
*/
|
|
62
|
+
this.vertexByteSize = 0;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* the size of a single vertex in floats
|
|
66
|
+
* (will automatically be calculated as attributes definitions are added)
|
|
67
|
+
* @see WebGLCompositor.addAttribute
|
|
68
|
+
* @type {number}
|
|
69
|
+
*/
|
|
70
|
+
this.vertexSize = 0;
|
|
71
|
+
|
|
72
|
+
// register to the CANVAS resize channel
|
|
73
|
+
event.on(event.CANVAS_ONRESIZE, (width, height) => {
|
|
74
|
+
this.flush();
|
|
75
|
+
this.setViewport(0, 0, width, height);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Reset compositor internal state
|
|
81
|
+
* @ignore
|
|
82
|
+
*/
|
|
83
|
+
reset() {
|
|
84
|
+
// WebGL context
|
|
85
|
+
this.gl = this.renderer.gl;
|
|
86
|
+
|
|
87
|
+
this.flush();
|
|
88
|
+
|
|
89
|
+
// initial viewport size
|
|
90
|
+
this.setViewport(
|
|
91
|
+
0, 0,
|
|
92
|
+
this.renderer.getCanvas().width,
|
|
93
|
+
this.renderer.getCanvas().height
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Initialize clear color
|
|
97
|
+
this.clearColor(0.0, 0.0, 0.0, 0.0);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* add vertex attribute property definition to the compositor
|
|
102
|
+
* @param {string} name - name of the attribute in the vertex shader
|
|
103
|
+
* @param {number} size - number of components per vertex attribute. Must be 1, 2, 3, or 4.
|
|
104
|
+
* @param {GLenum} type - data type of each component in the array
|
|
105
|
+
* @param {boolean} normalized - whether integer data values should be normalized into a certain range when being cast to a float
|
|
106
|
+
* @param {number} offset - offset in bytes of the first component in the vertex attribute array
|
|
107
|
+
*/
|
|
108
|
+
addAttribute(name, size, type, normalized, offset) {
|
|
109
|
+
this.attributes.push({
|
|
110
|
+
name: name,
|
|
111
|
+
size: size,
|
|
112
|
+
type: type,
|
|
113
|
+
normalized: normalized,
|
|
114
|
+
offset: offset
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
switch (type) {
|
|
118
|
+
case this.gl.BYTE:
|
|
119
|
+
this.vertexByteSize += size * Int8Array.BYTES_PER_ELEMENT;
|
|
120
|
+
break;
|
|
121
|
+
case this.gl.UNSIGNED_BYTE:
|
|
122
|
+
this.vertexByteSize += size * Uint8Array.BYTES_PER_ELEMENT;
|
|
123
|
+
break;
|
|
124
|
+
case this.gl.SHORT:
|
|
125
|
+
this.vertexByteSize += size * Int16Array.BYTES_PER_ELEMENT;
|
|
126
|
+
break;
|
|
127
|
+
case this.gl.UNSIGNED_SHORT:
|
|
128
|
+
this.vertexByteSize += size * Uint16Array.BYTES_PER_ELEMENT;
|
|
129
|
+
break;
|
|
130
|
+
case this.gl.INT:
|
|
131
|
+
this.vertexByteSize += size * Int32Array.BYTES_PER_ELEMENT;
|
|
132
|
+
break;
|
|
133
|
+
case this.gl.UNSIGNED_INT:
|
|
134
|
+
this.vertexByteSize += size * Uint32Array.BYTES_PER_ELEMENT;
|
|
135
|
+
break;
|
|
136
|
+
case this.gl.FLOAT:
|
|
137
|
+
this.vertexByteSize += size * Float32Array.BYTES_PER_ELEMENT;
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
throw new Error("Invalid GL Attribute type");
|
|
141
|
+
}
|
|
142
|
+
this.vertexSize = this.vertexByteSize / Float32Array.BYTES_PER_ELEMENT;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Sets the viewport
|
|
147
|
+
* @param {number} x - x position of viewport
|
|
148
|
+
* @param {number} y - y position of viewport
|
|
149
|
+
* @param {number} w - width of viewport
|
|
150
|
+
* @param {number} h - height of viewport
|
|
151
|
+
*/
|
|
152
|
+
setViewport(x, y, w, h) {
|
|
153
|
+
this.gl.viewport(x, y, w, h);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* set/change the current projection matrix
|
|
158
|
+
* @param {Matrix3d} matrix
|
|
159
|
+
*/
|
|
160
|
+
setProjection(matrix) {
|
|
161
|
+
this.activeShader.setUniform("uProjectionMatrix", matrix);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Select the shader to use for compositing
|
|
166
|
+
* @see GLShader
|
|
167
|
+
* @param {GLShader} shader - a reference to a GLShader instance
|
|
168
|
+
*/
|
|
169
|
+
useShader(shader) {
|
|
170
|
+
if (this.activeShader !== shader) {
|
|
171
|
+
this.flush();
|
|
172
|
+
this.activeShader = shader;
|
|
173
|
+
this.activeShader.bind();
|
|
174
|
+
this.activeShader.setUniform("uProjectionMatrix", this.renderer.projectionMatrix);
|
|
175
|
+
this.activeShader.setVertexAttributes(this.gl, this.attributes, this.vertexByteSize);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Flush batched texture operations to the GPU
|
|
181
|
+
* @param {number} [mode=gl.TRIANGLES] - the GL drawing mode
|
|
182
|
+
*/
|
|
183
|
+
flush(mode = this.mode) {
|
|
184
|
+
var vertex = this.vertexBuffer;
|
|
185
|
+
var vertexCount = vertex.vertexCount;
|
|
186
|
+
|
|
187
|
+
if (vertexCount > 0) {
|
|
188
|
+
var gl = this.gl;
|
|
189
|
+
var vertexSize = vertex.vertexSize;
|
|
190
|
+
|
|
191
|
+
// Copy data into stream buffer
|
|
192
|
+
if (this.renderer.WebGLVersion > 1) {
|
|
193
|
+
gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(), gl.STREAM_DRAW, 0, vertexCount * vertexSize);
|
|
194
|
+
} else {
|
|
195
|
+
gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(0, vertexCount * vertexSize), gl.STREAM_DRAW);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
gl.drawArrays(mode, 0, vertexCount);
|
|
199
|
+
|
|
200
|
+
// clear the vertex buffer
|
|
201
|
+
vertex.clear();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Clear the frame buffer
|
|
207
|
+
* @param {number} [alpha = 0.0] - the alpha value used when clearing the framebuffer
|
|
208
|
+
*/
|
|
209
|
+
clear(alpha = 0) {
|
|
210
|
+
var gl = this.gl;
|
|
211
|
+
gl.clearColor(0, 0, 0, alpha);
|
|
212
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
|
|
217
|
+
* @param {number} [r = 0] - the red color value used when the color buffers are cleared
|
|
218
|
+
* @param {number} [g = 0] - the green color value used when the color buffers are cleared
|
|
219
|
+
* @param {number} [b = 0] - the blue color value used when the color buffers are cleared
|
|
220
|
+
* @param {number} [a = 0] - the alpha color value used when the color buffers are cleared
|
|
221
|
+
*/
|
|
222
|
+
clearColor(r = 0, g = 0, b = 0, a = 0) {
|
|
223
|
+
var gl = this.gl;
|
|
224
|
+
gl.clearColor(r, g, b, a);
|
|
225
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
226
|
+
}
|
|
227
|
+
}
|