muklin
October 25th, 2020, 03:58
Hi all,
I create a lot of my own maps, and wanted the ability to use GIMP to select the negative areas of the maps, and use that as the basis for my walls.
I know theres been some conversations about how to create LOS Walls, in the forums, but this is my own take on it.
The process is based around making a selection in GIMP.
40490
Convert that to a PATH, (Menu: Select-> To Path)
Now Export it as a SVG File.
40491
The SVG export from GIMP seems to be pretty specific SVG format, so I don't promise this works for all SVGs.
40492
Then run the below powershell script that, for all SVG files in a directory:
1. Gets the image size. (This is needed to convert to FGU's Frame of Reference: 0,0 at the centre, and orientation: Y axis reversed)
2. Parse the path coords, and storing them in a List.
3. Parse the List, removing doubles, (I extended this to reduce the number of points, by distance.)
4. Output the list to the same filename as the svg, in the XML Occluder format that FGU's db.xml expects.
Then you take that xml, find your Image Layer in your dbxml and put it in there.
40493
Done!!
40494
Note it only handles walls. But of course, you could just make selection paths for all the different features in gimp, and just toggle their type in the db.xml.
Hope this helps someone!!
Muklin
Here is the powershell:
param(
[String]$filePath = $PWD,
[Int]$SmoothDistance = 10
)
if(test-path -path $filePath){
$files = Get-ChildItem -name $filePath -Include *.svg
}
$files | %{
$file= $filePath+"\"+$_
$filename = $_ -replace ".svg",".occ"
Write-Output "Processing $file..."
if([System.IO.File]::Exists($file)){
$content = get-content $file
}else{
Write-Error "Could not find file $file"
exit 2
}
$matchResult = [regex]::Match($content,"viewBox=\`"0 0 ([0-9]+) ([0-9]+)\`"")
$xWide = $matchResult.Groups[1].Value
$yHigh = $matchResult.Groups[2].Value
Write-Host "Detected an image $xWide by $yHigh"
$xWideMod = $xWide/2
$yHighMod = $yHigh/2
"<occluders>" | Out-file -Filepath $filename
$occludercount = 0
$m = Select-String -InputObject $content -Pattern "C[0-9., `r`n]+Z" -AllMatches
$array = [System.Collections.ArrayList]@()
$m.Matches | %{
$line = $_.Value.trim("C").trim("Z")
$matching = Select-String -InputObject $line -Pattern "([0-9\.,]+)" -AllMatches
foreach($match in $matching.Matches){
$coord = $match.Value.split(",")
$coord[0] = $coord[0] -as [int]
$coord[1] = $coord[1] -as [int]
if($array.Count -gt 0 -and [Math]::Pow($array[-1][0]-$coord[0],2)+[Math]::Pow($array[-1][1]-$coord[1],2) -lt [Math]::Pow($SmoothDistance,2) ) {
#"discarded a point"
}else{
$array.Add($coord) | Out-Null
}
}
$out = ""
$array | %{
$modX = $_[0]-$xWideMod -as [String]
$modY = $yHighMod-$_[1] -as [String]
$out = $out+$modX+","+$modY+","
}
"`t<occluder>" | Out-file -append -Filepath $filename
"`t`t<id>$occludercount</id>" | Out-file -append -Filepath $filename
"`t`t<points>$($out.trim(","))</points>" | Out-file -append -Filepath $filename
"`t`t<closedpolygon>true</closedpolygon>" | Out-file -append -Filepath $filename
"`t</occluder>" | Out-file -append -Filepath $filename
$occludercount++
$array.RemoveRange(0,$array.Count)
}
"</occluders>" | Out-file -append -Filepath $filename
}
I create a lot of my own maps, and wanted the ability to use GIMP to select the negative areas of the maps, and use that as the basis for my walls.
I know theres been some conversations about how to create LOS Walls, in the forums, but this is my own take on it.
The process is based around making a selection in GIMP.
40490
Convert that to a PATH, (Menu: Select-> To Path)
Now Export it as a SVG File.
40491
The SVG export from GIMP seems to be pretty specific SVG format, so I don't promise this works for all SVGs.
40492
Then run the below powershell script that, for all SVG files in a directory:
1. Gets the image size. (This is needed to convert to FGU's Frame of Reference: 0,0 at the centre, and orientation: Y axis reversed)
2. Parse the path coords, and storing them in a List.
3. Parse the List, removing doubles, (I extended this to reduce the number of points, by distance.)
4. Output the list to the same filename as the svg, in the XML Occluder format that FGU's db.xml expects.
Then you take that xml, find your Image Layer in your dbxml and put it in there.
40493
Done!!
40494
Note it only handles walls. But of course, you could just make selection paths for all the different features in gimp, and just toggle their type in the db.xml.
Hope this helps someone!!
Muklin
Here is the powershell:
param(
[String]$filePath = $PWD,
[Int]$SmoothDistance = 10
)
if(test-path -path $filePath){
$files = Get-ChildItem -name $filePath -Include *.svg
}
$files | %{
$file= $filePath+"\"+$_
$filename = $_ -replace ".svg",".occ"
Write-Output "Processing $file..."
if([System.IO.File]::Exists($file)){
$content = get-content $file
}else{
Write-Error "Could not find file $file"
exit 2
}
$matchResult = [regex]::Match($content,"viewBox=\`"0 0 ([0-9]+) ([0-9]+)\`"")
$xWide = $matchResult.Groups[1].Value
$yHigh = $matchResult.Groups[2].Value
Write-Host "Detected an image $xWide by $yHigh"
$xWideMod = $xWide/2
$yHighMod = $yHigh/2
"<occluders>" | Out-file -Filepath $filename
$occludercount = 0
$m = Select-String -InputObject $content -Pattern "C[0-9., `r`n]+Z" -AllMatches
$array = [System.Collections.ArrayList]@()
$m.Matches | %{
$line = $_.Value.trim("C").trim("Z")
$matching = Select-String -InputObject $line -Pattern "([0-9\.,]+)" -AllMatches
foreach($match in $matching.Matches){
$coord = $match.Value.split(",")
$coord[0] = $coord[0] -as [int]
$coord[1] = $coord[1] -as [int]
if($array.Count -gt 0 -and [Math]::Pow($array[-1][0]-$coord[0],2)+[Math]::Pow($array[-1][1]-$coord[1],2) -lt [Math]::Pow($SmoothDistance,2) ) {
#"discarded a point"
}else{
$array.Add($coord) | Out-Null
}
}
$out = ""
$array | %{
$modX = $_[0]-$xWideMod -as [String]
$modY = $yHighMod-$_[1] -as [String]
$out = $out+$modX+","+$modY+","
}
"`t<occluder>" | Out-file -append -Filepath $filename
"`t`t<id>$occludercount</id>" | Out-file -append -Filepath $filename
"`t`t<points>$($out.trim(","))</points>" | Out-file -append -Filepath $filename
"`t`t<closedpolygon>true</closedpolygon>" | Out-file -append -Filepath $filename
"`t</occluder>" | Out-file -append -Filepath $filename
$occludercount++
$array.RemoveRange(0,$array.Count)
}
"</occluders>" | Out-file -append -Filepath $filename
}