SVGImport.wiki
changeset 1422 a6f2064e67a5
parent 749 db0eeafa0cdf
child 1423 39ebd4eac1dd
equal deleted inserted replaced
1421:ac35ef6e999f 1422:a6f2064e67a5
    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 {{{s/\(\d\) \(\d\)/\1 L\2/g}}}  and {{{s/,/ /g}}} and {{{s/\([LM]\)\s*/\1/g}}}
    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 
       
    33 {{{
       
    34 :s/\(\d\) \(\d\)/\1 L\2/g
       
    35 :s/,/ /g
       
    36 :s/\([LM]\)\s*/\1/g
       
    37 }}}
    33 
    38 
    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.
    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.
    35 {{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}}
    40 {{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}}
    36 
    41 
    37 Also, it is probably a good idea to remove duplicate points.  Here's a regex for that. {{{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.
    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.
    38 Since this page is a mass of hacks, here's one more redundancy reducer, in bash this time.
    44 Since this page is a mass of hacks, here's one more redundancy reducer, in bash this time.
    39 {{{rm dupes.txt;PREVXY=(99999 99999);sed 's/\([LM]\)/\n\1/g' inputfile | while read f;do read -a XY <<< "${f:1}";if [ "${f:0:1}" != "M" ];then if((${XY[0]}-${PREVXY[0]}<3&&${XY[0]}-${PREVXY[0]}>-3&&${XY[1]}-${PREVXY[1]}<3&&${XY[1]}-${PREVXY[1]}>-3));then echo "$f" >> dupes.txt;else echo $f;fi;else echo $f;fi;PREVXY[0]=${XY[0]};PREVXY[1]=${XY[1]};done | xargs > inputfile.dedupe}}}
    45 {{{
       
    46 rm dupes.txt
       
    47 PREVXY=(99999 99999)
       
    48 sed 's/\([LM]\)/\n\1/g' inputfile | while read f
       
    49 do 
       
    50     read -a XY <<< "${f:1}"
       
    51     if [ "${f:0:1}" != "M" ]
       
    52     then
       
    53         if((${XY[0]}-${PREVXY[0]}<3&&${XY[0]}-${PREVXY[0]}>-3&&${XY[1]}-${PREVXY[1]}<3&&${XY[1]}-${PREVXY[1]}>-3))
       
    54         then
       
    55              echo "$f" >> dupes.txt
       
    56         else echo $f
       
    57     fi
       
    58     else echo $f;fi;PREVXY[0]=${XY[0]};PREVXY[1]=${XY[1]}
       
    59 done | xargs > inputfile.dedupe
       
    60 }}}
    40 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.
    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.
    41 
    62 
    42 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).
    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).
    43 If you want larger lines you can pick anything between 0x00 and 0x3F.  That's 6-636.  See the [DrawnMapFormat] wiki page.
    64 If you want larger lines you can pick anything between 0x00 and 0x3F.  That's 6-636.  See the [DrawnMapFormat] wiki page.
    44 {{{
    65 {{{
    85 {{{base64 -w0 hwpointdata.Z > mynewhedgewars.hwmap}}}
   106 {{{base64 -w0 hwpointdata.Z > mynewhedgewars.hwmap}}}
    86 
   107 
    87 Enjoy.
   108 Enjoy.
    88 
   109 
    89 Here are some example hwmap files from the process above.  They look better in 0.9.18+ due to the added size support, allowing thinner lines.
   110 Here are some example hwmap files from the process above.  They look better in 0.9.18+ due to the added size support, allowing thinner lines.
    90 http://m8y.org/hw/drawn/
   111 https://m8y.org/hw/drawn/