Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
fix: tint and spine skeleton/slot/attachment color (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidetan authored Aug 1, 2024
1 parent 6cca188 commit 9f697b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/BatchableSpineSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export class BatchableSpineSlot implements BatchableObject

const parentColor:number = this.renderable.groupColor;
const parentAlpha:number = this.renderable.groupAlpha;

let abgr:number;

const mixedA = (slotColor.a * parentAlpha) * 255;
Expand All @@ -121,9 +120,9 @@ export class BatchableSpineSlot implements BatchableObject
const parentG = (parentColor >> 8) & 0xFF;
const parentR = parentColor & 0xFF;

const mixedR = (slotColor.r * parentR) * 255;
const mixedG = (slotColor.g * parentG) * 255;
const mixedB = (slotColor.b * parentB) * 255;
const mixedR = (slotColor.r * parentR);
const mixedG = (slotColor.g * parentG);
const mixedB = (slotColor.b * parentB);

abgr = ((mixedA) << 24) | (mixedB << 16) | (mixedG << 8) | mixedR;
}
Expand Down
18 changes: 15 additions & 3 deletions src/Spine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface AttachmentCacheData
vertices: Float32Array;
uvs: Float32Array;
indices: number[];
color: { r: number; g: number; b: number; a: number };
color: Color;
clippedData?: {
vertices: Float32Array;
uvs: Float32Array;
Expand Down Expand Up @@ -419,6 +419,18 @@ export class Spine extends Container implements View
);
}

const skeleton = slot.bone.skeleton;
const skeletonColor = skeleton.color;
const slotColor = slot.color;
const attachmentColor = attachment.color;

cacheData.color.set(
skeletonColor.r * slotColor.r * attachmentColor.r,
skeletonColor.g * slotColor.g * attachmentColor.g,
skeletonColor.b * slotColor.b * attachmentColor.b,
skeletonColor.a * slotColor.a * attachmentColor.a,
);

cacheData.clipped = false;

if (clipper.isClipping())
Expand Down Expand Up @@ -570,7 +582,7 @@ export class Spine extends Container implements View
clipped: false,
indices: [0, 1, 2, 0, 2, 3],
uvs: attachment.uvs as Float32Array,
color: slot.color,
color: new Color(1, 1, 1, 1),
};
}
else
Expand All @@ -583,7 +595,7 @@ export class Spine extends Container implements View
clipped: false,
indices: attachment.triangles,
uvs: attachment.uvs as Float32Array,
color: slot.color,
color: new Color(1, 1, 1, 1),
};
}

Expand Down

0 comments on commit 9f697b1

Please sign in to comment.