Fix terrain curriculum traversal and hfield roughness

This commit is contained in:
8x54zj-m
2026-07-22 16:46:32 +08:00
parent a0e8501d11
commit 913d5061ff
3 changed files with 58 additions and 36 deletions

View File

@@ -22,7 +22,12 @@ BORDER_M = 5.0
PROPORTIONS = [0.1, 0.1, 0.35, 0.35, 0.1]
CUM = [sum(PROPORTIONS[:i + 1]) for i in range(len(PROPORTIONS))]
PLATFORM_M = 3.0
_SLOPE_SCALE = 0.4 # 上游原值(已验证 z_scale 上限远超 0.54
_SLOPE_SCALE = 0.25 # MotrixSim-friendly slope range
ROUGH_GRID_M = 0.20 # Correlate roughness over 20 cm, not each 5 cm pixel.
ROUGH_BASE_M = 0.01
ROUGH_GAIN_M = 0.03
OBSTACLE_BASE_M = 0.03
OBSTACLE_GAIN_M = 0.10
CELL_PX = int(CELL_M / HS) # 160
BORDER_PX = int(BORDER_M / HS) # 100
@@ -61,11 +66,16 @@ def draw_slope(canvas, x0, y0, difficulty, noise=False):
hi = max(edge_h, 0)
hf = np.clip(hf, lo, hi).astype(np.uint16)
if noise:
na = int(0.05 / VS)
n = np.random.randint(-na, na + 1, (CELL_PX, CELL_PX), dtype=np.int16)
# 噪声也只在平台外
# Independent 5 cm samples created 10 cm jumps between adjacent
# pixels. Interpolate a 20 cm grid for physically coherent roughness.
coarse_px = max(2, int(round(ROUGH_GRID_M / HS)))
amp = ROUGH_BASE_M + ROUGH_GAIN_M * difficulty
coarse = np.random.uniform(
-amp, amp, (coarse_px, coarse_px)).astype(np.float32)
n = cv2.resize(coarse, (CELL_PX, CELL_PX), interpolation=cv2.INTER_LINEAR)
n[cx - p2:cx + p2, cy - p2:cy + p2] = 0
hf = np.clip(hf.astype(np.int32) + n, 0, 65535).astype(np.uint16)
hf = np.clip(hf.astype(np.float32) * VS + n, 0, None)
hf = np.rint(hf / VS).astype(np.uint16)
canvas[y0:y0 + CELL_PX, x0:x0 + CELL_PX] += hf
@@ -105,7 +115,7 @@ def draw_obstacles(canvas, x0, y0, difficulty):
"""离散障碍物(随机矩形块)。"""
if difficulty <= 0:
return
max_h = int((0.05 + 0.2 * difficulty) / VS)
max_h = int((OBSTACLE_BASE_M + OBSTACLE_GAIN_M * difficulty) / VS)
if max_h <= 0:
return
p2 = PLATFORM_PX // 2