Skip to content

Commit 72b320f

Browse files
author
DD Liu
committed
Change e local space to clamp to texture space
1 parent 749b110 commit 72b320f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/Drawable.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ const getLocalPosition = (drawable, vec) => {
3737
// localPosition matches that transformation.
3838
localPosition[0] = 0.5 - (((v0 * m[0]) + (v1 * m[4]) + m[12]) / d);
3939
localPosition[1] = (((v0 * m[1]) + (v1 * m[5]) + m[13]) / d) + 0.5;
40-
// Fix floating point issues near 0.
41-
// TODO: Check if this can be removed after render pull 479 is merged
42-
if (Math.abs(localPosition[0] < 1e-8)) localPosition[0] = 0;
43-
if (Math.abs(localPosition[1] < 1e-8)) localPosition[1] = 0;
4440
// Apply texture effect transform if the localPosition is within the drawable's space,
4541
// and any effects are currently active.
4642
if (drawable.enabledEffects !== 0 &&
@@ -716,21 +712,25 @@ class Drawable {
716712
* Sample a color from a drawable's texture.
717713
* The caller is responsible for ensuring this drawable's inverse matrix & its skin's silhouette are up-to-date.
718714
* @see updateCPURenderAttributes
719-
* @param {twgl.v3} vec The scratch space [x,y] vector
715+
* @param {twgl.v3} vec The scratch space [x,y] vector. This will be clamped to the texture space, to match the
716+
* GL code (See https://github.com/LLK/scratch-render/blob/develop/src/BitmapSkin.js#L88)
720717
* @param {Drawable} drawable The drawable to sample the texture from
721718
* @param {Uint8ClampedArray} dst The "color4b" representation of the texture at point.
722719
* @param {number} [effectMask] A bitmask for which effects to use. Optional.
723720
* @returns {Uint8ClampedArray} The dst object filled with the color4b
724721
*/
725722
static sampleColor4b (vec, drawable, dst, effectMask) {
726723
const localPosition = getLocalPosition(drawable, vec);
727-
if (localPosition[0] < 0 || localPosition[1] < 0 ||
728-
localPosition[0] > 1 || localPosition[1] > 1) {
729-
dst[0] = 0;
730-
dst[1] = 0;
731-
dst[2] = 0;
732-
dst[3] = 0;
733-
return dst;
724+
if (localPosition[0] < 0) {
725+
localPosition[0] = 0;
726+
} else if (localPosition[0] > 1) {
727+
localPosition[0] = 1;
728+
}
729+
730+
if (localPosition[1] < 0) {
731+
localPosition[1] = 0;
732+
} else if (localPosition[1] > 1) {
733+
localPosition[1] = 1;
734734
}
735735
const textColor =
736736
// commenting out to only use nearest for now

0 commit comments

Comments
 (0)