SVGImport.wiki
changeset 334 612048d0890b
parent 331 8a16017f175f
child 363 c6e60247e9d4
equal deleted inserted replaced
333:5b70b52c17c4 334:612048d0890b
     1 #summary Importing an SVG into Hedgewars
     1 #summary Importing an SVG into Hedgewars
     2 
     2 
     3 = Introduction =
     3 = Introduction =
     4 
     4 
     5 This is a quick and dirty description of converting an SVG into hedgewars HWMAP format.  It is not at all pretty. Hopefully someone will make a prettier process.  It currently makes use of Inkscape, vim, perl, g++ and a bit of manual labour.  It looks best in 0.9.18 which makes use of the variable brush size (the examples below use the smallest size, or 16px wide)
     5 This is a quick and dirty description of converting an SVG into hedgewars HWMAP format.  It is not at all pretty. Hopefully someone will make a prettier process.  It currently makes use of Inkscape, vim, perl, g++ and a bit of manual labour.  It looks best in 0.9.18+ which makes use of the variable brush size (the examples below use the smallest size, or 16px wide)
     6 
     6 
     7 
     7 
     8 = Details =
     8 = Details =
     9 
     9 
    10 Open Inkscape.
    10 Open Inkscape.
    13     * Transforms->Store transformation  is set to Optimized
    13     * Transforms->Store transformation  is set to Optimized
    14 
    14 
    15 Open an SVG. Ideally one of simple line art, without too much use of fill or filters.
    15 Open an SVG. Ideally one of simple line art, without too much use of fill or filters.
    16 
    16 
    17 1) Select all in the image and choose ungroup, then combine all paths in the drawing (select them, then choose Path->Combine). 
    17 1) Select all in the image and choose ungroup, then combine all paths in the drawing (select them, then choose Path->Combine). 
    18 Note. I had some difficulty doing that with some images even after repeated use of ungroup. I ended up just going into the SVG file and deleting all the groups.  This usually happens if there are filters in place. Removing all the g tags (keeping the paths inside) in the SVG might be faster than cleaning up in Inkscape.
    18 Note. I had some difficulty doing that with some images even after repeated use of ungroup. I ended up just going into the SVG file and deleting all the groups.  This usually happens if there are filters in place. Removing all the g tags but keeping the paths inside the groups in the SVG in a text editor might be faster than cleaning up in Inkscape.
    19 Also, some paths might be worth eliminating altogether.  In order to get a better idea of what it'll look like, try: View->Display Mode->Outline.  To simulate occluding, you can try combining individual paths first, and using union to combine into larger groups. This takes a bit more work.  If it still doesn't look right, you're going to have to go in and delete nodes, and generally rework the shape to simulate occlusion.
    19 Also, some paths might be worth eliminating altogether.  In order to get a better idea of what it'll look like, try: View->Display Mode->Outline.  To simulate occluding, you can try combining individual paths first, and using union to combine into larger groups. This takes a bit more work.  If it still doesn't look right, you're going to have to go in and delete nodes, and generally rework the shape to simulate occlusion.
    20 
    20 
    21 2) Click on the path, and choose dimensions for W and H that would look good in the game (no more than 4096 for W and 2048 for H).  The Lock button may be helpful here
    21 2) Click on the path, and choose dimensions for W and H that would look good in the game (no more than 4096 for W and 2048 for H).  The Lock button may be helpful here
    22 
    22 
    23 3) Go to File->Document Properties and specify 4096 for W and 2048 for H.  You may want to then reposition the art to be more centred vertically or horizontally.
    23 3) Go to File->Document Properties and specify 4096 for W and 2048 for H.  You may want to then reposition the art to be more centred vertically or horizontally.
    32 7) Save and Quit again
    32 7) Save and Quit again
    33 
    33 
    34 8) Edit the file, and delete everything but the path data.  You should have a one-line file starting with something like  M1234.3 456.78L3298.3 9023.34 and so on.
    34 8) Edit the file, and delete everything but the path data.  You should have a one-line file starting with something like  M1234.3 456.78L3298.3 9023.34 and so on.
    35 If instead you have a format like M 1234.678,9875.323 2345.0,123.45  - you'll want to convert if you want to try the crude script in (10) - otherwise a smarter script would be needed.  Here's some Vim commands for that syntax {{{s/\(\d\) \(\d\)/\1 L\2/g}}}  and {{{s/,/ /g}}} and {{{s/\([LM]\)\s*/\1/g}}}
    35 If instead you have a format like M 1234.678,9875.323 2345.0,123.45  - you'll want to convert if you want to try the crude script in (10) - otherwise a smarter script would be needed.  Here's some Vim commands for that syntax {{{s/\(\d\) \(\d\)/\1 L\2/g}}}  and {{{s/,/ /g}}} and {{{s/\([LM]\)\s*/\1/g}}}
    36 
    36 
    37 The coordinates should now be rounded unless you plan to handle that yourself in some way.  Here is a vim one-liner to do it.
    37 The coordinates should now be rounded for use by the crude script in (10) unless you plan to handle that yourself in some way.  Here is a vim one-liner to do it.
    38 {{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}}
    38 {{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}}
    39 
    39 
    40 
    40 
    41 9) Convert the path data.  Here is a crude script to do that.  Note this one uses a line size of 1 (that's the 0x01 business).
    41 9) Convert the path data.  Here is a crude script to do that.  Note this one uses a line size of 1 (that's the 0x01 business).
    42 If you want larger lines you can pick anything between 0x01 and 0x3F.  That's 16-636.  See the map format wiki page.
    42 If you want larger lines you can pick anything between 0x01 and 0x3F.  That's 16-636.  See the map format wiki page.
    77     }
    77     }
    78 }
    78 }
    79 }}}
    79 }}}
    80 {{{./a.out hwpointdata hwpointdata.Z}}}
    80 {{{./a.out hwpointdata hwpointdata.Z}}}
    81 
    81 
    82 11) Convert to base64 and you're done!
    82 11) Convert to base64 and you're done! (whew)
    83 
    83 
    84 {{{base64 -w0 hwpointdata.Z > mynewhedgewars.hwmap}}}
    84 {{{base64 -w0 hwpointdata.Z > mynewhedgewars.hwmap}}}
    85 
    85 
    86 Enjoy.
    86 Enjoy.
    87 
    87