Skip to content

Commit fed02ca

Browse files
authored
Merge pull request #544 from adroitwhiz/fix-vector-silhouette
Fix SVGSkin silhouettes
2 parents a67cd48 + 2985f2a commit fed02ca

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/RenderWebGL.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ class RenderWebGL extends EventEmitter {
972972

973973
drawable.updateMatrix();
974974
if (drawable.skin) {
975-
drawable.skin.updateSilhouette();
975+
drawable.skin.updateSilhouette(this._getDrawableScreenSpaceScale(drawable));
976976
} else {
977977
log.warn(`Could not find skin for drawable with id: ${drawableID}`);
978978
}
@@ -1008,7 +1008,7 @@ class RenderWebGL extends EventEmitter {
10081008
if (drawable.getVisible() && drawable.getUniforms().u_ghost !== 0) {
10091009
drawable.updateMatrix();
10101010
if (drawable.skin) {
1011-
drawable.skin.updateSilhouette();
1011+
drawable.skin.updateSilhouette(this._getDrawableScreenSpaceScale(drawable));
10121012
} else {
10131013
log.warn(`Could not find skin for drawable with id: ${id}`);
10141014
}
@@ -1243,7 +1243,7 @@ class RenderWebGL extends EventEmitter {
12431243
if (!drawable.skin || !drawable.skin.getTexture([100, 100])) return null;
12441244

12451245
drawable.updateMatrix();
1246-
drawable.skin.updateSilhouette();
1246+
drawable.skin.updateSilhouette(this._getDrawableScreenSpaceScale(drawable));
12471247
const bounds = drawable.getFastBounds();
12481248

12491249
// Limit queries to the stage size.
@@ -1281,7 +1281,7 @@ class RenderWebGL extends EventEmitter {
12811281
if (drawable.skin && drawable._visible) {
12821282
// Update the CPU position data
12831283
drawable.updateMatrix();
1284-
drawable.skin.updateSilhouette();
1284+
drawable.skin.updateSilhouette(this._getDrawableScreenSpaceScale(drawable));
12851285
const candidateBounds = drawable.getFastBounds();
12861286
if (bounds.intersects(candidateBounds)) {
12871287
result.push({
@@ -1659,6 +1659,18 @@ class RenderWebGL extends EventEmitter {
16591659
this._regionId = null;
16601660
}
16611661

1662+
/**
1663+
* Get the screen-space scale of a drawable, as percentages of the drawable's "normal" size.
1664+
* @param {Drawable} drawable The drawable whose screen-space scale we're fetching.
1665+
* @returns {Array<number>} The screen-space X and Y dimensions of the drawable's scale, as percentages.
1666+
*/
1667+
_getDrawableScreenSpaceScale (drawable) {
1668+
return [
1669+
drawable.scale[0] * this._gl.canvas.width / this._nativeSize[0],
1670+
drawable.scale[1] * this._gl.canvas.height / this._nativeSize[1]
1671+
];
1672+
}
1673+
16621674
/**
16631675
* Draw a set of Drawables, by drawable ID
16641676
* @param {Array<int>} drawables The Drawable IDs to draw, possibly this._drawList.
@@ -1691,10 +1703,7 @@ class RenderWebGL extends EventEmitter {
16911703
if (!drawable.getVisible() && !opts.ignoreVisibility) continue;
16921704

16931705
// Combine drawable scale with the native vs. backing pixel ratio
1694-
const drawableScale = [
1695-
drawable.scale[0] * this._gl.canvas.width / this._nativeSize[0],
1696-
drawable.scale[1] * this._gl.canvas.height / this._nativeSize[1]
1697-
];
1706+
const drawableScale = this._getDrawableScreenSpaceScale(drawable);
16981707

16991708
// If the skin or texture isn't ready yet, skip it.
17001709
if (!drawable.skin || !drawable.skin.getTexture(drawableScale)) continue;

src/SVGSkin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ class SVGSkin extends Skin {
104104
return mip;
105105
}
106106

107+
updateSilhouette (scale = 1) {
108+
// Ensure a silhouette exists.
109+
this.getTexture(scale);
110+
}
111+
107112
/**
108113
* @param {Array<number>} scale - The scaling factors to be used, each in the [0,100] range.
109114
* @return {WebGLTexture} The GL texture representation of this skin when drawing at the given scale.

0 commit comments

Comments
 (0)