Skip to content

Commit 283ef3e

Browse files
committed
Calculate convex hulls in texture space
1 parent 048b557 commit 283ef3e

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/Drawable.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,16 +596,13 @@ class Drawable {
596596
}
597597

598598
const projection = twgl.m4.ortho(-1, 1, -1, 1, -1, 1);
599-
const skinSize = this.skin.size;
600-
const halfXPixel = 1 / skinSize[0] / 2;
601-
const halfYPixel = 1 / skinSize[1] / 2;
602599
const tm = twgl.m4.multiply(this._uniforms.u_modelMatrix, projection);
603600
for (let i = 0; i < this._convexHullPoints.length; i++) {
604601
const point = this._convexHullPoints[i];
605602
const dstPoint = this._transformedHullPoints[i];
606603

607-
dstPoint[0] = 0.5 + (-point[0] / skinSize[0]) - halfXPixel;
608-
dstPoint[1] = (point[1] / skinSize[1]) - 0.5 + halfYPixel;
604+
dstPoint[0] = 0.5 - point[0];
605+
dstPoint[1] = point[1] - 0.5;
609606
twgl.m4.transformPoint(tm, dstPoint, dstPoint);
610607
}
611608

src/RenderWebGL.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,14 +1956,16 @@ class RenderWebGL extends EventEmitter {
19561956
_getConvexHullPointsForDrawable (drawableID) {
19571957
const drawable = this._allDrawables[drawableID];
19581958

1959-
const [width, height] = drawable.skin.size;
1959+
drawable.updateCPURenderAttributes();
1960+
1961+
const silhouette = drawable.skin._silhouette;
1962+
const width = silhouette._width;
1963+
const height = silhouette._height;
19601964
// No points in the hull if invisible or size is 0.
19611965
if (!drawable.getVisible() || width === 0 || height === 0) {
19621966
return [];
19631967
}
19641968

1965-
drawable.updateCPURenderAttributes();
1966-
19671969
/**
19681970
* Return the determinant of two vectors, the vector from A to B and the vector from A to C.
19691971
*
@@ -2016,8 +2018,8 @@ class RenderWebGL extends EventEmitter {
20162018
for (; x < width; x++) {
20172019
_pixelPos[0] = (x + 0.5) / width;
20182020
EffectTransform.transformPoint(drawable, _pixelPos, _effectPos);
2019-
if (drawable.skin.isTouchingLinear(_effectPos)) {
2020-
currentPoint = [x, y];
2021+
if (drawable.skin.isTouchingNearest(_effectPos)) {
2022+
currentPoint = [_pixelPos[0], _pixelPos[1]];
20212023
break;
20222024
}
20232025
}
@@ -2053,8 +2055,8 @@ class RenderWebGL extends EventEmitter {
20532055
for (x = width - 1; x >= 0; x--) {
20542056
_pixelPos[0] = (x + 0.5) / width;
20552057
EffectTransform.transformPoint(drawable, _pixelPos, _effectPos);
2056-
if (drawable.skin.isTouchingLinear(_effectPos)) {
2057-
currentPoint = [x, y];
2058+
if (drawable.skin.isTouchingNearest(_effectPos)) {
2059+
currentPoint = [_pixelPos[0], _pixelPos[1]];
20582060
break;
20592061
}
20602062
}

0 commit comments

Comments
 (0)