From 29187883644c1c4108952cedf1017a22758259dc Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Thu, 6 Nov 2025 11:07:22 +0100 Subject: [PATCH] Add set-physics-mode. --- spine-ts/spine-construct3/src/aces.json | 12 ++++++++++++ .../spine-construct3/src/c3runtime/actions.ts | 4 ++++ .../spine-construct3/src/c3runtime/instance.ts | 17 ++++++++++++++--- spine-ts/spine-construct3/src/lang/en-US.json | 17 +++++++++++++++++ spine-ts/spine-construct3/src/lang/zh-CN.json | 17 +++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/spine-ts/spine-construct3/src/aces.json b/spine-ts/spine-construct3/src/aces.json index 54fbb3bcd..d3621acfb 100644 --- a/spine-ts/spine-construct3/src/aces.json +++ b/spine-ts/spine-construct3/src/aces.json @@ -237,6 +237,18 @@ "type": "number" } ] + }, + { + "id": "set-physics-mode", + "scriptName": "SetPhysicsMode", + "highlight": false, + "params": [ + { + "id": "physics-mode", + "type": "combo", + "items": ["none", "reset", "update", "pose"] + } + ] } ], "expressions": [ diff --git a/spine-ts/spine-construct3/src/c3runtime/actions.ts b/spine-ts/spine-construct3/src/c3runtime/actions.ts index f69d77d3c..50bfcb9fa 100644 --- a/spine-ts/spine-construct3/src/c3runtime/actions.ts +++ b/spine-ts/spine-construct3/src/c3runtime/actions.ts @@ -63,6 +63,10 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts = SetAnimationMix (this: SDKInstanceClass, fromName: string, toName: string, duration: number) { this.setAnimationMix(fromName, toName, duration); + }, + + SetPhysicsMode (this: SDKInstanceClass, mode: 0 | 1 | 2 | 3) { + this.setPhysicsMode(mode); } }; diff --git a/spine-ts/spine-construct3/src/c3runtime/instance.ts b/spine-ts/spine-construct3/src/c3runtime/instance.ts index ae924301d..3ce961175 100644 --- a/spine-ts/spine-construct3/src/c3runtime/instance.ts +++ b/spine-ts/spine-construct3/src/c3runtime/instance.ts @@ -19,6 +19,7 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { propFlipX = false; isPlaying = true; animationSpeed = 1.0; + physicsMode = spine.Physics.update; customSkins: Record = {}; textureAtlas?: TextureAtlas; @@ -260,6 +261,16 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { } } + public setPhysicsMode (mode: 0 | 1 | 2 | 3) { + switch (mode) { + case 0: this.physicsMode = spine.Physics.none; break; + case 1: this.physicsMode = spine.Physics.reset; break; + case 2: this.physicsMode = spine.Physics.update; break; + case 3: this.physicsMode = spine.Physics.pose; break; + default: console.warn('[Spine] Invalid physics mode:', mode); + } + } + private _setSkin () { const { skeleton } = this; if (!skeleton) return; @@ -294,15 +305,15 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { } private update (delta: number) { - const { state, skeleton } = this; + const { state, skeleton, animationSpeed, physicsMode } = this; if (!skeleton || !state) return; - const adjustedDelta = delta * this.animationSpeed; + const adjustedDelta = delta * animationSpeed; state.update(adjustedDelta); skeleton.update(adjustedDelta); state.apply(skeleton); - skeleton.updateWorldTransform(spine.Physics.update); + skeleton.updateWorldTransform(physicsMode); } private async _loadAtlas () { diff --git a/spine-ts/spine-construct3/src/lang/en-US.json b/spine-ts/spine-construct3/src/lang/en-US.json index bfab7acf7..38db8c0f7 100644 --- a/spine-ts/spine-construct3/src/lang/en-US.json +++ b/spine-ts/spine-construct3/src/lang/en-US.json @@ -314,6 +314,23 @@ "desc": "Blend duration in seconds" } } + }, + "set-physics-mode": { + "list-name": "Set physics mode", + "display-text": "Set physics mode to {0}", + "description": "Set the physics mode to control how physics constraints are updated and applied", + "params": { + "physics-mode": { + "name": "Physics mode", + "desc": "Physics mode", + "items": { + "none": "None (physics not updated or applied)", + "reset": "Reset (physics reset to current pose)", + "update": "Update (physics updated and applied)", + "pose": "Pose (physics pose applied without update)" + } + } + } } }, "expressions": { diff --git a/spine-ts/spine-construct3/src/lang/zh-CN.json b/spine-ts/spine-construct3/src/lang/zh-CN.json index 9d8666aa7..5134cbbc4 100644 --- a/spine-ts/spine-construct3/src/lang/zh-CN.json +++ b/spine-ts/spine-construct3/src/lang/zh-CN.json @@ -316,6 +316,23 @@ } } }, + "set-physics-mode": { + "list-name": "设置物理模式", + "display-text": "设置物理模式为{0}", + "description": "设置物理模式以控制物理约束的更新和应用方式", + "params": { + "physics-mode": { + "name": "物理模式", + "desc": "物理模式", + "items": { + "none": "无(物理不更新也不应用)", + "reset": "重置(物理重置为当前姿势)", + "update": "更新(物理更新并应用)", + "pose": "姿势(应用物理姿势但不更新)" + } + } + } + }, "expressions": { "double": { "description": "将数字翻倍。",