Update kamaz5360 snow docs — persistent deformation map, volume conservation
Replace OldVertices transfer description with the final persistent TMap solution. Document plow ridge widening and AddDepth cap removal for snow volume conservation. Update project status with commit hash and next test steps. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a7452bb70d
commit
4302183027
3 changed files with 113 additions and 39 deletions
|
|
@ -6,8 +6,9 @@ Scene: `kamNiagraSnow`
|
|||
|
||||
## User Goal
|
||||
|
||||
Tracks on snow from all objects should always remain. Currently tracks disappeared after
|
||||
driving a short distance.
|
||||
- Tracks on snow from vehicle Kleos and plow never disappear.
|
||||
- Plow can pile snow into a heap/snowdrift (сугроб).
|
||||
- Total snow volume in the scene does not decrease.
|
||||
|
||||
## Root Cause Found
|
||||
|
||||
|
|
@ -17,19 +18,44 @@ surface origin. This reset all six vertex arrays from scratch, erasing all defor
|
|||
|
||||
## Fix Applied
|
||||
|
||||
`Source/kamaz5360/Snow/SnowTiledSurfaceManager.cpp` — `UpdateProceduralSnowSurface`:
|
||||
### SnowTiledSurfaceManager.h — added
|
||||
|
||||
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.
|
||||
```cpp
|
||||
TMap<FIntPoint, float> PersistentSurfaceDepths;
|
||||
TMap<FIntPoint, FColor> PersistentSurfaceColors;
|
||||
|
||||
## Verification
|
||||
FORCEINLINE FIntPoint WorldToSurfaceGridKey(float WorldX, float WorldY) const
|
||||
{
|
||||
const float Spacing = FMath::Max(SnowSurfaceVertexSpacingCm, 1.0f);
|
||||
return FIntPoint(FMath::RoundToInt(WorldX / Spacing), FMath::RoundToInt(WorldY / Spacing));
|
||||
}
|
||||
```
|
||||
|
||||
Log line: `KAMAZ_SNOW_SURFACE_REBUILD_TRANSFER transferred=N` should appear whenever
|
||||
the surface shifts. `N > 0` if tracks existed in the overlap region.
|
||||
### SnowTiledSurfaceManager.cpp changes
|
||||
|
||||
1. **`UpdateProceduralSnowSurface` vertex loop** — restores from map before pushing vertex:
|
||||
```cpp
|
||||
const FIntPoint PersistKey = WorldToSurfaceGridKey(WorldX, WorldY);
|
||||
if (const float* StoredDepth = PersistentSurfaceDepths.Find(PersistKey))
|
||||
LocalPosition.Z = LocalBasePosition.Z + *StoredDepth;
|
||||
```
|
||||
|
||||
2. **All stamp functions** (`StampProceduralSnowSurface`, `StampProceduralSnowBox`, plow cut,
|
||||
plow deposit) — write to map after modifying vertex:
|
||||
```cpp
|
||||
const FIntPoint PersistKey = WorldToSurfaceGridKey(WorldBase.X, WorldBase.Y);
|
||||
PersistentSurfaceDepths.Add(PersistKey, SnowSurfaceVertices[Index].Z - SnowSurfaceBaseVertices[Index].Z);
|
||||
PersistentSurfaceColors.Add(PersistKey, SnowSurfaceColors[Index]);
|
||||
```
|
||||
|
||||
3. **`ClearAllSnowTiles`** — empties both maps.
|
||||
|
||||
4. **Volume conservation** — removed `GlobalSnowDepthCm * 0.75f` cap on plow deposit `AddDepth`;
|
||||
widened ridge zone (`RidgeHalfY` 55→90 cm, factor 2.5→3.5). Full removed volume is deposited.
|
||||
|
||||
## Commit
|
||||
|
||||
`garage/kamaz5360` master: `4b9ff68`
|
||||
|
||||
## Knowledge Base Links
|
||||
|
||||
|
|
@ -39,7 +65,6 @@ the surface shifts. `N > 0` if tracks existed in the overlap region.
|
|||
## 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.
|
||||
- Agent can commit/push via SSH: `forgejo:infra/agent-knowledge-base` and `forgejo:garage/kamaz5360.git`.
|
||||
- API token stored only in local memory (`C:\Users\post\.claude\projects\...\memory\reference_forgejo_access.md`), never in git.
|
||||
|
|
|
|||
|
|
@ -26,31 +26,75 @@ status: solved
|
|||
|
||||
`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 (Final — Persistent Deformation Map)
|
||||
|
||||
## Fix
|
||||
### Header (`SnowTiledSurfaceManager.h`)
|
||||
|
||||
In `UpdateProceduralSnowSurface`, before resetting the vertex arrays:
|
||||
1. Save `OldVertices`, `OldBaseVertices`, `OldColors`, `OldOrigin`, `OldVerticesPerAxis`.
|
||||
Added to private section:
|
||||
|
||||
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.
|
||||
```cpp
|
||||
// Global deformation store: grid key → snow depth above ground (cm)
|
||||
// Written on every stamp; restored when the surface rebuilds or shifts.
|
||||
TMap<FIntPoint, float> PersistentSurfaceDepths;
|
||||
TMap<FIntPoint, FColor> PersistentSurfaceColors;
|
||||
|
||||
Vertices in the new surface that fall outside the old surface area receive the default snow depth as before (newly exposed terrain).
|
||||
FORCEINLINE FIntPoint WorldToSurfaceGridKey(float WorldX, float WorldY) const
|
||||
{
|
||||
const float Spacing = FMath::Max(SnowSurfaceVertexSpacingCm, 1.0f);
|
||||
return FIntPoint(FMath::RoundToInt(WorldX / Spacing), FMath::RoundToInt(WorldY / Spacing));
|
||||
}
|
||||
```
|
||||
|
||||
This preserves all tracks and plow marks in the overlapping region and adds newly visible terrain at the edges with default snow.
|
||||
### `UpdateProceduralSnowSurface` — vertex build loop
|
||||
|
||||
## Affected File
|
||||
After computing `LocalPosition` (default snow top), before pushing to `SnowSurfaceVertices`:
|
||||
|
||||
`Source/kamaz5360/Snow/SnowTiledSurfaceManager.cpp` — function `UpdateProceduralSnowSurface`.
|
||||
```cpp
|
||||
const FIntPoint PersistKey = WorldToSurfaceGridKey(WorldX, WorldY);
|
||||
if (const float* StoredDepth = PersistentSurfaceDepths.Find(PersistKey))
|
||||
{
|
||||
LocalPosition.Z = LocalBasePosition.Z + *StoredDepth;
|
||||
if (const FColor* StoredColor = PersistentSurfaceColors.Find(PersistKey))
|
||||
VertexColor = *StoredColor;
|
||||
}
|
||||
```
|
||||
|
||||
## Verification
|
||||
### Every stamp function writes to the map
|
||||
|
||||
Log line `KAMAZ_SNOW_SURFACE_REBUILD_TRANSFER transferred=N` confirms how many deformed vertices were carried over when the surface shifts.
|
||||
After updating `SnowSurfaceVertices[Index].Z` and `SnowSurfaceColors[Index]`:
|
||||
|
||||
```cpp
|
||||
const FIntPoint PersistKey = WorldToSurfaceGridKey(WorldBase.X, WorldBase.Y);
|
||||
PersistentSurfaceDepths.Add(PersistKey, SnowSurfaceVertices[Index].Z - SnowSurfaceBaseVertices[Index].Z);
|
||||
PersistentSurfaceColors.Add(PersistKey, SnowSurfaceColors[Index]);
|
||||
```
|
||||
|
||||
Applied in: `StampProceduralSnowSurface`, `StampProceduralSnowBox`, plow cut block in `StampProceduralPlowCutAndDeposit`, and DepositSide lambda.
|
||||
|
||||
### `ClearAllSnowTiles`
|
||||
|
||||
```cpp
|
||||
PersistentSurfaceDepths.Empty();
|
||||
PersistentSurfaceColors.Empty();
|
||||
```
|
||||
|
||||
## Volume Conservation (Plow)
|
||||
|
||||
In the DepositSide lambda of `StampProceduralPlowCutAndDeposit`:
|
||||
|
||||
- **Removed** the `GlobalSnowDepthCm * 0.75f` cap on `AddDepth` so the full removed volume is deposited.
|
||||
- **Widened** ridge zone: `RidgeHalfY` 55 → 90 cm, multiplier 2.5 → 3.5 vertex spacings.
|
||||
- Total snow volume is now conserved: snow cut by the plow blade accumulates as a ridge on the sides.
|
||||
|
||||
## Properties
|
||||
|
||||
- Tracks are permanent for the entire game session (until `ClearAllSnowTiles` is called).
|
||||
- Memory cost: O(deformed vertices) in `TMap`. Typically under 1 MB even for large sessions.
|
||||
- No log spam — removed `KAMAZ_SNOW_SURFACE_REBUILD_TRANSFER` log line (no longer needed).
|
||||
- Works across unlimited surface rebuilds regardless of how far the vehicle travels.
|
||||
|
||||
## 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).
|
||||
- Persistence is in-memory only. Tracks are lost on PIE restart or game quit.
|
||||
For cross-session persistence, serialize `PersistentSurfaceDepths` in `EndPlay`/`BeginPlay`.
|
||||
- The tiled-mesh mode (`bUseProceduralTileMeshes`) already persists deformation via `SaveDirtyTile`/`LoadTile` on disk. This fix only applies to the single-mesh mode.
|
||||
|
|
|
|||
|
|
@ -11,15 +11,19 @@ machine: wuu (C:\git\kamaz5360)
|
|||
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.
|
||||
(`bUseProceduralSnowSurface = true`). Full persistent deformation map implemented:
|
||||
wheel tracks, plow cuts, and ridge deposits are permanent for the game session.
|
||||
|
||||
## Recent Fix (2026-06-07)
|
||||
## Recent Changes (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.
|
||||
### Persistent Snow Deformation Map
|
||||
|
||||
- **Goal:** Tracks from vehicle (Kleos) and plow never disappear. Plow can pile snow into ridges. Total snow volume conserved.
|
||||
- **Root cause:** `UpdateProceduralSnowSurface` rebuilt vertex array from scratch on surface shift (~32 m travel), erasing all deformations.
|
||||
- **Fix:** `TMap<FIntPoint, float> PersistentSurfaceDepths` — global session cache keyed by world grid position. Every stamp writes to the map; every surface rebuild reads from it.
|
||||
- **Volume conservation:** Plow `AddDepth` cap removed; ridge zone widened (55→90 cm half-width). Snow volume cut by plow = snow deposited as ridge.
|
||||
- **Details:** `problems/2026-06-07-kamaz-snow-tracks-disappear-on-surface-rebuild.md`
|
||||
- **Commit:** `4b9ff68` on `master`
|
||||
|
||||
## Repo
|
||||
|
||||
|
|
@ -29,5 +33,6 @@ correctly near the vehicle. Track-persistence bug fixed on 2026-06-07.
|
|||
|
||||
## 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.
|
||||
- Compile and test in `kamNiagraSnow` — drive vehicle >30 m, confirm tracks remain on return.
|
||||
- Test plow ridge accumulation — verify ridge grows with each pass and snow volume is visually conserved.
|
||||
- Optional: cross-session persistence — serialize `PersistentSurfaceDepths` in `EndPlay`/`BeginPlay` so tracks survive editor restart.
|
||||
|
|
|
|||
Reference in a new issue