Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #59 from MikalDev/master
Browse files Browse the repository at this point in the history
feat (animation) add script interfaces for animationTimes
  • Loading branch information
MikalDev authored Oct 10, 2021
2 parents b3dd76a + ebba19a commit a3e5a12
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## Additional Spine project guidelines:
- Do not use minify on export of C3 project.
- Do not use worker mode for C3 (see below for details.)
- Do not use worker mode for C3.
- For jumping or large movments, animate Spine character 'in place', don't do large translations in the Spine project.
- Use C3 events and movement to do the large translations in the C3 project instead (e.g. a long jump.)
- If animation is clipping against the bounds of the C3 object, you can use the property bbox override and values to control the bounding box size and center offset. The values are based on Spine project coordinates.
Expand Down Expand Up @@ -109,7 +109,7 @@ Useful for Dragon Bones Spine JSON export and earlier Spine versions.
- Batch render for improved performance with multiple Spine instances and objects.
- Multiple atlas pages (multiple pngs).
- Mix and Match skins, custom runtime skins.
- C3 worker mode support.
- (Regression, no longer supported, fix in progress) C3 worker mode support.
- Color/Dark Color for Slot at runtime.
- BoundingBoxAttachment center expressions.
- Set Object Render Rate, controls number of ticks per render of the Spine object, distributed amongst the number of instances of the object. This can reduce the CPU performance and GPU performance vs the frame rate of the render.
Expand Down
Binary file added dist/Spine-v1.49.0.c3addon
Binary file not shown.
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": "1.48.0",
"version": "1.49.0",
"author": "Mikal and Igor Gritsenko",
"website": "https://gritsenko.github.io/c3_spine_plugin",
"documentation": "https://gritsenko.github.io/c3_spine_plugin",
Expand Down
20 changes: 2 additions & 18 deletions src/c3runtime/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,10 @@
return this.textureWidth;
},
AnimationStart(trackIndex){

if (!this.isLoaded) return 0;

const state = this.skeletonInfo.state;
if(!state || !state.tracks) return 0;
const track = state.tracks[trackIndex];
if(!track) return 0;

return track.animationStart;
return this._animationStart(trackIndex);
},
AnimationEnd(trackIndex){

if (!this.isLoaded) return 0;

const state = this.skeletonInfo.state;
if(!state || !state.tracks) return 0;
const track = state.tracks[trackIndex];
if(!track) return 0;

return track.animationEnd;
return this._animationEnd(trackIndex);
},
AnimationLast(trackIndex){

Expand Down
54 changes: 54 additions & 0 deletions src/c3runtime/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,45 @@

this.SetRenderOnce(1.0, true, this.uid);
}

_animationEnd(trackIndex)
{

if (!this.isLoaded) return 0;

const state = this.skeletonInfo.state;
if(!state || !state.tracks) return 0;
const track = state.tracks[trackIndex];
if(!track) return 0;

return track.animationEnd;
}

_animationStart(trackIndex)
{

if (!this.isLoaded) return 0;

const state = this.skeletonInfo.state;
if(!state || !state.tracks) return 0;
const track = state.tracks[trackIndex];
if(!track) return 0;

return track.animationStart;
}

_animationLength(trackIndex)
{

if (!this.isLoaded) return 0;

const state = this.skeletonInfo.state;
if(!state || !state.tracks) return 0;
const track = state.tracks[trackIndex];
if(!track) return 0;

return (track.animationEnd-track.animationStart);
}
};

// Script interface. Use a WeakMap to safely hide the internal implementation details from the
Expand Down Expand Up @@ -1157,5 +1196,20 @@
map.get(this)._applySlotColors();
}

animationStart(trackIndex)
{
return map.get(this)._animationStart(trackIndex);
}

animationEnd(trackIndex)
{
return map.get(this)._animationEnd(trackIndex);
}

animationLength(trackIndex)
{
return map.get(this)._animationLength(trackIndex);
}

};
}
6 changes: 5 additions & 1 deletion src/c3runtime/spine-draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SpineBatch {

init(canvas, runtime)
{
// @ts-ignore
const spine = globalThis.spine;

if (this._initialized) return
Expand Down Expand Up @@ -163,6 +164,7 @@ class SpineBatch {
return;
}

// @ts-ignore
const spine = globalThis.spine;

const gl = this.gl;
Expand Down Expand Up @@ -341,8 +343,10 @@ class SpineBatch {

}

// @ts-ignore
if (!globalThis.spineBatcher)
{
console.log('[Spine] SpineBatcher init, 1.48.0');
console.log('[Spine] SpineBatcher init, 1.49.0');
// @ts-ignore
globalThis.spineBatcher = new SpineBatch();
}
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const C3 = self.C3;

const PLUGIN_ID = "Gritsenko_Spine";
const PLUGIN_VERSION = "1.48.0";
const PLUGIN_VERSION = "1.49.0";
const PLUGIN_CATEGORY = "general";

const PLUGIN_CLASS = SDK.Plugins.Gritsenko_Spine = class SpinePlugin extends SDK.IPluginBase {
Expand Down

0 comments on commit a3e5a12

Please sign in to comment.