18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 21:24:58 +01:00

fix(editor): the orthophoto only on the chunks of the heightmap terrain in memory, and laid onto the ground again once it comes (#417)

* fix(editor): the orthophoto only on the chunks of the heightmap terrain in memory, and laid onto the ground again once it comes

Right after the editor started, the tiles of the orthophoto came from the disk cache at once and were fitted to the ground before
the chunks of the heightmap terrain had come (on IRT the orthophoto was on at 24.5 s, the first chunk came at 24.5 s, the last one
at 85 s). A tile with no ground under it, and none beside, stayed flat at the height of the layer (0 m, some 230 m under IRT);
one partly over the ground had its holes filled from the points beside. Neither was fitted again when the ground came: only the
guessed tiles were, by their middle and corners alone, and a tile with no chunk under it at all never got any. The overlay,
drawn over everything, then slid with the camera (WASD, turning) instead of lying on the ground. Turning the orthophoto off and on
hid it: by then the terrain was in and the tiles took their heights from it or from the edges of the tiles beside.

- With the heightmap terrain (the terrain streamer active), a tile of the orthophoto, of the WMS layers and of Ctrl+~ is asked
  for and shown only where its chunks are in memory (terrain_streamer::ground_under): it waits while one is still to come, and
  where no chunk is nor will be there's no imagery at all. A scenery without the heightmap terrain is as before.
- A tile remembers the points of its grid the ground didn't answer and is fitted again once the ground comes under any of them
  (every second point and the edges), not only the guessed tiles.

No asset changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(editor): the orthophoto waits only for the chunks that will come at this distance, and lies on the other ground or the guess elsewhere

After the reviews of maj00r and jerrrrycho on #417:

- A tile is no longer dropped where no chunk of the heightmap terrain is nor will be. There it lies on whatever ground there is (terrain models) or on the NMT guess, as on master; a scenery with a few chunks, or with chunks removed, keeps its imagery around them.

- A chunk counts as still to come only while it's being loaded or lies within the circle the streamer walks around the camera. The corners of the imagery in the 3D view, beyond that circle, no longer wait for chunks that won't load there: they lie on the guess and are sampled again when the camera comes near and the chunk loads.

- terrain_streamer::ground_under() (true / false / empty) became ground_coming() (bool), the cover source of the orthophoto the coming source, and on_ground() waits_for_ground(), which only holds back a new tile.

- In the scene (in_scene), the points a steep triangle leaves without a height but the heightmap terrain answers aren't kept as unanswered, so the tile isn't sampled again on every chunk that comes. The holes are counted from the heights again, as on master.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pol102
2026-11-21 10:39:53 +01:00
committed by GitHub
parent c5d14e93ac
commit c556c4c8fd
5 changed files with 118 additions and 13 deletions

View File

@@ -937,23 +937,47 @@ void editor_orthophoto::ground_arrived()
{
if (!m_height)
return;
for (auto &entry : m_tiles)
for (auto &[key, t] : m_tiles)
{
auto &t{entry.second};
if (!t.grounded || !t.guessed)
continue;
// the middle and the corners: a chunk of the terrain is much larger than a tile, it covers some of these when it comes. A tile
// lying flat, with nothing to go by, also goes onto the model once it's in
glm::dvec2 const corner = tile_corner(entry.first);
for (auto const &[u, v] : {std::pair{0.5, 0.5}, std::pair{0.0, 0.0}, std::pair{1.0, 0.0}, std::pair{0.0, 1.0}, std::pair{1.0, 1.0}})
if (double y; m_height(corner.x - u * tile_size, corner.y - v * tile_size, y) || (t.heights.empty() && m_guess && m_guess(corner.x - u * tile_size, corner.y - v * tile_size, y)))
{
t.grounded = false;
break;
}
if (t.grounded && ground_came(key, t))
t.grounded = false;
}
}
bool editor_orthophoto::waits_for_ground(tile_key const &Key) const
{
// a tile laid out already stays, sampled again when its ground comes (ground_came)
if (!m_coming || m_tiles.contains(Key))
return false;
glm::dvec2 const corner = tile_corner(Key);
return m_coming(corner - glm::dvec2{tile_size}, corner);
}
bool editor_orthophoto::ground_came(tile_key const &Key, tile const &Tile) const
{
glm::dvec2 const corner = tile_corner(Key);
// a tile lying flat, with nothing to go by, also goes onto the model once it's in: the middle and the corners
if (Tile.guessed && Tile.heights.empty() && m_guess)
for (auto const &[u, v] : {std::pair{0.5, 0.5}, std::pair{0.0, 0.0}, std::pair{1.0, 0.0}, std::pair{0.0, 1.0}, std::pair{1.0, 1.0}})
if (double y; m_guess(corner.x - u * tile_size, corner.y - v * tile_size, y))
return true;
// the points the ground didn't answer, every second one of the grid (16 m) and the edges: a chunk of the terrain is about as
// large as a tile and comes over a part of it, often a band along a side; partly answered tiles count too, not only the guessed
static_assert(ground_grid % 2 == 0, "the edges of the grid are among its even points");
int constexpr samples{ground_grid + 1};
double constexpr step{tile_size / ground_grid};
for (auto const index : Tile.unanswered)
{
int const i{index % samples};
int const j{index / samples};
if (i % 2 != 0 || j % 2 != 0)
continue;
if (double y; m_height(corner.x - i * step, corner.y - j * step, y))
return true;
}
return false;
}
void editor_orthophoto::detach_scene()
{
for (auto &entry : m_tiles)
@@ -1247,6 +1271,7 @@ void editor_orthophoto::sample_ground(tile_key const &Key, tile &Tile)
Tile.scene_dirty = true;
Tile.heights.clear();
Tile.surface.clear();
Tile.unanswered.clear();
glm::dvec2 const corner = tile_corner(Key);
glm::dvec2 const min(corner.x - tile_size, corner.y - tile_size);
@@ -1318,6 +1343,21 @@ void editor_orthophoto::sample_ground(tile_key const &Key, tile &Tile)
}
}
// the points the ground didn't answer: the ground coming there later (the terrain loaded after the imagery, which comes from the
// disk cache at once) has the tile sampled again, rather than left at the heights filled in or guessed now
Tile.unanswered.clear();
auto const columns{static_cast<std::size_t>(samples)};
for (std::size_t index = 0; index < heights.size(); ++index)
{
if (heights[index] != no_height)
continue;
// in the scene the heights come from the triangles, and a steep spot (a wall, a quarry face) gives none: where the heightmap
// terrain answers the point, its ground is there already, and ground_came() would find it again on every chunk that comes
if (double y; surface && m_height && m_height(corner.x - static_cast<double>(index % columns) * step, corner.y - static_cast<double>(index / columns) * step, y))
continue;
Tile.unanswered.push_back(static_cast<std::uint16_t>(index));
}
// holes (places without ground) take the average of their neighbours, spreading inwards
std::size_t missing = std::count(heights.begin(), heights.end(), no_height);
if (missing == heights.size())
@@ -1653,6 +1693,8 @@ void editor_orthophoto::update(glm::dvec3 const &Camera)
}
continue;
}
if (waits_for_ground(key))
continue;
tile &t = m_tiles[key];
if (!in_service_area(key.first, key.second))
t.empty = true;