step: kamaz snow tracks persist fix — root cause + solution documented

This commit is contained in:
krustophski 2026-06-07 03:57:48 +03:00
parent 169a4b694d
commit 25103240be
4 changed files with 135 additions and 0 deletions

View file

@ -0,0 +1,45 @@
# 2026-06-07 KAMAZ Snow Tracks Persistence Fix
Project: `garage/kamaz5360`
Machine: `wuu` (`C:\git\kamaz5360`)
Scene: `kamNiagraSnow`
## User Goal
Tracks on snow from all objects should always remain. Currently tracks disappeared after
driving a short distance.
## Root Cause Found
`ASnowTiledSurfaceManager::UpdateProceduralSnowSurface` was called with `bForceRebuild=true`
whenever the vehicle moved more than `SnowSurfaceHalfExtentCm * 0.65` (~32 m) from the
surface origin. This reset all six vertex arrays from scratch, erasing all deformations.
## Fix Applied
`Source/kamaz5360/Snow/SnowTiledSurfaceManager.cpp` — `UpdateProceduralSnowSurface`:
1. Before resetting vertex arrays, copy `OldVertices`, `OldBaseVertices`, `OldColors`,
`OldOrigin`, `OldVerticesPerAxis`.
2. After building fresh vertices from `GlobalSnowDepthCm`, run a transfer pass:
for each new vertex within the old surface bounds, compute the exact old grid index
(both grids snap to the same `SnowSurfaceVertexSpacingCm`), compare depths, and
copy the old depth + colour if deformation differs by > 0.05 cm.
## Verification
Log line: `KAMAZ_SNOW_SURFACE_REBUILD_TRANSFER transferred=N` should appear whenever
the surface shifts. `N > 0` if tracks existed in the overlap region.
## Knowledge Base Links
- `problems/2026-06-07-kamaz-snow-tracks-disappear-on-surface-rebuild.md`
- `projects/kamaz5360/status.md`
## About git.4min.pro Access
- Forgejo instance at `192.168.170.41` (alias `forgejo` in SSH config).
- Public HTTPS URL `https://git.4min.pro` also works.
- SSH key: `C:/Users/post/.ssh/id_ed25519_forgejo`.
- Agent can commit/push to `forgejo:infra/agent-knowledge-base` and `forgejo:garage/kamaz5360.git` via SSH.
- HTTPS API returns 404 for private repos without a token — use SSH instead.

View file

@ -31,3 +31,4 @@ YYYY-MM-DD-short-topic.md
- `2026-06-04-actionstreamer-obs-srt-receiver.md`
- `2026-06-06-home-cluster-ssl-pxe-forgejo-backup.md`
- `2026-06-07-snowwater-forgejo-ssh-windows.md`
- `2026-06-07-kamaz-snow-tracks-persist.md`

View file

@ -0,0 +1,56 @@
---
date: 2026-06-07
project: garage/kamaz5360
scene: kamNiagraSnow
status: solved
---
# Snow Tracks Disappear When Vehicle Drives Far
## Symptoms
- Wheel tracks, plow marks, and brush clearings made on the snow surface disappear.
- Tracks vanish after driving roughly 30–40 metres from where they were made.
- On return the snow looks untouched again.
## Environment
- Project: `C:\git\kamaz5360`
- Scene: `Content/kamaz5360/Maps/kamNiagraSnow.umap`
- Class: `ASnowTiledSurfaceManager` — single-mesh mode (`bUseProceduralSnowSurface = true`)
- File: `Source/kamaz5360/Snow/SnowTiledSurfaceManager.cpp`
## Root Cause
`UpdateActiveTiles` in `KamazSnowTruckPawn.cpp` calls `UpdateProceduralSnowSurface(FocusLocation, bForceRebuild=true)` whenever the vehicle moves more than `SnowSurfaceHalfExtentCm * 0.65` (default 5000 × 0.65 = 3250 cm ≈ 32 m) from the current surface origin.
`UpdateProceduralSnowSurface` with `bForceRebuild=true` resets all six vertex arrays from scratch and re-fills them from `GlobalSnowDepthCm`. This completely erases all deformations: wheel tracks, plow cuts, ridges, and brush clearings.
The single-surface mode had no mechanism to preserve deformations across a rebuild.
## Fix
In `UpdateProceduralSnowSurface`, before resetting the vertex arrays:
1. Save `OldVertices`, `OldBaseVertices`, `OldColors`, `OldOrigin`, `OldVerticesPerAxis`.
After the vertex build loop, before the triangle loop, add a transfer pass:
- For each new vertex, compute its corresponding index in the old surface grid (both grids are snapped to the same `SnowSurfaceVertexSpacingCm`, so indices are exact integers).
- If the old vertex was deformed (`|OldDepthCm - NewDefaultDepthCm| > 0.05 cm`), copy its Z depth and colour into the new surface.
Vertices in the new surface that fall outside the old surface area receive the default snow depth as before (newly exposed terrain).
This preserves all tracks and plow marks in the overlapping region and adds newly visible terrain at the edges with default snow.
## Affected File
`Source/kamaz5360/Snow/SnowTiledSurfaceManager.cpp` — function `UpdateProceduralSnowSurface`.
## Verification
Log line `KAMAZ_SNOW_SURFACE_REBUILD_TRANSFER transferred=N` confirms how many deformed vertices were carried over when the surface shifts.
## Notes
- Memory cost: three extra `TArray<FVector/FColor>` copies made at rebuild time (~10 MB for 500×500 vertex grid with 20 cm spacing). Freed immediately after transfer.
- The tiled-mesh mode (`bUseProceduralTileMeshes`) already persists deformation via `SaveDirtyTile`/`LoadTile` on disk. This bug only affects the single-mesh mode.
- If `GlobalSnowDepthCm` is changed between rebuilds, the transferred vertices keep their absolute depth above ground, which is the desired behaviour (tracks remain shallow, fresh areas get the new global depth).

View file

@ -0,0 +1,33 @@
---
project: kamaz5360
updated: 2026-06-07
machine: wuu (C:\git\kamaz5360)
---
# KAMAZ 5360 Snow Plow — Project Status
## Current State
Active development scene: `kamNiagraSnow.umap`.
Snow surface system (`ASnowTiledSurfaceManager`) runs in single-mesh procedural mode
(`bUseProceduralSnowSurface = true`). Wheel tracks, plow cuts, and brush clearings work
correctly near the vehicle. Track-persistence bug fixed on 2026-06-07.
## Recent Fix (2026-06-07)
- **Bug:** Tracks disappeared after driving ~30 m from origin.
- **Root cause:** `UpdateProceduralSnowSurface` rebuilt vertex array from scratch on surface shift, erasing all deformations.
- **Fix:** Deformation transfer pass added in `SnowTiledSurfaceManager.cpp::UpdateProceduralSnowSurface`. Old vertex depths are carried over to matching positions in the new surface.
- **Details:** `problems/2026-06-07-kamaz-snow-tracks-disappear-on-surface-rebuild.md`
## Repo
- Local: `C:\git\kamaz5360`
- Remote: `forgejo:garage/kamaz5360.git`
- Branch: `master`
## Next Actions
- Compile and test the fix in `kamNiagraSnow` — verify `KAMAZ_SNOW_SURFACE_REBUILD_TRANSFER` log appears and tracks persist across a surface shift.
- Consider whether the scene needs a `ASnowTiledSurfaceManager` actor placed, or if `bEnableTilePersistence` should be toggled for full cross-session persistence.