Skip to content

Commit

Permalink
feat (physics) add support for 4.2 spine-ts / webgl runtime
Browse files Browse the repository at this point in the history
Also mark the changes required for C3
Add physics mode ACE
  • Loading branch information
MikalDev committed May 14, 2024
1 parent 1488282 commit 23dec76
Show file tree
Hide file tree
Showing 9 changed files with 4,463 additions and 1,800 deletions.
Binary file added dist/Spine-v2.9.0.c3addon
Binary file not shown.
17 changes: 17 additions & 0 deletions src/aces.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@
}
]
},
{
"id": "set-physics-mode",
"scriptName": "SetPhysicsMode",
"highlight": false,
"params": [
{
"id": "physics-mode",
"type": "combo",
"items": [
"none",
"reset",
"update",
"pose"
]
}
]
},
{
"id": "play",
"scriptName": "Play",
Expand Down
2 changes: 1 addition & 1 deletion src/addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "plugin",
"name": "Spine",
"id": "Gritsenko_Spine",
"version": "2.8.4",
"version": "2.9.0",
"author": "Mikal and Igor Gritsenko",
"website": "https://gritsenko.github.io/c3_spine_plugin",
"documentation": "https://gritsenko.github.io/c3_spine_plugin",
Expand Down
4 changes: 4 additions & 0 deletions src/c3runtime/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@
this.skeletonInfo.sequenceAutoplay = false;
}
this.skeletonInfo.sequenceFPS = fps;
},

SetPhysicsMode(mode) {
this._setPhysicsMode(mode);
}

}
Expand Down
32 changes: 27 additions & 5 deletions src/c3runtime/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@
this.textureWidth = 0;
this.textureHeight = 0;
this.completeEventData = { }

const spine = globalThis.spine;
// this.physicsMode = spine.Physics.none
this.physicsMode = spine.Physics.update
// this.physicsMode = spine.Physics.pose
// this.physicsMode = spine.Physics.reset

// @ts-ignore
const wi = this.GetWorldInfo();
Expand Down Expand Up @@ -335,7 +339,7 @@
};

state.apply(skeleton);
skeleton.updateWorldTransform();
skeleton.updateWorldTransform(this.physicsMode);
// @ts-ignore
var offset = new spine.Vector2();
// @ts-ignore
Expand Down Expand Up @@ -429,7 +433,7 @@
const state = this.skeletonInfo.state;
const skeleton = this.skeletonInfo.skeleton;
state.apply(skeleton);
skeleton.updateWorldTransform();
skeleton.updateWorldTransform(this.physicsMode);
// @ts-ignore
var offset = new spine.Vector2();
// @ts-ignore
Expand Down Expand Up @@ -490,7 +494,7 @@
// If starting later, apply time, then enable listeners so they do not trigger on past events
{
// state.apply(skeleton);
// skeleton.updateWorldTransform();
// skeleton.updateWorldTransform(this.physicsMode);
this.delayedTrackListeners.push(trackIndex);
// this.setTrackListeners(state, trackIndex);
}
Expand Down Expand Up @@ -651,6 +655,7 @@
this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnSkeletonLoaded);
}


Release() {
this.currentKey = null;
this.currentValue = null;
Expand Down Expand Up @@ -703,6 +708,7 @@
this.indexSize = null;
this.palette = null;
this.sdkType = null;
this.physicsMode = null;
}

Tick() {
Expand Down Expand Up @@ -776,7 +782,7 @@

// Override bones under bone control
this.spineBoneControl.applyBoneControl(active.skeleton);
active.skeleton.updateWorldTransform();
active.skeleton.updateWorldTransform(this.physicsMode);

this.runtime.UpdateRender();
if (this.animateOnce > 0)
Expand Down Expand Up @@ -962,6 +968,17 @@
this.SetRenderOnce(1.0, true, this.uid);
}

_setPhysicsMode(mode)
{
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.log("Invalid physics mode", mode);
}
}

_setAnimationSpeed(speed){
this.animationSpeed = speed;
}
Expand Down Expand Up @@ -1381,5 +1398,10 @@
map.get(this)._flip(isFlipped)
}

setPhysicsMode(mode)
{
map.get(this)._setPhysicsMode(mode);
}

};
}
4 changes: 2 additions & 2 deletions src/c3runtime/spine-draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class SpineBatch {
// Render
this.renderer.premultipliedAlpha = premultipliedAlpha;
// YYY this.renderer.draw(this.batcher, skeletonInstance.skeletonInfo.skeleton, -1, -1, skeletonInstance.palette);
this.renderer.draw(this.batcher, skeletonInstance.skeletonInfo.skeleton, -1, -1, sequenceAutoplay, sequenceFPS);
this.renderer.draw(this.batcher, skeletonInstance.skeletonInfo.skeleton, -1, -1, null, sequenceAutoplay, sequenceFPS);
this.batcher.end();
this.shader.unbind();
}
Expand Down Expand Up @@ -359,7 +359,7 @@ class SpineBatch {
// @ts-ignore
if (!globalThis.spineBatcher)
{
console.info('[Spine] SpineBatcher init, 2.8.4, Spine 4.1.x compatible');
console.info('[Spine] SpineBatcher init, 2.9.0, Spine 4.2.x compatible');
// @ts-ignore
globalThis.spineBatcher = new SpineBatch();
}
Loading

0 comments on commit 23dec76

Please sign in to comment.