Lines are pretty important in Manifold Garden. They connect switches to doors or other objects, and a light travels through them to know when it has been switched on.
Originally, lines were made with separate individual prefabs.
Each segment had to be scaled and placed manually, and every corner needed a separate piece. Not only that, I also had to manually toggle the corner to invert the material if the bend was going the other way. The default corner material is for bending right, so if it was left bend, the material needed to get flipped.
The segments also needed to be placed in the right order, as that was how the line manager figured out in which sequences the lines should turn on. It was a bit of a mess from the code standpoint as well, with each line having to check the previous line to get the timing of when it should turn on.
Anyway, here’s how it was built:
As you can see, very tedious.
Decided to finally write a tool for this. Here’s the line mesh generator in action:
How this works is I bring up the tool, and I can select what kind of line (cube, button activator, or independent). The difference is that it will attach the finished line mesh to the appropriate object with the appropriate script.
Then, I just hit ‘P’ to place down the marker. There is also undo, which is great, as occasionally you can place the marker just a little off. David wrote the undo feature, but I believe it’s just using a stack and putting things on and taking them off accordingly.
A preview of the mesh is generated as the markers are placed down, and when you’re ready, just hit “Form Mesh” and the final mesh is formed. All as one piece, instead of multiple different segments, so much easier to manage.
The trickiest part was getting the correct offsets and UI for it. The actual mesh generating stuff is actually almost exactly the same as the mesh generation for water, which Chris Wade had written several weeks back.
The new water system actually generates a new mesh every frame, and simply updates the points of the mesh based on what happens. Because the water also handles bends in various directions (left, right, up, and down), the code for setting the vertices of the mesh was just what I needed for the line mesh generator.
The key for the tool was setting up markers as line is placed. They are restricted to be along the axis of the previous marker, so that you can’t make diagonal lines (which I don’t want anyway). Also, a marker doesn’t know which way it is bending until the next marker is placed, so there is some back communication.