feat: real-time distance modifier curve updates

This commit is contained in:
Sara Gerretsen 2026-02-23 21:15:30 +01:00
parent fc6034242e
commit c5457ffbc0
4 changed files with 61 additions and 25 deletions

View file

@ -35,7 +35,6 @@ void Terrain::child_exiting(Node *node) {
if (Engine::get_singleton()->is_editor_hint() && !is_queued_for_deletion()) {
mod->disconnect(TerrainModifier::sig_changed, callable_mp(this, &self_type::on_terrain_changed));
}
on_terrain_changed();
}
}

View file

@ -10,6 +10,22 @@ void TerrainModifier::_bind_methods() {
ADD_SIGNAL(MethodInfo(sig_changed));
}
void TerrainModifier::_notification(int what) {
switch (what) {
default:
return;
case NOTIFICATION_ENTER_TREE:
if (Engine::get_singleton()->is_editor_hint()) {
set_notify_transform(true);
}
case NOTIFICATION_TRANSFORM_CHANGED:
if (Engine::get_singleton()->is_editor_hint()) {
emit_signal(sig_changed);
}
return;
}
}
float TerrainModifier::blend(float under, float over) {
float const difference{ under - over };
float const distance{ Math::abs(difference) };
@ -38,20 +54,8 @@ float TerrainModifier::blend(float under, float over) {
}
}
void TerrainModifier::_notification(int what) {
switch (what) {
default:
return;
case NOTIFICATION_ENTER_TREE:
if (Engine::get_singleton()->is_editor_hint()) {
set_notify_transform(true);
}
case NOTIFICATION_TRANSFORM_CHANGED:
if (Engine::get_singleton()->is_editor_hint()) {
emit_signal(sig_changed);
}
return;
}
void TerrainModifier::changed() {
emit_signal(sig_changed);
}
float TerrainModifier::evaluate_at(Vector2 world_coordinate, float before) {
@ -117,9 +121,17 @@ PackedStringArray TerrainModifierDistance::get_configuration_warnings() const {
}
void TerrainModifierDistance::set_distance_weight_curve(Ref<Curve> curve) {
if (Engine::get_singleton()->is_editor_hint()) {
if (this->distance_weight_curve.is_valid()) {
this->distance_weight_curve->disconnect_changed(callable_mp(cast_to<TerrainModifier>(this), &self_type::changed));
}
if (curve.is_valid()) {
curve->connect_changed(callable_mp(cast_to<TerrainModifier>(this), &self_type::changed));
}
}
this->distance_weight_curve = curve;
update_configuration_warnings();
emit_signal(sig_changed);
changed();
}
Ref<Curve> TerrainModifierDistance::get_distance_weight_curve() const {
@ -127,9 +139,17 @@ Ref<Curve> TerrainModifierDistance::get_distance_weight_curve() const {
}
void TerrainModifierDistance::set_distance_height_curve(Ref<Curve> curve) {
if (Engine::get_singleton()->is_editor_hint()) {
if (this->distance_height_curve.is_valid()) {
this->distance_height_curve->disconnect_changed(callable_mp(cast_to<TerrainModifier>(this), &self_type::changed));
}
if (curve.is_valid()) {
curve->connect_changed(callable_mp(cast_to<TerrainModifier>(this), &self_type::changed));
}
}
this->distance_height_curve = curve;
update_configuration_warnings();
emit_signal(sig_changed);
changed();
}
Ref<Curve> TerrainModifierDistance::get_distance_height_curve() const {

View file

@ -15,6 +15,7 @@ public:
protected:
void _notification(int what);
void changed();
float blend(float under, float over);
public:

View file

@ -14,22 +14,32 @@ sky = SubResource("Sky_w3uoq")
[sub_resource type="Curve" id="Curve_kbmr5"]
_limits = [0.0, 1.0, 0.0, 50.0]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(28.063416, 1), -0.0013848883, -0.0013848883, 0, 0, Vector2(45.36001, 0.5595594), -0.05797184, -0.05797184, 0, 0, Vector2(50, 0), -0.002701958, 0.0, 0, 0]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(13.919096, 1), -0.0013848883, -0.0013848883, 0, 0, Vector2(31.5764, 0.6719189), -0.05797184, -0.05797184, 0, 0, Vector2(50, 0), -0.002701958, 0.0, 0, 0]
point_count = 4
[sub_resource type="Curve" id="Curve_w3uoq"]
_limits = [-30.0, 0.0, 0.0, 60.0]
_data = [Vector2(0, -0.02282238), 0.0, -0.0014457313, 0, 0, Vector2(60, -30), -1.1081353, 0.0, 0, 0]
_data = [Vector2(0, -0.02282238), 0.0, 0.045714226, 0, 0, Vector2(59.622047, -28.110518), -0.58994067, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_chm2y"]
_limits = [0.0, 1.0, 0.0, 40.0]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(40, 0), 0.00012987918, -0.05797184, 0, 0]
_limits = [0.0, 1.0, 0.0, 70.0]
_data = [Vector2(0, 1), 0.0, -0.026974231, 0, 0, Vector2(70, 0), 0.000552969, -0.05797184, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_o3i6r"]
_limits = [-30.0, 0.0, 0.0, 60.0]
_data = [Vector2(0, -0.02282238), 0.0, -1.6655813, 0, 0, Vector2(60, -30), -0.088242374, 0.0, 0, 0]
_limits = [-30.0, 0.0, 0.0, 100.0]
_data = [Vector2(0, 0), 0.0, -0.56894803, 0, 0, Vector2(100, -30), -0.030805072, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_nonsf"]
_limits = [0.0, 1.0, 0.0, 100.0]
_data = [Vector2(0, 1), 0.0, -0.0047784625, 0, 0, Vector2(40.63028, 0), 0.00063475175, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_4kj3c"]
_limits = [0.0, 1.0, 0.0, 100.0]
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(79.36902, 1), 0.036407854, 0.0, 0, 0]
point_count = 2
[sub_resource type="BoxMesh" id="BoxMesh_kbmr5"]
@ -42,17 +52,23 @@ environment = SubResource("Environment_o3i6r")
[node name="Terrain" type="Terrain" parent="." unique_id=1169843565]
[node name="TerrainModifierDistance" type="TerrainModifierDistance" parent="Terrain" unique_id=1885116624]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 13.434517, 11.863001, 11.648043)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.565483, 13.050577, -13.351957)
blend_distance = 4.0
distance_weight_curve = SubResource("Curve_kbmr5")
distance_height_curve = SubResource("Curve_w3uoq")
[node name="TerrainModifierDistance3" type="TerrainModifierDistance" parent="Terrain" unique_id=1846439541]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15.406048, 36.456497, -40.285374)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -44.773727, 29.812996, -46.40037)
blend_distance = 4.0
distance_weight_curve = SubResource("Curve_chm2y")
distance_height_curve = SubResource("Curve_o3i6r")
[node name="TerrainModifierDistance2" type="TerrainModifierDistance" parent="Terrain" unique_id=2110821264]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -50.95575, -7.074575, 5.691742)
blend_mode = 1
distance_weight_curve = SubResource("Curve_nonsf")
distance_height_curve = SubResource("Curve_4kj3c")
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=1089775425]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 11.772341, 0)
mesh = SubResource("BoxMesh_kbmr5")