melonjs 15.0.0 → 15.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.
- package/README.md +4 -4
- 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 +7 -3
- 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 +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +17 -17
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +53 -53
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +5 -5
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +58 -58
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +21 -21
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- 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 +2 -2
- 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 +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +11 -11
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -63
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +2 -2
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +10 -9
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +35 -109
- package/dist/melonjs.mjs/video/renderer.js +74 -7
- package/dist/melonjs.mjs/video/texture/atlas.js +37 -37
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- 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 +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +18 -15
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- 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 +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +55 -38
- package/dist/melonjs.module.js +1747 -1809
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/index.d.ts +4 -3
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -11
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -76
- package/dist/types/video/renderer.d.ts +48 -0
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +13 -9
- package/package.json +14 -14
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +16 -16
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +52 -52
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +3 -2
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +20 -20
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +10 -10
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -65
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +1 -1
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +9 -8
- package/src/text/textmetrics.js +14 -14
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +34 -108
- package/src/video/renderer.js +72 -5
- package/src/video/texture/atlas.js +36 -36
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +4 -4
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +17 -14
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +54 -37
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -93,8 +93,8 @@ class TextureAtlas {
|
|
|
93
93
|
if (typeof (atlases) !== "undefined") {
|
|
94
94
|
// normalize to array to keep the following code generic
|
|
95
95
|
atlases = Array.isArray(atlases) ? atlases : [atlases];
|
|
96
|
-
for (
|
|
97
|
-
|
|
96
|
+
for (let i in atlases) {
|
|
97
|
+
let atlas = atlases[i];
|
|
98
98
|
|
|
99
99
|
if (typeof(atlas.meta) !== "undefined") {
|
|
100
100
|
// Texture Packer or Free Texture Packer
|
|
@@ -103,7 +103,7 @@ class TextureAtlas {
|
|
|
103
103
|
// set the texture
|
|
104
104
|
if (typeof(src) === "undefined") {
|
|
105
105
|
// get the texture name from the atlas meta data
|
|
106
|
-
|
|
106
|
+
let image = getImage(atlas.meta.image);
|
|
107
107
|
if (!image) {
|
|
108
108
|
throw new Error(
|
|
109
109
|
"Atlas texture '" + image + "' not found"
|
|
@@ -174,17 +174,17 @@ class TextureAtlas {
|
|
|
174
174
|
* @ignore
|
|
175
175
|
*/
|
|
176
176
|
parse(data) {
|
|
177
|
-
|
|
177
|
+
let atlas = {};
|
|
178
178
|
|
|
179
179
|
data.frames.forEach((frame) => {
|
|
180
180
|
// fix wrongly formatted JSON (e.g. last dummy object in ShoeBox)
|
|
181
181
|
if (frame.hasOwnProperty("filename")) {
|
|
182
182
|
// Source coordinates
|
|
183
|
-
|
|
183
|
+
let s = frame.frame;
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
let originX, originY;
|
|
186
186
|
// Pixel-based offset origin from the top-left of the source frame
|
|
187
|
-
|
|
187
|
+
let hasTextureAnchorPoint = (frame.spriteSourceSize && frame.sourceSize && frame.pivot);
|
|
188
188
|
if (hasTextureAnchorPoint) {
|
|
189
189
|
originX = (frame.sourceSize.w * frame.pivot.x) - ((frame.trimmed) ? frame.spriteSourceSize.x : 0);
|
|
190
190
|
originY = (frame.sourceSize.h * frame.pivot.y) - ((frame.trimmed) ? frame.spriteSourceSize.y : 0);
|
|
@@ -211,16 +211,16 @@ class TextureAtlas {
|
|
|
211
211
|
* @ignore
|
|
212
212
|
*/
|
|
213
213
|
parseFromSpriteSheet(data) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
214
|
+
let atlas = {};
|
|
215
|
+
let image = data.image;
|
|
216
|
+
let spacing = data.spacing || 0;
|
|
217
|
+
let margin = data.margin || 0;
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
219
|
+
let width = image.width;
|
|
220
|
+
let height = image.height;
|
|
221
221
|
|
|
222
222
|
// calculate the sprite count (line, col)
|
|
223
|
-
|
|
223
|
+
let spritecount = pool.pull("Vector2d",
|
|
224
224
|
~~((width - margin + spacing) / (data.framewidth + spacing)),
|
|
225
225
|
~~((height - margin + spacing) / (data.frameheight + spacing))
|
|
226
226
|
);
|
|
@@ -228,8 +228,8 @@ class TextureAtlas {
|
|
|
228
228
|
// verifying the texture size
|
|
229
229
|
if ((width % (data.framewidth + spacing)) !== 0 ||
|
|
230
230
|
(height % (data.frameheight + spacing)) !== 0) {
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
let computed_width = spritecount.x * (data.framewidth + spacing);
|
|
232
|
+
let computed_height = spritecount.y * (data.frameheight + spacing);
|
|
233
233
|
if (computed_width - width !== spacing && computed_height - height !== spacing) {
|
|
234
234
|
// "truncate size" if delta is different from the spacing size
|
|
235
235
|
width = computed_width;
|
|
@@ -245,8 +245,8 @@ class TextureAtlas {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
// build the local atlas
|
|
248
|
-
for (
|
|
249
|
-
|
|
248
|
+
for (let frame = 0, count = spritecount.x * spritecount.y; frame < count; frame++) {
|
|
249
|
+
let name = "" + frame;
|
|
250
250
|
atlas[name] = {
|
|
251
251
|
name : name,
|
|
252
252
|
texture : "default", // the source texture
|
|
@@ -317,10 +317,10 @@ class TextureAtlas {
|
|
|
317
317
|
console.warn("Adding texture region", name, "for texture", this);
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
320
|
+
let source = this.getTexture();
|
|
321
|
+
let atlas = this.getAtlas();
|
|
322
|
+
let dw = source.width;
|
|
323
|
+
let dh = source.height;
|
|
324
324
|
|
|
325
325
|
atlas[name] = {
|
|
326
326
|
name : name,
|
|
@@ -342,7 +342,7 @@ class TextureAtlas {
|
|
|
342
342
|
* @returns {object}
|
|
343
343
|
*/
|
|
344
344
|
getRegion(name, atlas) {
|
|
345
|
-
|
|
345
|
+
let region;
|
|
346
346
|
if (typeof atlas === "string") {
|
|
347
347
|
region = this.getAtlas(atlas)[name];
|
|
348
348
|
} else {
|
|
@@ -365,11 +365,11 @@ class TextureAtlas {
|
|
|
365
365
|
*/
|
|
366
366
|
getUVs(name) {
|
|
367
367
|
// Get the source texture region
|
|
368
|
-
|
|
368
|
+
let region = this.getRegion(name);
|
|
369
369
|
|
|
370
370
|
if (typeof(region) === "undefined") {
|
|
371
371
|
// TODO: Require proper atlas regions instead of caching arbitrary region keys
|
|
372
|
-
|
|
372
|
+
let keys = name.split(","),
|
|
373
373
|
sx = +keys[0],
|
|
374
374
|
sy = +keys[1],
|
|
375
375
|
sw = +keys[2],
|
|
@@ -391,9 +391,9 @@ class TextureAtlas {
|
|
|
391
391
|
// ignore if using the Canvas Renderer
|
|
392
392
|
if (typeof renderer.gl !== "undefined") {
|
|
393
393
|
// Source coordinates
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
394
|
+
let s = atlas[name].offset;
|
|
395
|
+
let sw = atlas[name].width;
|
|
396
|
+
let sh = atlas[name].height;
|
|
397
397
|
|
|
398
398
|
atlas[name].uvs = new Float32Array([
|
|
399
399
|
s.x / w, // u0 (left)
|
|
@@ -403,7 +403,7 @@ class TextureAtlas {
|
|
|
403
403
|
]);
|
|
404
404
|
// Cache source coordinates
|
|
405
405
|
// TODO: Remove this when the Batcher only accepts a region name
|
|
406
|
-
|
|
406
|
+
let key = s.x + "," + s.y + "," + w + "," + h;
|
|
407
407
|
atlas[key] = atlas[name];
|
|
408
408
|
}
|
|
409
409
|
return atlas[name].uvs;
|
|
@@ -424,13 +424,13 @@ class TextureAtlas {
|
|
|
424
424
|
* ...
|
|
425
425
|
* ...
|
|
426
426
|
* // create a new "coin" sprite
|
|
427
|
-
*
|
|
427
|
+
* let sprite = game.texture.createSpriteFromName("coin.png");
|
|
428
428
|
* // set the renderable position to bottom center
|
|
429
429
|
* sprite.anchorPoint.set(0.5, 1.0);
|
|
430
430
|
* ...
|
|
431
431
|
* ...
|
|
432
432
|
* // create a 9-slice sprite
|
|
433
|
-
*
|
|
433
|
+
* let dialogPanel = game.texture.createSpriteFromName(
|
|
434
434
|
* "rpg_dialo.png",
|
|
435
435
|
* // width & height are mandatory for 9-slice sprites
|
|
436
436
|
* { width: this.width, height: this.height },
|
|
@@ -463,7 +463,7 @@ class TextureAtlas {
|
|
|
463
463
|
* );
|
|
464
464
|
*
|
|
465
465
|
* // create a new Animated Sprite
|
|
466
|
-
*
|
|
466
|
+
* let sprite = game.texture.createAnimationFromName([
|
|
467
467
|
* "walk0001.png", "walk0002.png", "walk0003.png",
|
|
468
468
|
* "walk0004.png", "walk0005.png", "walk0006.png",
|
|
469
469
|
* "walk0007.png", "walk0008.png", "walk0009.png",
|
|
@@ -480,12 +480,12 @@ class TextureAtlas {
|
|
|
480
480
|
* sprite.anchorPoint.set(0.5, 1.0);
|
|
481
481
|
*/
|
|
482
482
|
createAnimationFromName(names, settings) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
483
|
+
let tpAtlas = [], indices = {};
|
|
484
|
+
let width = 0, height = 0;
|
|
485
|
+
let region;
|
|
486
486
|
// iterate through the given names
|
|
487
487
|
// and create a "normalized" atlas
|
|
488
|
-
for (
|
|
488
|
+
for (let i = 0; i < names.length; ++i) {
|
|
489
489
|
region = this.getRegion(names[i]);
|
|
490
490
|
if (region == null) {
|
|
491
491
|
// throw an error
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -9,8 +9,7 @@ import { renderer } from '../video.js';
|
|
|
9
9
|
import { getBasename } from '../../utils/file.js';
|
|
10
10
|
import { createAtlas, TextureAtlas } from './atlas.js';
|
|
11
11
|
import { isPowerOfTwo } from '../../math/math.js';
|
|
12
|
-
import '../../node_modules/@teppeis/multimaps/dist/
|
|
13
|
-
import { __exports as src } from '../../_virtual/index.js';
|
|
12
|
+
import { ArrayMultimap } from '../../node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* a basic texture cache object
|
|
@@ -23,7 +22,7 @@ class TextureCache {
|
|
|
23
22
|
*/
|
|
24
23
|
constructor(max_size) {
|
|
25
24
|
// cache uses an array to allow for duplicated key
|
|
26
|
-
this.cache = new
|
|
25
|
+
this.cache = new ArrayMultimap();
|
|
27
26
|
this.tinted = new Map();
|
|
28
27
|
this.units = new Map();
|
|
29
28
|
this.max_size = max_size || Infinity;
|
|
@@ -57,14 +56,14 @@ class TextureCache {
|
|
|
57
56
|
* @ignore
|
|
58
57
|
*/
|
|
59
58
|
get(image, atlas) {
|
|
60
|
-
|
|
59
|
+
let entry;
|
|
61
60
|
|
|
62
61
|
if (typeof atlas === "undefined") {
|
|
63
62
|
entry = this.cache.get(image)[0];
|
|
64
63
|
} else {
|
|
65
64
|
// manage cases where a specific atlas is specified
|
|
66
65
|
this.cache.forEach((value, key) => {
|
|
67
|
-
|
|
66
|
+
let _atlas = value.getAtlas()[0];
|
|
68
67
|
if (key === image && _atlas.width === atlas.framewidth && _atlas.height === atlas.frameheight) {
|
|
69
68
|
entry = value;
|
|
70
69
|
}
|
|
@@ -96,7 +95,7 @@ class TextureCache {
|
|
|
96
95
|
*/
|
|
97
96
|
tint(src, color) {
|
|
98
97
|
// make sure the src is in the cache
|
|
99
|
-
|
|
98
|
+
let image_cache = this.tinted.get(src);
|
|
100
99
|
|
|
101
100
|
if (image_cache === undefined) {
|
|
102
101
|
image_cache = this.tinted.set(src, new Map());
|
|
@@ -113,12 +112,12 @@ class TextureCache {
|
|
|
113
112
|
* @ignore
|
|
114
113
|
*/
|
|
115
114
|
set(image, texture) {
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
let width = image.width;
|
|
116
|
+
let height = image.height;
|
|
118
117
|
|
|
119
118
|
// warn if a non POT texture is added to the cache when using WebGL1
|
|
120
119
|
if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(width) || !isPowerOfTwo(height))) {
|
|
121
|
-
|
|
120
|
+
let src = typeof image.src !== "undefined" ? image.src : image;
|
|
122
121
|
console.warn(
|
|
123
122
|
"[Texture] " + src + " is not a POT texture " +
|
|
124
123
|
"(" + width + "x" + height + ")"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -10,7 +10,7 @@ import { setPrefixed } from '../../utils/agent.js';
|
|
|
10
10
|
import { clamp } from '../../math/math.js';
|
|
11
11
|
|
|
12
12
|
// default canvas settings
|
|
13
|
-
|
|
13
|
+
let defaultAttributes = {
|
|
14
14
|
offscreenCanvas : false,
|
|
15
15
|
willReadFrequently : false,
|
|
16
16
|
antiAlias : false,
|
|
@@ -72,7 +72,7 @@ class CanvasTexture {
|
|
|
72
72
|
* @param {boolean} [enable=false]
|
|
73
73
|
*/
|
|
74
74
|
setAntiAlias(enable = false) {
|
|
75
|
-
|
|
75
|
+
let canvas = this.canvas;
|
|
76
76
|
|
|
77
77
|
// enable/disable antialias on the given Context2d object
|
|
78
78
|
setPrefixed("imageSmoothingEnabled", enable, this.context);
|
|
@@ -124,6 +124,66 @@ class CanvasTexture {
|
|
|
124
124
|
return this.context.getImageData(x, y, width, height);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* creates a Blob object representing the image contained in this canvas texture
|
|
129
|
+
* @param {Object} [options] - An object with the following properties:
|
|
130
|
+
* @param {String} [options.type="image/png"] - A string indicating the image format
|
|
131
|
+
* @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
|
|
132
|
+
* @return {Promise} A Promise returning a Blob object representing the image contained in this canvas texture
|
|
133
|
+
* @example
|
|
134
|
+
* canvasTexture.convertToBlob().then((blob) => console.log(blob));
|
|
135
|
+
*/
|
|
136
|
+
toBlob(options) {
|
|
137
|
+
if (typeof this.canvas.convertToBlob === "function") {
|
|
138
|
+
return this.canvas.convertToBlob(options);
|
|
139
|
+
} else {
|
|
140
|
+
return new Promise(function(resolve) {
|
|
141
|
+
this.canvas.toBlob((blob) => {
|
|
142
|
+
resolve(blob);
|
|
143
|
+
}, options ? options.type : undefined, options ? options.quality : undefined);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* creates an ImageBitmap object from the most recently rendered image of this canvas texture
|
|
150
|
+
* @param {Object} [options] - An object with the following properties:
|
|
151
|
+
* @param {String} [options.type="image/png"] - A string indicating the image format
|
|
152
|
+
* @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
|
|
153
|
+
* @return {Promise} A Promise returning an ImageBitmap.
|
|
154
|
+
* @example
|
|
155
|
+
* canvasTexture.transferToImageBitmap().then((bitmap) => console.log(bitmap));
|
|
156
|
+
*/
|
|
157
|
+
toImageBitmap(options) {
|
|
158
|
+
return new Promise((resolve) => {
|
|
159
|
+
if (typeof this.canvas.transferToImageBitmap === "function") {
|
|
160
|
+
resolve(this.canvas.transferToImageBitmap());
|
|
161
|
+
} else {
|
|
162
|
+
let image = new Image();
|
|
163
|
+
image.src = this.canvas.toDataURL(options);
|
|
164
|
+
image.onload = () => {
|
|
165
|
+
createImageBitmap(image).then((bitmap) => resolve(bitmap));
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* returns a data URL containing a representation of the most recently rendered image of this canvas texture
|
|
173
|
+
* (not supported by OffscreenCanvas)
|
|
174
|
+
* @param {Object} [options] - An object with the following properties:
|
|
175
|
+
* @param {String} [options.type="image/png"] - A string indicating the image format
|
|
176
|
+
* @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
|
|
177
|
+
* @return {Promise} A Promise returning a string containing the requested data URL.
|
|
178
|
+
* @example
|
|
179
|
+
* renderer.toDataURL().then((dataURL) => console.log(dataURL));
|
|
180
|
+
*/
|
|
181
|
+
toDataURL(options) {
|
|
182
|
+
return new Promise((resolve) => {
|
|
183
|
+
resolve(this.canvas.toDataURL(options));
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
127
187
|
/**
|
|
128
188
|
* @ignore
|
|
129
189
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -156,7 +156,7 @@ function init(width, height, options) {
|
|
|
156
156
|
* @returns {HTMLCanvasElement|OffscreenCanvas}
|
|
157
157
|
*/
|
|
158
158
|
function createCanvas(width, height, returnOffscreenCanvas = false) {
|
|
159
|
-
|
|
159
|
+
let _canvas;
|
|
160
160
|
|
|
161
161
|
if (width === 0 || height === 0) {
|
|
162
162
|
throw new Error("width or height was zero, Canvas could not be initialized !");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// save a reference to the previous data
|
|
63
|
-
|
|
63
|
+
let data = this.bufferF32;
|
|
64
64
|
|
|
65
65
|
// recreate ArrayBuffer and views
|
|
66
66
|
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
* @ignore
|
|
79
79
|
*/
|
|
80
80
|
push(x, y, u, v, tint) {
|
|
81
|
-
|
|
81
|
+
let offset = this.vertexCount * this.vertexSize;
|
|
82
82
|
|
|
83
83
|
if (this.vertexCount >= this.maxVertex) {
|
|
84
84
|
this.resize(this.vertexCount);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -210,12 +210,12 @@ import GLShader from '../glshader.js';
|
|
|
210
210
|
* @param {number} [mode=gl.TRIANGLES] - the GL drawing mode
|
|
211
211
|
*/
|
|
212
212
|
flush(mode = this.mode) {
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
let vertex = this.vertexData;
|
|
214
|
+
let vertexCount = vertex.vertexCount;
|
|
215
215
|
|
|
216
216
|
if (vertexCount > 0) {
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
let gl = this.gl;
|
|
218
|
+
let vertexSize = vertex.vertexSize;
|
|
219
219
|
|
|
220
220
|
// Copy data into stream buffer
|
|
221
221
|
if (this.renderer.WebGLVersion > 1) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -40,10 +40,10 @@ import Compositor from './compositor.js';
|
|
|
40
40
|
* @param {number} [vertexCount=verts.length] - amount of points defined in the points array
|
|
41
41
|
*/
|
|
42
42
|
drawVertices(mode, verts, vertexCount = verts.length) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
let viewMatrix = this.viewMatrix;
|
|
44
|
+
let vertexData = this.vertexData;
|
|
45
|
+
let color = this.renderer.currentColor;
|
|
46
|
+
let alpha = this.renderer.getGlobalAlpha();
|
|
47
47
|
|
|
48
48
|
if (vertexData.isFull(vertexCount)) {
|
|
49
49
|
// is the vertex buffer full if we add more vertices
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -12,7 +12,7 @@ import quadFragment from '../shaders/quad.frag.js';
|
|
|
12
12
|
import Compositor from './compositor.js';
|
|
13
13
|
|
|
14
14
|
// a pool of resuable vectors
|
|
15
|
-
|
|
15
|
+
let V_ARRAY = [
|
|
16
16
|
new Vector2d(),
|
|
17
17
|
new Vector2d(),
|
|
18
18
|
new Vector2d(),
|
|
@@ -56,8 +56,8 @@ var V_ARRAY = [
|
|
|
56
56
|
super.reset();
|
|
57
57
|
|
|
58
58
|
// delete all related bound texture
|
|
59
|
-
for (
|
|
60
|
-
|
|
59
|
+
for (let i = 0; i < this.renderer.maxTextures; i++) {
|
|
60
|
+
let texture2D = this.getTexture2D(i);
|
|
61
61
|
if (typeof texture2D !== "undefined") {
|
|
62
62
|
this.deleteTexture2D(texture2D);
|
|
63
63
|
}
|
|
@@ -78,12 +78,12 @@ var V_ARRAY = [
|
|
|
78
78
|
* @returns {WebGLTexture} a WebGL texture
|
|
79
79
|
*/
|
|
80
80
|
createTexture2D(unit, pixels = null, filter, repeat = "no-repeat", w = pixels.width, h = pixels.height, premultipliedAlpha = true, mipmap = true) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
let gl = this.gl;
|
|
82
|
+
let isPOT = isPowerOfTwo(w) && isPowerOfTwo(h);
|
|
83
|
+
let rs = (repeat.search(/^repeat(-x)?$/) === 0) && (isPOT || this.renderer.WebGLVersion > 1) ? gl.REPEAT : gl.CLAMP_TO_EDGE;
|
|
84
|
+
let rt = (repeat.search(/^repeat(-y)?$/) === 0) && (isPOT || this.renderer.WebGLVersion > 1) ? gl.REPEAT : gl.CLAMP_TO_EDGE;
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
let texture = gl.createTexture();
|
|
87
87
|
|
|
88
88
|
this.bindTexture2D(texture, unit);
|
|
89
89
|
|
|
@@ -97,6 +97,9 @@ var V_ARRAY = [
|
|
|
97
97
|
if (pixels === null || typeof pixels.byteLength !== "undefined") {
|
|
98
98
|
// if pixels is undefined, or if it's Uint8Array/Float32Array TypedArray
|
|
99
99
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels, 0);
|
|
100
|
+
} else if (pixels instanceof OffscreenCanvas) {
|
|
101
|
+
// convert to ImageBitmap first (else Safari 16.4 and higher will throw an TypeError exception)
|
|
102
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels.transferToImageBitmap());
|
|
100
103
|
} else {
|
|
101
104
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
|
102
105
|
}
|
|
@@ -134,7 +137,7 @@ var V_ARRAY = [
|
|
|
134
137
|
* @param {number} unit - Texture unit to which the given texture is bound
|
|
135
138
|
*/
|
|
136
139
|
bindTexture2D(texture, unit) {
|
|
137
|
-
|
|
140
|
+
let gl = this.gl;
|
|
138
141
|
|
|
139
142
|
if (texture !== this.boundTextures[unit]) {
|
|
140
143
|
this.flush();
|
|
@@ -176,8 +179,8 @@ var V_ARRAY = [
|
|
|
176
179
|
* @ignore
|
|
177
180
|
*/
|
|
178
181
|
uploadTexture(texture, w, h, force = false) {
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
let unit = this.renderer.cache.getUnit(texture);
|
|
183
|
+
let texture2D = this.boundTextures[unit];
|
|
181
184
|
|
|
182
185
|
if (typeof texture2D === "undefined" || force) {
|
|
183
186
|
this.createTexture2D(
|
|
@@ -210,7 +213,7 @@ var V_ARRAY = [
|
|
|
210
213
|
* @param {number} tint - tint color to be applied to the texture in UINT32 (argb) format
|
|
211
214
|
*/
|
|
212
215
|
addQuad(texture, x, y, w, h, u0, v0, u1, v1, tint) {
|
|
213
|
-
|
|
216
|
+
let vertexData = this.vertexData;
|
|
214
217
|
|
|
215
218
|
if (vertexData.isFull(6)) {
|
|
216
219
|
// is the vertex buffer full if we add 6 more vertices
|
|
@@ -218,13 +221,13 @@ var V_ARRAY = [
|
|
|
218
221
|
}
|
|
219
222
|
|
|
220
223
|
// upload and activate the texture if necessary
|
|
221
|
-
|
|
224
|
+
let unit = this.uploadTexture(texture);
|
|
222
225
|
|
|
223
226
|
// set fragment sampler accordingly
|
|
224
227
|
this.currentShader.setUniform("uSampler", unit);
|
|
225
228
|
|
|
226
229
|
// Transform vertices
|
|
227
|
-
|
|
230
|
+
let m = this.viewMatrix,
|
|
228
231
|
vec0 = V_ARRAY[0].set(x, y),
|
|
229
232
|
vec1 = V_ARRAY[1].set(x + w, y),
|
|
230
233
|
vec2 = V_ARRAY[2].set(x, y + h),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -25,7 +25,7 @@ import { minify } from './utils/string.js';
|
|
|
25
25
|
* @see https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders
|
|
26
26
|
* @example
|
|
27
27
|
* // create a basic shader
|
|
28
|
-
*
|
|
28
|
+
* let myShader = new me.GLShader(
|
|
29
29
|
* // WebGL rendering context
|
|
30
30
|
* gl,
|
|
31
31
|
* // vertex shader
|
|
@@ -100,7 +100,7 @@ import { minify } from './utils/string.js';
|
|
|
100
100
|
* @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise
|
|
101
101
|
*/
|
|
102
102
|
getAttribLocation(name) {
|
|
103
|
-
|
|
103
|
+
let attr = this.attributes[name];
|
|
104
104
|
if (typeof attr !== "undefined") {
|
|
105
105
|
return attr;
|
|
106
106
|
} else {
|
|
@@ -116,7 +116,7 @@ import { minify } from './utils/string.js';
|
|
|
116
116
|
* myShader.setUniform("uProjectionMatrix", this.projectionMatrix);
|
|
117
117
|
*/
|
|
118
118
|
setUniform(name, value) {
|
|
119
|
-
|
|
119
|
+
let uniforms = this.uniforms;
|
|
120
120
|
if (typeof uniforms[name] !== "undefined") {
|
|
121
121
|
if (typeof value === "object" && typeof value.toArray === "function") {
|
|
122
122
|
uniforms[name] = value.toArray();
|
|
@@ -136,9 +136,9 @@ import { minify } from './utils/string.js';
|
|
|
136
136
|
*/
|
|
137
137
|
setVertexAttributes(gl, attributes, vertexByteSize) {
|
|
138
138
|
// set the vertex attributes
|
|
139
|
-
for (
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
for (let index = 0; index < attributes.length; ++index) {
|
|
140
|
+
let element = attributes[index];
|
|
141
|
+
let location = this.getAttribLocation(element.name);
|
|
142
142
|
|
|
143
143
|
if (location !== -1) {
|
|
144
144
|
gl.enableVertexAttribArray(location);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.1.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @ignore
|
|
10
10
|
*/
|
|
11
11
|
function extractAttributes(gl, shader) {
|
|
12
|
-
|
|
12
|
+
let attributes = {},
|
|
13
13
|
attrRx = /attribute\s+\w+\s+(\w+)/g,
|
|
14
14
|
match,
|
|
15
15
|
i = 0;
|