melonjs 10.3.0 → 10.5.1
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 +6 -6
- package/dist/melonjs.js +3147 -3293
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3411 -3852
- package/dist/melonjs.module.js +3448 -3210
- package/package.json +18 -17
- package/src/audio/audio.js +29 -30
- package/src/camera/camera2d.js +46 -56
- package/src/entity/entity.js +30 -36
- package/src/game.js +21 -22
- package/src/geometries/ellipse.js +40 -46
- package/src/geometries/line.js +9 -11
- package/src/geometries/poly.js +53 -53
- package/src/geometries/rectangle.js +42 -44
- package/src/index.js +9 -26
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +30 -31
- package/src/input/pointerevent.js +26 -26
- package/src/lang/deprecated.js +65 -6
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -8
- package/src/level/tiled/TMXLayer.js +30 -32
- package/src/level/tiled/TMXObject.js +21 -21
- package/src/level/tiled/TMXTile.js +18 -18
- package/src/level/tiled/TMXTileMap.js +39 -44
- package/src/level/tiled/TMXTileset.js +12 -15
- package/src/level/tiled/TMXTilesetGroup.js +9 -9
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -5
- package/src/level/tiled/renderer/TMXRenderer.js +24 -25
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -4
- package/src/loader/loader.js +14 -15
- package/src/loader/loadingscreen.js +2 -4
- package/src/math/color.js +47 -66
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -58
- package/src/math/matrix3.js +56 -62
- package/src/math/observable_vector2.js +75 -76
- package/src/math/observable_vector3.js +79 -80
- package/src/math/vector2.js +91 -92
- package/src/math/vector3.js +94 -96
- package/src/particles/emitter.js +38 -40
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +46 -143
- package/src/physics/bounds.js +47 -47
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -19
- package/src/physics/sat.js +26 -26
- package/src/physics/world.js +24 -28
- package/src/plugin/plugin.js +11 -14
- package/src/renderable/GUI.js +41 -46
- package/src/renderable/collectable.js +4 -8
- package/src/renderable/colorlayer.js +6 -10
- package/src/renderable/container.js +87 -72
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -31
- package/src/renderable/nineslicesprite.js +41 -41
- package/src/renderable/renderable.js +114 -125
- package/src/renderable/sprite.js +62 -68
- package/src/renderable/trigger.js +25 -30
- package/src/state/stage.js +13 -17
- package/src/state/state.js +26 -27
- package/src/system/device.js +74 -75
- package/src/system/event.js +71 -72
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -54
- package/src/text/bitmaptextdata.js +10 -10
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +44 -49
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +43 -44
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +58 -59
- package/src/video/renderer.js +49 -53
- package/src/video/texture.js +98 -111
- package/src/video/texture_cache.js +24 -6
- package/src/video/video.js +16 -17
- package/src/video/webgl/glshader.js +37 -38
- package/src/video/webgl/webgl_compositor.js +31 -32
- package/src/video/webgl/webgl_renderer.js +79 -80
- package/src/entity/draggable.js +0 -130
- package/src/entity/droptarget.js +0 -101
package/src/video/texture.js
CHANGED
|
@@ -28,42 +28,41 @@ export function createAtlas(width, height, name = "default", repeat = "no-repeat
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* @classdesc
|
|
31
|
-
* A Texture atlas
|
|
31
|
+
* A Texture atlas class, currently supports : <br>
|
|
32
32
|
* - [TexturePacker]{@link http://www.codeandweb.com/texturepacker/} : through JSON export (standard and multipack texture atlas) <br>
|
|
33
33
|
* - [ShoeBox]{@link http://renderhjs.net/shoebox/} : through JSON export using the
|
|
34
34
|
* melonJS setting [file]{@link https://github.com/melonjs/melonJS/raw/master/media/shoebox_JSON_export.sbx} <br>
|
|
35
35
|
* - [Free Texture Packer]{@link http://free-tex-packer.com/app/} : through JSON export (standard and multipack texture atlas) <br>
|
|
36
36
|
* - Standard (fixed cell size) spritesheet : through a {framewidth:xx, frameheight:xx, anchorPoint:me.Vector2d} object
|
|
37
|
-
* @class Texture
|
|
38
|
-
* @memberof me.Renderer
|
|
39
|
-
* @param {object|object[]} atlases atlas information. See {@link me.loader.getJSON}
|
|
40
|
-
* @param {HTMLImageElement|HTMLCanvasElement|string|HTMLImageElement[]|HTMLCanvasElement[]|string[]} [src=atlas.meta.image] Image source
|
|
41
|
-
* @param {boolean} [cache=false] Use true to skip caching this Texture
|
|
42
|
-
* @example
|
|
43
|
-
* // create a texture atlas from a JSON Object
|
|
44
|
-
* game.texture = new me.video.renderer.Texture(
|
|
45
|
-
* me.loader.getJSON("texture")
|
|
46
|
-
* );
|
|
47
|
-
*
|
|
48
|
-
* // create a texture atlas from a multipack JSON Object
|
|
49
|
-
* game.texture = new me.video.renderer.Texture([
|
|
50
|
-
* me.loader.getJSON("texture-0"),
|
|
51
|
-
* me.loader.getJSON("texture-1"),
|
|
52
|
-
* me.loader.getJSON("texture-2")
|
|
53
|
-
* ]);
|
|
54
|
-
*
|
|
55
|
-
* // create a texture atlas for a spritesheet with an anchorPoint in the center of each frame
|
|
56
|
-
* game.texture = new me.video.renderer.Texture(
|
|
57
|
-
* {
|
|
58
|
-
* framewidth : 32,
|
|
59
|
-
* frameheight : 32,
|
|
60
|
-
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
61
|
-
* },
|
|
62
|
-
* me.loader.getImage("spritesheet")
|
|
63
37
|
* );
|
|
64
38
|
*/
|
|
65
|
-
export class
|
|
66
|
-
|
|
39
|
+
export class TextureAtlas {
|
|
40
|
+
/**
|
|
41
|
+
* @param {object|object[]} atlases atlas information. See {@link loader.getJSON}
|
|
42
|
+
* @param {HTMLImageElement|HTMLCanvasElement|string|HTMLImageElement[]|HTMLCanvasElement[]|string[]} [src=atlas.meta.image] Image source
|
|
43
|
+
* @param {boolean} [cache=false] Use true to skip caching this Texture
|
|
44
|
+
* @example
|
|
45
|
+
* // create a texture atlas from a JSON Object
|
|
46
|
+
* game.texture = new me.TextureAtlas(
|
|
47
|
+
* me.loader.getJSON("texture")
|
|
48
|
+
* );
|
|
49
|
+
*
|
|
50
|
+
* // create a texture atlas from a multipack JSON Object
|
|
51
|
+
* game.texture = new me.TextureAtlas([
|
|
52
|
+
* me.loader.getJSON("texture-0"),
|
|
53
|
+
* me.loader.getJSON("texture-1"),
|
|
54
|
+
* me.loader.getJSON("texture-2")
|
|
55
|
+
* ]);
|
|
56
|
+
*
|
|
57
|
+
* // create a texture atlas for a spritesheet with an anchorPoint in the center of each frame
|
|
58
|
+
* game.texture = new me.TextureAtlas(
|
|
59
|
+
* {
|
|
60
|
+
* framewidth : 32,
|
|
61
|
+
* frameheight : 32,
|
|
62
|
+
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
63
|
+
* },
|
|
64
|
+
* me.loader.getImage("spritesheet")
|
|
65
|
+
*/
|
|
67
66
|
constructor (atlases, src, cache) {
|
|
68
67
|
/**
|
|
69
68
|
* to identify the atlas format (e.g. texture packer)
|
|
@@ -200,7 +199,7 @@ export class Texture {
|
|
|
200
199
|
height : s.h,
|
|
201
200
|
angle : (frame.rotated === true) ? -ETA : 0
|
|
202
201
|
};
|
|
203
|
-
this.
|
|
202
|
+
this.addUVs(atlas, frame.filename, data.meta.size.w, data.meta.size.h);
|
|
204
203
|
}
|
|
205
204
|
});
|
|
206
205
|
return atlas;
|
|
@@ -260,7 +259,7 @@ export class Texture {
|
|
|
260
259
|
height : data.frameheight,
|
|
261
260
|
angle : 0
|
|
262
261
|
};
|
|
263
|
-
this.
|
|
262
|
+
this.addUVs(atlas, name, width, height);
|
|
264
263
|
}
|
|
265
264
|
|
|
266
265
|
pool.push(spritecount);
|
|
@@ -268,63 +267,8 @@ export class Texture {
|
|
|
268
267
|
return atlas;
|
|
269
268
|
}
|
|
270
269
|
|
|
271
|
-
/**
|
|
272
|
-
* @ignore
|
|
273
|
-
*/
|
|
274
|
-
addUvsMap(atlas, frame, w, h) {
|
|
275
|
-
// ignore if using the Canvas Renderer
|
|
276
|
-
if (renderer instanceof WebGLRenderer) {
|
|
277
|
-
// Source coordinates
|
|
278
|
-
var s = atlas[frame].offset;
|
|
279
|
-
var sw = atlas[frame].width;
|
|
280
|
-
var sh = atlas[frame].height;
|
|
281
|
-
|
|
282
|
-
atlas[frame].uvs = new Float32Array([
|
|
283
|
-
s.x / w, // u0 (left)
|
|
284
|
-
s.y / h, // v0 (top)
|
|
285
|
-
(s.x + sw) / w, // u1 (right)
|
|
286
|
-
(s.y + sh) / h // v1 (bottom)
|
|
287
|
-
]);
|
|
288
|
-
// Cache source coordinates
|
|
289
|
-
// TODO: Remove this when the Batcher only accepts a region name
|
|
290
|
-
var key = s.x + "," + s.y + "," + w + "," + h;
|
|
291
|
-
atlas[key] = atlas[frame];
|
|
292
|
-
}
|
|
293
|
-
return atlas[frame];
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* @ignore
|
|
298
|
-
*/
|
|
299
|
-
addQuadRegion(name, x, y, w, h) {
|
|
300
|
-
// TODO: Require proper atlas regions instead of caching arbitrary region keys
|
|
301
|
-
if (renderer.settings.verbose === true) {
|
|
302
|
-
console.warn("Adding texture region", name, "for texture", this);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
var source = this.getTexture();
|
|
306
|
-
var atlas = this.getAtlas();
|
|
307
|
-
var dw = source.width;
|
|
308
|
-
var dh = source.height;
|
|
309
|
-
|
|
310
|
-
atlas[name] = {
|
|
311
|
-
name : name,
|
|
312
|
-
offset : new Vector2d(x, y),
|
|
313
|
-
width : w,
|
|
314
|
-
height : h,
|
|
315
|
-
angle : 0
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
this.addUvsMap(atlas, name, dw, dh);
|
|
319
|
-
|
|
320
|
-
return atlas[name];
|
|
321
|
-
}
|
|
322
|
-
|
|
323
270
|
/**
|
|
324
271
|
* return the default or specified atlas dictionnary
|
|
325
|
-
* @name getAtlas
|
|
326
|
-
* @memberof me.Renderer.Texture
|
|
327
|
-
* @function
|
|
328
272
|
* @param {string} [name] atlas name in case of multipack textures
|
|
329
273
|
* @returns {object}
|
|
330
274
|
*/
|
|
@@ -338,9 +282,6 @@ export class Texture {
|
|
|
338
282
|
|
|
339
283
|
/**
|
|
340
284
|
* return the format of the atlas dictionnary
|
|
341
|
-
* @name getFormat
|
|
342
|
-
* @memberof me.Renderer.Texture
|
|
343
|
-
* @function
|
|
344
285
|
* @returns {string} will return "texturepacker", or "ShoeBox", or "melonJS", or "Spritesheet (fixed cell size)"
|
|
345
286
|
*/
|
|
346
287
|
getFormat() {
|
|
@@ -349,9 +290,6 @@ export class Texture {
|
|
|
349
290
|
|
|
350
291
|
/**
|
|
351
292
|
* return the source texture for the given region (or default one if none specified)
|
|
352
|
-
* @name getTexture
|
|
353
|
-
* @memberof me.Renderer.Texture
|
|
354
|
-
* @function
|
|
355
293
|
* @param {object} [region] region name in case of multipack textures
|
|
356
294
|
* @returns {HTMLImageElement|HTMLCanvasElement}
|
|
357
295
|
*/
|
|
@@ -363,11 +301,41 @@ export class Texture {
|
|
|
363
301
|
}
|
|
364
302
|
}
|
|
365
303
|
|
|
304
|
+
/**
|
|
305
|
+
* add a region to the atlas
|
|
306
|
+
* @param {string} name region mame
|
|
307
|
+
* @param {number} x x origin of the region
|
|
308
|
+
* @param {number} y y origin of the region
|
|
309
|
+
* @param {number} w width of the region
|
|
310
|
+
* @param {number} h height of the region
|
|
311
|
+
* @returns {object} the created region
|
|
312
|
+
*/
|
|
313
|
+
addRegion(name, x, y, w, h) {
|
|
314
|
+
// TODO: Require proper atlas regions instead of caching arbitrary region keys
|
|
315
|
+
if (renderer.settings.verbose === true) {
|
|
316
|
+
console.warn("Adding texture region", name, "for texture", this);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
var source = this.getTexture();
|
|
320
|
+
var atlas = this.getAtlas();
|
|
321
|
+
var dw = source.width;
|
|
322
|
+
var dh = source.height;
|
|
323
|
+
|
|
324
|
+
atlas[name] = {
|
|
325
|
+
name : name,
|
|
326
|
+
offset : new Vector2d(x, y),
|
|
327
|
+
width : w,
|
|
328
|
+
height : h,
|
|
329
|
+
angle : 0
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
this.addUVs(atlas, name, dw, dh);
|
|
333
|
+
|
|
334
|
+
return atlas[name];
|
|
335
|
+
}
|
|
336
|
+
|
|
366
337
|
/**
|
|
367
338
|
* return a normalized region (or frame) information for the specified sprite name
|
|
368
|
-
* @name getRegion
|
|
369
|
-
* @memberof me.Renderer.Texture
|
|
370
|
-
* @function
|
|
371
339
|
* @param {string} name name of the sprite
|
|
372
340
|
* @param {string} [atlas] name of a specific atlas where to search for the region
|
|
373
341
|
* @returns {object}
|
|
@@ -390,9 +358,6 @@ export class Texture {
|
|
|
390
358
|
|
|
391
359
|
/**
|
|
392
360
|
* return the uvs mapping for the given region
|
|
393
|
-
* @name getUVs
|
|
394
|
-
* @memberof me.Renderer.Texture
|
|
395
|
-
* @function
|
|
396
361
|
* @param {object} name region (or frame) name
|
|
397
362
|
* @returns {Float32Array} region Uvs
|
|
398
363
|
*/
|
|
@@ -407,23 +372,48 @@ export class Texture {
|
|
|
407
372
|
sy = +keys[1],
|
|
408
373
|
sw = +keys[2],
|
|
409
374
|
sh = +keys[3];
|
|
410
|
-
region = this.
|
|
375
|
+
region = this.addRegion(name, sx, sy, sw, sh);
|
|
411
376
|
}
|
|
412
377
|
return region.uvs;
|
|
413
378
|
}
|
|
414
379
|
|
|
380
|
+
/**
|
|
381
|
+
* add uvs mapping for the given region
|
|
382
|
+
* @param {object} atlas the atlas dictionnary where the region is define
|
|
383
|
+
* @param {object} name region (or frame) name
|
|
384
|
+
* @returns {Float32Array} the created region UVs
|
|
385
|
+
*/
|
|
386
|
+
addUVs(atlas, name, w, h) {
|
|
387
|
+
// ignore if using the Canvas Renderer
|
|
388
|
+
if (renderer instanceof WebGLRenderer) {
|
|
389
|
+
// Source coordinates
|
|
390
|
+
var s = atlas[name].offset;
|
|
391
|
+
var sw = atlas[name].width;
|
|
392
|
+
var sh = atlas[name].height;
|
|
393
|
+
|
|
394
|
+
atlas[name].uvs = new Float32Array([
|
|
395
|
+
s.x / w, // u0 (left)
|
|
396
|
+
s.y / h, // v0 (top)
|
|
397
|
+
(s.x + sw) / w, // u1 (right)
|
|
398
|
+
(s.y + sh) / h // v1 (bottom)
|
|
399
|
+
]);
|
|
400
|
+
// Cache source coordinates
|
|
401
|
+
// TODO: Remove this when the Batcher only accepts a region name
|
|
402
|
+
var key = s.x + "," + s.y + "," + w + "," + h;
|
|
403
|
+
atlas[key] = atlas[name];
|
|
404
|
+
}
|
|
405
|
+
return atlas[name].uvs;
|
|
406
|
+
}
|
|
407
|
+
|
|
415
408
|
/**
|
|
416
409
|
* Create a sprite object using the first region found using the specified name
|
|
417
|
-
* @name createSpriteFromName
|
|
418
|
-
* @memberof me.Renderer.Texture
|
|
419
|
-
* @function
|
|
420
410
|
* @param {string} name name of the sprite
|
|
421
|
-
* @param {object} [settings] Additional settings passed to the {@link
|
|
411
|
+
* @param {object} [settings] Additional settings passed to the {@link Sprite} contructor
|
|
422
412
|
* @param {boolean} [nineSlice=false] if true returns a 9-slice sprite
|
|
423
|
-
* @returns {
|
|
413
|
+
* @returns {Sprite|NineSliceSprite}
|
|
424
414
|
* @example
|
|
425
415
|
* // create a new texture object under the `game` namespace
|
|
426
|
-
* game.texture = new me.
|
|
416
|
+
* game.texture = new me.TextureAtlas(
|
|
427
417
|
* me.loader.getJSON("texture"),
|
|
428
418
|
* me.loader.getImage("texture")
|
|
429
419
|
* );
|
|
@@ -457,16 +447,13 @@ export class Texture {
|
|
|
457
447
|
|
|
458
448
|
/**
|
|
459
449
|
* Create an animation object using the first region found using all specified names
|
|
460
|
-
* @name createAnimationFromName
|
|
461
|
-
* @memberof me.Renderer.Texture
|
|
462
|
-
* @function
|
|
463
450
|
* @param {string[]|number[]} names list of names for each sprite
|
|
464
451
|
* (when manually creating a Texture out of a spritesheet, only numeric values are authorized)
|
|
465
|
-
* @param {object} [settings] Additional settings passed to the {@link
|
|
466
|
-
* @returns {
|
|
452
|
+
* @param {object} [settings] Additional settings passed to the {@link Sprite} contructor
|
|
453
|
+
* @returns {Sprite}
|
|
467
454
|
* @example
|
|
468
455
|
* // create a new texture object under the `game` namespace
|
|
469
|
-
* game.texture = new me.
|
|
456
|
+
* game.texture = new me.TextureAtlas(
|
|
470
457
|
* me.loader.getJSON("texture"),
|
|
471
458
|
* me.loader.getImage("texture")
|
|
472
459
|
* );
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { renderer } from "./video.js";
|
|
2
2
|
import * as fileUtil from "./../utils/file.js";
|
|
3
|
-
import {
|
|
3
|
+
import { TextureAtlas, createAtlas } from "./texture.js";
|
|
4
4
|
import { isPowerOfTwo} from "./../math/math.js";
|
|
5
|
+
import {ArrayMultimap} from "@teppeis/multimaps";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -14,7 +15,8 @@ class TextureCache {
|
|
|
14
15
|
* @ignore
|
|
15
16
|
*/
|
|
16
17
|
constructor(max_size) {
|
|
17
|
-
|
|
18
|
+
// cache uses an array to allow for duplicated key
|
|
19
|
+
this.cache = new ArrayMultimap();
|
|
18
20
|
this.tinted = new Map();
|
|
19
21
|
this.units = new Map();
|
|
20
22
|
this.max_size = max_size || Infinity;
|
|
@@ -48,13 +50,29 @@ class TextureCache {
|
|
|
48
50
|
* @ignore
|
|
49
51
|
*/
|
|
50
52
|
get(image, atlas) {
|
|
51
|
-
|
|
53
|
+
var entry;
|
|
54
|
+
|
|
55
|
+
if (typeof atlas === "undefined") {
|
|
56
|
+
entry = this.cache.get(image)[0];
|
|
57
|
+
} else {
|
|
58
|
+
// manage cases where a specific atlas is specified
|
|
59
|
+
this.cache.forEach((value, key) => {
|
|
60
|
+
var _atlas = value.getAtlas();
|
|
61
|
+
if (key === image && _atlas[0].width === atlas.framewidth && _atlas[0].height === atlas.frameheight) {
|
|
62
|
+
entry = value;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof entry === "undefined") {
|
|
52
68
|
if (!atlas) {
|
|
53
69
|
atlas = createAtlas(image.width, image.height, image.src ? fileUtil.getBasename(image.src) : undefined);
|
|
54
70
|
}
|
|
55
|
-
|
|
71
|
+
entry = new TextureAtlas(atlas, image, false);
|
|
72
|
+
this.set(image, entry);
|
|
56
73
|
}
|
|
57
|
-
|
|
74
|
+
|
|
75
|
+
return entry;
|
|
58
76
|
}
|
|
59
77
|
|
|
60
78
|
/**
|
|
@@ -99,7 +117,7 @@ class TextureCache {
|
|
|
99
117
|
"(" + width + "x" + height + ")"
|
|
100
118
|
);
|
|
101
119
|
}
|
|
102
|
-
this.cache.
|
|
120
|
+
return this.cache.put(image, texture);
|
|
103
121
|
}
|
|
104
122
|
|
|
105
123
|
/**
|
package/src/video/video.js
CHANGED
|
@@ -9,8 +9,7 @@ import { initialized, version } from "./../index.js";
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* video functions
|
|
12
|
-
* @namespace
|
|
13
|
-
* @memberof me
|
|
12
|
+
* @namespace video
|
|
14
13
|
*/
|
|
15
14
|
|
|
16
15
|
var designRatio = 1;
|
|
@@ -126,7 +125,7 @@ function onresize() {
|
|
|
126
125
|
/**
|
|
127
126
|
* Select the HTML5 Canvas renderer
|
|
128
127
|
* @name CANVAS
|
|
129
|
-
* @memberof
|
|
128
|
+
* @memberof video
|
|
130
129
|
* @constant
|
|
131
130
|
*/
|
|
132
131
|
export const CANVAS = 0;
|
|
@@ -134,7 +133,7 @@ export const CANVAS = 0;
|
|
|
134
133
|
/**
|
|
135
134
|
* Select the WebGL renderer
|
|
136
135
|
* @name WEBGL
|
|
137
|
-
* @memberof
|
|
136
|
+
* @memberof video
|
|
138
137
|
* @constant
|
|
139
138
|
*/
|
|
140
139
|
export const WEBGL = 1;
|
|
@@ -142,7 +141,7 @@ export const WEBGL = 1;
|
|
|
142
141
|
/**
|
|
143
142
|
* Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
|
|
144
143
|
* @name AUTO
|
|
145
|
-
* @memberof
|
|
144
|
+
* @memberof video
|
|
146
145
|
* @constant
|
|
147
146
|
*/
|
|
148
147
|
export const AUTO = 2;
|
|
@@ -153,24 +152,24 @@ export const AUTO = 2;
|
|
|
153
152
|
* @type {HTMLElement}
|
|
154
153
|
* @readonly
|
|
155
154
|
* @name parent
|
|
156
|
-
* @memberof
|
|
155
|
+
* @memberof video
|
|
157
156
|
*/
|
|
158
157
|
export let parent = null;
|
|
159
158
|
|
|
160
159
|
/**
|
|
161
160
|
* the scaling ratio to be applied to the display canvas
|
|
162
161
|
* @name scaleRatio
|
|
163
|
-
* @type {
|
|
162
|
+
* @type {Vector2d}
|
|
164
163
|
* @default <1,1>
|
|
165
|
-
* @memberof
|
|
164
|
+
* @memberof video
|
|
166
165
|
*/
|
|
167
166
|
export let scaleRatio = new Vector2d(1, 1);
|
|
168
167
|
|
|
169
168
|
/**
|
|
170
169
|
* A reference to the active Canvas or WebGL active renderer renderer
|
|
171
170
|
* @name renderer
|
|
172
|
-
* @type {
|
|
173
|
-
* @memberof
|
|
171
|
+
* @type {CanvasRenderer|WebGLRenderer}
|
|
172
|
+
* @memberof video
|
|
174
173
|
*/
|
|
175
174
|
export let renderer = null;
|
|
176
175
|
|
|
@@ -191,12 +190,12 @@ export let renderer = null;
|
|
|
191
190
|
* <center><img src="images/scale-flex-height.png"/></center><br>
|
|
192
191
|
* - <i><b>`stretch`</b></i> : Canvas is resized to fit; content is scaled to screen aspect ratio
|
|
193
192
|
* <center><img src="images/scale-stretch.png"/></center><br>
|
|
194
|
-
* @function
|
|
193
|
+
* @function video.init
|
|
195
194
|
* @param {number} width The width of the canvas viewport
|
|
196
195
|
* @param {number} height The height of the canvas viewport
|
|
197
196
|
* @param {object} [options] The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
|
|
198
197
|
* @param {string|HTMLElement} [options.parent=document.body] the DOM parent element to hold the canvas in the HTML file
|
|
199
|
-
* @param {number} [options.renderer=
|
|
198
|
+
* @param {number} [options.renderer=video.AUTO] renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO)
|
|
200
199
|
* @param {boolean} [options.doubleBuffering=false] enable/disable double buffering
|
|
201
200
|
* @param {number|string} [options.scale=1.0] enable scaling of the canvas ('auto' for automatic scaling)
|
|
202
201
|
* @param {string} [options.scaleMethod="fit"] screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
@@ -274,7 +273,7 @@ export function init(width, height, options) {
|
|
|
274
273
|
|
|
275
274
|
// default scaled size value
|
|
276
275
|
settings.zoomX = width * scaleRatio.x;
|
|
277
|
-
settings.zoomY =
|
|
276
|
+
settings.zoomY = height * scaleRatio.y;
|
|
278
277
|
|
|
279
278
|
//add a channel for the onresize/onorientationchange event
|
|
280
279
|
window.addEventListener(
|
|
@@ -380,7 +379,7 @@ export function init(width, height, options) {
|
|
|
380
379
|
|
|
381
380
|
/**
|
|
382
381
|
* Create and return a new Canvas element
|
|
383
|
-
* @function
|
|
382
|
+
* @function video.createCanvas
|
|
384
383
|
* @param {number} width width
|
|
385
384
|
* @param {number} height height
|
|
386
385
|
* @param {boolean} [offscreen=false] will returns an OffscreenCanvas if supported
|
|
@@ -412,7 +411,7 @@ export function createCanvas(width, height, offscreen = false) {
|
|
|
412
411
|
|
|
413
412
|
/**
|
|
414
413
|
* return a reference to the parent DOM element holding the main canvas
|
|
415
|
-
* @function
|
|
414
|
+
* @function video.getParent
|
|
416
415
|
* @returns {HTMLElement}
|
|
417
416
|
*/
|
|
418
417
|
export function getParent() {
|
|
@@ -423,8 +422,8 @@ export function getParent() {
|
|
|
423
422
|
* scale the "displayed" canvas by the given scalar.
|
|
424
423
|
* this will modify the size of canvas element directly.
|
|
425
424
|
* Only use this if you are not using the automatic scaling feature.
|
|
426
|
-
* @function
|
|
427
|
-
* @see
|
|
425
|
+
* @function video.scale
|
|
426
|
+
* @see video.init
|
|
428
427
|
* @param {number} x x scaling multiplier
|
|
429
428
|
* @param {number} y y scaling multiplier
|
|
430
429
|
*/
|
|
@@ -197,36 +197,35 @@ function minify(src) {
|
|
|
197
197
|
/**
|
|
198
198
|
* @classdesc
|
|
199
199
|
* a base GL Shader object
|
|
200
|
-
* @class GLShader
|
|
201
|
-
* @memberof me
|
|
202
|
-
* @param {WebGLRenderingContext} gl the current WebGL rendering context
|
|
203
|
-
* @param {string} vertex a string containing the GLSL source code to set
|
|
204
|
-
* @param {string} fragment a string containing the GLSL source code to set
|
|
205
|
-
* @param {string} [precision=auto detected] float precision ('lowp', 'mediump' or 'highp').
|
|
206
|
-
* @see https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders
|
|
207
|
-
* @example
|
|
208
|
-
* // create a basic shader
|
|
209
|
-
* var myShader = new me.GLShader(
|
|
210
|
-
* // WebGL rendering context
|
|
211
|
-
* gl,
|
|
212
|
-
* // vertex shader
|
|
213
|
-
* [
|
|
214
|
-
* "void main() {",
|
|
215
|
-
* " gl_Position = doMathToMakeClipspaceCoordinates;",
|
|
216
|
-
* "}"
|
|
217
|
-
* ].join("\n"),
|
|
218
|
-
* // fragment shader
|
|
219
|
-
* [
|
|
220
|
-
* "void main() {",
|
|
221
|
-
* " gl_FragColor = doMathToMakeAColor;",
|
|
222
|
-
* "}"
|
|
223
|
-
* ].join("\n")
|
|
224
|
-
* )
|
|
225
|
-
* // use the shader
|
|
226
|
-
* myShader.bind();
|
|
227
200
|
*/
|
|
228
201
|
class GLShader {
|
|
229
|
-
|
|
202
|
+
/**
|
|
203
|
+
* @param {WebGLRenderingContext} gl the current WebGL rendering context
|
|
204
|
+
* @param {string} vertex a string containing the GLSL source code to set
|
|
205
|
+
* @param {string} fragment a string containing the GLSL source code to set
|
|
206
|
+
* @param {string} [precision=auto detected] float precision ('lowp', 'mediump' or 'highp').
|
|
207
|
+
* @see https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders
|
|
208
|
+
* @example
|
|
209
|
+
* // create a basic shader
|
|
210
|
+
* var myShader = new me.GLShader(
|
|
211
|
+
* // WebGL rendering context
|
|
212
|
+
* gl,
|
|
213
|
+
* // vertex shader
|
|
214
|
+
* [
|
|
215
|
+
* "void main() {",
|
|
216
|
+
* " gl_Position = doMathToMakeClipspaceCoordinates;",
|
|
217
|
+
* "}"
|
|
218
|
+
* ].join("\n"),
|
|
219
|
+
* // fragment shader
|
|
220
|
+
* [
|
|
221
|
+
* "void main() {",
|
|
222
|
+
* " gl_FragColor = doMathToMakeAColor;",
|
|
223
|
+
* "}"
|
|
224
|
+
* ].join("\n")
|
|
225
|
+
* )
|
|
226
|
+
* // use the shader
|
|
227
|
+
* myShader.bind();
|
|
228
|
+
*/
|
|
230
229
|
constructor(gl, vertex, fragment, precision) {
|
|
231
230
|
|
|
232
231
|
/**
|
|
@@ -234,7 +233,7 @@ class GLShader {
|
|
|
234
233
|
* @public
|
|
235
234
|
* @type {WebGLRenderingContext}
|
|
236
235
|
* @name gl
|
|
237
|
-
* @memberof
|
|
236
|
+
* @memberof GLShader
|
|
238
237
|
*/
|
|
239
238
|
this.gl = gl;
|
|
240
239
|
|
|
@@ -243,7 +242,7 @@ class GLShader {
|
|
|
243
242
|
* @public
|
|
244
243
|
* @type {string}
|
|
245
244
|
* @name vertex
|
|
246
|
-
* @memberof
|
|
245
|
+
* @memberof GLShader
|
|
247
246
|
*/
|
|
248
247
|
this.vertex = setPrecision(minify(vertex), precision || device.getMaxShaderPrecision(this.gl));
|
|
249
248
|
|
|
@@ -252,7 +251,7 @@ class GLShader {
|
|
|
252
251
|
* @public
|
|
253
252
|
* @type {string}
|
|
254
253
|
* @name vertex
|
|
255
|
-
* @memberof
|
|
254
|
+
* @memberof GLShader
|
|
256
255
|
*/
|
|
257
256
|
this.fragment = setPrecision(minify(fragment), precision || device.getMaxShaderPrecision(this.gl));
|
|
258
257
|
|
|
@@ -261,7 +260,7 @@ class GLShader {
|
|
|
261
260
|
* @public
|
|
262
261
|
* @type {GLint[]}
|
|
263
262
|
* @name attributes
|
|
264
|
-
* @memberof
|
|
263
|
+
* @memberof GLShader
|
|
265
264
|
*/
|
|
266
265
|
this.attributes = extractAttributes(this.gl, this);
|
|
267
266
|
|
|
@@ -271,7 +270,7 @@ class GLShader {
|
|
|
271
270
|
* @public
|
|
272
271
|
* @type {WebGLProgram}
|
|
273
272
|
* @name program
|
|
274
|
-
* @memberof
|
|
273
|
+
* @memberof GLShader
|
|
275
274
|
*/
|
|
276
275
|
this.program = compileProgram(this.gl, this.vertex, this.fragment, this.attributes);
|
|
277
276
|
|
|
@@ -280,7 +279,7 @@ class GLShader {
|
|
|
280
279
|
* @public
|
|
281
280
|
* @type {object}
|
|
282
281
|
* @name uniforms
|
|
283
|
-
* @memberof
|
|
282
|
+
* @memberof GLShader
|
|
284
283
|
*/
|
|
285
284
|
this.uniforms = extractUniforms(this.gl, this);
|
|
286
285
|
|
|
@@ -293,7 +292,7 @@ class GLShader {
|
|
|
293
292
|
/**
|
|
294
293
|
* Installs this shader program as part of current rendering state
|
|
295
294
|
* @name bind
|
|
296
|
-
* @memberof
|
|
295
|
+
* @memberof GLShader
|
|
297
296
|
* @function
|
|
298
297
|
*/
|
|
299
298
|
bind() {
|
|
@@ -303,7 +302,7 @@ class GLShader {
|
|
|
303
302
|
/**
|
|
304
303
|
* returns the location of an attribute variable in this shader program
|
|
305
304
|
* @name getAttribLocation
|
|
306
|
-
* @memberof
|
|
305
|
+
* @memberof GLShader
|
|
307
306
|
* @function
|
|
308
307
|
* @param {string} name the name of the attribute variable whose location to get.
|
|
309
308
|
* @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise
|
|
@@ -320,7 +319,7 @@ class GLShader {
|
|
|
320
319
|
/**
|
|
321
320
|
* Set the uniform to the given value
|
|
322
321
|
* @name setUniform
|
|
323
|
-
* @memberof
|
|
322
|
+
* @memberof GLShader
|
|
324
323
|
* @function
|
|
325
324
|
* @param {string} name the uniform name
|
|
326
325
|
* @param {object|Float32Array} value the value to assign to that uniform
|
|
@@ -343,7 +342,7 @@ class GLShader {
|
|
|
343
342
|
/**
|
|
344
343
|
* destroy this shader objects resources (program, attributes, uniforms)
|
|
345
344
|
* @name destroy
|
|
346
|
-
* @memberof
|
|
345
|
+
* @memberof GLShader
|
|
347
346
|
* @function
|
|
348
347
|
*/
|
|
349
348
|
destroy() {
|