Compare commits

...

40 Commits

Author SHA1 Message Date
greenkeeper[bot]
ccd74ba5ef chore(package): update tap to version 14.6.3
Closes #289
2019-09-15 17:48:58 +00:00
Karishma Chadha
832b0274be Merge pull request #505 from LLK/revert-496-revert-493-revert-470-skin-alter-push
Revert "Revert "Revert "Skin alter push"""
2019-09-12 13:42:23 -04:00
Karishma Chadha
1cd9e54834 Revert "Revert "Revert "Skin alter push""" 2019-09-12 13:24:03 -04:00
Chris Willis-Ford
928cd60dd5 Merge pull request #496 from LLK/revert-493-revert-470-skin-alter-push
Revert "Revert "Skin alter push""
2019-09-04 18:14:41 -07:00
Chris Willis-Ford
30ef2b1e51 Merge pull request #497 from adroitwhiz/set-costume-size-synchronously-2
Set SVG skin size synchronously
2019-09-04 18:03:29 -07:00
Chris Willis-Ford
ad62542a52 Merge branch 'revert-493-revert-470-skin-alter-push' into set-costume-size-synchronously-2 2019-09-04 18:01:59 -07:00
DD Liu
2d4419c929 Merge pull request #443 from adroitwhiz/effects-nearest
Always use linear interpolation on vector skins with distortion effects applied
2019-09-04 17:19:52 -04:00
adroitwhiz
ad6ddd9f99 add more parentheses 2019-09-04 15:40:49 -04:00
Karishma Chadha
c3ede9c3d5 Merge pull request #495 from LLK/revert-494-revert-467-rect-init-matrix
Revert "Revert "Initialialize AABB Rectangle ""
2019-08-30 15:35:32 -04:00
Chris Willis-Ford
ab517fff51 Merge pull request #442 from adroitwhiz/pen-stamp-region-optimization
Don't _doExitDrawRegion in penStamp until we're sure we're stamping
2019-08-30 20:19:26 +01:00
Chris Willis-Ford
1371b6f685 Merge pull request #486 from adroitwhiz/fix-calculaterotationcenter
Fix calculateRotationCenter() for SVG skins
2019-08-30 20:13:50 +01:00
DD Liu
5c6997131b Merge pull request #484 from adroitwhiz/fix-cpu-render-playground
Attach V2 adapters in CPU render playground
2019-08-30 14:58:59 -04:00
Chris Willis-Ford
b4c7dbf0ea Merge pull request #441 from adroitwhiz/region-exit-fix
Clear _regionId when exiting draw region
2019-08-30 19:51:20 +01:00
Karishma Chadha
c0e5115bfc Merge pull request #444 from adroitwhiz/rectangle-clamp-fix
Fix Rectangle.Clamp()
2019-08-30 14:43:18 -04:00
DD Liu
3819b66683 Merge pull request #502 from fsih/turnOffAntiAlias
Turn off antialias
2019-08-30 11:27:30 -04:00
DD Liu
b9732c222c Fix space
Co-Authored-By: adroitwhiz <adroitwhiz@protonmail.com>
2019-08-28 19:00:16 -04:00
DD Liu
afaa758615 turn off antialias 2019-08-28 17:04:51 -04:00
DD Liu
a3a526d6a3 Merge pull request #499 from LLK/greenkeeper/scratch-svg-renderer-0.2.0-prerelease.20190820171249
Update scratch-svg-renderer to the latest version 🚀
2019-08-22 16:42:38 -04:00
DD Liu
d77afaa6c4 Update to latest svg-renderer 2019-08-22 16:28:31 -04:00
greenkeeper[bot]
3bfd4c65fb fix(package): update scratch-svg-renderer to version 0.2.0-prerelease.20190820171249 2019-08-20 17:24:08 +00:00
DD Liu
131f5372db Merge pull request #498 from LLK/revert-482-greenkeeper/scratch-svg-renderer-0.2.0-prerelease.20190715144718
Revert "Update scratch-svg-renderer to the latest version 🚀"
2019-08-19 11:43:06 -04:00
DD Liu
ef13d3bb08 Revert "Update scratch-svg-renderer to the latest version 🚀" 2019-08-19 11:40:51 -04:00
adroitwhiz
94257a4214 Set SVG skin size synchronously 2019-08-13 16:38:45 -04:00
Karishma Chadha
7c4393787b Revert "Revert "Skin alter push"" 2019-08-13 11:42:51 -04:00
Karishma Chadha
a340b8a04b Revert "Revert "Initialialize AABB Rectangle "" 2019-08-13 11:41:11 -04:00
Karishma Chadha
c2e32d2baf Merge pull request #494 from LLK/revert-467-rect-init-matrix
Revert "Initialialize AABB Rectangle "
2019-08-13 11:38:41 -04:00
Karishma Chadha
c8839b2feb Merge pull request #493 from LLK/revert-470-skin-alter-push
Revert "Skin alter push"
2019-08-13 11:38:24 -04:00
Karishma Chadha
c8f7496fba Revert "Initialialize AABB Rectangle " 2019-08-13 11:26:07 -04:00
Karishma Chadha
4a28cffcd4 Revert "Skin alter push" 2019-08-13 11:22:27 -04:00
adroitwhiz
dce90a3f56 Fix calculateRotationCenter for SVG skins 2019-07-20 17:27:45 -04:00
adroitwhiz
471d4b91a4 Attach V2 adapters in CPU render playground 2019-07-15 23:44:18 -04:00
adroitwhiz
1b51f1f393 Merge remote-tracking branch 'upstream/develop' into effects-nearest 2019-05-23 05:35:56 -04:00
adroitwhiz
d0ed283c72 Merge remote-tracking branch 'upstream/develop' into effects-nearest 2019-05-22 16:10:30 -04:00
adroitwhiz
34f265ab22 strict inequality 2019-05-22 04:52:30 -04:00
adroitwhiz
6646041ba4 Fix Rectangle.Clamp() 2019-04-22 08:49:20 -04:00
adroitwhiz
f9309b1ace be more s e m a n t i c 2019-04-20 08:12:22 -04:00
adroitwhiz
7599a82406 Never useNearest on distorted vector skins 2019-04-20 07:59:09 -04:00
adroitwhiz
6e755ea015 Add "disappearing pen" test 2019-04-20 02:47:25 -04:00
adroitwhiz
750f40ddf2 Exit draw region in penStamp less 2019-04-20 02:31:04 -04:00
adroitwhiz
603fd87782 Clear _regionId when exiting draw region 2019-04-20 02:27:34 -04:00
12 changed files with 68 additions and 126 deletions

View File

@@ -38,7 +38,7 @@
"jsdoc": "^3.5.5",
"json": "^9.0.4",
"scratch-vm": "0.2.0-prerelease.20190207224121",
"tap": "^11.0.0",
"tap": "^14.6.3",
"travis-after-all": "^1.4.4",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^4.8.0",
@@ -53,7 +53,7 @@
"minilog": "3.1.0",
"raw-loader": "^0.5.1",
"scratch-storage": "^1.0.0",
"scratch-svg-renderer": "0.2.0-prerelease.20190715153806",
"scratch-svg-renderer": "0.2.0-prerelease.20190822202608",
"twgl.js": "4.4.0"
}
}

View File

@@ -23,12 +23,6 @@ class BitmapSkin extends Skin {
/** @type {Array<int>} */
this._textureSize = [0, 0];
/**
* The "native" size, in texels, of this skin.
* @type {Array<number>}
*/
this.size = [0, 0];
}
/**
@@ -49,6 +43,13 @@ class BitmapSkin extends Skin {
return true;
}
/**
* @return {Array<number>} the "native" size, in texels, of this skin.
*/
get size () {
return [this._textureSize[0] / this._costumeResolution, this._textureSize[1] / this._costumeResolution];
}
/**
* @param {Array<number>} scale - The scaling factors to be used.
* @return {WebGLTexture} The GL texture representation of this skin when drawing at the given scale.
@@ -109,7 +110,6 @@ class BitmapSkin extends Skin {
// Do these last in case any of the above throws an exception
this._costumeResolution = costumeResolution || 2;
this._textureSize = BitmapSkin._getBitmapSize(bitmapData);
this.size = [this._textureSize[0] / this._costumeResolution, this._textureSize[1] / this._costumeResolution];
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
this.setRotationCenter.apply(this, rotationCenter);

View File

@@ -3,6 +3,7 @@ const twgl = require('twgl.js');
const Rectangle = require('./Rectangle');
const RenderConstants = require('./RenderConstants');
const ShaderManager = require('./ShaderManager');
const Skin = require('./Skin');
const EffectTransform = require('./EffectTransform');
/**
@@ -100,6 +101,8 @@ class Drawable {
/** @todo move convex hull functionality, maybe bounds functionality overall, to Skin classes */
this._convexHullPoints = null;
this._convexHullDirty = true;
this._skinWasAltered = this._skinWasAltered.bind(this);
}
/**
@@ -138,7 +141,13 @@ class Drawable {
*/
set skin (newSkin) {
if (this._skin !== newSkin) {
if (this._skin) {
this._skin.removeListener(Skin.Events.WasAltered, this._skinWasAltered);
}
this._skin = newSkin;
if (this._skin) {
this._skin.addListener(Skin.Events.WasAltered, this._skinWasAltered);
}
this._skinWasAltered();
}
}
@@ -424,6 +433,16 @@ class Drawable {
return true;
}
// If the effect bits for mosaic, pixelate, whirl, or fisheye are set, use linear
if ((this._effectBits & (
ShaderManager.EFFECT_INFO.fisheye.mask |
ShaderManager.EFFECT_INFO.whirl.mask |
ShaderManager.EFFECT_INFO.pixelate.mask |
ShaderManager.EFFECT_INFO.mosaic.mask
)) !== 0) {
return false;
}
// We can't use nearest neighbor unless we are a multiple of 90 rotation
if (this._direction % 90 !== 0) {
return false;

View File

@@ -88,9 +88,6 @@ class PenSkin extends Skin {
/** @type {HTMLCanvasElement} */
this._canvas = document.createElement('canvas');
/** @type {Array<number>} */
this._canvasSize = twgl.v3.create();
/** @type {WebGLTexture} */
this._texture = null;
@@ -168,7 +165,7 @@ class PenSkin extends Skin {
* @return {Array<number>} the "native" size, in texels, of this skin. [width, height]
*/
get size () {
return this._canvasSize;
return [this._canvas.width, this._canvas.height];
}
/**
@@ -191,13 +188,13 @@ class PenSkin extends Skin {
clear () {
const gl = this._renderer.gl;
twgl.bindFramebufferInfo(gl, this._framebuffer);
/* Reset framebuffer to transparent black */
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
const ctx = this._canvas.getContext('2d');
ctx.clearRect(0, 0, this._canvasSize[0], this._canvasSize[1]);
ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
this._silhouetteDirty = true;
}
@@ -454,7 +451,7 @@ class PenSkin extends Skin {
* @param {number} x - centered at x
* @param {number} y - centered at y
*/
_drawRectangle (currentShader, texture, bounds, x = -this._canvasSize[0] / 2, y = this._canvasSize[1] / 2) {
_drawRectangle (currentShader, texture, bounds, x = -this._canvas.width / 2, y = this._canvas.height / 2) {
const gl = this._renderer.gl;
const projection = twgl.m4.ortho(
@@ -517,7 +514,7 @@ class PenSkin extends Skin {
* @param {number} x - texture centered at x
* @param {number} y - texture centered at y
*/
_drawToBuffer (texture = this._texture, x = -this._canvasSize[0] / 2, y = this._canvasSize[1] / 2) {
_drawToBuffer (texture = this._texture, x = -this._canvas.width / 2, y = this._canvas.height / 2) {
if (texture !== this._texture && this._canvasDirty) {
this._drawToBuffer();
}
@@ -531,7 +528,7 @@ class PenSkin extends Skin {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._canvas);
const ctx = this._canvas.getContext('2d');
ctx.clearRect(0, 0, this._canvasSize[0], this._canvasSize[1]);
ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
this._canvasDirty = false;
}
@@ -567,8 +564,8 @@ class PenSkin extends Skin {
this._bounds = new Rectangle();
this._bounds.initFromBounds(width / 2, width / -2, height / 2, height / -2);
this._canvas.width = this._canvasSize[0] = width;
this._canvas.height = this._canvasSize[1] = height;
this._canvas.width = width;
this._canvas.height = height;
this._rotationCenter[0] = width / 2;
this._rotationCenter[1] = height / 2;
@@ -654,8 +651,8 @@ class PenSkin extends Skin {
this._renderer.enterDrawRegion(this._toBufferDrawRegionId);
// Sample the framebuffer's pixels into the silhouette instance
const skinPixels = new Uint8Array(Math.floor(this._canvasSize[0] * this._canvasSize[1] * 4));
gl.readPixels(0, 0, this._canvasSize[0], this._canvasSize[1], gl.RGBA, gl.UNSIGNED_BYTE, skinPixels);
const skinPixels = new Uint8Array(Math.floor(this._canvas.width * this._canvas.height * 4));
gl.readPixels(0, 0, this._canvas.width, this._canvas.height, gl.RGBA, gl.UNSIGNED_BYTE, skinPixels);
const skinCanvas = this._canvas;
skinCanvas.width = bounds.width;

View File

@@ -123,11 +123,11 @@ class Rectangle {
this.right = Math.min(this.right, right);
this.bottom = Math.max(this.bottom, bottom);
this.top = Math.min(this.top, top);
// Ensure rectangle coordinates in order.
this.left = Math.min(this.left, this.right);
this.right = Math.max(this.right, this.left);
this.bottom = Math.min(this.bottom, this.top);
this.top = Math.max(this.top, this.bottom);
this.left = Math.min(this.left, right);
this.right = Math.max(this.right, left);
this.bottom = Math.min(this.bottom, top);
this.top = Math.max(this.top, bottom);
}
/**

View File

@@ -3,7 +3,6 @@ const EventEmitter = require('events');
const hull = require('hull.js');
const twgl = require('twgl.js');
const Skin = require('./Skin');
const BitmapSkin = require('./BitmapSkin');
const Drawable = require('./Drawable');
const Rectangle = require('./Rectangle');
@@ -106,7 +105,7 @@ class RenderWebGL extends EventEmitter {
* @private
*/
static _getContext (canvas) {
return twgl.getWebGLContext(canvas, {alpha: false, stencil: true});
return twgl.getWebGLContext(canvas, {alpha: false, stencil: true, antialias: false});
}
/**
@@ -292,20 +291,6 @@ class RenderWebGL extends EventEmitter {
this.emit(RenderConstants.Events.NativeSizeChanged, {newSize: this._nativeSize});
}
/**
* Notify Drawables whose skin is the skin that changed.
* @param {Skin} skin - the skin that changed.
* @private
*/
_skinWasAltered (skin) {
for (let i = 0; i < this._allDrawables.length; i++) {
const drawable = this._allDrawables[i];
if (drawable && drawable._skin === skin) {
drawable._skinWasAltered();
}
}
}
/**
* Create a new bitmap skin from a snapshot of the provided bitmap data.
* @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmapData - new contents for this skin.
@@ -318,7 +303,6 @@ class RenderWebGL extends EventEmitter {
const skinId = this._nextSkinId++;
const newSkin = new BitmapSkin(skinId, this);
newSkin.setBitmap(bitmapData, costumeResolution, rotationCenter);
newSkin.addListener(Skin.Events.WasAltered, this._skinWasAltered.bind(this, newSkin));
this._allSkins[skinId] = newSkin;
return skinId;
}
@@ -334,7 +318,6 @@ class RenderWebGL extends EventEmitter {
const skinId = this._nextSkinId++;
const newSkin = new SVGSkin(skinId, this);
newSkin.setSVG(svgData, rotationCenter);
newSkin.addListener(Skin.Events.WasAltered, this._skinWasAltered.bind(this, newSkin));
this._allSkins[skinId] = newSkin;
return skinId;
}
@@ -346,7 +329,6 @@ class RenderWebGL extends EventEmitter {
createPenSkin () {
const skinId = this._nextSkinId++;
const newSkin = new PenSkin(skinId, this);
newSkin.addListener(Skin.Events.WasAltered, this._skinWasAltered.bind(this, newSkin));
this._allSkins[skinId] = newSkin;
return skinId;
}
@@ -363,7 +345,6 @@ class RenderWebGL extends EventEmitter {
const skinId = this._nextSkinId++;
const newSkin = new TextBubbleSkin(skinId, this);
newSkin.setTextBubble(type, text, pointsLeft);
newSkin.addListener(Skin.Events.WasAltered, this._skinWasAltered.bind(this, newSkin));
this._allSkins[skinId] = newSkin;
return skinId;
}
@@ -1436,8 +1417,6 @@ class RenderWebGL extends EventEmitter {
* @param {int} stampID - the unique ID of the Drawable to use as the stamp.
*/
penStamp (penSkinID, stampID) {
this._doExitDrawRegion();
const stampDrawable = this._allDrawables[stampID];
if (!stampDrawable) {
return;
@@ -1448,6 +1427,8 @@ class RenderWebGL extends EventEmitter {
return;
}
this._doExitDrawRegion();
const skin = /** @type {PenSkin} */ this._allSkins[penSkinID];
const gl = this._gl;
@@ -1568,6 +1549,7 @@ class RenderWebGL extends EventEmitter {
this._exitRegion();
}
this._exitRegion = null;
this._regionId = null;
}
/**

View File

@@ -30,24 +30,6 @@ class SVGSkin extends Skin {
/** @type {Number} */
this._maxTextureScale = 0;
/**
* The natural size, in Scratch units, of this skin.
* @type {Array<number>}
*/
this.size = [0, 0];
/**
* The viewbox offset of the svg.
* @type {Array<number>}
*/
this._viewOffset = [0, 0];
/**
* The rotation center before offset by _viewOffset.
* @type {Array<number>}
*/
this._rawRotationCenter = [NaN, NaN];
}
/**
@@ -61,17 +43,21 @@ class SVGSkin extends Skin {
super.dispose();
}
/**
* @return {Array<number>} the natural size, in Scratch units, of this skin.
*/
get size () {
return this._svgRenderer.size;
}
/**
* Set the origin, in object space, about which this Skin should rotate.
* @param {number} x - The x coordinate of the new rotation center.
* @param {number} y - The y coordinate of the new rotation center.
*/
setRotationCenter (x, y) {
if (x !== this._rawRotationCenter[0] || y !== this._rawRotationCenter[1]) {
this._rawRotationCenter[0] = x;
this._rawRotationCenter[1] = y;
super.setRotationCenter(x - this._viewOffset[0], y - this._viewOffset[1]);
}
const viewOffset = this._svgRenderer.viewOffset;
super.setRotationCenter(x - viewOffset[0], y - viewOffset[1]);
}
/**
@@ -148,11 +134,7 @@ class SVGSkin extends Skin {
}
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
this.size = this._svgRenderer.size;
this._viewOffset = this._svgRenderer.viewOffset;
// Reset rawRotationCenter when we update viewOffset.
this._rawRotationCenter = [NaN, NaN];
this.setRotationCenter(rotationCenter[0], rotationCenter[1]);
this.setRotationCenter.apply(this, rotationCenter);
this.emit(Skin.Events.WasAltered);
});
}

View File

@@ -33,13 +33,6 @@ class Skin extends EventEmitter {
/** @type {Vec3} */
this._rotationCenter = twgl.v3.create(0, 0);
/**
* The "native" size, in texels, of this skin.
* @member size
* @abstract
* @type {Array<number>}
*/
/**
* The uniforms to be used by the vertex and pixel shaders.
* Some of these are used by other parts of the renderer as well.
@@ -104,6 +97,14 @@ class Skin extends EventEmitter {
return this._rotationCenter;
}
/**
* @abstract
* @return {Array<number>} the "native" size, in texels, of this skin.
*/
get size () {
return [0, 0];
}
/**
* Set the origin, in object space, about which this Skin should rotate.
* @param {number} x - The x coordinate of the new rotation center.

View File

@@ -1,35 +0,0 @@
const Skin = require('../../src/Skin');
class MockSkinPool {
constructor () {
this._allDrawables = [];
}
static forDrawableSkin (drawable) {
const pool = new MockSkinPool();
pool.addDrawable(drawable);
pool.addSkin(drawable.skin);
return pool;
}
_skinWasAltered (skin) {
for (let i = 0; i < this._allDrawables.length; i++) {
const drawable = this._allDrawables[i];
if (drawable && drawable._skin === skin) {
drawable._skinWasAltered();
}
}
}
addDrawable (drawable) {
this._allDrawables.push(drawable);
return drawable;
}
addSkin (skin) {
skin.addListener(Skin.Events.WasAltered, this._skinWasAltered.bind(this, skin));
return skin;
}
}
module.exports = MockSkinPool;

View File

@@ -1,6 +1,7 @@
<body>
<script src="../../node_modules/scratch-vm/dist/web/scratch-vm.js"></script>
<script src="../../node_modules/scratch-storage/dist/web/scratch-storage.js"></script>
<script src="../../node_modules/scratch-svg-renderer/dist/web/scratch-svg-renderer.js"></script>
<!-- note: this uses the BUILT version of scratch-render! make sure to npm run build -->
<script src="../../dist/web/scratch-render.js"></script>
@@ -21,6 +22,8 @@
vm.attachStorage(storage);
vm.attachRenderer(render);
vm.attachV2SVGAdapter(new ScratchSVGRenderer.SVGRenderer());
vm.attachV2BitmapAdapter(new ScratchSVGRenderer.BitmapAdapter());
document.getElementById('file').addEventListener('click', e => {
document.body.removeChild(document.getElementById('loaded'));

Binary file not shown.

View File

@@ -8,7 +8,6 @@ global.document = {
const Drawable = require('../../src/Drawable');
const MockSkin = require('../fixtures/MockSkin');
const MockSkinPool = require('../fixtures/MockSkinPool');
const Rectangle = require('../../src/Rectangle');
/**
@@ -32,7 +31,6 @@ test('translate by position', t => {
const drawable = new Drawable();
drawable.skin = new MockSkin();
drawable.skin.size = [200, 50];
MockSkinPool.forDrawableSkin(drawable);
expected.initFromBounds(0, 200, -50, 0);
t.same(snapToNearest(drawable.getAABB()), expected);
@@ -49,7 +47,6 @@ test('translate by costume center', t => {
const drawable = new Drawable();
drawable.skin = new MockSkin();
drawable.skin.size = [200, 50];
MockSkinPool.forDrawableSkin(drawable);
drawable.skin.setRotationCenter(1, 0);
expected.initFromBounds(-1, 199, -50, 0);
@@ -67,7 +64,6 @@ test('translate and rotate', t => {
const drawable = new Drawable();
drawable.skin = new MockSkin();
drawable.skin.size = [200, 50];
MockSkinPool.forDrawableSkin(drawable);
drawable.updateProperties({position: [1, 2], direction: 0});
expected.initFromBounds(1, 51, 2, 202);
@@ -94,7 +90,6 @@ test('rotate by non-right-angles', t => {
drawable.skin = new MockSkin();
drawable.skin.size = [10, 10];
drawable.skin.setRotationCenter(5, 5);
MockSkinPool.forDrawableSkin(drawable);
expected.initFromBounds(-5, 5, -5, 5);
t.same(snapToNearest(drawable.getAABB()), expected);
@@ -111,7 +106,6 @@ test('scale', t => {
const drawable = new Drawable();
drawable.skin = new MockSkin();
drawable.skin.size = [200, 50];
MockSkinPool.forDrawableSkin(drawable);
drawable.updateProperties({scale: [100, 50]});
expected.initFromBounds(0, 200, -25, 0);
@@ -134,7 +128,6 @@ test('rotate and scale', t => {
const drawable = new Drawable();
drawable.skin = new MockSkin();
drawable.skin.size = [100, 1000];
MockSkinPool.forDrawableSkin(drawable);
drawable.skin.setRotationCenter(50, 50);
expected.initFromBounds(-50, 50, -950, 50);