SVGImport.wiki
changeset 1680 cec5c4d1cf78
parent 1423 39ebd4eac1dd
child 1682 22a1cfe0eaf3
equal deleted inserted replaced
1679:3f5e880b0375 1680:cec5c4d1cf78
    17 
    17 
    18 1) Select all in the image and choose ungroup, then combine all paths in the drawing (select them, then choose Path->Combine). 
    18 1) Select all in the image and choose ungroup, then combine all paths in the drawing (select them, then choose Path->Combine). 
    19 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 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.
    20 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 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.
    21 
    21 
    22 2) 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.
    22 2) 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. Make sure Scale: X and Y are set to 1.
    23 
    23 
    24 3) 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.  Generally resize it and reposition it using the document white area as a guide to how it will look on the in-game drawing area, then save and quit.
    24 3) 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.  Generally resize it and reposition it using the document white area as a guide to how it will look on the in-game drawing area, then save and quit.
    25 
    25 
    26 4) Open in a text editor and verify there is one path. Change sodipodi:namedview's ID attribute to id="base" - this is to work around a bug in the current stable Inkscape (0.48.3.1) extensions tool which was crashing it.  This is probably fixed in 0.48.4. Note that I haven't tested this workaround. su_v says this is the correct way to do it because apparently id="base" is a reserved name for namedview in sodipodi - which seems like a rather common and collision-likely name.  I had misread him and changed the path's id to base, and that seemed to work fine.  If changing namedview doesn't work, try renaming the path instead.
    26 4) Open in a text editor and verify there is one path. Change sodipodi:namedview's ID attribute to id="base" - this is to work around a bug in the current stable Inkscape (0.48.3.1) extensions tool which was crashing it.  This is probably fixed in 0.48.4. Note that I haven't tested this workaround. su_v says this is the correct way to do it because apparently id="base" is a reserved name for namedview in sodipodi - which seems like a rather common and collision-likely name.  I had misread him and changed the path's id to base, and that seemed to work fine.  If changing namedview doesn't work, try renaming the path instead.
    27 Make sure all those groups are removed.
    27 Make sure all those groups are removed.
    28 
    28 
    29 5) Open the file in Inkscape again, Click on the path again, then go to Extensions->Modify Path->Flatten Beziers and flatten out the curves to your taste. Default of 10 seems fine most of the time, but for small curved objects you might want something like 5.  Keep in mind, the more the approximation, the more points that Hedgewars has to draw, which can be rough on the engine and network communication, then save and quit.
    29 5) Open the file in Inkscape again, Click on the path again, then go to Extensions->Modify Path->Flatten Beziers and flatten out the curves to your taste. Default of 10 seems fine most of the time, but for small curved objects you might want something like 5.  Keep in mind, the more the approximation, the more points that Hedgewars has to draw, which can be rough on the engine and network communication, then save and quit.
    30 
    30 
    31 6) 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.
    31 6) 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.
    32 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 
    32 
       
    33 7)
       
    34 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.
       
    35 {{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}}
       
    36 
       
    37 8) If in step (6) you have stuff other than just moves in the format listed, you'll have to 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 to try and fix up the paths.
    33 {{{
    38 {{{
    34 :s/\(\d\) \(\d\)/\1 L\2/g
    39 :s/\(\d\) \(\d\)/\1 L\2/g
    35 :s/,/ /g
    40 :s/,/ /g
       
    41 :s/\(\d\+\) \(\d\+\) V/\1 \2 L\1/g
    36 :s/\([LM]\)\s*/\1/g
    42 :s/\([LM]\)\s*/\1/g
    37 }}}
    43 }}}
    38 
    44 
    39 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.
    45 9) It is probably a good idea to remove duplicate points.  Here's a regex for that. 
    40 {{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}}
       
    41 
       
    42 Also, it is probably a good idea to remove duplicate points.  Here's a regex for that. 
       
    43 {{{ s/\(L\d\+ \d\+ \)\1/\1/g}}}  - you should run that a couple of times, then {{{s/M\(\d\+ \d\+ \)L\1/M\1/g}}}.  That just cuts down on a bit of redundancy.  If these regexes match anything, you probably should rerun them.
    46 {{{ s/\(L\d\+ \d\+ \)\1/\1/g}}}  - you should run that a couple of times, then {{{s/M\(\d\+ \d\+ \)L\1/M\1/g}}}.  That just cuts down on a bit of redundancy.  If these regexes match anything, you probably should rerun them.
    44 Since this page is a mass of hacks, here's one more redundancy reducer, in bash this time.
    47 Since this page is a mass of hacks, here's one more redundancy reducer, in bash this time.
    45 {{{
    48 {{{
    46 rm dupes.txt
    49 rm dupes.txt
    47 PREVXY=(99999 99999)
    50 PREVXY=(99999 99999)
    58     else echo $f;fi;PREVXY[0]=${XY[0]};PREVXY[1]=${XY[1]}
    61     else echo $f;fi;PREVXY[0]=${XY[0]};PREVXY[1]=${XY[1]}
    59 done | xargs > inputfile.dedupe
    62 done | xargs > inputfile.dedupe
    60 }}}
    63 }}}
    61 If dupes.txt has anything in it, you probably should run it again.  Anyway, running these reduced a complex test trace from ~8800 points down to ~6500.
    64 If dupes.txt has anything in it, you probably should run it again.  Anyway, running these reduced a complex test trace from ~8800 points down to ~6500.
    62 
    65 
    63 7) 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).
    66 10) 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).
    64 If you want larger lines you can pick anything between 0x00 and 0x3F.  That's 6-636.  See the [DrawnMapFormat] wiki page.
    67 If you want larger lines you can pick anything between 0x00 and 0x3F.  That's 6-636.  See the [DrawnMapFormat] wiki page.
    65 {{{
    68 {{{
    66 #!/usr/bin/perl
    69 #!/usr/bin/perl
    67 # just a one-line list of points. at least, it had better be one-line
    70 # just a one-line list of points. at least, it had better be one-line
    68 open FILE, $ARGV[0];
    71 open FILE, $ARGV[0];
    81     return;
    84     return;
    82 }
    85 }
    83 }}}
    86 }}}
    84 {{{script pointdata > hwpointdata}}}
    87 {{{script pointdata > hwpointdata}}}
    85 
    88 
    86 8) qCompress the data.
    89 11) qCompress the data.
    87 {{{g++ -I /usr/include/qt4 -I /usr/include/qt4/QtCore qcompress.cpp -lQtCore}}}
    90 {{{g++ -I /usr/include/qt4 -I /usr/include/qt4/QtCore qcompress.cpp -lQtCore}}}
    88 {{{
    91 {{{
    89 #include <QFile>
    92 #include <QFile>
    90 #include <QByteArray>
    93 #include <QByteArray>
    91 using namespace std;
    94 using namespace std;
    99     }
   102     }
   100 }
   103 }
   101 }}}
   104 }}}
   102 {{{./a.out hwpointdata hwpointdata.Z}}}
   105 {{{./a.out hwpointdata hwpointdata.Z}}}
   103 
   106 
   104 9) Convert to base64 and you're done! (whew)
   107 12) Convert to base64 and you're done! (whew)
   105 
   108 
   106 {{{base64 -w0 hwpointdata.Z > mynewhedgewars.hwmap}}}
   109 {{{base64 -w0 hwpointdata.Z > mynewhedgewars.hwmap}}}
   107 
   110 
   108 Enjoy.
   111 Enjoy.
   109 
   112