From 86a0950a5f80279a24a4f3d2b57f59242e3ccb49 Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Sun, 23 Nov 2025 15:07:56 +0100 Subject: [PATCH] Fixed colors non premultiplied also in the editor. --- spine-ts/spine-construct3/src/c3runtime/instance.ts | 3 ++- spine-ts/spine-construct3/src/instance.ts | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/spine-ts/spine-construct3/src/c3runtime/instance.ts b/spine-ts/spine-construct3/src/c3runtime/instance.ts index c933eecb7..22b429d64 100644 --- a/spine-ts/spine-construct3/src/c3runtime/instance.ts +++ b/spine-ts/spine-construct3/src/c3runtime/instance.ts @@ -163,6 +163,7 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { private renderSkeleton (renderer: IRenderer, skeleton: Skeleton) { let command = this.skeletonRenderer.render(skeleton); + const opacity = this.opacity; const inv255 = 1 / 255; while (command) { const { numVertices, positions, uvs, colors, indices, numIndices, blendMode } = command; @@ -186,7 +187,7 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { const color = colors[i]; const colorDst = i * 4; - const alpha = (color >>> 24 & 0xFF) * inv255 * this.opacity; + const alpha = (color >>> 24 & 0xFF) * inv255 * opacity; const alphaInverse = inv255 * alpha; c3colors[colorDst] = (color >>> 16 & 0xFF) * alphaInverse; c3colors[colorDst + 1] = (color >>> 8 & 0xFF) * alphaInverse; diff --git a/spine-ts/spine-construct3/src/instance.ts b/spine-ts/spine-construct3/src/instance.ts index 252c3023e..25392b8a5 100644 --- a/spine-ts/spine-construct3/src/instance.ts +++ b/spine-ts/spine-construct3/src/instance.ts @@ -118,7 +118,7 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase { skeleton.scaleY = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_Y) as number; } - + const opacity = _inst.GetOpacity(); const cos = Math.cos(offsetAngle); const sin = Math.sin(offsetAngle); const inv255 = 1 / 255; @@ -147,10 +147,12 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase { const color = colors[i]; const colorDst = i * 4; - c3colors[colorDst] = (color >>> 16 & 0xFF) * inv255; - c3colors[colorDst + 1] = (color >>> 8 & 0xFF) * inv255; - c3colors[colorDst + 2] = (color & 0xFF) * inv255; - c3colors[colorDst + 3] = (color >>> 24 & 0xFF) * inv255; + const alpha = (color >>> 24 & 0xFF) * inv255 * opacity; + const alphaInverse = inv255 * alpha; + c3colors[colorDst] = (color >>> 16 & 0xFF) * alphaInverse; + c3colors[colorDst + 1] = (color >>> 8 & 0xFF) * alphaInverse; + c3colors[colorDst + 2] = (color & 0xFF) * alphaInverse; + c3colors[colorDst + 3] = alpha; } iRenderer.ResetColor();