author | kyberneticist@gmail.com |
Sun, 24 Jun 2012 22:55:51 +0000 | |
changeset 228 | 13f07e078365 |
parent 227 | c7897b5d10c5 |
child 229 | 5c20e3d492e8 |
permissions | -rw-r--r-- |
227
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
1 |
#summary Importing an SVG into Hedgewars |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
2 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
3 |
= Introduction = |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
4 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
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. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
6 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
7 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
8 |
= Details = |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
9 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
10 |
Open Inkscape. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
11 |
Go to File->Inkscape Preferences and make sure that |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
12 |
* SVG Output->Allow relative coordinates is unchecked |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
13 |
* Transforms->Store transformation is set to Optimized |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
14 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
15 |
Open an SVG. Ideally one of simple line art, without too much use of fill or filters. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
16 |
|
228
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
17 |
1) Combine all paths in the drawing (select them, then choose Path->Combine). 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. |
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
18 |
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 |
227
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
19 |
|
228
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
20 |
2) select the combined path, and ungroup. |
227
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
21 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
22 |
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. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
23 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
24 |
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. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
25 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
26 |
5) Save and Quit |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
27 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
28 |
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. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
29 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
30 |
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. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
31 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
32 |
8) Save and Quit again |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
33 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
34 |
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. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
35 |
{{{:s/[0-9][0-9.]*/\=float2nr(floor(submatch(0)*1))/g}}} |
228
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
36 |
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 a Vim one-liner for that syntax {{{s/\(\d\) \(\d\)/\1 L\2/g}}} and {{{s/,/ /g}}} |
227
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
37 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
38 |
10) Convert the path data. Here is a crude script to do that. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
39 |
{{{ |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
40 |
#!/usr/bin/perl |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
41 |
# just a one-line list of points. at least, it had better be one-line |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
42 |
open FILE, $ARGV[0]; |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
43 |
while(<FILE>) |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
44 |
{ |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
45 |
chomp; |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
46 |
s/([LM])(\d+) (\d+)\s*/point($1,$2,$3)/eg; |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
47 |
print; |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
48 |
} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
49 |
sub point |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
50 |
{ |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
51 |
($t, $x, $y) = @_; |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
52 |
$x+=0; |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
53 |
$y+=0; # just in case |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
54 |
printf("%c%c%c%c%c",$x>>8,$x&0xff,$y>>8,$y&0xff,($t=~m/M/)?0x81:0x01); |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
55 |
return; |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
56 |
} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
57 |
}}} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
58 |
{{{script pointdata > hwpointdata}}} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
59 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
60 |
11) qCompress the data. |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
61 |
{{{g++ -I /usr/include/qt4 -I /usr/include/qt4/QtCore qcompress.cpp -lQtCore}}} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
62 |
{{{ |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
63 |
#include <QFile> |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
64 |
#include <QByteArray> |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
65 |
using namespace std; |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
66 |
int main(int argc, char **argv) |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
67 |
{ |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
68 |
QFile fromFile(argv[1]); |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
69 |
QFile toFile(argv[2]); |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
70 |
if(fromFile.open(QIODevice::ReadOnly) && toFile.open(QIODevice::WriteOnly)) |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
71 |
{ |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
72 |
toFile.write(qCompress(fromFile.readAll())); |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
73 |
} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
74 |
} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
75 |
}}} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
76 |
{{{./a.out hwpointdata hwpointdata.Z}}} |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
77 |
|
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
78 |
12) Convert to base64 and you're done! |
c7897b5d10c5
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
79 |
|
228
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
80 |
{{{base64 -w0 hwpointdata.Z > mynewhedgewars.hwmap}}} |
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
81 |
|
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
82 |
Enjoy. |
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
83 |
|
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
84 |
Here are some example hwmap files from the process above. They look better in 0.9.18. |
13f07e078365
Edited wiki page SVGImport through web user interface.
kyberneticist@gmail.com
parents:
227
diff
changeset
|
85 |
http://m8y.org/hw/drawn/ |