Compare commits
5 Commits
greenkeepe
...
greenkeepe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d26648b259 | ||
|
|
bc893f86dd | ||
|
|
74a7a8c0b6 | ||
|
|
99af15a974 | ||
|
|
c25d1f37b8 |
@@ -32,13 +32,13 @@
|
|||||||
"chromeless": "^1.5.1",
|
"chromeless": "^1.5.1",
|
||||||
"copy-webpack-plugin": "^4.5.1",
|
"copy-webpack-plugin": "^4.5.1",
|
||||||
"docdash": "^0.4.0",
|
"docdash": "^0.4.0",
|
||||||
"eslint": "^4.6.1",
|
"eslint": "^6.6.0",
|
||||||
"eslint-config-scratch": "^5.0.0",
|
"eslint-config-scratch": "^5.0.0",
|
||||||
"gh-pages": "^1.0.0",
|
"gh-pages": "^1.0.0",
|
||||||
"jsdoc": "^3.5.5",
|
"jsdoc": "^3.5.5",
|
||||||
"json": "^9.0.4",
|
"json": "^9.0.4",
|
||||||
"scratch-vm": "0.2.0-prerelease.20190207224121",
|
"scratch-vm": "0.2.0-prerelease.20190207224121",
|
||||||
"tap": "^14.8.0",
|
"tap": "^11.0.0",
|
||||||
"travis-after-all": "^1.4.4",
|
"travis-after-all": "^1.4.4",
|
||||||
"uglifyjs-webpack-plugin": "^1.2.5",
|
"uglifyjs-webpack-plugin": "^1.2.5",
|
||||||
"webpack": "^4.8.0",
|
"webpack": "^4.8.0",
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class BitmapSkin extends Skin {
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
getTexture (scale) {
|
getTexture (scale) {
|
||||||
return this._texture;
|
return this._texture || super.getTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,6 +78,10 @@ class BitmapSkin extends Skin {
|
|||||||
* @fires Skin.event:WasAltered
|
* @fires Skin.event:WasAltered
|
||||||
*/
|
*/
|
||||||
setBitmap (bitmapData, costumeResolution, rotationCenter) {
|
setBitmap (bitmapData, costumeResolution, rotationCenter) {
|
||||||
|
if (!bitmapData.width || !bitmapData.height) {
|
||||||
|
super.setEmptyImageData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const gl = this._renderer.gl;
|
const gl = this._renderer.gl;
|
||||||
|
|
||||||
// Preferably bitmapData is ImageData. ImageData speeds up updating
|
// Preferably bitmapData is ImageData. ImageData speeds up updating
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ class SVGSkin extends Skin {
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
getTexture (scale) {
|
getTexture (scale) {
|
||||||
|
if (!this._svgRenderer.canvas.width || !this._svgRenderer.canvas.height) {
|
||||||
|
return super.getTexture();
|
||||||
|
}
|
||||||
|
|
||||||
// The texture only ever gets uniform scale. Take the larger of the two axes.
|
// The texture only ever gets uniform scale. Take the larger of the two axes.
|
||||||
const scaleMax = scale ? Math.max(Math.abs(scale[0]), Math.abs(scale[1])) : 100;
|
const scaleMax = scale ? Math.max(Math.abs(scale[0]), Math.abs(scale[1])) : 100;
|
||||||
const requestedScale = Math.min(scaleMax / 100, this._maxTextureScale);
|
const requestedScale = Math.min(scaleMax / 100, this._maxTextureScale);
|
||||||
@@ -108,6 +112,12 @@ class SVGSkin extends Skin {
|
|||||||
// updating Silhouette and is better handled by more browsers in
|
// updating Silhouette and is better handled by more browsers in
|
||||||
// regards to memory.
|
// regards to memory.
|
||||||
const canvas = this._svgRenderer.canvas;
|
const canvas = this._svgRenderer.canvas;
|
||||||
|
|
||||||
|
if (!canvas.width || !canvas.height) {
|
||||||
|
super.setEmptyImageData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const context = canvas.getContext('2d');
|
const context = canvas.getContext('2d');
|
||||||
const textureData = context.getImageData(0, 0, canvas.width, canvas.height);
|
const textureData = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
|||||||
34
src/Skin.js
34
src/Skin.js
@@ -140,7 +140,7 @@ class Skin extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
getTexture (scale) {
|
getTexture (scale) {
|
||||||
return null;
|
return this._emptyImageTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,6 +171,38 @@ class Skin extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
updateSilhouette () {}
|
updateSilhouette () {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the contents of this skin to an empty skin.
|
||||||
|
* @fires Skin.event:WasAltered
|
||||||
|
*/
|
||||||
|
setEmptyImageData () {
|
||||||
|
// Free up the current reference to the _texture
|
||||||
|
this._texture = null;
|
||||||
|
|
||||||
|
if (!this._emptyImageData) {
|
||||||
|
// Create a transparent pixel
|
||||||
|
this._emptyImageData = new ImageData(1, 1);
|
||||||
|
|
||||||
|
// Create a new texture and update the silhouette
|
||||||
|
const gl = this._renderer.gl;
|
||||||
|
|
||||||
|
const textureOptions = {
|
||||||
|
auto: true,
|
||||||
|
wrap: gl.CLAMP_TO_EDGE,
|
||||||
|
src: this._emptyImageData
|
||||||
|
};
|
||||||
|
|
||||||
|
// Note: we're using _emptyImageTexture here instead of _texture
|
||||||
|
// so that we can cache this empty texture for later use as needed.
|
||||||
|
// this._texture can get modified by other skins (e.g. BitmapSkin
|
||||||
|
// and SVGSkin, so we can't use that same field for caching)
|
||||||
|
this._emptyImageTexture = twgl.createTexture(gl, textureOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._silhouette.update(this._emptyImageData);
|
||||||
|
this.emit(Skin.Events.WasAltered);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does this point touch an opaque or translucent point on this skin?
|
* Does this point touch an opaque or translucent point on this skin?
|
||||||
* Nearest Neighbor version
|
* Nearest Neighbor version
|
||||||
|
|||||||
Reference in New Issue
Block a user