chore: improved smoothness of paths

This commit is contained in:
Sara Gerretsen 2026-03-03 18:16:18 +01:00
parent e2207eec68
commit 0446f302f7
2 changed files with 19 additions and 91 deletions

View file

@ -287,10 +287,10 @@ float TerrainModifierPath::evaluate_line(Vector3 a, bool a_end, Vector3 b, bool
out_dot = right.normalized().dot(relative_coordinate);
out_distance = world_coordinate.distance_to({ closest_on_line.x, closest_on_line.z });
out_percentage = w;
if (!a_end) {
if (false && !a_end) {
w = w < 0 ? 0 : w;
}
if (!b_end) {
if (false && !b_end) {
w = w > 1 ? 1 : w;
}
return a.y + (b.y - a.y) * w;
@ -306,8 +306,7 @@ float TerrainModifierPath::evaluate_at(Vector2 world_coordinate, float before) {
if (right_curve.is_null()) {
right_curve = this->curve_left_buffer;
}
float out_score{ 0.f };
float out_delta{ 0.f };
float out_height{ before };
long const count{ this->closed ? this->points.size() : this->points.size() - 1 };
for (int i{ 0 }; i < count; i++) {
Vector3 const ipos{ this->points[i] };
@ -319,37 +318,15 @@ float TerrainModifierPath::evaluate_at(Vector2 world_coordinate, float before) {
float const right{ right_curve->sample(distance) };
float const ndot{ dot / distance };
float separation{ ndot / 2.f + 0.5f };
float turn{ 0.f };
Vector3 const right_direction{ (next_pos - ipos).normalized().cross({ 0, 1, 0 }) };
Vector3 turn_vector{ 0, 0, 0 };
if (!is_end && percentage >= 1.f) {
turn_vector = this->points[Math::wrapi(i + 2, 0, this->points.size())] - next_pos;
turn = (turn_vector).dot(right_direction);
separation = turn >= 0 ? 0 : 1;
} else if (!is_start && percentage <= 0.f) {
turn_vector = this->points[Math::wrapi(i - 1, 0, this->points.size())] - ipos;
turn = (turn_vector).dot(right_direction);
separation = turn >= 0 ? 0 : 1;
} else if (!is_start && !is_end) {
if (percentage > 0.f && percentage < 1.f) {
separation = Math::round(separation);
turn = -dot;
}
if ((percentage > -Math::abs(turn) && percentage < 1.f + Math::abs(turn)) || Math::abs(turn) / turn != Math::abs(dot) / dot) {
float const weight{ left * (1 - separation) + right * separation };
float const blended_height{ Math::lerp(before, height, weight) };
float const delta{ blended_height - before };
float const score{ Math::abs(delta) };
if (score > out_score) {
out_score = score;
out_delta = delta;
}
}
float const weight{ left * (1.f - separation) + right * separation };
float const blended_height{ Math::lerp(out_height, height, weight) };
out_height = blended_height;
}
this->lock.unlock_shared();
if (out_score == 0.f) {
return before;
}
return before + out_delta;
return out_height;
}
void TerrainModifierPath::path_changed() {

View file

@ -12,20 +12,10 @@ sky_material = SubResource("ProceduralSkyMaterial_kbmr5")
background_mode = 2
sky = SubResource("Sky_w3uoq")
[sub_resource type="Curve" id="Curve_w3uoq"]
_limits = [0.0, 1.0, 0.0, 300.0]
_data = [Vector2(0, 1), 0.0, -0.00018586064, 0, 0, Vector2(300, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_o3i6r"]
_limits = [0.0, 1.0, 0.0, 100.0]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(52.483585, 0.53811765), -0.024930112, -0.024930112, 0, 0, Vector2(71.53754, 0.12219274), -0.012579738, -0.012579738, 0, 0, Vector2(100, 0), 0.0, 0.0, 0, 0]
point_count = 4
[sub_resource type="Curve" id="Curve_kbmr5"]
_limits = [0.0, 1.0, 0.0, 300.0]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(69.40413, 0.8155421), -0.008522048, -0.008522048, 0, 0, Vector2(124.08008, 0.34781557), -0.0070376517, -0.0070376517, 0, 0, Vector2(244.43303, 0), 0.00011380972, 0.0, 0, 0]
point_count = 4
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(159.58649, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="BoxMesh" id="BoxMesh_kbmr5"]
@ -40,66 +30,27 @@ chunk_size = 100
thread_count = 5
[node name="TerrainModifierPath2" type="TerrainModifierPath" parent="Terrain" unique_id=645020759]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 251.12363, 255.25969, 248.8021)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 251.12363, 238.12749, 248.8021)
gizmo_extents = 100.0
curve_left = SubResource("Curve_w3uoq")
curve_left = SubResource("Curve_kbmr5")
[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=59754729]
gizmo_extents = 50.0
[node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=1474399635]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 595.01825, -141.92302, 42.69197)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 208.39258, -151.63309, -3.5208893)
gizmo_extents = 50.0
[node name="TerrainModifierPath4" type="TerrainModifierPath" parent="Terrain" unique_id=1865212969]
transform = Transform3D(0.17220415, 0, -0.9850613, 0, 1, 0, 0.9850613, 0, 0.17220415, 847.4274, 114.188705, 296.454)
gizmo_extents = 100.0
curve_left = SubResource("Curve_w3uoq")
[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath4" unique_id=1307746348]
[node name="TerrainModifierPathPoint4" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=827455271]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 398.07617, -92.98459, 55.261307)
gizmo_extents = 50.0
[node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath4" unique_id=331993744]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 595.01825, -12.977875, 42.69197)
[node name="TerrainModifierPathPoint5" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=1713795815]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 406.39465, 1.3392181, 172.78859)
gizmo_extents = 50.0
[node name="TerrainModifierPath3" type="TerrainModifierPath" parent="Terrain" unique_id=1721431246]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 482.5311, 36.249924, 85.91423)
curve_left = SubResource("Curve_o3i6r")
[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=1744128498]
[node name="TerrainModifierPathPoint2" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=560389606]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 116.74786)
[node name="TerrainModifierPathPoint4" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=221640403]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -32.71512, 229.67038)
[node name="TerrainModifierPathPoint5" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=2015729881]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -77.74802, 319.90332)
[node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath3" unique_id=2010545766]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -120.10968, 381.31598)
[node name="TerrainModifierPath" type="TerrainModifierPath" parent="Terrain" unique_id=314094590]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1033.4109, 14.052078, 504.81018)
gizmo_extents = 100.0
curve_left = SubResource("Curve_kbmr5")
[node name="TerrainModifierPathPoint" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath" unique_id=183585959]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -33.743713, 0)
gizmo_extents = 50.0
[node name="TerrainModifierPathPoint2" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath" unique_id=597094982]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -287.58557, -82.655075, -121.09625)
gizmo_extents = 50.0
[node name="TerrainModifierPathPoint3" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath" unique_id=225558441]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -762.8348, -186.70262, 158.77417)
gizmo_extents = 50.0
[node name="TerrainModifierPathPoint4" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath" unique_id=423129060]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1223.7019, -259.18048, 0)
[node name="TerrainModifierPathPoint6" type="TerrainModifierPathPoint" parent="Terrain/TerrainModifierPath2" unique_id=1627846467]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 406.39465, 2.132721, 207.86342)
gizmo_extents = 50.0
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=1089775425]