Malhavok / Spriter2Unity

Tool for converting SCML files into Unity prefab and anim
12 stars 27 forks source link

SCML export - events #8

Open mythgarr opened 10 years ago

mythgarr commented 10 years ago

Hey - I have the plugin version pretty well functional at this point. I'm running into a bit of a problem with the events - it seems to only fire the first 8 at any given frame? Did you run into this, and if so how did you get around it? Thanks!

EDIT: Nevermind - for some reason some of the frames were being set with different times (within 10^-40 seconds) causing some to fire on the first pass and others to not. YAY!

Malhavok commented 10 years ago

oh, i honestly didn’t check it O.o was only checking does the animations look like they should… my bad :/

the only problem that i found with events is that, when in transitions, events are called from both animations at once. but you’ve probably already seen my solution (the ugly parser and string-calling frames)

i’d advice to ask on animation forum for Unity, but honestly - don’t expect any answers

how did you solve the problem with animations being unable to be added to animator controller?

On 25 Jan 2014, at 06:25, mythgarr notifications@github.com wrote:

Hey - I have the plugin version pretty well functional at this point. I'm running into a bit of a problem with the events - it seems to only fire the first 8 at any given frame? Did you run into this, and if so how did you get around it? Thanks!

— Reply to this email directly or view it on GitHub.

Malhavok commented 10 years ago

i've checked your plugin, great work! i have to admit that you managed to do something i wasn't able to ^^ and this idea with adding animations to the prefab - brilliant

if you want i can just close my repo and pass notice to everyone (including Michael and Lucid from Spriter) that you're the guy doing the plugin. you can cleanup any mess i left then and i'll pass you problematic projects that are showing some various problems (i've tested the worst one yet and it doesn't work well :/)

also, it seems that loop flag is missing from animation clips (all of them). when i'll find a moment i'll try to find the clean way to add it (or you'll do it in seconds)

Malhavok commented 10 years ago

btw - how did you know about AnimationUtility.SetAnimationType? it's not in the doc and i didn't even think about using reflection on it to check some other methods O.o

pjwaixingren commented 10 years ago

Excuse me, mythgarr and malhavok! i see malhavok say you developed new version of S2U.: )! i use you the new version try it.but the problem is aways in the project. malhavok give me some advise i try so many times ,it's no use too .

could you help me . why i change the animations ,but the picture(spriter) is still not been change??? i make a video that you can see the question!!:)! https://vimeo.com/84789083

i upload the problem project in the web .you can download see the problem! https://www.dropbox.com/s/pw1qyudsdztvrg7/bug_export_animas.zip

i use the spriterB5 (mac or win ) try,the bug is the same .. i use the python2.7.6,mac10.9,unity4.3.2f1(unity4.3.3f1)! (Did you have to use the unity4.3.3? )

thank you mythgarr and malhavok!!

mythgarr commented 10 years ago

I noticed that the reason for the animations not working by default was the m_animationtype flag. I hunted through the documentation but didn't find it mentioned anywhere. I ended up using .NET Reflector to peek at what was setting that flag and found the AnimationUtility.SetAnimationType method.

I think I'll also toss in support for generating a generic avatar today/tonight - should be fairly easy (http://docs.unity3d.com/Documentation/ScriptReference/AvatarBuilder.BuildGenericAvatar.html). That should eventually make it possible to use Mecanim's root motion with Spriter animations as well as masking animations. Maybe - I hope :)

It's up to you on the repository - your work and advice have been absolutely instrumental to building this. I want to make sure you continue to get appropriate credit - for now I have the line 'Based on 'Spriter2Unity' python code by Malhavok' in the copyright notice at the top of each file. Let me know what else I should do to credit you.

@pjwaixingren I'll take a look at your project, but it looks like you're missing the S2U_AssignSprite (I think?) component on these. You could try the plugin even though it's EXTREMELY alpha (https://github.com/mythgarr/Spriter2Unity - copy the entire UnityPlugin folder into your Assets Folder) version. You should then be able to just copy the SCML file into your project to generate a prefab (which will already have the component added). Let me know if you run into any problems or Unity crashes.

pjwaixingren commented 10 years ago

mythgarr i use the SCML file the prefab. the picture will change in the animations playing . but you animation have a bug, is no Complete. i test so many times.it's looks something keys lost .

i use the outside file the animations playing(the Malhavok S2U Original export the file ) ,he export the animation playing is OK!but the prefab playing the picture not been change still!

you are real the Partner...mythgarr ,you animations have bug,the prefab picture will change.. Malhavok ,you animations playing OK,but the prefab picture not been change!...

mythgarr i am on the line await for you new U2S Version,I will first test the success version ,i see the success will coming soon.... haha ...... : )!!

pjwaixingren commented 10 years ago

mythgarr, i record the video you can see the bug, you animantions is all no loop.if you can see you animations playing had loop playing..may be that is my set the loop in the record the video before!

https://www.dropbox.com/s/nbhba1yatsok6zf/animations_playing_BUG.mp4 (if you on the web look is too Blur,you can download the video file in the upper right corner)

thank you!mythgarr and malhavok!! ^-^!!!

mythgarr commented 10 years ago

@pjwaixingren Is there any way you could upload your Bug test project? I've fixed the looping issue, but I'm having trouble determining what's going on with the animation itself. Also, it might be easier to communicate through Skype, Google Chat or something a little more real-time. Let me know if there's something that could work out for you.

pjwaixingren commented 10 years ago

i am upload the file. https://www.dropbox.com/s/ra3p4pr2kbyivx8/animation_BUG.zip i skypy:pjwaixingren or google chat:pjwaixingren@gmail.com :)!

mythgarr commented 10 years ago

@Malhavok I found a big issue with how I'm building the keyframes - on fall_start for instance the head rotation goes from 5 degrees to 350 degrees. What it's SUPPOSED to do here is go from 5 to -10 (a change of 15 degrees) but instead it's swinging clear around (345 degrees). It looks like what Spriter does internally is limit rotation between keyframes to less than 180 degrees. How did you go about determining what the rotation should be for any given frame? In this case using a range of [-180,180] would work, but a rotation from (for instance) 170 degrees to 190 degrees would break. Do you just peek at the last rotation to determine which it should be?

EDIT: Nevermind, realized just how easy it was to simply grab the previous rotation. Should be fixed in the latest push

Malhavok commented 10 years ago

@mythgarr - yup, i know what you're talking about. the solution for this problem is implemented in Unity/Curves/CurveLinearAngle.py what it does, basically, is just finding the closest angle. calc_angle_diff and wrap_angle are the methods to check

on the other hand, inside scml, there is a param called "spin" on, i believe, keyframes. it was supposed to be the direction of rotation for given element, so probably it's the better solution.

oh, btw, if you'll find some time, in the first post of this issue you'll find a project that was killing my algorithm. https://github.com/Malhavok/Spriter2Unity/issues/5 if you open it with Spriter, everything shows fine (idle animation, chest moving via scaling), but exporting it breaks. it looks like the scale propagation fails (however all test projects that i made for scale didn't have this problem). i've tested it yesterday with the plugin and a similar problem occurs. maybe you'll have some ideas.

btw - Spriter isn't using TSR for transformations because sone 2d engines can't handle trapezoid transformations (3x3 and 4x4 matrix transformations for 2d elements). this forced me to pass scale "under the table" and apply it to the sprites only. i was considering however rotating the scale and using it with TSR, sadly nothing working came from it.

as for credit - it's more than enough. i'd also advice moving my whole code into "deprecated" directory, so no one tries to use it by mistake. i've updated readme on my project and will pass the word.

another thing - you can find ref on given time pointing to a bone/object with a different time. this doesn't mean "use this transformation", it means "i'm visible at this time, don't add any keyframe for this". i'll try to get a project for you with that error.

pjwaixingren commented 10 years ago

@mythgarr ,i test you the newest the S2U,i told you all the animations have some keys may be lost in the end or read the file not Incomplete(all the animations have the question), when playing the loop animation, you can feel the animation looks like Stuck a Moment.. i contrast export the malhavok anims and yours anims. the walk and run animation file is Special evidence。。 you can see the video: https://www.dropbox.com/s/jdoj2jrcmi4b4ai/lost_keys_bug%21.mp4 (if you on the web look is too Blur,you can download the video file in the upper right corner)

i upload the project file : https://www.dropbox.com/s/hbu3u8aa2swslgx/animation_lost_keys_BUG.zip

all is fine..just the keys lost.. thank you mythgarr !: )!!

Malhavok commented 10 years ago

@mythgarr - i've been solving problem with the same named sprites just by using path relative to the scml file as the base path for loading them. now i think i did it in a terrible way :/ i should've just make "get sprite" from the level of S2U_Folders, but i wanted to keep parsers as close to spriter as possible to keep spriter changes in one place :/

loading and preparing the names is in Experimental/Spriter2Unity/Parsers/S2U_Folders.js S2U_Folders::getPath, where i combine location of the scml file with path from scml folders section

using it is on Experimental/Spriter2Unity/Builders/S2U_Prefab.js S2U_Prefab:: generateGOFromObject line 113 reading full path of the sprite, line 166 loading sprite asset

mythgarr commented 10 years ago

@Malhavok I'm beginning to see why you decided to just resample the keys - I didn't realize that Spriter allows both curves on the Mainline (global time distortion) and individual Timelines. Combined with the quartic, quintic and spline curves that certainly makes things interesting.

AlexanderYoshi commented 9 years ago

Did you ever learn anything about creating an Avatar? I'm struggling to figure it out now.

mythgarr commented 9 years ago

@AlexanderYoshi - Yes, although I don't remember exactly how. There's another version of this that handles exporting avatars at https://github.com/mythgarr/Spriter2Unity/, although I've stopped maintaining it. Occasionally I'll get a pull request that I merge in, but that's the extent of my development. If you're just looking for an example of programmatically creating an avatar though, the code should help.

AlexanderYoshi commented 9 years ago

That's what I need. Thank you, Mythgarr.

I still don't understand how to create a mask from it though.