I wasn't so clever with this - I'm sorry. Now that I have managed to
link up my local render & vm projects I am able to fix the issue
properly. Many appologies!
When a new skin is added, previously the rotation center was set to `[0, 0]`. In the case of costumes and backdrops added from libraries, the center should be calculated from the bounding box of the imported skin.
Toward LLK/scratch-gui#18
This change tweaks the expression of paths in the Webpack config to make
`webpack-dev-server` work again. This opened the door for some minor
cleanup of `path` & `filename` in the `output` configuration entries.
Thanks to @rschamp for help resolving the `webpack-dev-server` problems.
Scratch uses y=up, whereas WebGL and the Canvas element both use y=down.
To make this work, we set a non-conventional projection matrix when
rendering to the stage. Some of the internal renders (touching color,
stamp, etc.) were using a y-flipped projection matrix, though, which
means that the output was double-flipped and would appear incorrect. For
the touching-color block this just meant a cosmetic issue: the debug
canvas looks upside-down. For pen stamp, though, it's a real issue since
the stamp was appearing upside down on the stage.
This change ensures that the projection matrix for every internal render
follows WebGL / Canvas conventions, and that we only y-flip on the final
render to the stage.
Also clean up the code around our calls to `readPixels`:
- Use `Uint8Array` instead of `Buffer` to hold the pixels
- Use `ImageData.data.set` instead of a `for` loop when copying pixels
to a canvas
- `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.
The `setStageSize` wasn't working correctly. This change fixes that and
also notifies active `PenDrawable` instances about the resize. This was
implemented by making the renderer an `EventEmitter`.
To test, load the playground and type `renderer.createPenDrawable()`
into the JS console. Note that the pen layer is now just another
drawable object, so it can move and use effects.
It turns out that it might make sense for the pen to share these
features. Splitting them out would likely work too, but would introduce
unnecessary complexity.