Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Script] Walls - SVG Path importer for dynamic lighting. -- Revisited

1415737463

Edited 1589032364
The Aaron
Pro
API Scripter
Updated Thread: <a href="https://app.roll20.net/forum/post/7785026/script-walls-svg-path-importer-for-dynamic-lighting-now-with-advanced-fog-of-war-support" rel="nofollow">https://app.roll20.net/forum/post/7785026/script-walls-svg-path-importer-for-dynamic-lighting-now-with-advanced-fog-of-war-support</a> I originally posted this script back in June. At that time, you had to have a running version of PHP locally so that you could parse the SVG file into usable commands. With the advent of Dynamic Light Walls block movement, I've dusted this off and added web hosting of this script so that step 2 is much easier. You'll still need to be able to navigate The GIMP, but I hope my directions below are sufficient for your needs there. I'll try and improve this script in the coming months if there is any interest. Prerequisites: The GIMP for creating and exporting the path SVG file for your map Post Processing Website for turning the SVG into commands to setup your walls. You may be able to use Photoshop or Inkscape or some other program to generate the path SVG file. PM me if you'd like to try and I'll try to help you. The Basic Process: In The GIMP Load your map. Generate a path for your walls. Export your path to a file (SVG). On the Post Processing Website Upload your SVG file from step 1.3 Copy the output commands In Roll20 On the map layer, select the image that is your map Paste the commands into the chat and send them. Wait about a minute (feel free to watch the log, there are status messages so you know it's working). Enjoy! Detailed Instructions: 1. In The GIMP 1. Load your Map From the menu, select File-&gt;Open...Browse to your map and click the Open button. 2. Generate a path for your walls and Export your path to a file There are several ways of doing this, the methods I like best involve selecting an area and turning it into a path. I'll cover two ways of doing that, but feel free to do more advanced things or experiment further. The Magic Wand Tool Selections on a Grid Select the Magic Wand tool from the toolbox. The Magic Wand creates a selection by flooding out from a point across all the pixels whose colors are "close" to the color of the pixel you clicked on. The "close" is controlled by the Threshold setting in the Tool Options dialog (From the menu, choose Windows-&gt;Dockable Dialogs-&gt;Tool Options ). You can hold Shift to add several regions to your selection, if you have walls multiple dungeon levels on the same map, or areas accessed through some other means than a door. The image I'm using here has a light grey grid in the background, so I have to adjust the Threshold up quite a bit to flood past the grid and hit the walls. In this case, I used a value around 48. The mouse cursor shows where I clicked to get this selection Now that I have a selection for my walls, I need to adjust it a bit. I want some of the texture of the wall to show through, so I'm going to move the selection back into the walls a little ways. From the menu, choose Select-&gt;grow... For my map, 15px allows a nice bit of the cave wall to show. You may need to play with the number a bit to get the effect you want. You can undo adjustments to the selection in the usual way (From the menu, choose Edit-&gt;Undo ) Now you need to turn this selection into a path. From the menu, choose Select-&gt;To PathNext, open up the Path dialog. From the menu, choose Windows-&gt;Dockable Dialogs-&gt;Path You should see the path you just created, named Selection . Right click it and choose Export Path... Save the path to a file you will be able to find. That's it for the Magic Wand method! If your map is laid out on a grid and has lots of intervening details, it may be easier to just select the walls directly using the Rectangle Select Tool . You can turn on the grid to make this easier. (If you don't know the size of your grid, you can measure features of the map with the Measure Tool or just play with the size until it looks right.) From the menu, select Image-&gt;Configure Grid... Under Spacing , adjust the Width and Height to the correct size. The grid updates as you change it, so you should be able to match the grid on an image just by clicking the up and down arrows. (It may help to set the Foreground color to something especially distinct, like a bright red or blue.) If your map doesn't begin precisely on the grid, you can change the Offset in order to align it. If your map features a grid that isn't square, click the chain link ( see mouse cursor in above image ) below the Width and Height of Spacing or Offset in order to adjust Width and Height separately. Now that you have a grid you just need to select your walls. There are many ways of doing this, but I prefer to either select the individual walls with the Rectangle Select tool, or start with everything selected and deselect the rooms (On a Mac, hold down Command while selecting to subtract. On Windows, you can change to subtract mode in the Tool Options dialog. From the menu, choose Windows-&gt;Dockable Dialogs-&gt;Tool Options ). Now that I have my selection for the walls, I need to adjust it a bit. I want some of the texture of the wall to show through, so I'm going to move the selection back into the walls a little ways. In my example, I have selected the walls, but I think you get better effects from adjusting based on the floor. This is easily fixed by inverting the selection. From the menu, choose Select-&gt;Invert Now we can proceed as in the other example. From the menu, choose Select-&gt;grow... For my map, 5px allows a little of the dungeon wall to show. on this grid, 15px was more than I wanted to show, but use whatever you like. Now you need to turn this selection into a path. From the menu, choose Select-&gt;To Path Next, open up the Path dialog. From the menu, choose Windows-&gt;Dockable Dialogs-&gt;Path You should see the path you just created, named Selection . Right click it and choose Export Path... Save the path to a file you will be able to find. That's it for the Selections on a Grid method! 2. On the Post Processing Website Follow the instructions on the website to upload your SVG file and click 'Parse'. Click in the output box and copy the generated commands. Now we'll take those commands to Roll20. 3. In Roll20 With the Walls Roll20 API script installed, you can add your walls to the map. Start by selecting a map token on the map layer. The script will use that map for positioning and scaling. Because the commands all come through as separate api messages, it will have to do all of the work regardless of if you have selected a map, and then tell you afterwards that you didn't, so do yourself a favor and select one now. =D Paste the commands into the chat and hit enter. You can watch the log file to make sure it's actually doing something. Depending on the complexity of the Path, it can take a while to run. For the caves in the Magic Wand example above, it took about a minute to parse all the commands. This one took only a few seconds. Here is the view of the Dynamic Lights layer after running the commands. You can see the walls we added in red as well as their effects on the lights. 4. Enjoy! Current Limitations: Only the SVG commands M, C, and Z are supported. These are the absolute position commands for moving to a point, drawing a curve, and closing a curve. I couldn't actually get The GIMP to export a path with anything but these 3 commands in it, so this is only a limitation if you are coming from some other source. If other commands become necessary, I'm happy to add them in. PM me with details if you need this. No support for Rotation, Flip Horizontal, Flip Vertical. If you need these operations, you're either on your own with adjusting the paths afterwards, or you need to do them in TheGIMP and then export the path. Future Features: Support for Rotation -- this won't be terribly difficult, let me know if you need it and I'll prioritize it. Support for Flip Horizontal and Flip Vertical -- Also not too difficult Support for generating smaller path segments to allow post import customization. Support for applying a loaded path to a map if you forgot to select one. Support for color selection and stroke size. GitHub:&nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/W" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/W</a>... Support my work on If you use my scripts, want to contribute, and have the spare bucks to do so , go right ahead. However, please don't feel like you must contribute just to use them! I'd much rather have happy Roll20 users armed with my scripts than people not using them out of some sense of shame. Use them and be happy, completely guilt-free! Disclaimer: This Patreon campaign is not affiliated with Roll20; as such, contributions are voluntary and Roll20 cannot provide support or refunds for contributions.
1415753729
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
I have put this to good use and intent to use it a lot more. The Gimp instructions are fine and it works like a charm. Was able to take +4000px sqaure map with dozens of room and hall to DL paths in no time. saved my Sunday game from my procrastination.
1415755882
The Aaron
Pro
API Scripter
Sky's the limit from here! :)
I'm curious, does this produce lines as resource intensive (from a dynamic lighting standpoint) as the freehand tool did? Seems like that would be an issue on the magic wand style map. Am I missing something?
1415761789
The Aaron
Pro
API Scripter
It does not. With the free hand tool, it had to create a new line very very often. It was dealing in vector space, so that could easily be interpolated into more than one line per pixel depending on the algorithm. Now, I'm not saying that you couldn't make an SVG to import that wouldn't make freakish amounts of lines, but the directions I outlined above do not create such issues. The key is in the shrinking, which simplifies the lines into less detailed curves. Additionally, The GIMP does a very good job of producing optimal paths from the selection. If you'd like to see how that particular map feels, send me a PM and I'll invite you to a campaign with it. =D
My computer handles even the freehand tool light walls like a champ. Some of the other people I have played with had issues when the gm used it for caves though. I was just curious about the potential for issues since I know that that was the reason they disabled the freehand tool on the dynamic light layer.
1415764501
The Aaron
Pro
API Scripter
Understandable. =D If the path still seems overly complex, there are some plugins for The GIMP that will smooth them for you . Let me know if you run into issues with the path complexity, and maybe I can add Bezier interpolation as an option in my transform website. =D
I don't know how Roll20 handles the paths w.r.t. dynamic lighting (specifically, if it uses lower-order path segments where appropriate), but I did notice that GIMP (and the script above, presumably as a result) seems to use cubic curves for everything. If Roll20 doesn't turn cubic curves into quadratic curves or lines where appropriate, it would probably improve performance to do so in the script.
1415769288
vÍnce
Pro
Sheet Author
This is very cool Aaron. I added a somewhat complex map and everything was created easily. Fun.
1415769628
The Aaron
Pro
API Scripter
Awesome! Glad to hear about success! =D