Cutting a hole in terrain made of 1 m squares
Terrain3D only holes whole vertices, so a cellar's cut overshoots and frays. A hole made too wide, under a concrete apron, fixed it.
Buildings in the game can now have the terrain cut away under their cellars and priest hole pits, with the collision cut too and the hole lined in concrete. Nothing is cut in the live game yet, because the cellar branch doesn’t fill in the building’s below-ground boxes until the next work item lands. The call and its tests are ready for it.
Why did the terrain run through the stairwell?
The cellars go 3 m below the ground storey and a priest hole 6 m, but the world’s terrain is one surface that doesn’t know a building is there. It passed straight through the stairwell and the cellar room. The cellar tests had hidden this by standing the houses on a flat bench with holes. The work item asked for the terrain and its collision to be cut to the cellar’s footprint where such a building stands.
How can you cut a rectangle out of a grid of vertices?
You can’t, quite. Terrain3D holes a vertex, and the terrains I use have one vertex per 1 m. A holed vertex takes the drawn square from it to the next vertex out of the surface, and every collision triangle touching it. So the cut always overshoots the box, and the drawn hole frays into the next square by a triangle. TerrainStream._hole_vertices counts what a hole takes: the vertex under each low edge and the one at or past each high edge. The project runs Jolt, because Terrain3D’s holes hung GodotPhysics.
So the hole is made on purpose too wide. BuildingGroundCut groups the boxes whose margins meet (a cellar, its stairwell and its pit), takes the bounding rectangle of the group’s margins, which is three vertices past each low edge and two past each high edge, and cuts that rectangle less its outer two vertices on every side. The streamed terrain takes the hole through TerrainStream.cut. A terrain loaded whole has the vertices marked by the node, counted per vertex so two overlapping cuts don’t free each other’s. When the building’s cell is freed, the new TerrainStream.uncut clears the hole bit on every vertex that no other hole keeps and that wasn’t sculpted in the editor, then rebuilds the collision tiles around it.
A heightfield has no earth faces, so through a hole you would see the sky’s color. Each box gets a lining, one solid StaticBody3D of concrete slabs 0.3 m thick, just outside its four sides and floor. A slab isn’t laid where it would run inside another box.
What the hole took too much of, up to 3 m round a box, is made up by a kerb, a concrete apron over the group’s whole rectangle. Out of doors its top is 0.04 m over the highest terrain vertex left inside the rectangle, so no grass can come through it, and it reaches 0.3 m under the lowest ground in it. Under the building’s footprint it is level with the floor, just under it. The party steps onto its edge through StepRule.
Why did the first kerb look wrong?
The first kerb was laid per box, so it followed the cut’s 1 m steps. A judge sent it back with three faults. Grass came through the kerb on the island at its notches and corners. Thin rim strips floated 5 m or more off into the sand. And the outline was a sawtooth of 1 m steps, like a slab dropped on the grass. Making each group one rectangle with its top over the highest vertex fixed all three, and I dropped the rim, because an edge that stands over the ground has no slit to cover. The judge agreed on the next round. A test that walks a capsule down the stairwell also caught a stray collision triangle at a hole’s far corner.
Why was there sea water in the cellar?
On the island the first take showed water standing in the cellar. The sea is one flat opaque plane that runs on under the land, and the island’s low land is only 1 or 2 m over it, so a cut below it shows the sea. BuildingGroundCut.flooded takes the boxes and says which ones a water sheet lies over, and the caller should lay no cellar there. Nothing calls it yet. That is the next item.
What is still left?
The film never goes close to the east door, so the 16 cm step up from the apron there wasn’t judged. Three test scenes (the streamed field, the field loaded whole, and the island) passed 30, 28 and 30 checks, and the building and terrain tests in the suite passed 37 of 37.