Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to speed up band selection tool in a Dart WebGL application
    primarykey
    data
    text
    <p>The task at hand is to add a band selection tool to a Dart WebGL application. The tool will be used to draw a rectangle over multiple objects by dragging the mouse. Thus multiple objects can be selected/picked in a single user action. I'm currently using gl.readPixels() to read colors from an off-screen renderbuffer. Problem is, when a large area is band-selected, gl.readPixels() issues millions of pixels. Scanning such a big amount of colors wastes precious seconds just to locate few objects.</p> <p>Please anyone point possibly faster methods for band-selecting multiple objects with Dart+WebGL.</p> <p>For reference, I show below the current main portion of the band selection tool.</p> <pre class="lang-dart prettyprint-override"><code>Uint8List _color = new Uint8List(4); void bandSelection(int x, y, width, height, PickerShader picker, RenderingContext gl, bool shift) { if (picker == null) { err("bandSelection: picker not available"); return; } int size = 4 * width * height; if (size &gt; _color.length) { _color = new Uint8List(size); } gl.bindFramebuffer(RenderingContext.FRAMEBUFFER, picker.framebuffer); gl.readPixels(x, y, width, height, RenderingContext.RGBA, RenderingContext.UNSIGNED_BYTE, _color); if (!shift) { // shift is released _selection.clear(); } for (int i = 0; i &lt; size; i += 4) { if (_selection.length &gt;= picker.numberOfInstances) { // selected all available objects, no need to keep searching break; } PickerInstance pi = picker.findInstanceByColor(_color[i], _color[i+1], _color[i+2]); if (pi == null) { continue; } _selection.add(pi); } debug("bandSelection: $_selection"); } // findInstanceByColor is method from PickerShader PickerInstance findInstanceByColor(int r, g, b) { return colorHit(_instanceList, r, g, b); } PickerInstance colorHit(Iterable&lt;Instance&gt; list, int r,g,b) { bool match(Instance i) { Float32List f = i.pickColor; return (255.0*f[0] - r.toDouble()).abs() &lt; 1.0 &amp;&amp; (255.0*f[1] - g.toDouble()).abs() &lt; 1.0 &amp;&amp; (255.0*f[2] - b.toDouble()).abs() &lt; 1.0; } Instance pi; try { pi = list.firstWhere(match); } catch (e) { return null; } return pi as PickerInstance; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload