265 Commits

Author SHA1 Message Date
Christopher Willis-Ford
b18ddadbe6 Rename color4bToID to color3bToID
A recent change made this function take only RGB instead of RGBA, so the
name might as well change to match.
2016-12-15 10:26:24 -08:00
Christopher Willis-Ford
4afbba3657 Respond to review feedback
- Remove unused alpha parameter from `color4bToID`
- Don't wrap URLs for default skins in `Drawable`
2016-12-14 13:38:43 -08:00
Christopher Willis-Ford
d1ea82b2bf Use this inside => callbacks
Some callbacks used a variable called `instance` to stash `this` for use
inside the callback. Now that those callbacks have been converted from
`function` to `=>`, they can just use `this` instead.
2016-12-13 15:51:46 -08:00
Christopher Willis-Ford
b700560198 Convert class methods to ES6 style
Also un-wrap lines which were originally written for an 80-column limit
but don't need to wrap now that the limit is 120 columns.
2016-12-13 15:32:07 -08:00
Christopher Willis-Ford
3c80ed73a7 Fix lint warnings 2016-12-12 12:06:19 -08:00
Christopher Willis-Ford
5db860efed Use eslint-config-scratch, fix linting errors 2016-12-12 12:06:19 -08:00
Christopher Willis-Ford
47b46fb1aa Update Webpack config like scratch-storage
- Move build outputs into `dist/`
- Make build output file names more consistent
- Update `playground/index.html` for new output file name
- Explicitly specify target => Node output is much smaller
- Minor fixes / cleanup in `.gitignore` and `src/index*.js`
2016-12-12 12:06:05 -08:00
Tim Mickel
b35f684478 A start on SVG "quirks mode" (#56)
* Start of an SVG rendering quirks mode

* Provide font defaults in SVG quirks mode

* Remove svg-to-image dependency

* Remove fonts and use package fonts instead.

* try/finally for getBBox
2016-11-07 17:40:59 -05:00
Christopher Willis-Ford
6c4715f793 Change whirl direction to match Scratch 2.0 3D
The whirl effect's direction was reversed in Scratch 2.0 with the
introduction of Stage3D. This "bug" has existed for long enough to
become the expected whirl direction. This change adjusts the Scratch 3.0
whirl direction to match the Scratch 2.0 3D whirl direction instead of
the Scratch 2.0 2D whirl direction.
2016-11-02 10:32:40 -04:00
Tim Mickel
be6d2dc4e4 Bounding-box optimizations for touching color, touching drawables (#55)
* Add Rectangle utility and use it in Drawable.getBounds

* Add `getAABB`, `getFastBounds`.

* Add width and height getters to Rectangle

* Add rectangle clamp

* Optimized isTouchingColor

* Optimized isTouchingDrawables

* Rectangle.ceil -> Rectangle.snapToInt

* Refactor to common _touchingQueryCandidates

* Split helper into two
2016-10-24 13:19:20 -04:00
Tim Mickel
2cffa7b643 Add rotation center and bitmap/costume resolution (#51) 2016-10-19 17:02:04 -04:00
Tim Mickel
85c8b599a0 Update dirty transform before calculating bounds (#47) 2016-10-12 15:20:40 -04:00
Tim Mickel
8e7a85d1a6 Fix y coordinates of bounding box (#46) 2016-10-12 14:32:14 -04:00
Tim Mickel
c00f0f55fc Math.max mix-up
Bounding to a minimum, we should use `Math.max`...
2016-10-12 13:46:32 -04:00
Tim Mickel
1fa97d248b Expose skin/costume size (#45)
* Expose skin/costume size

* Return skin size as a copy
2016-10-11 18:43:57 -04:00
Tim Mickel
a62d52a2d0 Calculating tight bounding boxes for Drawables (#42) 2016-10-11 18:14:14 -04:00
Tim Mickel
f1ac1a8211 Add RenderWebGL.prototype.isTouchingDrawables (#43) 2016-10-11 18:13:46 -04:00
Tim Mickel
14018f5ff6 Apply ghost effect after discard (#44) 2016-10-11 17:37:28 -04:00
Tim Mickel
7629b2ab6d Add setDrawableOrder for layering (#41)
* Add `setDrawableOrder` for layering

* Add 0-limit for newIndex
2016-10-07 17:57:47 -04:00
Tim Mickel
fb3f677e2c Remove worker support (#36)
* Remove WebWorker support

* Recompile Sept. 14
2016-09-15 19:01:44 -04:00
Tim Mickel
2b81b791b3 Use the right skin format in playground demo (#33) 2016-09-12 12:08:56 -04:00
Tim Mickel
042f0f0353 Fix asset URL handling from #27 (#32)
* Fix URL handling of assets

* Recompile 2 Sept 12
2016-09-12 11:55:08 -04:00
TheBrokenRail
3277584da9 Offline Sprites (#27)
* Added Scratch Cat SVG

* Offline Scratch Cat

* Moved To SRC

* Update README.md

* Delete Travis

* Add Travis YML

* Recompile

* Add files via upload

* Recompile Part 1

* Recompile Part 1

* Recompile Part 1

* Recompile Part 1

* Recompile!

* Not Needed

* Recompile For Real

* Update README.md

* Added Stage Offline

* Less Hacky Offline

* Recompile

* Fixed Line Length
2016-09-12 11:03:57 -04:00
Andrew Sliwinski
92fc916b86 Synchronize with master branch 2016-08-08 14:58:35 -04:00
Christopher Willis-Ford
543f05d6d4 Use babel-polyfill, plus compatibility fixes 2016-06-16 14:30:32 -07:00
Christopher Willis-Ford
ef100bf91e Make API consistent from page and worker
RenderWebGL{Local,Worker} class methods return Promise instances from
all methods returning a value. This makes the API consistent from a
Web Worker vs. the local page, and also allows the possibility of
asynchronous render queries in the future.
2016-06-16 12:59:48 -07:00
Christopher Willis-Ford
b00ec4c501 Rename WorkerRemote to RenderWebGLWorker 2016-06-15 15:36:46 -07:00
Christopher Willis-Ford
ad94df4afe Use ES6 class definitions 2016-06-15 15:21:58 -07:00
Christopher Willis-Ford
2c9e17d486 Use babel for ES6 / ES2015 support 2016-06-15 14:39:44 -07:00
Christopher Willis-Ford
f3a80c3429 Split 'index' files into 3: node, web, worker 2016-06-15 13:48:02 -07:00
Christopher Willis-Ford
fc10df7e41 Allow driving the renderer from a web worker
The build generates a new output set called `render-webgl-worker`, meant
to be imported from a web worker. This exposes the `RenderWebGLRemote`
class to facilitate communication with the renderer using `postMessage`
and `onmessage`.
Only a few messages are implemented so far, but it's enough to run the
demo page.
2016-06-14 11:45:35 -07:00
Christopher Willis-Ford
f0dae7aa48 Fix GL errors when using SVG Drawable early
Drawable now creates its own temporary texture upon construction. This
1x1 transparent texture is ready immediately and is replaced once a real
skin is loaded. This slightly simplifies some of the skin loading code
but more importantly prevents GL errors caused when trying to draw a
Drawable if it hasn't yet created its "real" texture, as in the SVG load
path.
2016-06-13 10:23:54 -07:00
Christopher Willis-Ford
b74f9448f5 Simplify draw modes again
The ability to bitwise-combine draw modes turns out to not be a benefit:
it's not safe to short-circuit drawing in the way that I had intended
because it could change the results of blending. Blending could create a
color that matches a "touching color?" check without that color existing
anywhere else.
2016-06-09 16:30:26 -07:00
Christopher Willis-Ford
04cebb9eed Improve color handling in isTouchingColor
- Always take color in unsigned-byte terms.
- Moved tolerance value into a class constant.
- Use the same tolerance in JS color comparison as in the shader.
2016-06-09 15:32:23 -07:00
Christopher Willis-Ford
aeefe8e5a3 Add setDebugCanvas method
Some debug code has been moved inside conditionals instead of comments
2016-06-09 15:17:21 -07:00
Christopher Willis-Ford
1edb753ac8 Add silhouette color to Drawable's uniforms 2016-06-09 13:44:04 -07:00
Christopher Willis-Ford
91cc797c3b Refactor ShaderManager's DRAW_MODE and effect info
Draw modes are now enabled/disabled by bitmask and can be combined.
Combining silhouette mode and color mask mode will be useful for
color-touching-color, for example.

Effect converters are now one field in a larger EFFECT_INFO map, which
also contains bitmask values for each effect. Drawable no longer makes
any assumptions regarding how ShaderManager will unpack the effect bits.

The shader cache is now an array of arrays, where the outer index is the
mask of active draw modes and the inner index is the mask of active
effects (as it was before). Effects which cannot impact the shape of a
Drawable are masked out in silhouette mode in order to avoid compiling
redundant shaders.
2016-06-09 12:17:12 -07:00
Christopher Willis-Ford
a21bd1aff1 Simplify coordinate system specification
The renderer now calculates the native render target size based on the
edge coordinates provided to the constructor. This native size will be
used directly for queries such as "touching color?" and will be scaled
when rendering for display.
2016-06-09 10:59:19 -07:00
Christopher Willis-Ford
1040189e27 Move shader management to new ShaderManager class 2016-06-08 13:38:49 -07:00
Christopher Willis-Ford
9f59b42901 Implement color-touching-color
The `isTouchingColor` function now takes an optional mask parameter. If
provided, only the parts of the Drawable which match the mask color will
be used for the test. For example:
```
  isTouchingColor(4, red, blue);
```
This means "are there any parts of Drawable #4 which are blue and are
touching a red pixel on some other Drawable?"
2016-06-06 16:21:24 -07:00
Christopher Willis-Ford
6b0f3379bf Allow overriding the candidates for picking
This can be used to implement the "touching {mouse-pointer}?" block.
2016-06-03 09:21:36 -07:00
Christopher Willis-Ford
eb7e87730c Move RenderWebGL class into its own file
The `index.js` file now handles module-level exports only.
2016-06-03 08:47:50 -07:00
Christopher Willis-Ford
4d04ef5de7 Use Buffer instead of Uint8Array (lint fix)
Also suppress lint warning about unused alpha in color4ubToID since
that's intentional (for now).
2016-06-02 15:42:55 -07:00
Christopher Willis-Ford
bdf65d4284 Add isTouchingColor(drawableID, color3ub)
Also eliminate the ability to specify background alpha, since that can
affect page-level compositing in undesirable ways.
Also avoid some redundant GL state calls.
2016-06-02 15:09:02 -07:00
Christopher Willis-Ford
25d8148ec4 Add more flexibility to draw-time object filtering
The `_drawThese` call now takes both a list of Drawable IDs for positive
filtering and a filter function for negative filtering.
2016-06-01 16:17:56 -07:00
Christopher Willis-Ford
137e4a642e Skin loading improvements
Fixed timing errors related to calling `setSkin()` a second time before
the first callback chain completes.
Fixed a typo causing problems when more than one Drawable is registered.
2016-06-01 15:28:08 -07:00
Christopher Willis-Ford
e03e9a0929 Drop lightness threshold for color effect
HSL's lightness is, in this case, basically the same as half of HSV's
value, so this change halves the threshold value used by the color
effect to make it similar in appearance to the HSV implementation.
2016-06-01 14:23:13 -07:00
Christopher Willis-Ford
f6b78b2216 Picking improvements
- Increased canvas border in demo.html to make it more obvious if future
  code forgets to compensate for the border.
- Fixed picking code to compensate for a border around the canvas.
- Completed support for picking with a touch larger than a single point.
2016-05-31 14:00:39 -07:00
Christopher Willis-Ford
94cbe8999d Implement pick(x,y) -> Drawable ID 2016-05-27 16:10:22 -07:00
Christopher Willis-Ford
36439bf665 Multiply projection and model matrices in shader
This will allow rendering the primary view, picking view, and "touching
color" view with different projection matrices without needing to
recalculate the model matrix for every Drawable every time.
2016-05-27 11:55:15 -07:00