Skip to content

Commit

Permalink
1.34.2 Fix bbox values when Spine is mirrored/flipped.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikalDev committed Feb 4, 2021
1 parent 2ca1df9 commit ab3a220
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
Binary file added dist/Spine-v1.34.2.c3addon
Binary file not shown.
2 changes: 1 addition & 1 deletion src/addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "plugin",
"name": "Spine",
"id": "Gritsenko_Spine",
"version": "1.34.1",
"version": "1.34.2",
"author": "Mikal and Igor Gritsenko",
"website": "https://gritsenko.github.io/c3_spine_plugin",
"documentation": "https://gritsenko.github.io/c3_spine_plugin",
Expand Down
5 changes: 4 additions & 1 deletion src/c3runtime/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
centerX+=points[i];
}
centerX = centerX/(points.length/2)+this.skeletonInfo.bounds.offset.x+this.skeletonInfo.bounds.size.x;
if (this.isMirrored) centerX = this.skeletonInfo.bounds.size.x - centerX;

let wi = this.GetInstance().GetWorldInfo();
let x = wi.GetX()-wi.GetWidth()/2+centerX/(this.textureWidth/wi.GetWidth());
Expand Down Expand Up @@ -196,6 +197,7 @@
centerX+=points[i];
}
centerX = centerX/(points.length/2)+this.skeletonInfo.bounds.offset.x+this.skeletonInfo.bounds.size.x;
if (this.isMirrored) centerX = this.skeletonInfo.bounds.size.x - centerX;
let x = wi.GetX()-wi.GetWidth()/2+centerX/(this.textureWidth/wi.GetWidth());
// If rotated, return rotate centerX by angle around center
return Math.sin(wi.GetAngle()) * (x-wi.GetX()) + Math.cos(wi.GetAngle()) * (y-wi.GetY()) + wi.GetY();
Expand Down Expand Up @@ -233,8 +235,9 @@
const points = Array.from(this.skeletonInfo.skeletonBounds.getPolygon(bBox));
for(let i=0;i<points.length;i+=2)
{
let offsetPointX = points[i]+offsetX+sizeX;
// X unroated
points[i] = points[i]+offsetX+sizeX;
points[i] = this.isMirrored ? sizeX - offsetPointX : offsetPointX;
points[i] = x-halfWidth+points[i]/(xScale);
// Y unroated
points[i+1] = sizeY-points[i+1]+offsetY;
Expand Down
2 changes: 1 addition & 1 deletion src/c3runtime/spine-draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ class SpineBatch {

if (!globalThis.spineBatcher)
{
console.log('[Spine] SpineBatcher init, 1.34.1');
console.log('[Spine] SpineBatcher init, 1.34.2');
globalThis.spineBatcher = new SpineBatch();
}
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const C3 = self.C3;

const PLUGIN_ID = "Gritsenko_Spine";
const PLUGIN_VERSION = "1.34.1";
const PLUGIN_VERSION = "1.34.2";
const PLUGIN_CATEGORY = "general";

const PLUGIN_CLASS = SDK.Plugins.Gritsenko_Spine = class SpinePlugin extends SDK.IPluginBase {
Expand Down

0 comments on commit ab3a220

Please sign in to comment.