- `Drawable` now removes its `Skin` on `dispose`, disconnecting events.
- Creating a new `Drawable` doesn't always create a new `Skin` any more:
now it can share an existing skin.
- Don't throw when asked to update the properties of a `Drawable` that
has already been destroyed. This seems like a VM bug but was causing
overwhelming output in the browser for some projects.
- Add & correct a few comments
- Make `Drawable` IDs work like `Skin` IDs
- Remove some dead code
- Fix costume resolution in `BitmapSkin` before first `setBitmap` call
- Rename `Drawable` & `Skin` management variables in `RenderWebGL` to
clarify their purpose and better distinguish them from each other
- Remove problematic premature optimization in `_drawThese`
- Fix missing return statement in `Skin`'s `setRotationCenter`
- Fix mismatch between getTexture & getUniforms in the `Skin` class
There is now a `Skin` base class along with `SVGSkin` and `BitmapSkin`
classes for vector and bitmap skin support. Loading a skin by URL is in
the process of being deprecated. In the future skin data should be
downloaded outside the renderer and supplied through new `create*Skin`
API calls.
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.
* 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
* 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
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.
- 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.
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.
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?"
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.
- 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.
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.
Pixelate still needs a bit more work: at certain scales the edges of the
"pixels" are ragged. This happens in Scratch 2.0 as well, but for me it
seems slightly worse in this implementation.
The renderer now uses premultiplied alpha in the frame buffer, though
textures are still stored without premultiplied alpha. This makes it
easier to get the desired results from the browser's canvas compositing
step, and might be nicer for mobile hardware depending on which parts of
the Internet you believe.
This implementation of the pixel effect is now very similar to the
PixelBender implementation in Scratch 2.0
I also added a slider to demo.html as a debugging aid: it manipulates a
value that is passed into the shader and used in whatever way helps.
The combination of effects is encoded bitwise as an index into the
shader cache array. The `getShader` function fetches the relevant index
if it's present, or calls `_buildShader()` to compile a new shader. The
effects are enabled by prepending lines like `#define ENABLE_whirl` at
the beginning of the vertex and fragment shader texts.
The renderer can now update any combination of a Drawable's position,
direction, scale, and effect values through a single function call. The
effect values will be adjusted according to per-effect conversion
functions to prepare the values for use inside the shader.
This change introduces the Drawable class, which corresponds to a
Scratch sprite or clone. It supports setting its "skin" (corresponding
to a Scratch costume) by md5+extension, but currently only supports
bitmap skins. Drawables can be created, destroyed, and otherwise
manipulated by ID through the renderer.