From c47b82901905d3397272ff44a90b8aa058b033ef Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Thu, 6 Nov 2025 12:00:38 +0100 Subject: [PATCH] Add set-track-alpha and set-track-mix-blend. --- spine-ts/spine-construct3/src/aces.json | 31 ++++++++++++++ .../spine-construct3/src/c3runtime/actions.ts | 8 ++++ .../src/c3runtime/instance.ts | 40 ++++++++++++++++++- spine-ts/spine-construct3/src/lang/en-US.json | 36 +++++++++++++++++ spine-ts/spine-construct3/src/lang/zh-CN.json | 36 +++++++++++++++++ 5 files changed, 150 insertions(+), 1 deletion(-) diff --git a/spine-ts/spine-construct3/src/aces.json b/spine-ts/spine-construct3/src/aces.json index 9cb3e423a..c4ebbeb3e 100644 --- a/spine-ts/spine-construct3/src/aces.json +++ b/spine-ts/spine-construct3/src/aces.json @@ -261,6 +261,37 @@ } ] }, + { + "id": "set-track-alpha", + "scriptName": "SetTrackAlpha", + "highlight": false, + "params": [ + { + "id": "alpha", + "type": "number" + }, + { + "id": "track-index", + "type": "number" + } + ] + }, + { + "id": "set-track-mix-blend", + "scriptName": "SetTrackMixBlend", + "highlight": false, + "params": [ + { + "id": "mix-blend", + "type": "combo", + "items": ["setup", "first", "replace", "add"] + }, + { + "id": "track-index", + "type": "number" + } + ] + }, { "id": "set-slot-color", "scriptName": "SetSlotColor", diff --git a/spine-ts/spine-construct3/src/c3runtime/actions.ts b/spine-ts/spine-construct3/src/c3runtime/actions.ts index 1954472ee..f4859e79a 100644 --- a/spine-ts/spine-construct3/src/c3runtime/actions.ts +++ b/spine-ts/spine-construct3/src/c3runtime/actions.ts @@ -73,6 +73,14 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts = this.setSkeletonColor(color); }, + SetTrackAlpha (this: SDKInstanceClass, alpha: number, trackIndex: number) { + this.setTrackAlpha(alpha, trackIndex); + }, + + SetTrackMixBlend (this: SDKInstanceClass, mixBlend: 0 | 1 | 2 | 3, trackIndex: number) { + this.setTrackMixBlend(mixBlend, trackIndex); + }, + SetSlotColor (this: SDKInstanceClass, slotName: string, color: string) { this.setSlotColor(slotName, color); }, diff --git a/spine-ts/spine-construct3/src/c3runtime/instance.ts b/spine-ts/spine-construct3/src/c3runtime/instance.ts index f15658dd1..ef26e1606 100644 --- a/spine-ts/spine-construct3/src/c3runtime/instance.ts +++ b/spine-ts/spine-construct3/src/c3runtime/instance.ts @@ -1,4 +1,4 @@ -import type { AnimationState, AnimationStateListener, AssetLoader, Event, Skeleton, SkeletonRendererCore, Skin, TextureAtlas, } from "@esotericsoftware/spine-construct3-lib"; +import { type AnimationState, type AnimationStateListener, type AssetLoader, type Event, MathUtils, type Skeleton, type SkeletonRendererCore, type Skin, type TextureAtlas, } from "@esotericsoftware/spine-construct3-lib"; const C3 = globalThis.C3; const spine = globalThis.spine; @@ -281,6 +281,44 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { skeleton.color.setFromString(color); } + public setTrackAlpha (alpha: number, trackIndex: number) { + const { state } = this; + if (!state) { + console.warn('[Spine] setAlpha: no state'); + return; + } + + const track = state.tracks[trackIndex]; + if (!track) { + console.warn(`[Spine] setAlpha: track ${trackIndex} not found`); + return; + } + + track.alpha = MathUtils.clamp(0, 1, alpha); + } + + public setTrackMixBlend (mixBlend: 0 | 1 | 2 | 3, trackIndex: number) { + const { state } = this; + if (!state) { + console.warn('[Spine] setMixBlend: no state'); + return; + } + + const track = state.tracks[trackIndex]; + if (!track) { + console.warn(`[Spine] setMixBlend: track ${trackIndex} not found`); + return; + } + + switch (mixBlend) { + case 0: track.mixBlend = spine.MixBlend.setup; break; + case 1: track.mixBlend = spine.MixBlend.first; break; + case 2: track.mixBlend = spine.MixBlend.replace; break; + case 3: track.mixBlend = spine.MixBlend.add; break; + default: console.warn('[Spine] Invalid mix blend mode:', mixBlend); + } + } + public setSlotColor (slotName: string, color: string) { const { skeleton } = this; if (!skeleton) { diff --git a/spine-ts/spine-construct3/src/lang/en-US.json b/spine-ts/spine-construct3/src/lang/en-US.json index af57ccb25..f7921921b 100644 --- a/spine-ts/spine-construct3/src/lang/en-US.json +++ b/spine-ts/spine-construct3/src/lang/en-US.json @@ -343,6 +343,42 @@ } } }, + "set-track-alpha": { + "list-name": "Set track alpha", + "display-text": "Set alpha {0} on track {1}", + "description": "Set the alpha/opacity of an animation track. Used for blending animations on different tracks.", + "params": { + "alpha": { + "name": "Alpha", + "desc": "Alpha value (0.0 to 1.0, where 0 is transparent and 1 is opaque)" + }, + "track-index": { + "name": "Track index", + "desc": "Track index to set alpha for" + } + } + }, + "set-track-mix-blend": { + "list-name": "Set track mix blend", + "display-text": "Set mix blend {0} on track {1}", + "description": "Set the mix blend mode for an animation track. Controls how animations are layered and combined.", + "params": { + "mix-blend": { + "name": "Mix blend", + "desc": "Mix blend mode", + "items": { + "setup": "Setup (transition to/from setup pose)", + "first": "First (for first animations applied)", + "replace": "Replace (for layered animations)", + "add": "Add (additive blending for layered animations)" + } + }, + "track-index": { + "name": "Track index", + "desc": "Track index to set mix blend for" + } + } + }, "set-slot-color": { "list-name": "Set slot color", "display-text": "Set slot {0} color to {1}", diff --git a/spine-ts/spine-construct3/src/lang/zh-CN.json b/spine-ts/spine-construct3/src/lang/zh-CN.json index 56fea38da..c6f5f355a 100644 --- a/spine-ts/spine-construct3/src/lang/zh-CN.json +++ b/spine-ts/spine-construct3/src/lang/zh-CN.json @@ -344,6 +344,42 @@ } } }, + "set-track-alpha": { + "list-name": "设置轨道透明度", + "display-text": "在轨道{1}上设置透明度为{0}", + "description": "设置动画轨道的透明度/不透明度。用于混合不同轨道上的动画。", + "params": { + "alpha": { + "name": "透明度", + "desc": "透明度值(0.0 到 1.0,其中 0 为完全透明,1 为完全不透明)" + }, + "track-index": { + "name": "轨道索引", + "desc": "要设置透明度的轨道索引" + } + } + }, + "set-track-mix-blend": { + "list-name": "设置轨道混合模式", + "display-text": "在轨道{1}上设置混合模式为{0}", + "description": "设置动画轨道的混合模式。控制动画如何分层和组合。", + "params": { + "mix-blend": { + "name": "混合模式", + "desc": "混合模式", + "items": { + "setup": "设置(过渡到/从设置姿势)", + "first": "首次(用于首次应用的动画)", + "replace": "替换(用于分层动画)", + "add": "叠加(用于分层动画的叠加混合)" + } + }, + "track-index": { + "name": "轨道索引", + "desc": "要设置混合模式的轨道索引" + } + } + }, "set-slot-color": { "list-name": "设置插槽颜色", "display-text": "设置插槽{0}的颜色为{1}",