Compare commits
9 Commits
0.1.0-prer
...
0.1.0-prer
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bc1528dac | ||
|
|
59d66f562c | ||
|
|
ec053748cd | ||
|
|
bf2820aeda | ||
|
|
0120a77b8e | ||
|
|
e8d6f957fa | ||
|
|
c0f1afe104 | ||
|
|
4ebea93adf | ||
|
|
75a4792f93 |
@@ -53,7 +53,7 @@
|
|||||||
"minilog": "3.1.0",
|
"minilog": "3.1.0",
|
||||||
"raw-loader": "^0.5.1",
|
"raw-loader": "^0.5.1",
|
||||||
"scratch-storage": "^1.0.0",
|
"scratch-storage": "^1.0.0",
|
||||||
"scratch-svg-renderer": "0.2.0-prerelease.20200610220938",
|
"scratch-svg-renderer": "0.2.0-prerelease.20201019174008",
|
||||||
"twgl.js": "4.4.0"
|
"twgl.js": "4.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,12 @@ class Drawable {
|
|||||||
this._convexHullPoints = null;
|
this._convexHullPoints = null;
|
||||||
this._convexHullDirty = true;
|
this._convexHullDirty = true;
|
||||||
|
|
||||||
|
// The precise bounding box will be from the transformed convex hull points,
|
||||||
|
// so initialize the array of transformed hull points in setConvexHullPoints.
|
||||||
|
// Initializing it once per convex hull recalculation avoids unnecessary creation of twgl.v3 objects.
|
||||||
|
this._transformedHullPoints = null;
|
||||||
|
this._transformedHullDirty = true;
|
||||||
|
|
||||||
this._skinWasAltered = this._skinWasAltered.bind(this);
|
this._skinWasAltered = this._skinWasAltered.bind(this);
|
||||||
|
|
||||||
this.isTouching = this._isTouchingNever;
|
this.isTouching = this._isTouchingNever;
|
||||||
@@ -137,6 +143,7 @@ class Drawable {
|
|||||||
setTransformDirty () {
|
setTransformDirty () {
|
||||||
this._transformDirty = true;
|
this._transformDirty = true;
|
||||||
this._inverseTransformDirty = true;
|
this._inverseTransformDirty = true;
|
||||||
|
this._transformedHullDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -457,6 +464,14 @@ class Drawable {
|
|||||||
setConvexHullPoints (points) {
|
setConvexHullPoints (points) {
|
||||||
this._convexHullPoints = points;
|
this._convexHullPoints = points;
|
||||||
this._convexHullDirty = false;
|
this._convexHullDirty = false;
|
||||||
|
|
||||||
|
// Re-create the "transformed hull points" array.
|
||||||
|
// We only do this when the hull points change to avoid unnecessary allocations and GC.
|
||||||
|
this._transformedHullPoints = [];
|
||||||
|
for (let i = 0; i < points.length; i++) {
|
||||||
|
this._transformedHullPoints.push(twgl.v3.create());
|
||||||
|
}
|
||||||
|
this._transformedHullDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -611,23 +626,27 @@ class Drawable {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_getTransformedHullPoints () {
|
_getTransformedHullPoints () {
|
||||||
|
if (!this._transformedHullDirty) {
|
||||||
|
return this._transformedHullPoints;
|
||||||
|
}
|
||||||
|
|
||||||
const projection = twgl.m4.ortho(-1, 1, -1, 1, -1, 1);
|
const projection = twgl.m4.ortho(-1, 1, -1, 1, -1, 1);
|
||||||
const skinSize = this.skin.size;
|
const skinSize = this.skin.size;
|
||||||
const halfXPixel = 1 / skinSize[0] / 2;
|
const halfXPixel = 1 / skinSize[0] / 2;
|
||||||
const halfYPixel = 1 / skinSize[1] / 2;
|
const halfYPixel = 1 / skinSize[1] / 2;
|
||||||
const tm = twgl.m4.multiply(this._uniforms.u_modelMatrix, projection);
|
const tm = twgl.m4.multiply(this._uniforms.u_modelMatrix, projection);
|
||||||
const transformedHullPoints = [];
|
|
||||||
for (let i = 0; i < this._convexHullPoints.length; i++) {
|
for (let i = 0; i < this._convexHullPoints.length; i++) {
|
||||||
const point = this._convexHullPoints[i];
|
const point = this._convexHullPoints[i];
|
||||||
const glPoint = twgl.v3.create(
|
const dstPoint = this._transformedHullPoints[i];
|
||||||
0.5 + (-point[0] / skinSize[0]) - halfXPixel,
|
|
||||||
(point[1] / skinSize[1]) - 0.5 + halfYPixel,
|
dstPoint[0] = 0.5 + (-point[0] / skinSize[0]) - halfXPixel;
|
||||||
0
|
dstPoint[1] = (point[1] / skinSize[1]) - 0.5 + halfYPixel;
|
||||||
);
|
twgl.m4.transformPoint(tm, dstPoint, dstPoint);
|
||||||
twgl.m4.transformPoint(tm, glPoint, glPoint);
|
|
||||||
transformedHullPoints.push(glPoint);
|
|
||||||
}
|
}
|
||||||
return transformedHullPoints;
|
|
||||||
|
this._transformedHullDirty = false;
|
||||||
|
|
||||||
|
return this._transformedHullPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user