miletbaker Posted October 22, 2012 Report Share Posted October 22, 2012 Hi, I just wanted to know if anyone was already working on a Moai SDK plugin for Spriter. If not I may have a go at creating something. Regards, Jon Quote Link to comment Share on other sites More sharing options...
Mike at BrashMonkey Posted October 23, 2012 Report Share Posted October 23, 2012 Hmm. I guess your best bet is to post about Spriter in forums specific to the Moai SDK comunity to dtum up interest in Spriter and making a plug-in. Best of luck. In the mean time, We'll do our best to make Spriter so fantastic everyone will want to support it for every dev system. Mike at BrashMonkey Quote Link to comment Share on other sites More sharing options...
laurens Posted November 2, 2012 Report Share Posted November 2, 2012 Any new word on this? Quote Link to comment Share on other sites More sharing options...
miletbaker Posted November 2, 2012 Author Report Share Posted November 2, 2012 Any new word on this? I have made a start on something for this. I am taking my lead from mariocaprino's Love2d plugin https://github.com/capmar/spriter-love2d, where the first step is to convert the SCML file into a lua script rather than get Moai to load the xml into memory at runtime. I have a fair few other commitments and this is just a side project for me but as soon as I have something working I will push it to github and share here. Jon Quote Link to comment Share on other sites More sharing options...
miletbaker Posted November 9, 2012 Author Report Share Posted November 9, 2012 I have made fairly good progress on the Moai library for spriter and pushed an initial commit to github here: https://github.com/miletbaker/spriter2moai There are still a few of issues with the code, in particular with the angles, which are likely down to my miscalculating the angle deltas here or not fully understanding the SCML spec. I need to go back over this and have also seen a helpful post on the forum which may point me in the right direction. Another issue is the animation isn't particularly smooth. I think this could be down to the animation easing but any help with this and the above would be gratefully received. Animations with bones in are are currently not supported. I think this should be easy to resolve and it should simply be a case of incrementing the object positions and angles by their parent bones. Correct me if I am wrong? Lastly, I have had to take the decision to require assets to be packaged into a single texture with Texture Packer. I know this probably isn't ideal but I am not sure it is possible to animate switching decks with MoaiAnimCurvs and would require taking a lower level and more time consuming approach. The added benefit is that you get the performance and memory advantages of using Texture Packer for your Spriter assets. You just need to make sure Texture Packer doesn't add and folder paths to the generated texture mapping lua file. I suspect you can use other texture / sprite packers like Texture Packer with minimal changes to the code. To use the plugin you need to convert the scml to lua. I have taken the same approach mariocaprino took with his Love2d plugin and created a python script to convert the scml file. Again I know this probably isn't the ideal solution for everyone but I wanted to avoid loading and parsing XML at runtime seeing as the most likely target platforms would be smart phones and tablets for developers using Moai. The readme on Github should have all the instructions you need. Feel free to submit comments or pull requests if anyone wants to enhance it further / or help iron out the remaining issues. I'll also post this in the Moai forum and see if anyone is interested in assisting. Thanks, Jon Quote Link to comment Share on other sites More sharing options...
grimfang4 Posted November 10, 2012 Report Share Posted November 10, 2012 Those images look similar to my early results. The second one in particular I fixed by offsetting the pivot points by half the image dimensions. Quote Link to comment Share on other sites More sharing options...
lucid Posted November 15, 2012 Report Share Posted November 15, 2012 also, looks like angles could be reversed (try fix with angle=360-angle) Quote Link to comment Share on other sites More sharing options...
miletbaker Posted November 16, 2012 Author Report Share Posted November 16, 2012 Hi Guys, Still struggling with this. I recoded a video and it does look like the example in grimfang4's video for inverted angles but I have tried inverting angles which seems to make it worse and also offsetting the pivot points as also suggested. For the pivot points Moai need these as pixel offsets rather than proportions and I simply multiply the width and by the pivot_x proportion and height * pivot.y. I don't think the issue is here as the first frame shows all the parts correctly placed and if these values are adjusted the monster is all over the place. For the angles I need to work out the rotation deltas which I am doing as follows: spin = prev_spin #int(keyframe['spin']) if spin >= 0 and iii > 0 and new_angle != prev_angle: #clockwise angle = new_angle - prev_angle if new_angle > prev_angle else (360 - prev_angle) + new_angle elif spin < 0 and iii > 0 and new_angle != prev_angle: #anti-clockwise angle = new_angle - prev_angle if new_angle < prev_angle else (-360 - prev_angle) + new_angle else: angle = new_angle prev_angle = angle In the python code above from the scml2moai.py converter. spin is find the spin value on the previous keyframe rather than the current keyframe (which I believe is correct as the spin value specified the direction to be spun, not what has just been spun). iii is just a keyframe index. If we are on the first keyframe the delta is 0. For all other keyframes if we are going clockwise we would out a positive delta and if anticlockwise a negative delta. I have run through the maths manually on paper and also looked at the output in the lua file compared to this. For example for forearm_a here:https://github.com/miletbaker/spriter2moai/blob/master/example.lua#L215 and it looks okay. Thanks for the help so far guys I am sure it is something simple / obvious I am missing. Time for a break I think! Quote Link to comment Share on other sites More sharing options...
grimfang4 Posted November 16, 2012 Report Share Posted November 16, 2012 Maybe it is the angle calculation? The one you posted looks suspicious because they shouldn't be deltas. You should be interpolating (tweening/lerping) between them. Here's the relevant code (edited slightly) from SCMLpp.cpp line 2628: if(prev_spin != 0) { if(prev_spin > 0 && prev_angle > next_angle) prev_angle = lerp(prev_angle, next_angle + 360, t); else if(prev_spin < 0 && prev_angle < next_angle) prev_angle = lerp(prev_angle, next_angle - 360, t); else prev_angle = lerp(prev_angle, next_angle, t); } 't' is the interpolation ratio (a free parameter): t = (current_time_in_animation - prev_time)/float(next_time - prev_time); And lerp() is defined like so (SCMLpp.cpp line 2452): inline float lerp(float a, float b, float t){ return a + (b-a)*t;} Quote Link to comment Share on other sites More sharing options...
miletbaker Posted November 16, 2012 Author Report Share Posted November 16, 2012 HI Jonny D Thanks for this. I am not sure to be honest. I am not tweening the objects myself but rather trying to leverage Moai's MOAIAnimCurve class which basically does the tweening for me. My approach is to extract the SCML file into a lua table which is stored in a .lua file and then the MOAI library I created iterates over the lua table to generate the MOAIAnimCurve keyframes. A MOAIAnimCurve is created for each property being animated here: https://github.com/miletbaker/spriter2m ... er.lua#L69 and then are linked to the MOAIAnim here https://github.com/miletbaker/spriter2m ... er.lua#L26 I have based my approach on the example the MOAI SDK provides for flash here: https://github.com/moai/moai-dev/blob/m ... n/main.lua There is another example of MOAIAnimCurve here: https://github.com/moai/moai-dev/blob/m ... s/main.lua The MOAI transform in question is linked to the Z_ROT property on the MOAITransform class (Unfortunately not very well documented here: http://getmoai.com/docs/class_m_o_a_i_transform2_d.html) But maybe I have misunderstood... Quote Link to comment Share on other sites More sharing options...
miletbaker Posted November 16, 2012 Author Report Share Posted November 16, 2012 Okay you are not going to believe this. Talk about my mind overcomplicating the mater. On writing my response above I suddenly thought, hang on these are keyframes so should be the angle we are seeking. Outputting the angles as they are in the scml file solves the issue. The only issue now is how to resolve the spin direction. The example animation works but I suspect there are instances where this will break as I make no use of the spin value. I will push the updated code to github now and think further on this. Thanks for your help guys, if anything you helped me think it through. Quote Link to comment Share on other sites More sharing options...
lucid Posted November 16, 2012 Report Share Posted November 16, 2012 hi milet currently Spriter always uses the shortest direction to spin. which if you have this already it's fine for now (careful with changes like 359 to 2, that you don't take the long way around but in the scml documentation it gives a detailed description of how to do spin tweening so it's always going the right way. also keep in mind, Spriter will be expanded later to give you options for spin direction so spin will be important Quote Link to comment Share on other sites More sharing options...
miletbaker Posted November 17, 2012 Author Report Share Posted November 17, 2012 hi miletcurrently Spriter always uses the shortest direction to spin. which if you have this already it's fine for now (careful with changes like 359 to 2, that you don't take the long way around but in the scml documentation it gives a detailed description of how to do spin tweening so it's always going the right way. also keep in mind, Spriter will be expanded later to give you options for spin direction so spin will be important Thanks for the heads up lucid. The plugin does indeed use the shortest distance. I will investigate how I can implement this with Moai. Quote Link to comment Share on other sites More sharing options...
paw9000 Posted January 26, 2013 Report Share Posted January 26, 2013 hi First thanks for working on this converter! I'm made some comments on how I got the angles to rotate correctly in the getmoai forums, its kind of a hack, but got your sample to spin correctly and smothly in moai. http://getmoai.com/forums/post8608.html#p8608 Now I'm having some problems getting your python script to run. I've never used Python before today so my apologies if this is a noob mistake on my part but here are some of the issues I'm having so far: Without changing anything if I try to run the script like this I'll get the following error: python scml2moai.py test.scml I'll get errors like this: File "scml2moai.py", line 102print "Writing animation to %s" % outpath ^ SyntaxError: invalid syntax The carrot is pointing to the 2nd quote mark I'm using Python 3.3, not sure if that maters. I commented out all of the print statements and then I started getting this error: Traceback (most recent call last):File "scml2moai.py", line 199, in main() File "scml2moai.py", line 181, in main xml.sax.parse (inpath, handler) File "C:\Python33\lib\xml\sax\__init__.py", line 33, in parse parser.parse(source) File "C:\Python33\lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python33\lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python33\lib\xml\sax\expatreader.py", line 207, in feed self._parser.Parse(data, isFinal) File "C:\Python33\lib\xml\sax\expatreader.py", line 304, in start_element self._cont_handler.startElement(name, AttributesImpl(attrs)) File "scml2moai.py", line 52, in startElement keys = self.timelines[timeline] if self.timelines.has_key(timeline) else Ord eredDict() AttributeError: 'OrderedDict' object has no attribute 'has_key' Any ideas? Quote Link to comment Share on other sites More sharing options...
laurens Posted January 28, 2013 Report Share Posted January 28, 2013 my guess is that you'll need to run a python version in the 2.x range, which should be available from python.org or your distro if you're running Linux Quote Link to comment Share on other sites More sharing options...
Ascorbius Posted February 6, 2013 Report Share Posted February 6, 2013 Hi Milet, I just wanted to post on here to give you some encouragement. I'm investigating Moai as a potential (and very likely) candidate for our next game - we're keeping things old school, 2D platforms -but with Skeletal animation sprites (built in Spriter) I've run your previous example without bones and it works like a charm (when the minor tweak is made for the angles and the smooth animation). I'm really impressed with your progress thus far. We'd like to use the bones though, so I'm hoping that you're making good progress :) I wish you the best and hope that if you need any assistance, I'll help if I can. 8-) Quote Link to comment Share on other sites More sharing options...
bitraven Posted March 4, 2013 Report Share Posted March 4, 2013 I'm interested in getting bones working for this plugin too ... I'm willing to help out is there any recent progress? Quote Link to comment Share on other sites More sharing options...
samcsss Posted June 22, 2013 Report Share Posted June 22, 2013 Hi guys, Don't know how many of you are still looking for Moai support for Spriter, but I've coded up a little demo that works with bones. (Though be warned, I just got my sample file working and haven't really tested it with anything else yet) Its based off miletbaker's python script. I don't do python so good, and the data structure in that script really can't pull out the bone information, so I coded up a command line tool in C++. I was originally trying to get the transformations working with matrix math, but it was not quite working. Then I came across grimfang4's work and fooled around with that. While this is probably a bit more stable in terms of reading the xml, I couldn't quite get this outputting the lua format that miletbaker's plugin uses, so I gave up on that approach. I did however steal grimfang4's transform class, which solved my transformation problems. So, the final tool will take a SCML animation that includes bones, and will output a .lua file that can be used by miletbaker's lua code without change. I will update as I solve problems, but this is really just something Im fooling around with, so I'm hoping that anyone who finds it useful will take it and run with it. So here's the git for it https://github.com/baronpantaloons/NekoPunch.git My Scml2Moai tool lives in the tools folder. There is a complete scml sample inside the 'raw' folder, and the final built resource lives in the 'neko_punch/resources' folder (so if you rebuild it, copy the lua file to this folder to get it in the moai project) As a bonus, there's also a custom OSX host that uses opengl. Enjoy... and let me know if you found it helpful. Quote Link to comment Share on other sites More sharing options...
laurens Posted July 3, 2013 Report Share Posted July 3, 2013 I haven't looked at it yet, but it sounds very cool! Thank you for your work! I hope to take a look i the future! Quote Link to comment Share on other sites More sharing options...
Rurouni Posted May 15, 2014 Report Share Posted May 15, 2014 Hi! Is there any work in progress on the Moai implementation? Using bones would be awesome! scml2moai has some bugs on not so complex animations... but still is very useful! Thanks! Quote Link to comment Share on other sites More sharing options...
Rurouni Posted May 16, 2014 Report Share Posted May 16, 2014 So, the final tool will take a SCML animation that includes bones, and will output a .lua file that can be used by miletbaker's lua code without change. Hi! Is there any way to get running it on Linux? It's build on Xcode and I don't see any way to compile it with GCC. Thank you! Quote Link to comment Share on other sites More sharing options...
samcsss Posted May 18, 2014 Report Share Posted May 18, 2014 @Rurouni I havent looked at that code in about a year. The tool to convert from SCML to lua is written in python, so you should be able to get that working in linux. Is in the tools folder. The xcode project is the moai host. The moai engine comes with a linux version, so you'll want to download the moai_dev git repo and build the linux host, and you should be able to run main.lua in the neco_punch folder without any drama. FYI, all this has turned out to be quite a bit of work to get going. I'm moving away from Spriter for the moment and towards Spine with Cocos2D since thats a more stable combination (moai 1.5 is a bit unstable at the moment) Quote Link to comment Share on other sites More sharing options...
sshukul Posted May 6, 2016 Report Share Posted May 6, 2016 If anyone is still looking to use Spriter with Moai, I've built upon the great work of miletbaker and kreios to create a fully functional and stable Spriter integration with Moai now. https://github.com/sshukul/MoaiSpriter Kreios' plugin worked with bones at a basic level but it broke in most real world bones animations, as soon as there was nesting of bones with higher level bones moving independently. It also didn't work with custom pivot points, and there was a problem with the "spin" attribute for rotations that went past 360 degrees. Neither of the plugins worked with sprite texture changes or alpha tweens. All of these problems have been solved in this new version, I've also simplified the project structure and added a more complex real world sample project of a scorpion animation demonstrating these features. The exporter is built upon the C++ version made by kreios, so you will need to compile it unless you use Mac 64 which is what I have. Please also note you'll have to git clone --recursive to get a submodule that is included in the repo. This submodule can also be cloned into your Moai game folders to integrate exported animations. In the future I intend to add all remaining Spriter features such as meta-data etc. as well as exporter binaries / build setups for Windows and Linux to save people the trouble. For more details, please read the README on github. Please let me know if anyone finds this useful or needs more features urgently. Quote Link to comment Share on other sites More sharing options...
Mike at BrashMonkey Posted May 6, 2016 Report Share Posted May 6, 2016 Great job sshukul, Thanks for sharing! cheers. -Mike at BrashMonkey sshukul 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.