Compare commits

...

9 Commits

Author SHA1 Message Date
picklesrus
2bc1528dac Merge pull request #712 from LLK/dependabot/npm_and_yarn/scratch-svg-renderer-0.2.0-prerelease.20201019174008
Bump scratch-svg-renderer from 0.2.0-prerelease.20201016121710 to 0.2.0-prerelease.20201019174008
2020-10-20 06:37:09 -04:00
dependabot-preview[bot]
59d66f562c Bump scratch-svg-renderer
Bumps [scratch-svg-renderer](https://github.com/LLK/scratch-svg-renderer) from 0.2.0-prerelease.20201016121710 to 0.2.0-prerelease.20201019174008.
- [Release notes](https://github.com/LLK/scratch-svg-renderer/releases)
- [Commits](https://github.com/LLK/scratch-svg-renderer/commits/0.2.0-prerelease.20201019174008)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-20 02:34:34 +00:00
picklesrus
ec053748cd Merge pull request #710 from LLK/picklesrus-patch-1-1
Bump scratch-svg-renderer
2020-10-16 13:36:56 -04:00
picklesrus
bf2820aeda Bump scratch-svg-renderer 2020-10-16 13:05:13 -04:00
Ray Schamp
0120a77b8e Merge pull request #703 from LLK/hotfix/enable-hotfixing
add hotfix capability to .travis.yml
2020-10-16 08:09:56 -04:00
picklesrus
e8d6f957fa Merge pull request #709 from LLK/dependabot/npm_and_yarn/scratch-svg-renderer-0.2.0-prerelease.20201015194358
Bump scratch-svg-renderer from 0.2.0-prerelease.20200610220938 to 0.2.0-prerelease.20201015194358
2020-10-16 06:36:49 -04:00
dependabot-preview[bot]
c0f1afe104 Bump scratch-svg-renderer
Bumps [scratch-svg-renderer](https://github.com/LLK/scratch-svg-renderer) from 0.2.0-prerelease.20200610220938 to 0.2.0-prerelease.20201015194358.
- [Release notes](https://github.com/LLK/scratch-svg-renderer/releases)
- [Commits](https://github.com/LLK/scratch-svg-renderer/commits/0.2.0-prerelease.20201015194358)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-15 21:44:55 +00:00
Chris Willis-Ford
4ebea93adf Merge pull request #445 from adroitwhiz/optimize-transformed-hull
Cache and don't re-create transformed hull points
2020-10-08 12:46:53 -07:00
adroitwhiz
75a4792f93 Cache and don't re-create transformed hull points 2020-06-25 16:33:22 -04:00
2 changed files with 29 additions and 10 deletions

View File

@@ -53,7 +53,7 @@
"minilog": "3.1.0",
"raw-loader": "^0.5.1",
"scratch-storage": "^1.0.0",
"scratch-svg-renderer": "0.2.0-prerelease.20200610220938",
"scratch-svg-renderer": "0.2.0-prerelease.20201019174008",
"twgl.js": "4.4.0"
}
}

View File

@@ -117,6 +117,12 @@ class Drawable {
this._convexHullPoints = null;
this._convexHullDirty = true;
// The precise bounding box will be from the transformed convex hull points,
// so initialize the array of transformed hull points in setConvexHullPoints.
// Initializing it once per convex hull recalculation avoids unnecessary creation of twgl.v3 objects.
this._transformedHullPoints = null;
this._transformedHullDirty = true;
this._skinWasAltered = this._skinWasAltered.bind(this);
this.isTouching = this._isTouchingNever;
@@ -137,6 +143,7 @@ class Drawable {
setTransformDirty () {
this._transformDirty = true;
this._inverseTransformDirty = true;
this._transformedHullDirty = true;
}
/**
@@ -457,6 +464,14 @@ class Drawable {
setConvexHullPoints (points) {
this._convexHullPoints = points;
this._convexHullDirty = false;
// Re-create the "transformed hull points" array.
// We only do this when the hull points change to avoid unnecessary allocations and GC.
this._transformedHullPoints = [];
for (let i = 0; i < points.length; i++) {
this._transformedHullPoints.push(twgl.v3.create());
}
this._transformedHullDirty = true;
}
/**
@@ -611,23 +626,27 @@ class Drawable {
* @private
*/
_getTransformedHullPoints () {
if (!this._transformedHullDirty) {
return this._transformedHullPoints;
}
const projection = twgl.m4.ortho(-1, 1, -1, 1, -1, 1);
const skinSize = this.skin.size;
const halfXPixel = 1 / skinSize[0] / 2;
const halfYPixel = 1 / skinSize[1] / 2;
const tm = twgl.m4.multiply(this._uniforms.u_modelMatrix, projection);
const transformedHullPoints = [];
for (let i = 0; i < this._convexHullPoints.length; i++) {
const point = this._convexHullPoints[i];
const glPoint = twgl.v3.create(
0.5 + (-point[0] / skinSize[0]) - halfXPixel,
(point[1] / skinSize[1]) - 0.5 + halfYPixel,
0
);
twgl.m4.transformPoint(tm, glPoint, glPoint);
transformedHullPoints.push(glPoint);
const dstPoint = this._transformedHullPoints[i];
dstPoint[0] = 0.5 + (-point[0] / skinSize[0]) - halfXPixel;
dstPoint[1] = (point[1] / skinSize[1]) - 0.5 + halfYPixel;
twgl.m4.transformPoint(tm, dstPoint, dstPoint);
}
return transformedHullPoints;
this._transformedHullDirty = false;
return this._transformedHullPoints;
}
/**