Wang Tiles, and Filling Improvements

This topic is the center for The GSoC Wang tiles project.

Much of the discusion thus far (5/4/17) is hosted on a git hub issue thread #1455. The details of the project can be found in my project proposal. If you have any questions, or suggestions, feel free to post bellow.


An exemple of wang tiles used in the game industrie

I’ve written the first bit of code for this project in the form of the WangSet class. The code can be found in my fork of Tiled in the branch “WangTiles”.

A WangSet holds info connecting tiles of a TileSet to wangIds. These wang ids are an unsigned int which can be parsed for info on the color of each corner edge. (More info on this on the git hub ticket for wang tiles here near the bottom). There are functions for basic info access/setting, as well for finding a tile in the set which matches a given wangTile. This finds all viable tiles, and returns one at random.

Another necessary functionality is to, given a tile, find that tile’s wangId. Right now this is stored as a map from tileId to wangId. This isn’t super ideal, as the info is being stored twice (the other in a map from wangId to tile). There are some reasons I think it’s best to do it this way, but I’m open to ideas to streamline it a bit.

Also included in the header file are a number of functions which work with wangIds. Currently none are actually in use, but I went ahead and included them as I think they will be useful later on. Ill remove any unused functions if I continue not to use them.

The next steps in this project will be finalizing how wang tiles will work, and moving forward to make that happen.

1 Like

Hey @Benjamin_Trotter, great to see you getting your project started!

To ease commenting on the code, please open a pull request. For now I’ve responded to your GitHub issue.

If you need both lookups to be fast, it is perfectly reasonable to maintain a double index.

Some weeks in now, and finally time to do some big UI work. In question right now is the assignment of tiles to their respective WangIds. This will need to be fluid and intuitive for the user, and as such a few approaches may be tried out before one is settled on.

For the first take, I’ve made a mock up of how it should work:

Based on the number of edge and corner colors chosen for a given wang set, a template set will be generated. In the above image a 2 corner set is shown. A user will then select a tile from this set (shown bottom right) and “paint” this onto the appropriate tile in their own tileset. At this point Tiled will automatically move to the next template tile, as this will usually be the desired behavior. Likely hotkeys could also be used to move between the template tiles. Notably the template tile will become darkened to indicate it has been used, but it can still be assigned to more tiles.

For the general case this covers assignment, but it is also possible one may want a tile to represent a different wangId in its rotated state. In my current plan, this will be handled through a context based pop-up menu. A very rough mock up here:

From this, one can manually input the color of each corner/edge. In the final version The edge inputs would be hidden if the edge count was 0 or 1 (same for corners). Also shown are numbers for this input. In the final version this would likely be a drop down with a selection of colors.

To create a different version (for rotation flipping) one would be able to press a button under the Translations heading on the right (buttons missing from mockup) and this would create a copy of the current tile and wangId.

Around the top and right are arrows, which would act as buttons to create the “Translated version” which would appear as a list on the right. This would automatically rotate/flip the wangId as expected.

In the main view, there would be some symbol/indication that a tile has variations, but in this plan to actually see these, one would have to go into the above menu.

Interested in feedback on this plan before I move too far forward on it!
Thanks, Ben

1 Like

I really like the first part, even though for a high number of edges and/or corners, the number of different wang tiles is going to make this unwieldy. However, I think it isn’t a problem because it could probably be combined with the option to draw single colors as done in the terrain editing mode.

The second part where we allow flipped or rotated versions of the tiles to get a wang pattern assigned seems a little complicated. Alternatively, I just thought that maybe we should add some buttons that change the display of the entire tileset to be flipped or rotated, in which case you could paint on the flipped/rotated version of the tileset just like you could on the regular version. These buttons could even be made available while editing the map as well, to allow picking flipped/rotated tiles directly from the tileset.

In any case, it’s awesome to see the first parts of this tool working and it looks very promising!

Yes I agree Bjorn with the fact of the second case being too complicated, I was also suggesting to add a contextual menu with posible rotations and add the duplicated ones at the end of the tileset but your proposals sounds good too.

Will it be possible to make some box drawing by defining which case is valid or not?
For example for 1 line type there is only 11 cases out of 16 which are valid for a 4 edge patern.

This should be possible… I’m not totally sure what you’re asking. For sure you would be able to define the set of the box pieces and manually paint the boxes with the wangbrush

1 Like