|
1 #summary Importing an SVG into Hedgewars |
|
2 |
|
3 = Introduction = |
|
4 |
|
5 This is a quick and dirty description of converted 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. |
|
6 |
|
7 |
|
8 = Details = |
|
9 |
|
10 Open Inkscape. |
|
11 Go to File->Inkscape Preferences and make sure that |
|
12 * SVG Output->Allow relative coordinates is unchecked |
|
13 * Transforms->Store transformation is set to Optimized |
|
14 |
|
15 Open an SVG. Ideally one of simple line art, without too much use of fill or filters. |
|
16 |
|
17 1) combine all paths in the drawing (select them, then choose Path->Combine) |
|
18 |
|
19 2) select the combined path, and ungroup |
|
20 |
|
21 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. |
|
22 |
|
23 4) Go to File->Document Properties and choose Resize Page to Drawing or Selection. You may want to then reposition the art to be more centred vertically or horizontally. |
|
24 |
|
25 5) Save and Quit |
|
26 |
|
27 6) Open in an editor and verify there is one path. change the path ID attribute to id="base" - this is to work around a bug in the current stable Inkscape extensions tool which was crashing it. |
|
28 |
|
29 7) 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. |
|
30 |
|
31 8) Save and Quit again |
|
32 |
|
33 9) 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. 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. |
|
34 {{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}} |
|
35 |
|
36 10) Convert the path data. Here is a crude script to do that. |
|
37 {{{ |
|
38 #!/usr/bin/perl |
|
39 # just a one-line list of points. at least, it had better be one-line |
|
40 open FILE, $ARGV[0]; |
|
41 while(<FILE>) |
|
42 { |
|
43 chomp; |
|
44 s/([LM])(\d+) (\d+)\s*/point($1,$2,$3)/eg; |
|
45 print; |
|
46 } |
|
47 sub point |
|
48 { |
|
49 ($t, $x, $y) = @_; |
|
50 $x+=0; |
|
51 $y+=0; # just in case |
|
52 printf("%c%c%c%c%c",$x>>8,$x&0xff,$y>>8,$y&0xff,($t=~m/M/)?0x81:0x01); |
|
53 return; |
|
54 } |
|
55 }}} |
|
56 {{{script pointdata > hwpointdata}}} |
|
57 |
|
58 11) qCompress the data. |
|
59 {{{g++ -I /usr/include/qt4 -I /usr/include/qt4/QtCore qcompress.cpp -lQtCore}}} |
|
60 {{{ |
|
61 #include <QFile> |
|
62 #include <QByteArray> |
|
63 using namespace std; |
|
64 int main(int argc, char **argv) |
|
65 { |
|
66 QFile fromFile(argv[1]); |
|
67 QFile toFile(argv[2]); |
|
68 if(fromFile.open(QIODevice::ReadOnly) && toFile.open(QIODevice::WriteOnly)) |
|
69 { |
|
70 toFile.write(qCompress(fromFile.readAll())); |
|
71 } |
|
72 } |
|
73 }}} |
|
74 {{{./a.out hwpointdata hwpointdata.Z}}} |
|
75 |
|
76 12) Convert to base64 and you're done! |
|
77 |
|
78 {{{base64 -w0 hwpointdata.Z > mynewhedgewars.hwmap}}} |