Skip to content

Commit bcdae72

Browse files
committed
fix: calculate convex hulls in texture space
1 parent 4a24cd8 commit bcdae72

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
@@ -1861,14 +1861,16 @@ class RenderWebGL extends EventEmitter {
18611861
_getConvexHullPointsForDrawable (drawableID) {
18621862
const drawable = this._allDrawables[drawableID];
18631863

1864-
const [width, height] = drawable.skin.size;
1864+
drawable.updateCPURenderAttributes();
1865+
1866+
const silhouette = drawable.skin._silhouette;
1867+
const width = silhouette._width;
1868+
const height = silhouette._height;
18651869
// No points in the hull if invisible or size is 0.
18661870
if (!drawable.getVisible() || width === 0 || height === 0) {
18671871
return [];
18681872
}
18691873

1870-
drawable.updateCPURenderAttributes();
1871-
18721874
/**
18731875
* Return the determinant of two vectors, the vector from A to B and the vector from A to C.
18741876
*
@@ -1921,8 +1923,8 @@ class RenderWebGL extends EventEmitter {
19211923
for (; x < width; x++) {
19221924
_pixelPos[0] = (x + 0.5) / width;
19231925
EffectTransform.transformPoint(drawable, _pixelPos, _effectPos);
1924-
if (drawable.skin.isTouchingLinear(_effectPos)) {
1925-
currentPoint = [x, y];
1926+
if (drawable.skin.isTouchingNearest(_effectPos)) {
1927+
currentPoint = [_pixelPos[0], _pixelPos[1]];
19261928
break;
19271929
}
19281930
}
@@ -1958,8 +1960,8 @@ class RenderWebGL extends EventEmitter {
19581960
for (x = width - 1; x >= 0; x--) {
19591961
_pixelPos[0] = (x + 0.5) / width;
19601962
EffectTransform.transformPoint(drawable, _pixelPos, _effectPos);
1961-
if (drawable.skin.isTouchingLinear(_effectPos)) {
1962-
currentPoint = [x, y];
1963+
if (drawable.skin.isTouchingNearest(_effectPos)) {
1964+
currentPoint = [_pixelPos[0], _pixelPos[1]];
19631965
break;
19641966
}
19651967
}

0 commit comments

Comments
 (0)