SVG Loader/Native Format

Discuss new features and future development.
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

SVG Loader/Native Format

Post by lucas »

I'm sure this wouldn't go into the main library, but an SVG Loader (that turns an SVG into a body with shapes) wouldn't be that hard would it?
Otherwise, a much easier (and perhaps better) solution would be to make an editor which save chipmunk files, which could just be xml files like so:

Code: Select all

<chipmunk>
    <space>
        <body name="bodyA" mass="5.2" px="300" py="222"><!--you could have the loader calculate the moment of inertia-->
            <shape type="circle" radius="8" friction="0.4"/>
        </body>
        <body name="bodyB" mass="10" px="200" py="500">
            <shape type="poly">
                <vert x="-2" y="-2"/>
                <vert x="-2" y="2"/>
                <vert x="2" y="2"/>
                <vert x="2" y="-2"/>
            </shape>
        </body>
        <joint type="pin" bodya="bodyA" bodyb="bodyB" /><!--and so on-->
    </space>
</chipmunk>
Just a thought. Maybe I'll learn to parse xml in c++ and do it. :D
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
Kingdom Of Fish
Posts: 21
Joined: Sun Jan 27, 2008 10:56 am
Contact:

Re: SVG Loader/Native Format

Post by Kingdom Of Fish »

Haha, when i took a first glance at the xml code (not having read your message) my first thought was "wtf is my xml code doing here" but then I noticed the difference :P. Btw, great idea. I'm currently creating an app that can load xml specifications of chipmunk bodies and the sprite thats going with it. Using the svg format for setting shapes is a really good idea :) I think i'll try to implement it.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: SVG Loader/Native Format

Post by slembcke »

I know other people have done the same. Maybe we could get one of them to release their code as an addon library.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

Re: SVG Loader/Native Format

Post by lucas »

The only problem with using SVG is it would have to be written by hand, because looking at an svg made with inkscape is unreadable. Either that or a really complicated loader.
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
Blue Prawn
Posts: 22
Joined: Thu Jan 03, 2008 1:36 pm
Contact:

Re: SVG Loader/Native Format

Post by Blue Prawn »

Personaly I feel that loading levels from Inkscape-generated SVG is very simple.

Moreover while saving selecting "Inkscape SVG" instead of "Plain SVG",
Inkscape adds some very interesting arguments with its namespace.
For exemple to get circles I use:

Code: Select all

   cx = get_val "sodipodi:cx"
   cy = get_val "sodipodi:cy"
   rx = get_val "sodipodi:rx"
   ry = get_val "sodipodi:ry"
   assert(rx == ry)
Though to make the main code of the game the more simple related to the level data
I have made a first script that converts the Inkscape-SVG into binary datas.
You can have a look at this converter, it is very simple, only about 100 lines of code,
and quite trivial code, writen in about 30 minutes. This file is called 'mk-level-data.ml'
you can have a look at it in the tarball of the "simple-humble-toy-game" called rolling-moon:
http://www.linux-nantes.org/~fmonnier/O ... g-moon.php

To indicate which elements are of which kind, I've used the XML-editor of inkscape
to add "class" xml attributes, which is valid in svg, and which semanticaly is
close to the use done. The SVG reader then just reads this attribute to know
what to do with the different items.

The only tricky thing would be with non-polygon shapes defined with bezier curves.
I haven't handled this case yet, but it is not hard to convert the cubic beziers into segments.
I have copy-pasted bezier curves code from wikipedia yet in another project, so it
won't be hard at all.

I've seen that xmoto also uses Inkscape as its level design tool.
For C user, maybe there could be some code to steal from there?

I'm sure there should be other freedom software using inkscape too.

And about xmoto, do you know if there is someone who have tryed yet to make
an xmoto clone with Chipmunk? :)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: SVG Loader/Native Format

Post by slembcke »

Blue Prawn wrote:And about xmoto, do you know if there is someone who have tryed yet to make
an xmoto clone with Chipmunk? :)
Not that I know of. I've thought about it. Though I think about a lot of things and get very little done. :(
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
fictionpuss
Posts: 5
Joined: Tue Oct 02, 2007 9:22 pm
Contact:

Re: SVG Loader/Native Format

Post by fictionpuss »

The next version of xmoto will use chipmunk for the objects, but not the Bike:
http://xmoto.tuxfamily.org/
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: SVG Loader/Native Format

Post by slembcke »

Nice! I've played that game before, pretty fun. Fairly off topic though. :p
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
juanpi
Posts: 24
Joined: Wed Jan 30, 2008 3:52 pm
Contact:

Re: SVG Loader/Native Format

Post by juanpi »

Hi all,
So at the moment I am trying to define the XML format to describe cpBody, cpShape. As I can see here, everybody converges more or less to the same format. The question is how can add the description of joints?
My basic solution (I am not a programmer) was to give ids to the bodies and then the joints elements would connect this ids, but I am sure there is a more clear/compact way of doing this.
Can we set up something like Chipmunk XML standard?

There is a "physics simulator" called Phun http://www.phunland.com/wiki/Home that has a perl script (svg2phun) to convert Inkscape's svg to the format they need to load a scene. It would be great if we could do something similar for Chipmunk.

Any ideas?
User avatar
cpk
Posts: 24
Joined: Wed Sep 02, 2009 9:16 pm
Contact:

Re: SVG Loader/Native Format

Post by cpk »

I have taken to using Inkscape for generation of game layers. The "objects" in the game world are placed with rectangles given appropriate ids. The floors are created with lines in inkscape (the evil svg 'path'). I've spent a bit of time looking for an svg path parser into line segments that could be used by chipmunk. It's not simple. You need to be able to deal with quadratic and cubic bezier curves. Can anyone point me to code in the right direction?!

Thanks,
Charles
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests