Skip to content

Commit 8076f64

Browse files
committed
We have replaced the PolyK Triangulation calls within Pixi with EarCut 2.0.8. This allows for faster polygon triangulation, and also deals with more complex polygons that PolyK would crash on.
1 parent 3baf3e7 commit 8076f64

5 files changed

Lines changed: 632 additions & 6 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
279279
### Updates
280280

281281
* TypeScript definitions fixes and updates (thanks @clark-stevenson @zimpy @iamfreee @milkey-mouse @juanmirod @danzel @staff0rd @sanchopancho13)
282-
* Docs typo fixes (thanks @zeterain @staff0rd @milkey-mouse @dick-clark @nlotz @s4wny @jonjanisch @Alaxe @cdelstad @tsphillips)
282+
* Docs typo fixes (thanks @zeterain @staff0rd @milkey-mouse @dick-clark @nlotz @s4wny @jonjanisch @Alaxe @cdelstad @tsphillips @rblopes)
283283
* Emitter methods `at`, `explode`, `flow`, `kill`, `revive`, `setAlpha`, `setRotation`, `setScale`, `setSize`, `setXSpeed`, `setYSpeed` and `start` now return the Emitter instance for better method chaining (thanks @samme #2308)
284284
* Tilemap.hasTile will now return `false` if the Tile doesn't exist in the coordinates given (which can happen if the coordinates are out of bounds) (thanks @cy-ryo-fujiwara #2304)
285285
* Update FrameData to check if both the numeric index was set and exists. Should fix Phaser Tiled integration as a result (thanks @Weedshaker #2298)
@@ -301,6 +301,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
301301
* BitmapData.drawGroup can now handle drawing Emitters and BitmapText objects that are part of the Group.
302302
* SoundManager.setTouchLock is no longer set if `SoundManager.noAudio` is true, or if the PhaserGlobal setting `disableAudio` is true (thanks @bcjordan #2206)
303303
* Loader.audiosprite is renamed to Loader.audioSprite (the old one still works for legacy reasons) (thanks @epaezrubio #2145)
304+
* EarCut now replaces PolyK, which fixes advanced Graphics mask triangulation issues such as #1941
304305

305306
### Bug Fixes
306307

@@ -333,6 +334,7 @@ Please note that Phaser uses a custom build of Pixi and always has done. The fol
333334

334335
* BaseTexture.destroy no longer checks for the `_pixiId` property on the canvas before removing it from the CanvasPool, meaning it's now destroying a lot more canvas elements than it was in the past!
335336
* TilingSprite would ignore the `renderable` property, and render it regardless. Now it skips render if `renderable` is false (thanks @Green92 #2214)
337+
* We have replaced the PolyK Triangulation calls within Pixi with EarCut 2.0.8. This allows for faster polygon triangulation, and also deals with more complex polygons that PolyK would crash on.
336338

337339
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
338340

build/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
<script src="$path/src/pixi/display/SpriteBatch.js"></script>
5555
5656
<script src="$path/src/pixi/utils/Utils.js"></script>
57-
<script src="$path/src/pixi/utils/Polyk.js"></script>
57+
<script src="$path/src/pixi/utils/PolyK.js"></script>
58+
<script src="$path/src/pixi/utils/EarCut.js"></script>
5859
<script src="$path/src/pixi/utils/CanvasPool.js"></script>
5960
6061
<script src="$path/src/pixi/renderers/webgl/utils/WebGLShaderUtils.js"></script>

src/pixi/renderers/webgl/utils/WebGLGraphics.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,8 @@ PIXI.WebGLGraphics.buildRoundedRectangle = function(graphicsData, webGLData)
349349

350350
var vecPos = verts.length/6;
351351

352-
var triangles = PIXI.PolyK.Triangulate(recPoints);
352+
var triangles = PIXI.EarCut.Triangulate(recPoints, null, 2);
353353

354-
//
355-
356354
var i = 0;
357355
for (i = 0; i < triangles.length; i+=3)
358356
{
@@ -817,7 +815,7 @@ PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData)
817815
var g = color[1] * alpha;
818816
var b = color[2] * alpha;
819817

820-
var triangles = PIXI.PolyK.Triangulate(points);
818+
var triangles = PIXI.EarCut.Triangulate(points, null, 2);
821819

822820
if(!triangles)return false;
823821

0 commit comments

Comments
 (0)