Skip to content

Commit 571cd0e

Browse files
committed
Merge pull request #81885 from rmmh/fix-curve3d-twisting
Fix Curve3D baking up vectors for nontrivial curves.
2 parents f0a9931 + 734b9d2 commit 571cd0e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

scene/resources/curve.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ void Curve3D::_bake() const {
16621662
const Vector3 *forward_ptr = baked_forward_vector_cache.ptr();
16631663
const Vector3 *points_ptr = baked_point_cache.ptr();
16641664

1665-
Basis frame; // X-right, Y-up, Z-forward.
1665+
Basis frame; // X-right, Y-up, -Z-forward.
16661666
Basis frame_prev;
16671667

16681668
// Set the initial frame based on Y-up rule.
@@ -1683,7 +1683,7 @@ void Curve3D::_bake() const {
16831683
Vector3 forward = forward_ptr[idx];
16841684

16851685
Basis rotate;
1686-
rotate.rotate_to_align(frame_prev.get_column(2), forward);
1686+
rotate.rotate_to_align(-frame_prev.get_column(2), forward);
16871687
frame = rotate * frame_prev;
16881688
frame.orthonormalize(); // guard against float error accumulation
16891689

tests/scene/test_curve_3d.h

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ TEST_CASE("[Curve3D] Sampling") {
209209
CHECK(curve->get_closest_point(Vector3(50, 50, 0)) == Vector3(0, 50, 0));
210210
CHECK(curve->get_closest_point(Vector3(0, 100, 0)) == Vector3(0, 50, 0));
211211
}
212+
213+
SUBCASE("sample_baked_up_vector, off-axis") {
214+
// Regression test for issue #81879
215+
Ref<Curve3D> c = memnew(Curve3D);
216+
c->add_point(Vector3());
217+
c->add_point(Vector3(0, .1, 1));
218+
CHECK_LT((c->sample_baked_up_vector(c->get_closest_offset(Vector3(0, 0, .9))) - Vector3(0, 0.995037, -0.099504)).length(), 0.01);
219+
}
212220
}
213221

214222
TEST_CASE("[Curve3D] Tessellation") {

0 commit comments

Comments
 (0)