Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Curve3D baking up vectors for nontrivial curves. #81885

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scene/resources/curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ void Curve3D::_bake() const {
const Vector3 *forward_ptr = baked_forward_vector_cache.ptr();
const Vector3 *points_ptr = baked_point_cache.ptr();

Basis frame; // X-right, Y-up, Z-forward.
Basis frame; // X-right, Y-up, -Z-forward.
Basis frame_prev;

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

Basis rotate;
rotate.rotate_to_align(frame_prev.get_column(2), forward);
rotate.rotate_to_align(-frame_prev.get_column(2), forward);
TokageItLab marked this conversation as resolved.
Show resolved Hide resolved
frame = rotate * frame_prev;
frame.orthonormalize(); // guard against float error accumulation

Expand Down
8 changes: 8 additions & 0 deletions tests/scene/test_curve_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ TEST_CASE("[Curve3D] Sampling") {
CHECK(curve->get_closest_point(Vector3(50, 50, 0)) == Vector3(0, 50, 0));
CHECK(curve->get_closest_point(Vector3(0, 100, 0)) == Vector3(0, 50, 0));
}

SUBCASE("sample_baked_up_vector, off-axis") {
// Regression test for issue #81879
Ref<Curve3D> c = memnew(Curve3D);
c->add_point(Vector3());
c->add_point(Vector3(0, .1, 1));
CHECK_LT((c->sample_baked_up_vector(c->get_closest_offset(Vector3(0, 0, .9))) - Vector3(0, 0.995037, -0.099504)).length(), 0.01);
}
}

TEST_CASE("[Curve3D] Tessellation") {
Expand Down