feat(tools): Strata modifier quantises steep walls into ledges

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
OlivierandClaude Fable 5.1 committed 2026-10-06 21:39:30 +02:00
1 parent 6dd2e86f91
commit 26f29ce14f
2 files changed
+78 -1

No files matched your search

+39
View File
@@ -415,6 +415,45 @@ class Modifier extends RefCounted:
return elevation_m
## Quantises steep ground into horizontal ledges layer_height_m apart: the stratified
## walls of a canyon or cliff. Flat floors and summits are below minimum_slope_degrees and
## stay untouched; the effect is full from full_slope_degrees. sharpness 0 leaves the
## field unchanged, 1 cuts hard steps. radius_m 0 applies everywhere.
class Strata extends Modifier:
var layer_height_m: float
var sharpness: float
var centre: Vector2
var radius_m: float
var _minimum_tangent: float
var _full_tangent: float
func _init(
p_layer_height_m: float,
p_sharpness: float,
p_minimum_slope_degrees: float,
p_full_slope_degrees: float,
p_centre: Vector2,
p_radius_m: float
) -> void:
layer_height_m = p_layer_height_m
sharpness = clampf(p_sharpness, 0.0, 0.999)
centre = p_centre
radius_m = p_radius_m
_minimum_tangent = tan(deg_to_rad(p_minimum_slope_degrees))
_full_tangent = tan(deg_to_rad(p_full_slope_degrees))
func modify(x_m: float, z_m: float, elevation_m: float, gradient: Vector2) -> float:
var weight := smoothstep(_minimum_tangent, _full_tangent, gradient.length())
if radius_m > 0.0:
weight *= 1.0 - smoothstep(radius_m * 0.8, radius_m, Vector2(x_m, z_m).distance_to(centre))
if weight <= 0.0:
return elevation_m
var layer := floorf(elevation_m / layer_height_m)
var fraction := elevation_m / layer_height_m - layer
var sharpened := clampf((fraction - 0.5) / (1.0 - sharpness) + 0.5, 0.0, 1.0)
return lerpf(elevation_m, (layer + sharpened) * layer_height_m, weight)
class MaterialPatch extends RefCounted:
var centre: Vector2
var radius_m: float