Skip to content

Commit 3f099d6

Browse files
committed
Add setBoundsForSkinAnimation and setBoundsForSetupPose actions.
1 parent b9cbfa9 commit 3f099d6

File tree

5 files changed

+113
-1
lines changed

5 files changed

+113
-1
lines changed

spine-ts/spine-construct3/src/aces.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,28 @@
642642
"initial-value": 200
643643
}
644644
]
645+
},
646+
{
647+
"id": "set-bounds-for-skin-animation",
648+
"scriptName": "SetBoundsForSkinAnimation",
649+
"highlight": false,
650+
"params": [
651+
{
652+
"id": "skins",
653+
"type": "string",
654+
"initial-value": ""
655+
},
656+
{
657+
"id": "animation",
658+
"type": "string",
659+
"initial-value": ""
660+
}
661+
]
662+
},
663+
{
664+
"id": "set-bounds-for-setup-pose",
665+
"scriptName": "SetBoundsForSetupPose",
666+
"highlight": false
645667
}
646668
],
647669
"expressions": [

spine-ts/spine-construct3/src/c3runtime/actions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts =
182182

183183
SetBounds (this: SDKInstanceClass, x: number, y: number, width: number, height: number) {
184184
this.setBounds(x, y, width, height);
185+
},
186+
187+
SetBoundsForSkinAnimation (this: SDKInstanceClass, skins: string, animation: string) {
188+
this.setBoundsForSkinAnimation(skins === "" ? [] : skins.split(","), animation);
189+
},
190+
191+
SetBoundsForSetupPose (this: SDKInstanceClass) {
192+
this.setBoundsForSetupPose();
185193
}
186194

187195
};

spine-ts/spine-construct3/src/c3runtime/instance.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
11671167

11681168
this.spineBounds = { x, y, width, height };
11691169

1170-
this.setOrigin(-x / width, y / height);
1170+
this.setOrigin(-x / width, 1 + y / height);
11711171

11721172
this.width = width * scaleX * (this.isMirrored ? -1 : 1);
11731173
this.height = height * scaleY * (this.isFlipped ? -1 : 1);
@@ -1181,6 +1181,48 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
11811181
return { ...this.spineBounds };
11821182
}
11831183

1184+
public setBoundsForSkinAnimation (skins: string[], animation: string) {
1185+
if (!this.skeleton || !this.state) {
1186+
console.warn('[Spine] setBoundsForSkinAnimation: skeleton or state not loaded');
1187+
return;
1188+
}
1189+
1190+
const boundsProvider = new spine.SkinsAndAnimationBoundsProvider(
1191+
animation || undefined,
1192+
skins
1193+
);
1194+
1195+
const bounds = boundsProvider.calculateBounds(this);
1196+
1197+
if (bounds.width <= 0 || bounds.height <= 0) {
1198+
console.warn('[Spine] setBoundsForSkinAnimation: calculated bounds have invalid dimensions');
1199+
return;
1200+
}
1201+
1202+
const yUp = -(bounds.y + bounds.height);
1203+
1204+
this.setBounds(bounds.x, yUp, bounds.width, bounds.height);
1205+
}
1206+
1207+
public setBoundsForSetupPose () {
1208+
if (!this.skeleton) {
1209+
console.warn('[Spine] setBoundsForSetupPose: skeleton not loaded');
1210+
return;
1211+
}
1212+
1213+
const boundsProvider = new spine.SetupPoseBoundsProvider();
1214+
const bounds = boundsProvider.calculateBounds(this);
1215+
1216+
if (bounds.width <= 0 || bounds.height <= 0) {
1217+
console.warn('[Spine] setBoundsForSetupPose: calculated bounds have invalid dimensions');
1218+
return;
1219+
}
1220+
1221+
const yUp = -(bounds.y + bounds.height);
1222+
1223+
this.setBounds(bounds.x, yUp, bounds.width, bounds.height);
1224+
}
1225+
11841226
/**********/
11851227

11861228
};

spine-ts/spine-construct3/src/lang/en-US.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,26 @@
744744
"desc": "Height of the bounds in Spine world coordinates"
745745
}
746746
}
747+
},
748+
"set-bounds-for-skin-animation": {
749+
"list-name": "Set bounds for skin/animation",
750+
"display-text": "Set bounds for skins {0} and animation {1}",
751+
"description": "Calculate and set bounds based on the specified skins and animation. Uses a separate skeleton to compute the bounding box by stepping through the animation frames. The skeleton's visual size stays the same.",
752+
"params": {
753+
"skins": {
754+
"name": "Skins",
755+
"desc": "Comma-separated list of skin names. Leave empty to use the default skin."
756+
},
757+
"animation": {
758+
"name": "Animation",
759+
"desc": "Animation name to calculate bounds for. Leave empty to use setup pose."
760+
}
761+
}
762+
},
763+
"set-bounds-for-setup-pose": {
764+
"list-name": "Set bounds for setup pose",
765+
"display-text": "Set bounds for setup pose",
766+
"description": "Calculate and set bounds based on the skeleton's setup pose. The skeleton's visual size stays the same."
747767
}
748768
},
749769
"expressions": {

spine-ts/spine-construct3/src/lang/zh-CN.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,26 @@
744744
"desc": "边界在Spine世界坐标中的高度"
745745
}
746746
}
747+
},
748+
"set-bounds-for-skin-animation": {
749+
"list-name": "根据皮肤/动画设置边界",
750+
"display-text": "根据皮肤{0}和动画{1}设置边界",
751+
"description": "根据指定的皮肤和动画计算并设置边界。使用独立的骨架通过遍历动画帧来计算边界框。骨架的视觉大小保持不变。",
752+
"params": {
753+
"skins": {
754+
"name": "皮肤",
755+
"desc": "逗号分隔的皮肤名称列表。留空以使用默认皮肤。"
756+
},
757+
"animation": {
758+
"name": "动画",
759+
"desc": "用于计算边界的动画名称。留空以使用初始姿势。"
760+
}
761+
}
762+
},
763+
"set-bounds-for-setup-pose": {
764+
"list-name": "根据初始姿势设置边界",
765+
"display-text": "根据初始姿势设置边界",
766+
"description": "根据骨架的初始姿势计算并设置边界。骨架的视觉大小保持不变。"
747767
}
748768
},
749769
"expressions": {

0 commit comments

Comments
 (0)