Search Unity

[Release][Free] Unity Sprites And Bones - 2D skeleton animation

Discussion in 'Assets and Asset Store' started by TheRealBanbury, Dec 29, 2013.

  1. Kanapesh

    Kanapesh

    Joined:
    Mar 14, 2014
    Posts:
    1
    This sounds really interesting, I'll try it out ASAP !
     
  2. piXXem

    piXXem

    Joined:
    Mar 30, 2013
    Posts:
    6
    Thanks Banbury, my bad, I didn't try all parameters :p

    If I have time, i ll contribute by making a tutorial for a biped character (with running, jumping, shooting and switching clothes).
    By the way, I forked the Github, maybe I ll add some little features.
     
    Last edited: Mar 15, 2014
  3. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    No problem. That's what I'm here for. :)
     
  4. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Actually I've been looking into exporting the animation frames to PNG, I think it can probably be done with this:

    http://docs.unity3d.com/Documentation/ScriptReference/Application.CaptureScreenshot.html

    or this:

    https://docs.unity3d.com/Documentation/ScriptReference/Texture2D.EncodeToPNG.html

    I'm sure it will need ARGB32 to handle the transparency though.

    Basically have a camera created for taking screenshots, have a script attached to the camera that takes them at the resolution of the camera, and outputs them at a variable of frames per second you want to export for the PNG sequence. Play the animation and have it spit out the PNGs to files for the FPS specified.

    It might be possible using something like this, but may need Unity Pro (I have Pro BTW) for the render texture:
    http://answers.unity3d.com/questions/12070/capture-rendered-scene-to-png-with-background-tran.html

    This is also helpful:
    http://forum.unity3d.com/threads/45193-Render-Particles-to-Animated-Texture

    I'll see what I can cook up this week. Then we can add exporting animations to PNG sequences, and maybe even an Atlas for them.

    I'll also see what I can do about export/import for your pose data in an external file, I'll look more into the pose structure to see how it is done. I'm not that great of a coder, but maybe I can start something that someone can finish. This may be the start of making Unity a general 2D animation tool as well.
     
  5. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Well, that's why I made Sprites And Bones open source. To see what ideas others come up with.
    But without the render to texture feature (which is PRO only), you'll be hard pressed to render an animation to still frames. I wish you the best of luck with it.
     
  6. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    I changed the Sprite to Advanced, checked Read/Write Enabled and recreated my mesh, but I still got the error :

    SkinnedMeshRenderer requires a mesh with skinning or blendshape information.

    I can't use Skin2D because of this.

    Any advice?
     
  7. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Could you upload your project, where I can download it? Then I can have a look at it.
     
  8. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    After a whole week the review of Sprites And Bones is still 'pending'. I'm just glad, I don't have to do any business with these slackers.
     
  9. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Actually I got it to work using bitbutter's AlphaRendererHD.unitypackage, I'm going to do a modified script for Sprites and Bones. I'll upload the package to the Github when I am done.
     
  10. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    That sounds interesting. It could be useful for a lot of things.
     
  11. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Tried to commit to the Github, but I am not too familiar with it so it seemed to not work. Anyway here is a package with the files and an example.
     

    Attached Files:

  12. LightningMcNuts

    LightningMcNuts

    Joined:
    Dec 13, 2012
    Posts:
    1
    Hi all,

    Just wanted to drop in to thank Banbury and all the others who contributed for the awesome library!
     
  13. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Cool thanks! I just made a pull request for my AnimationToPNG script. I am going to post this on the Wiki as well.

    Edit: It's on the wiki here: http://wiki.unity3d.com/index.php/AnimationToPNG
     
    Last edited: Mar 27, 2014
  14. Rirath

    Rirath

    Joined:
    Dec 5, 2013
    Posts:
    30
    Saw this on /r/gamedev over on Reddit. Just wanted to drop by and thank the folks responsible. Nice work!

    And, as always, thanks to TheRealBanbury for his continued improvements.
     
  15. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    @playemgames: Do you think, you could make a short video tutorial, on how your script works with SpritesAndBones?
     
  16. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Yeah I'll see what I can do this afternoon :)

    Edit: Finished it, the video is here:

     
    Last edited: Mar 28, 2014
  17. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    This is a really nice tutorial. You have a good voice. Want to make all my tutorials :D.

    Instead of using black and white backgrounds, I would suggest using a single camera with a magenta background. Magenta is traditionally used for sprite backgrounds. With only one camera, it could be auto created with the AnmationToPNG component. And there would be no limitation of the screen size. I will give it a try and see what happens.
     
  18. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Okay the single camera setup didn't really work out that well.
    But I made a few other changes. The cameras are created automagically. And now there is a menu 'GameObject/Create Other/AnimationToPNG'. So no more prefab. This makes to whole thing a one click affair with almost zero configuration.
     
    Last edited: Mar 28, 2014
  19. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    The reason I did it with a black and white camera was to create an alpha channel for a transparent background. Using render textures with Unity Pro it works really well, but the only way I could get it to work in Free was to split the screen and then merge the 2 sides into one image and the alpha channel is created through the difference of the black and white background.

    Really if you just want to use a solid background it is possible, but the code would have to be changed to just have the one camera with a solid background and eliminate the alpha generation code. I figured if people wanted to add a solid background they could do that in their image editor if they want, as I believe most people would want transparency off the back to do their own image manipulation if needed. Maybe we can make that an option for the script and have it create the camera objects on its own. I can look into it later today.

    And I'll see what I can do about the tutorials, it took me a while to get a capture set up as I had never done this before :)
     
  20. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I already did the camera creation code. See above :).
     
  21. Gnurro

    Gnurro

    Joined:
    Mar 28, 2014
    Posts:
    1
    Basic physics/ragdoll stuff would be awesome. I'm especially looking for spring restraints between bones for dynamic animation. (Or can i hijack the kinetics for that?)
     
  22. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    The Asset Store Team just rejected Sprites And Bones. Mostly because they don't like open source and try to force me to relicense the asset under some proprietary license. I wouldn't do that, if I could. And I can't, because some of it was written by other people, including users on this forum.
    So Sprites And Bones will not be on the Asset Store and this severely impairs my ability to market it. This thread is the only thing, that keeps Sprites And Bones visible. But I can't bump this thread constantly. With the level of traffic on this board it will sink to the bottom very quickly.
     
  23. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Oh I totally missed that! Sorry! I'll have to try it out!
     
  24. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    I wouldn't worry about it, just keep tooting your horn about it on social media and stuff. It doesn't need to be on the Asset Store at all, just stay active on it and work on it when you can, I'll keep doing the same as I support the community and open source and I like making things that will help others. This is the way it used to be before the asset store, I really missed it, and now this project has brought that out again. I was reading of another guy on Reddit who just open sourced his stuff on the asset store to help benefit everyone as well. Just give it time, polish, and people will come to use this more than any other tool because of it!

    On another note, for the PSD importer I think we would manage the imported textures using TextureImporter to make sure the sprites are imported correctly:

    http://docs.unity3d.com/Documentation/ScriptReference/TextureImporter.html

    This way we can change them before or after they are created if needed. You can see how it is used here:

    http://wiki.unity3d.com/index.php?title=TextureImportSettings

    And here:

    http://www.jasperstocker.com/2013/0...s-readable-when-editor-scripting-for-unity3d/

    And here as well:

    http://spritesheetpacker.codeplex.com/discussions/476590

    And a look at how this TexturePackerImporter works with Unity sprites as well:

    https://github.com/ThirdPartyNinjas...pts/Editor/Importers/TexturePackerImporter.cs

    I'll look into it tonight.


    Ragdoll is definitely on the list to tackle, most likely the restraints will be covered when ragdoll is implemented. Banbury would know more about that one.
     
    Last edited: Mar 29, 2014
  25. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Hey Banbury, OK I didn't figure out the texture importing thing for the PSD importer, but I may have figured out a way to do the Sprite Atlas using the PSD layers:


    Code (csharp):
    1.     private void CreateAtlas() {
    2.         // Texture2D[] textures = (from layer in psd.Layers where layer.Visible select CreateTexture(layer) into tex where tex != null select tex).ToArray();
    3.  
    4.         Texture2D[] textures;
    5.  
    6.         // Track the spriteRenderers created via an array
    7.         SpriteRenderer[] spriteRenderers;
    8.  
    9.         int zOrder = 0;
    10.         foreach (var layer in psd.Layers) {
    11.             if (layer.Visible  layer.Rect.width > 0  layer.Rect.height > 0) {
    12.                 Texture2D tex = CreateTexture(layer);
    13.                 // Add the texture to the Texture Array
    14.                 textures[zOrder] = tex;
    15.  
    16.                 GameObject go = new GameObject(layer.Name);
    17.                 SpriteRenderer sr = go.AddComponent<SpriteRenderer>();
    18.                 go.transform.position = new Vector3((layer.Rect.width / 2 + layer.Rect.x) / 100, (-layer.Rect.height / 2 - layer.Rect.y) / 100, 0);
    19.                 // Add the sprite renderer to the SpriteRenderer Array
    20.                 spriteRenderers[zOrder] = sr;
    21.                 sr.sortingOrder = zOrder++;
    22.             }
    23.         }
    24.  
    25.         // The output of PackTextures returns a Rect array from which we can create our sprites
    26.         Rect[] rects;
    27.         Texture2D atlas = new Texture2D(atlassize, atlassize);
    28.         rects = atlas.PackTextures(textures, 2, atlassize);
    29.  
    30.         // For each rect in the Rect Array create the sprite and assign to the SpriteRenderer
    31.         for(int i = 0; i < rects.Length; i++)
    32.         {
    33.             Sprite spr = Sprite.Create(atlas, rects[i], new Vector2(0,0), 100.0f);  // The 100.0f is for the pixels to unit, maybe make that a public variable for the user to change before hand?
    34.  
    35.             // Add the sprite to the sprite renderer
    36.             spriteRenderers[i].sprite = spr;
    37.         }
    38.  
    39.         SaveAsset(atlas, "_atlas");
    40.  
    41.         foreach (Texture2D tex in textures) {
    42.             DestroyImmediate(tex);
    43.         }
    44.     }
    Let me know if this works for you, I wasn't sure how you compiled the PSD Importer so I couldn't test it.

    Also tested the PSD import in 2D mode and it only imported the layers and turned them to PNGs but did not create and assign the sprites to the sprite renderers on the game objects that were created.
     
    Last edited: Mar 29, 2014
  26. LeftyTwoGuns

    LeftyTwoGuns

    Joined:
    Jan 3, 2013
    Posts:
    260
    This is a really interesting tool

    Does it work with Mecanim?

    And are these actual deform bones, as in you can use IK in-engine for procedural animation?
     
  27. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    I does work with Mecanim. And there's no reason the IK shouldn't work with procedural animation. Actually the IK system is procedural animation. It's calculated at runtime.
     
  28. kshaja

    kshaja

    Joined:
    Sep 22, 2010
    Posts:
    148
    Great tool!!!
    Please continue making it more powerful and beautiful!
    Open source is the way, sharing the knowledge will help this world to be a better place!
    Don't let them stop you...
     
  29. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Who's "them"?
     
  30. Remiel

    Remiel

    Joined:
    Oct 17, 2012
    Posts:
    105
    I just wanted to say that you are awesome TheRealBanbury.
    I really respect what you are doing and how you are giving away for free such an incredible tool for everyone to play with.
    You should add a "donate" button somewhere on your site because I think there would be a lot of people who want to show their thanks and support by little (or big) donations. Some might even feel guilty by not giving something back. :)

    All the best to you and I hope you don't get discouraged. There are always going to be mean people but what you are doing is noble and right, and you should feel proud.
     
  31. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    He is awesome! I've been working with him to get the PSD Importer working for it, it looks like it is just about ready to go, I'll try to add groups for it, so you can maybe set up your images in a psd in a hierarchy like in the PSD file, but I'm still learning how things are organized with it. Right now it can create an atlas and sprites from the layers or create separate pngs for the layers and their sprites. It also has everything lined up like in the PSD file, so no having to position stuff like you had it in the PSD. Pretty cool huh?
     
  32. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    For tax reasons I can't take any donations. I'm doing this for fun and taxes are no fun at all.

    Small gifts would be okay, I guess. So if you feel the need to express your gratitude in a tangible way, I will add a short wish list to the first post in this thread.

    THEM!
     
  33. kshaja

    kshaja

    Joined:
    Sep 22, 2010
    Posts:
    148
    He he, a million dolar question ;)

    P.S.
    Great product, don't stop...
     
  34. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I hate taxes... there's nothing worse than spending hours and hours trying to figure out how to properly report your $40 in game development revenue lol.
     
  35. SkyWay

    SkyWay

    Joined:
    Aug 11, 2012
    Posts:
    1
    I'm going to try and dive in to this. I own Spriter, but there's no proper Unity support for it, just as I would need it :(

    Edit: Oh my...this was my first post on the forums.
     
    Last edited: Apr 11, 2014
  36. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Welcome to the forum. Have fun with Sprites And Bones.
     
  37. Denvil

    Denvil

    Joined:
    Jul 31, 2013
    Posts:
    5
    Hi.

    I was digging around with this addon and made few changes to make it work with multiple skinned meshes. I had to revamp little how character is build in scene.

    http://i.imgur.com/YR6ZjQ5.png

    I made Graphics "folder" for all skinned meshes. Here I have one but you can add more if needed there. Skin2D takes now only
    bones you wish to influence selected Skin2D element. As I did this I had to ingnore Bone.index and used the array indexin in Skin2D and in weightpainting.

    Bone influences do not match bones. I don't know if you already figured how to remove this error. This error was tied with Bone.index. When using bones in wrong order (SkinnedMeshRenderer bone array indexes didn't match with bone.index in scene.).

    I attached diff for these changes here. Nice work with this one. You don't usually see open source packages in unity so here is something back.
     

    Attached Files:

  38. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Thanks for the patch. I really appreciate it. I will have a look at it, as soon as I can.
    I didn't even know, that there was a problem with the skinned meshes. I thought I had it working. Could you describe, how the bug can be reproduced?
     
  39. Denvil

    Denvil

    Joined:
    Jul 31, 2013
    Posts:
    5
    Not a problem when using only one skinned mesh and all bones are indexed correctly. I noticed that "Bone influence do not match bones" message in your tutorial 4 video. In this patch you cannot use bone index for BoneWeight.boneIndex0 as whole skeleton is not used in Skin2D component and this messes up SkinnedMeshRenderer indexin. For example I use bones 1,3 and 5 for chest piece and renderer wants 0,1,2 to keep bones in right indexes.

    This came from creating skeleton where all body part where separated Skin2D elements and I wanted to separate bones and graphical elements here.

    Edit: Quick video how I used this.
     
    Last edited: Apr 13, 2014
  40. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Could you upload your project somewhere? It would help me understand, what you are trying to do.
     
  41. Denvil

    Denvil

    Joined:
    Jul 31, 2013
    Posts:
    5
  42. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    @TheRealBanbury still haven't figured out groups yet, but maybe you should compile the DLL with the latest changes and include the PSD Importer here or in a new post. It might be beneficial to someone else, or maybe someone else can figure out what I can't. I'll let you know if I come up with anything more soon.
     
  43. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Sadly this group stuff isn't as easy as it looked at first. And right now I'm busy with something else. I'd like to ask you, to take over the PSD importer project completely. You seem more than able to handle it. Actually you know much more about the intricacies of Unity than me.
    Also I think it would be better to move discussion of the PSD importer to its own thread. That would make it easier for interested people to find it.
     
  44. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    @Denvil:
    I have after some thought decided not to use your patch. I never intended to support multiple skins on the same skeleton. It makes things really complicated and for me too hard to understand. I would suggest to use two skeletons instead, that are parented together.
    I have also added support for non-deformable bones just now. The change is in the unstable branch, if you want to test it. The deform checkbox in the Bone component does something now. If not checked, the bone will ignored, when the bone weights are calculated. This at least allows to mix deformable and non-deformable bones in the same skeleton.
    I really hate to reject a patch, since that's what I'm always clamoring for :(. Of course you're free to use your changes anyway. And others might want them, too. TheValar mentioned, that he wanted to use multiple deformable meshes, I believe.
     
  45. Denvil

    Denvil

    Joined:
    Jul 31, 2013
    Posts:
    5
    Multiple deform meshes is something I need so I think I try to keep it. I made few changes how Skin2D works and calculates weights. I moved calculating weights to skeleton. Now you can add as many Skin2D objects to skeleton as you want. They are set same as sprites. Just add mesh to mesh filter and material to skinnedmesh component.

    When Calculate weights is pushed on skeleton it calculates all weights to Skin2D components inside its hierarchy and adds bones. This must be done if new bones are added to skeleton after weights calculation so that they appear in weight painting. Other skin examples work is skin is dropped inside skeleton and not outside. I added updated example project to zip and codes can be found in my fork in github if there is interest for this.

    In test scene it should play small animation using to skinned meshes if you press play.

    https://dl.dropboxusercontent.com/u/51709162/UnitySpritesAndBones_multiple2.zip
     
    Last edited: Apr 14, 2014
  46. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    No problem! I'll set up a new thread for it as soon as I get done with some polish here with my game. I think for now it is pretty functional, the group stuff would be good to auto set up hierarchies, but I have to look into it a bit deeper.
     
  47. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    hi i will try and ask question if needed but first ! ? the projet is stay alive ?

    $8b8b5.jpg

    i look trouble with uv texture must set in 512
     
    Last edited: Apr 16, 2014
  48. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    $8b8V0.jpg
    $8b97m.jpg

    ok i think's it's working !
     
  49. reiniat

    reiniat

    Joined:
    Apr 3, 2014
    Posts:
    6
    Hey i was reading the page 2 and i noticed that your solution for turning towards another direction is rotating along the y axis.
    Well thats going to mess up lighting,
    In 2D, sprites cannot be illuminated from behind. Rotating sprites works with ambient light.... But it wont work with any other kind of lights.
    In 3D, meshes can only render one side because of culling....
    So if someone wants to use lighting in his project (like me) the only solution i can think of is using cubes instead of planes or mirroring lights along the camera axis.... And none of that is performance friendly :p

    Im sure there should be a way to flip the character correctly, ill start searching when i get home
     
    Last edited: Apr 26, 2014
  50. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    @kilik128
    Let's say the project is on hiatus. When more people use it or even contribute to it, I'll be much more inclined to start working on it again. I'd also suggest, bugging Unity to allow open source projects on the Asset Store.
    I will continue to monitor this thread and answer any questions, that may arise.

    @reiniat
    Flipping the normals of the mesh could work. If you can come up with a good solution, I will integrate it.