Merge pull request #213 from paulkaplan/touching-invisible

Ignore sprite visibility when testing for touching color
This commit is contained in:
Paul Kaplan
2017-12-11 09:16:16 -05:00
committed by GitHub

View File

@@ -424,6 +424,7 @@ class RenderWebGL extends EventEmitter {
/**
* Check if a particular Drawable is touching a particular color.
* Unlike touching drawable, touching color tests invisible sprites.
* @param {int} drawableID The ID of the Drawable to check.
* @param {Array<int>} color3b Test if the Drawable is touching this color.
* @param {Array<int>} [mask3b] Optionally mask the check to this part of Drawable.
@@ -435,11 +436,11 @@ class RenderWebGL extends EventEmitter {
const bounds = this._touchingBounds(drawableID);
if (!bounds) {
return;
return false;
}
const candidateIDs = this._filterCandidatesTouching(drawableID, this._drawList, bounds);
if (!candidateIDs) {
return;
return false;
}
// Limit size of viewport to the bounds around the target Drawable,
@@ -477,7 +478,10 @@ class RenderWebGL extends EventEmitter {
ShaderManager.DRAW_MODE.colorMask :
ShaderManager.DRAW_MODE.silhouette,
projection,
{extraUniforms});
{
extraUniforms,
ignoreVisibility: true // Touching color ignores sprite visibility
});
gl.stencilFunc(gl.EQUAL, 1, 1);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
@@ -533,11 +537,11 @@ class RenderWebGL extends EventEmitter {
const bounds = this._touchingBounds(drawableID);
if (!bounds) {
return;
return false;
}
candidateIDs = this._filterCandidatesTouching(drawableID, candidateIDs, bounds);
if (!candidateIDs) {
return;
return false;
}
// Limit size of viewport to the bounds around the target Drawable,
@@ -1003,7 +1007,7 @@ class RenderWebGL extends EventEmitter {
try {
gl.disable(gl.BLEND);
this._drawThese([stampID], ShaderManager.DRAW_MODE.default, projection, {isStamping: true});
this._drawThese([stampID], ShaderManager.DRAW_MODE.default, projection, {ignoreVisibility: true});
} finally {
gl.enable(gl.BLEND);
}
@@ -1097,7 +1101,7 @@ class RenderWebGL extends EventEmitter {
* @param {idFilterFunc} opts.filter An optional filter function.
* @param {object.<string,*>} opts.extraUniforms Extra uniforms for the shaders.
* @param {int} opts.effectMask Bitmask for effects to allow
* @param {boolean} opts.isStamping Stamp mode ignores sprite visibility, always drawing.
* @param {boolean} opts.ignoreVisibility Draw all, despite visibility (e.g. stamping, touching color)
* @private
*/
_drawThese (drawables, drawMode, projection, opts = {}) {
@@ -1114,8 +1118,9 @@ class RenderWebGL extends EventEmitter {
const drawable = this._allDrawables[drawableID];
/** @todo check if drawable is inside the viewport before anything else */
// Hidden drawables (e.g., by a "hide" block) are not drawn unless stamping
if (!drawable.getVisible() && !opts.isStamping) continue;
// Hidden drawables (e.g., by a "hide" block) are not drawn unless
// the ignoreVisibility flag is used (e.g. for stamping or touchingColor).
if (!drawable.getVisible() && !opts.ignoreVisibility) continue;
const drawableScale = drawable.scale;