Thursday, September 13, 2012

Skeleton Based Sprite Editor

I am finally done with my Skeleton based sprite editor. Almost within 10 days of development my app is ready to use.

Features
  1. It can create skeletons with bones and add image over them.
  2. It can animate the skeletons easily with better motion, just like happens in reality.
  3. Joints behave realistic when moved since the skeletal engine has forward and inverse kinematics implemented.
  4. Made using java, therefore portable on most of operating systems. Tested on Windows & Linux.
  5. Export images of the animations.


Below is a snap of app running in Windows XP.






Limitations / future plannings:
  1. Export of videos. However you can use external snap apps to achieve it.
  2. Documentation, there is no documentation right now, but very soon I'll pack the app with tutorial PDF.
  3. Locked at 30FPS.

Download URL:
SpriteEditor_binary.7z ( version 2013.1.24 )

SpriteEditor.7z ( version 2013.04.02 )




How-to:
To test the app,
1. On Windows: double click the ".bat" file, from Menu click "Open Skeleton For Animation", then select human.skeleton from the res folder of this app from where you executed the bat file. A model will be shown in the screen on right of app window. Go to "Manage Animations" tab. Select any animation e.g. Jump. Click "Work on selected animation", click animate. Use the slider to control  animation speed. Never forget to click "Work on selected animation".

On Linux: execute the shell / .sh file from terminal. Or give executable flag to the sh file from its properties and double click it. The same as above in windows. Please report any bug you find.


If you want more powerful application then head towards Animata:
http://animata.kibu.hu/index.html

This little app is enough to let you achieve complex 2d animation/morphing you desire.



Search TAGs:
Sprite editor skeleton editor sprite maker skeletal animation system skeletal sprite

Monday, July 16, 2012

pstops tutorial (psutils)

I have recently started to port my game engine GGE to HTML5. So i downloaded javascript & HTML5 tutorials (PDFs) from http://www.tutorialspoint.com/.


But now a days i only keep pocket references for technologies i use instead of heavy books. So i wanted to make a pocket version of those PDFs. I found "pstops" after google'ing, in just an hour i was irritated by the mangled parameters it needed and badly documented manpages & stuffs on internet.


But these two pages made my concept clear and i achieved my task in few minutes.


[REF1] Read this first:
http://wiki.scribus.net/canvas/How_to_make_impositions_with_pstops

[REF2] Then ( this will make you clear about what exactly pstops does):
http://code.google.com/p/uwisdom/wiki/Pstops

My own description ( i assume you have read REF1):
pstops => postscript to postscript converter with desired arrangements, page layouts and sizes.

I will describe this powerful utility by small implementation because that in run accomplishes many people's job.

For experiments please get a ps file of atleast 16 pages. You can convert a PDF into ps by using pdftops utility (its a part of psutils). I am using 23 page file. Lets do some ps conversions.


1. Flip all the pages vertically Or horizontally
vertically:
pstops '1:0V' in.ps out.ps 



Horizontally:
pstops '1:0H' in.ps out.ps 



Description:
As you can see the parameters of pstops are:

pstops  [ -q ] [ -b ] [ -wwidth ] [ -hheight ] [ -ppaper ] [ -dlwidth ] pagespecs [ infile [ outfile ] ]


Most of us have difficulty in pagespecs parameter only. Which is described below:

pagespecs   = [modulo:]specs
specs          = spec[+specs][,specs]
spec            = [-]pageno[L][R][U][H][V][@scale][(xoff,yoff)]

In our flip example, we used '1:0H', What are these hex like codes? lets dissect -
1 => it tells that we want  to print 1 page of "in.ps" in 1 page of out.ps (A4 by default).
If we want to print 4 pages in 1 A4 page we have to use '4:0', for 8 we use '8:0'

:0  
: sign is followed by SPECS. But we have nothing after 0. It simply means that we want to use original unchanged source pages in output file. With -0 end becomes start and start becomes end page. i.e. page numbers get inverted.

2. Lets print two pages in one side, i.e. total 4 in 1 output page. Portrait mode 
pstops '4:0' in.ps out.ps
output => [1] [2] [3] [4] [5] [6] Wrote 6 pages, 1250990 bytes

We get 6 pages in output. But, upon seeing out.ps why we get only 6 pages printed from source instead of all pages? The answer is simple: Did we specified how and where the pages had to be printed? we told to print 0 only i.e. 1st page ( 0 index => 0+1 page number ) of every block.

You don't know what block is? Please refer to REF1 above. In brief i also write here:
Blocks = total pages in input file / total pages we want in our 1 page of output file

1 block simply means number of input pages we want to be printed in 1 output page, above we told to print only 0th index Or 1st page of every block. That is why only 1st pages were printed.

Below is the proper command to print all pages.
pstops '4:0@0.5(0.0w,0.5h)+2@0.5(0.0w,0.0h),1@0.5(0.0w,0.5h)+3@0.5(0.0w,0.0h)' in.ps out.ps

It will output 2 portrait pages per side. Lets understand all the parameters:
4: => 4 input pages / 1 output page

0@0.5(0.0w,0.5h) 
0 => 0th index of block i.e. 1st page
(0.0w,0.5h) => move right by 0% of page width. 50% of height. AFAIK the w,h are of source page.
@0.5 => scale to become 50% of original size.

+2@0.5(0.0w,0.0h)
+ => continuing page on 1st side.
2 => 2nd index of block i.e. 3rd page
(0.0w,0.0h) => no movement, just remain at output's Origin i.e. left-bottom. Just like Cartesian coordinates.
@0.5 => scale to become 50% of original size.

NOTE:
1. x,y are offsets, this is what i have understood, they are not exact render start points. Therefore you should have noticed to draw from top we just have to go 0.5h ( half of output page height instead of full height). 

2. I have not used rotations. You should keep in mind that after rotation the origin of that rotated page still remains at its own left-bottom. So the whole output will change after using rotations. Try it:

pstops '4:0L@0.5(0.0w,0.5h)+2L@0.5(0.0w,0.0h),1L@0.5(0.0w,0.5h)+3L@0.5(0.0w,0.0h)' in.ps out.ps

It outputs blank pages! You know why?
Because when we rotated left (imagine you are holding the paper at left-bottom and rotated it left. Then it goes outside of the output page boundaries. For that you have to translate all pages by full width.

so try this now:

pstops '4:0L@0.5(0.75w,0.5h)+2L@0.5(0.75w,0.0h),1L@0.5(0.75w,0.5h)+3L@0.5(0.75w,0.0h)' in.ps out.ps

in parameters we have described that 1st side of output page will follow this specification:
pages: 1, 3
0L@0.5(0.75w,0.5h)+2L@0.5(0.75w,0.0h)
and the second back side will follow this: ( separated by comma )
pages: 2, 4
1L@0.5(0.75w,0.5h)+3L@0.5(0.75w,0.0h)

Then all the coming blocks will follow these specifications.


For more details below is a simple illustration: please neglect the quality, i made it quickly to illustrate rather than writing 100 lines. :-)
























hope this tutorial will help you to understand how to utilize the power of pstops without Hit n Trials method :-p. Please let me know if you find some bugs or wrong info (if really it is).


Search TAGs:
linux 4-up, make 8 page booklet, linux pstops tutorial, pstops concept, how pstops works, make mini booklets, 8 page booklets 

Saturday, April 28, 2012

Gimp Script for exporting positions of all the layers.

Gimp Script for exporting positions of all the layers.


I have created a Python script which can export layer positions in a text file.

Usability:
Are you using GIMP for creating maps for your game? You want to create a 1024x768 map and put objects in it but cannot export the positions? This script can help you get the positions of your objects.

Procedure:
  1. Run GIMP and create a desired resolution image.
  2. Drag and add your object's images in gimp.
  3. Ensure that you crop the layers so that extra alpha (transparent) areas are not remained in objects.
  4. Duplicate the objects to the numbers you want and place them to positions you want.
  5.  Do same with other objects, backgrounds.
  6. Now export their positions. Filters -> Positioning -> Layers Position Dumper
  7. Put the file name with full path in next dialog. e.g. ~/my_game_map.txt in Linux Or c:\my_game_map.txt in windows. Click Ok.
  8. Now you can check the exported file which contains the positions of all the layers.

How to install the plug-in?
Firstly ensure that you have Python installed in your system. Try to install gimp until you see option of "GIMP python plugin" options checked while installation.

If you haven't installed it please install these packages, This is my installer package: gimp-2.6.11-i686-setup, python-2.5.2.msi

However you can download individual packages by google
gtk-2.12.9-win32-1.exe, pycairo-1.4.12-1.win32-py2.5.exe, pygobject-2.14.1-1.win32-py2.5.exe, pygtk-2.12.1-2.win32-py2.5.exe, python-2.5.2.msi


Or follow this page:
http://www.gimpusers.com/tutorials/install-python-for-gimp-2-6-windows


Install the plugin
Copy the python script to:
WIndows: C:\Documents and Settings\USER\.gimp-2.6\plug-ins
Linux: ~/.gimp-2.6/plug-ins
and restart gimp.

Verify that you have gimp python plugins enabled by following these steps:
Filters -> Python-Fu -> Console

type this:
>>> import gimpfu
>>> gimp.version
(2, 6, 11)


Sample exported file:


Format RATIONAL:
"layer name" X%-Pos Y%-Pos %Width %Height

Format PIXEL:
"layer name" X-Pos Y-Pos Width Height

RATIONAL: "Frame 1.png" 0.000000 0.000000 26.756757 94.634146
PIXEL:    "Frame 1.png" 0.000000 0.000000 99.000000 194.000000

RATIONAL: "Frame 2.png" 26.756757 0.000000 18.918919 99.512195
PIXEL:    "Frame 2.png" 99.000000 0.000000 70.000000 204.000000

RATIONAL: "Frame 3.png" 45.675676 0.000000 25.675676 98.048780
PIXEL:    "Frame 3.png" 169.000000 0.000000 95.000000 201.000000

RATIONAL: "Frame 5.png" 71.351351 0.000000 28.108108 97.073171
PIXEL:    "Frame 5.png" 264.000000 0.000000 104.000000 199.000000

... more dump stripped off



Download:
layer-position-dumper.7z (GIMP v2.6 & 2.8 both )

Raw code:


#!/usr/bin/env python

from gimpfu import *

gettext.install("gimp20-python", gimp.locale_directory, unicode=True)

def layer_position_dumper(img, drawable, filename):
out = file( filename,"w")
out.write( 'Developed by Bindesh Kumar Singh on 26 April 2012\n')
out.write( 'This Plugin is a utility of Greh Game Engine (C) 2009-2012\n')
out.write( 'It dumps the positions of all the layers in a specified text file\n\n')
out.write( 'Format RATIONAL:\n"layer name" X%-Pos Y%-Pos %Width %Height\n\n' )
out.write( 'Format PIXEL:\n"layer name" X-Pos Y-Pos Width Height\n\n\n\n' )
count = 0
w = float( img.width )
h = float( img.height )
for l in img.layers:
if 1 == pdb.gimp_item_is_group( l ):
#print 'group hai'
for gl in l.layers:
x = float( gl.offsets[0] ) * 100.0
y = float( gl.offsets[1] ) * 100.0
lw = float( gl.width ) * 100.0
lh = float( gl.height ) * 100.0
out.write( 'RATIONAL: "%s" %f %f %f %f\n' % ( gl.name, x / w, y / h, lw / w, lh / h ) )
out.write( 'PIXEL:    "%s" %f %f %f %f\n\n' % ( gl.name, gl.offsets[0], gl.offsets[1], gl.width, gl.height ) )
count += 1
else:
#print 'group nahin hai'
x = float( l.offsets[0] ) * 100.0
y = float( l.offsets[1] ) * 100.0
lw = float( l.width ) * 100.0
lh = float( l.height ) * 100.0
out.write( 'RATIONAL: "%s" %f %f %f %f\n' % ( l.name, x / w, y / h, lw / w, lh / h ) )
out.write( 'PIXEL:    "%s" %f %f %f %f\n\n' % ( l.name, l.offsets[0], l.offsets[1], l.width, l.height ) )
count += 1
out.close()


register(
"layer_position_dumper",
"Dump positions of the layers",
"Dumps the offsets/positions of all the layer in a specified file",
"Bindesh Kumar Singh",
"Developed for GrehGameEngine",
"2012",
"_Layers Position Dumper",
"RGB*, GRAY*",
[(PF_IMAGE, "image",       "Input image", None), (PF_DRAWABLE, "drawable", "Input drawable", None), (PF_STRING, "name",       _("_File name with full path"), _("layer_positions.txt"))],
[],
layer_position_dumper,
menu="/Filters/Positioning",
domain=("gimp20-python", gimp.locale_directory)
)

main()



[ 2.8 is currently limited in recursions of groups inside groups. ]

Search tags:
gimp export layer positions, export positions of layers in gim, gimp layer position dumper plugin.