Add set-bounds prop to manually reset the bounds. Improved automatic bounds reset.

This commit is contained in:
Davide Tantillo 2025-11-20 12:48:46 +01:00
parent 50a8a47ff0
commit 0620a9c841
4 changed files with 28 additions and 5 deletions

View File

@ -235,7 +235,6 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase {
if (id === PLUGIN_CLASS.PROP_SKIN) {
this.skins = [];
this.setSkin();
this.resetBounds();
this.layoutView?.Refresh();
return;
}
@ -247,7 +246,7 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase {
}
if (id === PLUGIN_CLASS.PROP_BOUNDS_PROVIDER) {
this.resetBounds();
this.resetBounds(true);
this.layoutView?.Refresh();
return
}
@ -353,9 +352,9 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase {
this.state = new spine.AnimationState(animationStateData);
this.setSkin();
this.setAnimation();
this.update(0);
console.log(this.skeleton, this.textureAtlas);
this.setBoundsFromBoundsProvider();
this.initBounds();
@ -385,7 +384,7 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase {
return true;
}
private resetBounds () {
public resetBounds (keepScale = false) {
if (!this.skeleton || !this.textureAtlas) {
this._inst.SetSize(200, 200);
this._inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_X, 0);
@ -401,7 +400,14 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase {
const { x, y, width, height } = this.spineBounds;
this._inst.SetOrigin(-x / width, -y / height);
this._inst.SetSize(width, height);
let scaleX = 1;
let scaleY = 1;
if (keepScale) {
scaleX = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_X) as number;
scaleY = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_Y) as number;
}
this._inst.SetSize(width * scaleX, height * scaleY);
this._inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_X, 0);
this._inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_Y, 0);

View File

@ -69,6 +69,11 @@
"spine-bounds-offset-angle": {
"name": "Offset Angle",
"desc": "Offset Angle"
},
"set-bounds": {
"name": "Reset bounds",
"desc": "Click to reset the bounds using the current configuration, but keeping the current scale.",
"link-text": "Reset"
}
},
"aceCategories": {

View File

@ -69,6 +69,11 @@
"spine-bounds-offset-angle": {
"name": "偏移角度",
"desc": "偏移角度"
},
"set-bounds": {
"name": "重置边界",
"desc": "点击以使用当前配置重置边界,但保持当前缩放。",
"link-text": "重置"
}
},
"aceCategories": {

View File

@ -87,6 +87,13 @@ const PLUGIN_CLASS = class SpineC3Plugin extends SDK.IPluginBase {
new SDK.PluginProperty("float", SpineC3Plugin.PROP_BOUNDS_OFFSET_ANGLE, 0),
new SDK.PluginProperty("float", SpineC3Plugin.PROP_SKELETON_SCALE_X, 1),
new SDK.PluginProperty("float", SpineC3Plugin.PROP_SKELETON_SCALE_Y, 1),
new SDK.PluginProperty("link", "set-bounds", {
linkCallback: (instance) => {
const sdkInst = instance as SDKEditorInstanceClass;
sdkInst.resetBounds(true);
},
callbackType: "for-each-instance"
}),
]);