Skip to content

Commit 1ffefcf

Browse files
committed
Implement interactive flag for drawable
false will exclude the drawable from pick() by default Related to performance issue described in TurboWarp/scratch-gui#1026
1 parent 2cf41be commit 1ffefcf

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Drawable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ class Drawable {
129129
this.isTouching = this._isTouchingNever;
130130

131131
this._highQuality = false;
132+
133+
/**
134+
* If false, this drawable will be ignored by pick() by default.
135+
* The drawable may still be considered by pick() if its ID is explicitly given to pick().
136+
*/
137+
this.interactive = true;
132138
}
133139

134140
setHighQuality (highQuality) {

src/RenderWebGL.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,18 @@ class RenderWebGL extends EventEmitter {
736736
skin.private = true;
737737
}
738738

739+
/**
740+
* Mark a drawable as being non-interactive by default.
741+
* @param {number} drawableID The drawable's ID
742+
*/
743+
markDrawableAsNoninteractive (drawableID) {
744+
const drawable = this._allDrawables[drawableID];
745+
if (!drawable) {
746+
return;
747+
}
748+
drawable.interactive = false;
749+
}
750+
739751
/**
740752
* Set the layer group ordering for the renderer.
741753
* @param {Array<string>} groupOrdering The ordered array of layer group
@@ -1370,12 +1382,14 @@ class RenderWebGL extends EventEmitter {
13701382

13711383
candidateIDs = (candidateIDs || this._drawList).filter(id => {
13721384
const drawable = this._allDrawables[id];
1385+
if (!candidateIDs && !drawable.interactive) {
1386+
return false;
1387+
}
13731388
// default pick list ignores visible and ghosted sprites.
13741389
if (drawable.getVisible() && drawable.getUniforms().u_ghost !== 0) {
13751390
const drawableBounds = drawable.getFastBounds();
13761391
const inRange = bounds.intersects(drawableBounds);
13771392
if (!inRange) return false;
1378-
if (drawable.skin instanceof PenSkin) return false;
13791393

13801394
drawable.updateCPURenderAttributes();
13811395
return true;

0 commit comments

Comments
 (0)