SVGImport.wiki
changeset 1422 a6f2064e67a5
parent 749 db0eeafa0cdf
child 1423 39ebd4eac1dd
--- a/SVGImport.wiki	Tue Jun 19 19:28:24 2018 -0400
+++ b/SVGImport.wiki	Thu Jun 21 11:58:10 2018 -0400
@@ -29,14 +29,35 @@
 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.
 
 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.
-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}}}
+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
+:s/,/ /g
+:s/\([LM]\)\s*/\1/g
+}}}
 
 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.
 {{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}}
 
-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.
+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.
 Since this page is a mass of hacks, here's one more redundancy reducer, in bash this time.
-{{{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}}}
+{{{
+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
+}}}
 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.
 
 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).
@@ -87,4 +108,4 @@
 Enjoy.
 
 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.
-http://m8y.org/hw/drawn/
\ No newline at end of file
+https://m8y.org/hw/drawn/