Compare commits

...

49 Commits

Author SHA1 Message Date
greenkeeper[bot]
51cd58ac64 fix(package): update twgl.js to version 4.11.4
Closes #352
2019-10-14 21:46:45 +00:00
Chris Willis-Ford
13b9ed7e16 Merge pull request #491 from adroitwhiz/dont-fudge-up-the-renderer
Remove u_fudge
2019-10-01 13:02:15 -07:00
DD Liu
e7a7c14032 Merge pull request #468 from mzgoddard/rm-update-fast-bounds
remove updateMatrix call from getFastBounds
2019-10-01 16:01:23 -04:00
DD Liu
503c3f7b0b Merge branch 'develop' into rm-update-fast-bounds 2019-10-01 15:53:19 -04:00
DD Liu
857b541e84 Merge pull request #469 from mzgoddard/update-drawable
Add update drawable methods for each property
2019-10-01 15:39:50 -04:00
DD Liu
8e836a7a11 Add a bug to the todos for missing drawable 2019-10-01 15:36:13 -04:00
Karishma Chadha
b7a3d32cde Merge pull request #508 from LLK/revert-506-revert-505-revert-496-revert-493-revert-470-skin-alter-push
Revert "Put Skin Alter Push Back In"
2019-09-26 09:57:26 -05:00
Karishma Chadha
11665299bc Revert "Put Skin Alter Push Back In" 2019-09-26 09:39:05 -05:00
Chris Willis-Ford
303464ddd4 Merge pull request #506 from LLK/revert-505-revert-496-revert-493-revert-470-skin-alter-push
Put Skin Alter Push Back In
2019-09-25 13:16:09 -07:00
Chris Willis-Ford
9da15b1326 Merge pull request #507 from mzgoddard/sync-svg-renderer-skin-props
synchronously store SVGRenderer props used in SVGSkin
2019-09-25 11:45:21 -07:00
Michael "Z" Goddard
110371b029 synchronously store SVGRenderer props used in SVGSkin
Some APIs need SVGSkin to update some of its values immediately when changing
the SVG. Namely size needs to be synchronously set. However rotation center
doesn't need to be set at that time so we can leave it to update where it
currently is.
2019-09-16 17:22:27 -04:00
Karishma Chadha
2a1d215e50 Revert "Revert "Revert "Revert "Skin alter push"""" 2019-09-12 13:43:32 -04: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
adroitwhiz
06def05119 Remove u_fudge 2019-08-08 12:15: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
Michael "Z" Goddard
96aa930895 update drawable calls 2019-06-07 18:32:04 -04:00
Michael "Z" Goddard
89e6de035d remove updateMatrix call from getFastBounds 2019-06-07 11:17:54 -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
8 changed files with 223 additions and 60 deletions

View File

@@ -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",
"twgl.js": "4.4.0"
"scratch-svg-renderer": "0.2.0-prerelease.20190822202608",
"twgl.js": "4.11.4"
}
}

View File

@@ -183,56 +183,99 @@ class Drawable {
return this._visible;
}
/**
* Update the position if it is different. Marks the transform as dirty.
* @param {Array.<number>} position A new position.
*/
updatePosition (position) {
if (this._position[0] !== position[0] ||
this._position[1] !== position[1]) {
this._position[0] = Math.round(position[0]);
this._position[1] = Math.round(position[1]);
this.setTransformDirty();
}
}
/**
* Update the direction if it is different. Marks the transform as dirty.
* @param {number} direction A new direction.
*/
updateDirection (direction) {
if (this._direction !== direction) {
this._direction = direction;
this._rotationTransformDirty = true;
this.setTransformDirty();
}
}
/**
* Update the scale if it is different. Marks the transform as dirty.
* @param {Array.<number>} scale A new scale.
*/
updateScale (scale) {
if (this._scale[0] !== scale[0] ||
this._scale[1] !== scale[1]) {
this._scale[0] = scale[0];
this._scale[1] = scale[1];
this._rotationCenterDirty = true;
this._skinScaleDirty = true;
this.setTransformDirty();
}
}
/**
* Update visibility if it is different. Marks the convex hull as dirty.
* @param {boolean} visible A new visibility state.
*/
updateVisible (visible) {
if (this._visible !== visible) {
this._visible = visible;
this.setConvexHullDirty();
}
}
/**
* Update an effect. Marks the convex hull as dirty if the effect changes shape.
* @param {string} effectName The name of the effect.
* @param {number} rawValue A new effect value.
*/
updateEffect (effectName, rawValue) {
const effectInfo = ShaderManager.EFFECT_INFO[effectName];
if (rawValue) {
this._effectBits |= effectInfo.mask;
} else {
this._effectBits &= ~effectInfo.mask;
}
const converter = effectInfo.converter;
this._uniforms[effectInfo.uniformName] = converter(rawValue);
if (effectInfo.shapeChanges) {
this.setConvexHullDirty();
}
}
/**
* Update the position, direction, scale, or effect properties of this Drawable.
* @deprecated Use specific update* methods instead.
* @param {object.<string,*>} properties The new property values to set.
*/
updateProperties (properties) {
let dirty = false;
if ('position' in properties && (
this._position[0] !== properties.position[0] ||
this._position[1] !== properties.position[1])) {
this._position[0] = Math.round(properties.position[0]);
this._position[1] = Math.round(properties.position[1]);
dirty = true;
if ('position' in properties) {
this.updatePosition(properties.position);
}
if ('direction' in properties && this._direction !== properties.direction) {
this._direction = properties.direction;
this._rotationTransformDirty = true;
dirty = true;
if ('direction' in properties) {
this.updateDirection(properties.direction);
}
if ('scale' in properties && (
this._scale[0] !== properties.scale[0] ||
this._scale[1] !== properties.scale[1])) {
this._scale[0] = properties.scale[0];
this._scale[1] = properties.scale[1];
this._rotationCenterDirty = true;
this._skinScaleDirty = true;
dirty = true;
if ('scale' in properties) {
this.updateScale(properties.scale);
}
if ('visible' in properties) {
this._visible = properties.visible;
this.setConvexHullDirty();
}
if (dirty) {
this.setTransformDirty();
this.updateVisible(properties.visible);
}
const numEffects = ShaderManager.EFFECTS.length;
for (let index = 0; index < numEffects; ++index) {
const effectName = ShaderManager.EFFECTS[index];
if (effectName in properties) {
const rawValue = properties[effectName];
const effectInfo = ShaderManager.EFFECT_INFO[effectName];
if (rawValue) {
this._effectBits |= effectInfo.mask;
} else {
this._effectBits &= ~effectInfo.mask;
}
const converter = effectInfo.converter;
this._uniforms[effectInfo.uniformName] = converter(rawValue);
if (effectInfo.shapeChanges) {
this.setConvexHullDirty();
}
this.updateEffect(effectName, properties[effectName]);
}
}
}
@@ -433,6 +476,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;
@@ -520,7 +573,6 @@ class Drawable {
* @return {!Rectangle} Bounds for the Drawable.
*/
getFastBounds (result) {
this.updateMatrix();
if (!this.needsConvexHullPoints()) {
return this.getBounds(result);
}

View File

@@ -332,8 +332,7 @@ class PenSkin extends Skin {
const uniforms = {
u_skin: this._texture,
u_projectionMatrix: projection,
u_fudge: 0
u_projectionMatrix: projection
};
twgl.setUniforms(currentShader, uniforms);
@@ -474,8 +473,7 @@ class PenSkin extends Skin {
0
), __modelScalingMatrix),
__modelMatrix
),
u_fudge: 0
)
};
twgl.setTextureParameters(gl, texture, {minMag: gl.NEAREST});

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

@@ -105,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});
}
/**
@@ -1314,9 +1314,122 @@ class RenderWebGL extends EventEmitter {
}, null);
}
/**
* Update a drawable's skin.
* @param {number} drawableID The drawable's id.
* @param {number} skinId The skin to update to.
*/
updateDrawableSkinId (drawableID, skinId) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.skin = this._allSkins[skinId];
}
/**
* Update a drawable's skin rotation center.
* @param {number} drawableID The drawable's id.
* @param {Array.<number>} rotationCenter The rotation center for the skin.
*/
updateDrawableRotationCenter (drawableID, rotationCenter) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.skin.setRotationCenter(rotationCenter[0], rotationCenter[1]);
}
/**
* Update a drawable's skin and rotation center together.
* @param {number} drawableID The drawable's id.
* @param {number} skinId The skin to update to.
* @param {Array.<number>} rotationCenter The rotation center for the skin.
*/
updateDrawableSkinIdRotationCenter (drawableID, skinId, rotationCenter) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.skin = this._allSkins[skinId];
drawable.skin.setRotationCenter(rotationCenter[0], rotationCenter[1]);
}
/**
* Update a drawable's position.
* @param {number} drawableID The drawable's id.
* @param {Array.<number>} position The new position.
*/
updateDrawablePosition (drawableID, position) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.updatePosition(position);
}
/**
* Update a drawable's direction.
* @param {number} drawableID The drawable's id.
* @param {number} direction A new direction.
*/
updateDrawableDirection (drawableID, direction) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.updateDirection(direction);
}
/**
* Update a drawable's scale.
* @param {number} drawableID The drawable's id.
* @param {Array.<number>} scale A new scale.
*/
updateDrawableScale (drawableID, scale) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.updateScale(scale);
}
/**
* Update a drawable's direction and scale together.
* @param {number} drawableID The drawable's id.
* @param {number} direction A new direction.
* @param {Array.<number>} scale A new scale.
*/
updateDrawableDirectionScale (drawableID, direction, scale) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.updateDirection(direction);
drawable.updateScale(scale);
}
/**
* Update a drawable's visibility.
* @param {number} drawableID The drawable's id.
* @param {boolean} visible Will the drawable be visible?
*/
updateDrawableVisible (drawableID, visible) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.updateVisible(visible);
}
/**
* Update a drawable's visual effect.
* @param {number} drawableID The drawable's id.
* @param {string} effectName The effect to change.
* @param {number} value A new effect value.
*/
updateDrawableEffect (drawableID, effectName, value) {
const drawable = this._allDrawables[drawableID];
// TODO: https://github.com/LLK/scratch-vm/issues/2288
if (!drawable) return;
drawable.updateEffect(effectName, value);
}
/**
* Update the position, direction, scale, or effect properties of this Drawable.
* @deprecated Use specific updateDrawable* methods instead.
* @param {int} drawableID The ID of the Drawable to update.
* @param {object.<string,*>} properties The new property values to set.
*/
@@ -1324,17 +1437,16 @@ class RenderWebGL extends EventEmitter {
const drawable = this._allDrawables[drawableID];
if (!drawable) {
/**
* @todo fix whatever's wrong in the VM which causes this, then add a warning or throw here.
* @todo(https://github.com/LLK/scratch-vm/issues/2288) fix whatever's wrong in the VM which causes this, then add a warning or throw here.
* Right now this happens so much on some projects that a warning or exception here can hang the browser.
*/
return;
}
if ('skinId' in properties) {
drawable.skin = this._allSkins[properties.skinId];
this.updateDrawableSkinId(drawableID, properties.skinId);
}
if ('rotationCenter' in properties) {
const newRotationCenter = properties.rotationCenter;
drawable.skin.setRotationCenter(newRotationCenter[0], newRotationCenter[1]);
this.updateDrawableRotationCenter(drawableID, properties.rotationCenter);
}
drawable.updateProperties(properties);
}
@@ -1351,7 +1463,7 @@ class RenderWebGL extends EventEmitter {
const drawable = this._allDrawables[drawableID];
if (!drawable) {
// TODO: fix whatever's wrong in the VM which causes this, then add a warning or throw here.
// @todo(https://github.com/LLK/scratch-vm/issues/2288) fix whatever's wrong in the VM which causes this, then add a warning or throw here.
// Right now this happens so much on some projects that a warning or exception here can hang the browser.
return [x, y];
}
@@ -1417,8 +1529,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;
@@ -1429,6 +1539,8 @@ class RenderWebGL extends EventEmitter {
return;
}
this._doExitDrawRegion();
const skin = /** @type {PenSkin} */ this._allSkins[penSkinID];
const gl = this._gl;
@@ -1549,6 +1661,7 @@ class RenderWebGL extends EventEmitter {
this._exitRegion();
}
this._exitRegion = null;
this._regionId = null;
}
/**
@@ -1607,8 +1720,7 @@ class RenderWebGL extends EventEmitter {
gl.useProgram(currentShader.program);
twgl.setBuffersAndAttributes(gl, currentShader, this._bufferInfo);
Object.assign(uniforms, {
u_projectionMatrix: projection,
u_fudge: window.fudge || 0
u_projectionMatrix: projection
});
}

View File

@@ -1,7 +1,5 @@
precision mediump float;
uniform float u_fudge;
#ifdef DRAW_MODE_silhouette
uniform vec4 u_silhouetteColor;
#else // DRAW_MODE_silhouette

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.