pixijs / spine

Pixi.js plugin that enables Spine support.
Other
564 stars 217 forks source link

TrackEntry.animation is null on all events #394

Open Nuffic opened 3 years ago

Nuffic commented 3 years ago

I'd like to filter by the animation name, but I can't since when "end" event comes, there's no value for animation property.

Steps to reproduce:

  1. Create new Spine
  2. Attach eventlistener with youranimation.state.addListener({end: (entry) => {console.log(entry)}})

Expected

entry.animation is not null

Actual

entry.animation is null

Versions

pixi-spine: ^3.0.1 pixi.js: ^6.0.4

gprzybylowicz commented 3 years ago

Yeah, seems like new pixi-spine is not backward compatible, i.e ITrackEvent doesn't have 'listeners' field too. Not sure if it's a bug or intended.

ivanpopelyshev commented 3 years ago

probably a bug

ivanpopelyshev commented 3 years ago

@Nuffic

entry is re-used in pool, so if you just consolelog it , you'll later see "entry.animation == null" in console, just because it was changed after the event. console.log(entry.animation) shows actual animation.

@gprzybylowicz

those interfaces are common part of all spine runtimes. If you want to see some extra fields there and you are sure they are the same in all runtimes (37, 38, 40) please tell me their exact types. I guess i can make it for listeners, but not for animation, because i dont even have the IAnimation yet.

gprzybylowicz commented 3 years ago

Hi @ivanpopelyshev I had to put migration on hold because I found more issues with compatibility and had to switch to other tasks. But i'm on migration again so will try to go through differences this week and give you followup or even create pull requests.

ivanpopelyshev commented 3 years ago

I found more issues with compatibility

Please describe them?

liamf1986 commented 3 years ago

@ivanpopelyshev and @gprzybylowicz I've had a similar issue with things missing from the ITrackEntry interface that used to be accessible so thought I'd try and put this together for you.

Looking at the runtimes for 3.7, 3.8 and 4.0 this seems to be all the shared items in TrackEntry. The only thing to note is listener which I've listed as AnimationStateListener | AnimationStateListener2 as it is AnimationStateListener2 in 3.7 and AnimationStateListener in 3.8 and 4.0. I'm not sure how you'd like to handle that.

animation: Animation;
next: TrackEntry;
mixingFrom: TrackEntry;
mixingTo: TrackEntry;
listener: AnimationStateListener | AnimationStateListener2;
trackIndex: number;
loop: boolean;
holdPrevious: boolean;
eventThreshold: number;
attachmentThreshold: number;
drawOrderThreshold: number;
animationStart: number;
animationEnd: number;
animationLast: number;
nextAnimationLast: number;
delay: number;
trackTime: number;
trackLast: number;
nextTrackLast: number;
trackEnd: number;
timeScale: number;
alpha: number;
mixTime: number;
mixDuration: number;
interruptAlpha: number;
totalAlpha: number;
mixBlend: MixBlend;
timelineMode: Array<number>;
timelineHoldMix: Array<TrackEntry>;
timelinesRotation: Array<number>;
 
reset (): void;
getAnimationTime (): number;
setAnimationLast(animationLast: number): void;
isComplete (): boolean;
resetRotationDirections (): void; 

Is this what you were after? Just for comparison this is what is listed in ITrackEntry inside pixi-spine currently:

export declare interface ITrackEntry {
    trackIndex: number;
    loop: boolean;
    delay: number;
    trackTime: number;
    trackLast: number;
    nextTrackLast: number;
    trackEnd: number;
    timeScale: number;
    alpha: number;
    mixTime: number;
    mixDuration: number;
    interruptAlpha: number;
    totalAlpha: number;
}
gprzybylowicz commented 3 years ago

Those are just quick findings based on transpilation errors right after installing newest version of pixi-spine:

1) Lack of timeScale, setEmptyAnimation, clearTracks in IAnimationState 2) Lack of data, findBone in ISkeleton 3) Lack of findSkin, in ISkeletonData 4) Lack of animation and listener ITrackEntry

All those properties/methods were there before, in ver 2.1.11. I will be investigating it more tomorrow morning.

ivanpopelyshev commented 3 years ago

new version of pixi-spine supports all spine runtimes, 3.7 3.8 and 4.0

Its not possible to add 2,3,4 to it because those types are different across spine versions, and its too much to make generics out of it.

If you want to work with 3.8, use @pixi-spine/all-3.8 , its exporting all the types from @pixi-spine/runtime-3.8. Same with 4.0 . I dont have dedicated bundle to 3.7. So, which version of spine do you use?

as for 1. i can look

liamf1986 commented 3 years ago

Its not possible to add 2,3,4 to it because those types are different across spine versions, and its too much to make generics out of it.

Just focusing on 4 for a moment (ITrackEntry) how is it not possible to add at least animation and listener there?

In the post above I listed all the properties that are shared across 3.7, 3.8 and 4.0 and those 2 are included, they all have the same types as well. I got that list by comparing the 3 versions on github at these links (3.7, 3.8 and 4.0).

Am I looking in the wrong place or is there something else I'm not taking into consideration?

There are still examples in the pixi-spine docs here that show to use listener from the ITracksEntry interface, which may need updating if that's not possible.

ivanpopelyshev commented 3 years ago

because there are three types: import('@pixi-spine/runtime-3.7') .Animation, import('@pixi-spine/runtime-3.8') .Animation, import('@pixi-spine/runtime-4.0') .Animation , need to add IAnimation for it, and add whatever else is needed there. Its possible but its work :)

If you need only 4.0, just use @pixi-spine/all-4.0, it exports the usual types, you dont need ITrackEntry, you can just use TrackEntry. Is there are problem with this package?

liamf1986 commented 3 years ago

I've personally not attempted to use @pixi-spine/all-4.0 yet was just curious what could be done to get the full version working for full support. Happy to use that if it's the only option.

So if you're saying that being able to use shared properties like TrackEntry.listener and others is not possible, what is the use case of the full version? Do correct me if I'm misunderstanding, but doesn't that mean it's only supporting all 3 versions in a limited capacity and people will often have to use the specific bundles like @pixi-spine/all-4.0?

ivanpopelyshev commented 3 years ago

Do correct me if I'm misunderstanding, but doesn't that mean it's only supporting all 3 versions in a limited capacity

It has full capacity, because runtimes are separated. The downside is that types of different runtimes are not compatble, so I added interfaces in full version so i can work on them slowly, your input about TrachEntry is really appreciated!

Full version works with any model version. The first thing people encounter when they try spine is that the models from tutorials in internet all have different version. I'm just tired of all the newbies.

Also, in case user doesnt know what types are - it works fine :)

gprzybylowicz commented 3 years ago

Using @pixi-spine/all-3.8 works and thats fine with me cause I don't need 3.7. However, now I'm getting runtime error class class constructor spine cannot be invoked without 'new' and I belive it's due to change in tsconfig.json, where you set target to es6. Do you think it's possible to set it back to es5 or should I make a fork and create my build?

ivanpopelyshev commented 3 years ago

@gprzybylowicz

Actually i dont know . Maybe copying file https://github.com/pixijs/spine/blob/master/bundles/all-3.8/src/index.ts into your project and adding corresponding deps is enough?

I'm not webpack master :(

gprzybylowicz commented 3 years ago

No problem. It's not about webpack. You set target to es6 so tsc produces es6 code for pixi-spine, not es5(as in ver 2.x.x) My code has es5 target as it still a bit more safer for web, but when I transpile my code it doesn't touch any lib in node_modules including pixi-spine, same webpack(it just bundles it into one file). Then, when I run app and it tries to use pixi-spine it expects to be in es5 as well and that's why I have this error. Solution will be to change target in pixi-spine tsconfig.json back to es5 and keep compatibility but I don't know the reason why you set it to es6 :) If it's not possible to change it here, I will make a fork cause not sure if there is any other solution.

ivanpopelyshev commented 3 years ago

hm, in pixijs target is es5. Maybe i should use it too

gprzybylowicz commented 3 years ago

That would be awesome. However I wanted to change it on my own and push to my private npm as temp solution to proceed with migration but seems like my changes in tsconfig.json are not taken into consideration by build scripts and still see es6 code in output in /lib dir. @ivanpopelyshev any tips what else should be changed to build es5? I guess it's somehow connected with rollup here.

ivanpopelyshev commented 3 years ago

Oh, right, its built with surcase: https://github.com/ShukantPal/pixi-build-tools/blob/df849b5625410d47fbe6fa6e0e579f0bddf84d0d/packages/rollup-configurator/main.js#L51 , i honestly dont know how to make different setting for it

Here I have modified rollup config for pixi-picture, it uses @rollup-plugin/typescript: https://github.com/pixijs/pixi-picture/blob/master/scripts/rollup.config.js#L22 , though i forgot to remove surcase

gprzybylowicz commented 3 years ago

Ok, i see. Never worked with surcase but seems like it's meant to be for developement builds only so I guess it has to be it :) Will dig more into it and will see.

gprzybylowicz commented 3 years ago

Hi @ivanpopelyshev I managed to do it but I had to copy entire rollup config(did it as separate package). Here is PR https://github.com/pixijs/spine/pull/397

FloodGames commented 2 years ago

I have pixi-spine but it does not have the IAnimation interface on ITrackEntry? export declare interface ITrackEntry { animation: IAnimation .,.. }

FloodGames commented 1 year ago

These functions work, but typescript says it's not ok

Property 'animation' does not exist on type 'ITrackEntry'

export const getCurrentAnimationString = (spineObject: SpineExtended): string =>
  spineObject.state.tracks[0].animation.name

export function getCurrentAnimationString2(spine: SpineExtended): string {
  return spine.state.getCurrent(0).animation.name
}