Commit Graph

116 Commits

Author SHA1 Message Date
jsjtxietian 34eff85014 Support “clear points” function in Path3D editor 2024-03-27 12:40:30 +08:00
Rémi Verschelde dc5b57ea44
Merge pull request #81325 from AttackButton/path_2d_editor_plugin-clear_points
Add a button to clear curve points in the Path2D editor
2024-01-05 12:02:41 +01:00
Rémi Verschelde b88eddb682
Merge pull request #78378 from 0xafbf/curve-evaluate-correct-transform
Changed the way the rotation of a curve at a point is evaluated to match PathFollow2D
2024-01-04 16:38:38 +01:00
Wilson E. Alvarez a3cb1b096f
Add const references detected by clang-tidy 2023-12-16 13:36:44 -05:00
Andrés Botero acae382010 Changed the way the rotation of a curve at a point is evaluated to match PathFollow2D 2023-10-28 01:23:38 -05:00
A Thousand Ships 034c0f1624 Replace `sanity` with `safety` for checks 2023-10-08 16:22:24 +02:00
AttackButton 93cccda827 Add a button to clear curve points in the Path2D editor 2023-10-03 09:33:38 -03:00
Ryan Hitchman 734b9d2379 Fix Curve3D baking up vectors for nontrivial curves.
The code was modified in 42aa539 to have a different basis vector, but
this line was missed and caused up vectors to invert sometimes.

Fixes #81879
2023-09-18 18:50:36 -06:00
Daniel Roberts 46e395abb1 Add handles to control Curve3D tilt 2023-08-12 14:55:38 +08:00
kobewi 5b85dabcc8 Use emit_changed() consistently 2023-06-02 22:45:18 +02:00
Rémi Verschelde 990943782a
Merge pull request #74959 from MewPurPur/nice-curves
Overhaul the Curve Editor
2023-05-29 10:28:53 +02:00
VolTer a3c4a4b039 Overhaul the Curve Editor 2023-05-28 14:17:51 +02:00
Silc Renew 42aa5398d9 Fix Pathfollow direction
Co-authored-by: aaronfranke <arnfranke@yahoo.com>
2023-05-24 17:37:00 +09:00
Biggles Bristol c920a4f051 [Fixed] for "off-by-1" bug when sampling "baked" curve data towards the end of the curve.
[Fixed] Failing test "[Curve] Custom curve with free tangents" by setting the curve's `bake_resolution` to 11.
[Fixed] test messages in "[Curve] Custom curve with free tangents" to match sample offset used in each test
[Added] New test "[Curve] Straight line offset test" in response to pull request feedback.
Update tests/scene/test_curve.h

Co-authored-by: kleonc <9283098+kleonc@users.noreply.github.com>
2023-05-20 11:28:09 +01:00
Rindbee 69f488e687 Property list changes are only notified when it did change in Curve
`Object::notify_property_list_changed()` should only be called when
the structure of the property has actually changed.

The structure of the property tree has not changed if the size of the
array has not changed, and the only possibility is that the element
value has changed.
2023-03-15 09:51:15 +08:00
Rémi Verschelde d95794ec8a
One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".
2023-01-05 13:25:55 +01:00
Rémi Verschelde 346efd29e0
Fix typos with codespell 2022-12-15 12:24:08 +01:00
Rémi Verschelde 45edf35f83
Merge pull request #69726 from xiongyaohua/tweak_curve
Handle corner cases for curve baking
2022-12-14 11:25:55 +01:00
Yaohua Xiong f806c679de Fix Curve2D::get_closest_offset 2022-12-14 09:46:07 +08:00
Yaohua Xiong adeef12b12 Handle corner cases for curve baking
When control point and point have equal position,
the derivative is 0 vector, which cause error message in Basis::look_at().
This commit handles this case.
2022-12-14 08:52:14 +08:00
Yaohua Xiong 322dbd0955 Fix Path2D fish bone direction 2022-12-06 20:45:17 +08:00
Yaohua Xiong 91e9ad92f5 Refactor baking code for Curve2D
The main change is to caculate tangent directly from bezier curve, without going
through discretized polyline, avoiding pitfalls of discretization. A similar refacor
had been applied to Curve3D.

The test cases for Curve2D is updated, comparing floating point with is_equal_approxmiate()
instead of `==`, in order to avoid float precision problem.
2022-12-05 21:22:05 +08:00
Yaohua Xiong 69f84563a3 Fix Curve3D::get_closest_point() broken
The problem is caused by calling adaptive tessellation baking function by mistake, which produce too few points for straight lines. Calling the even length tessellation fix the problem.

The code for `get_closest_point()` and `get_closest_offset()` are also updated. They used to assume bake interval to be exact, which is no longer true.

The out dated document for `get_closest_point()` is also updated.
2022-12-03 17:01:03 +08:00
Yaohua Xiong f9fa182abc Refactor Curve3D::_bake() method
The main change is to caculate tangent directly from bezier curve, without going
through discretized polyline, avoiding pitfalls of discretization.

Other changes are:
1. Add an bezier_derivative() method for Vector3, Vector2, and Math;
2. Add an tesselate_even_length() method to Curve3D, which tesselate bezier curve to even length segments adaptively;
3. Cache the tangent vectors in baked_tangent_vector_cache;
2022-11-24 10:52:06 +08:00
Yaohua Xiong 5241464a46 Refactor Curv3D and PathFollow3D
This commit makes the following major changes

1. Add "sample_baked_with_rotation()" to Curve3D, making it usable independently. A similar change was made to Curve2D previously.
2. Refactor the _bake() method on Curve3D, using Parallel Transport Frame instead of Frenet Frame.
3. Refactor the sample_* methods, including:
  i. Factor out common binary search code, following the DRY principe
  ii. sample_up_vector() interpolated up vector as part of rotation frame(posture) for consistancy and accuracy.
2022-11-12 12:03:54 +08:00
Yaohua Xiong 399c2a8dea Move rotation sampling from Path2D to Curve2D
The rotation sampling code is moved from Path2D to a new method
`sample_baked_with_rotation` on Curve2D.
2022-11-01 13:18:52 +08:00
Nikola Bunjevac e903362269 Handle last baked vector index early 2022-10-06 00:27:46 +02:00
Hugo Locurcio ae18928748
Rename Curve/Curve2D/Curve3D/Gradient `interpolate()` to `sample()`
"sampling" is a more accurate term than "interpolating" for what's
happening when using that function.
2022-08-30 22:08:38 +02:00
Micky 59e11934d8 Rename `str2var` to `str_to_var` and similar
Affects the Math class, a good chunk of the audio code, and a lot of other miscellaneous classes, too.

- `var2str` -> `var_to_str`
- `str2var` -> `str_to_var`
- `bytes2var` -> `bytes_to_var`
- `bytes2var_with_objects` -> `bytes_to_var_with_objects`
- `var2bytes` -> `var_to_bytes`
- `var2bytes_with_objects` -> `var_to_bytes_with_objects`
- `linear2db` -> `linear_to_db`
- `db2linear` -> `db_to_linear`
- `deg2rad` -> `deg_to_rad`
- `rad2deg` -> `rad_to_deg`

- `dict2inst` -> `dict_to_inst`
- `inst2dict` -> `inst_to_dict`
2022-08-26 14:58:22 +02:00
Yuri Sizov fff0e7b8e2 Clarify the Line2D, Curve2D/3D documentation and fix parameter names 2022-08-15 21:38:14 +03:00
Yuri Sizov 1362bc22bd Add tests for empty/unnamed arguments to ClassDB, Variant, GDScript 2022-08-08 16:36:01 +03:00
Hendrik Brucker 99ce0df3b1 Refactor bezier interpolation functions 2022-06-27 19:42:43 +02:00
Raul Santos adb81446a6
Fix Curve{2D,3D} notifying property list changed
Make `Curve2D` and `Curve3D` more consistent with `Curve` and avoid
calling `notify_property_list_changed` when the list of points doesn't
change.
2022-06-23 20:07:26 +02:00
Vitika9 6042b24745 Fixed dragging curve points 2022-06-22 22:17:49 +05:30
Raul Santos a9a41df0c8
Expose Curve points in the inspector
Exposes the Curve, Curve2D and Curve3D points as an array property.
2022-05-17 18:08:36 +02:00
Raul Santos 0ba0d51c9e
Implement `mark_dirty` in Curve2D and Curve3D
Implements a method `mark_dirty` in Curve2D and Curve3D like the one
that already exists in Curve, it's a convenient way to set
`baked_cache_dirty` to `true` and also emit the `changed` signal.
2022-05-17 18:08:34 +02:00
Hendrik Brucker bf9a836a50 Regression: Fix Curve2D/Curve3D baking 2022-05-16 18:17:02 +02:00
reduz 746dddc067 Replace most uses of Map by HashMap
* Map is unnecessary and inefficient in almost every case.
* Replaced by the new HashMap.
* Renamed Map to RBMap and Set to RBSet for cases that still make sense
  (order matters) but use is discouraged.

There were very few cases where replacing by HashMap was undesired because
keeping the key order was intended.
I tried to keep those (as RBMap) as much as possible, but might have missed
some. Review appreciated!
2022-05-16 10:37:48 +02:00
Raul Santos b3c37b9fe1
Fix Curve bake algorithm 2022-05-12 13:18:21 +02:00
Raul Santos a80bc715ad
Fix Curve idx calculation for baked tilts and up vectors 2022-05-12 13:18:20 +02:00
Anilforextra fc27636999 Vectors: Use clear() and has().
Use clear() instead of resize(0).

Use has() instead of "find(p_val) != -1".
2022-02-02 00:11:09 +05:45
Rémi Verschelde fe52458154
Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-03 21:27:34 +01:00
Aaron Franke 129911f61a
Improve Curve with const and real_t 2021-11-30 14:24:27 -06:00
Lightning_A e078f970db Rename `remove()` to `remove_at()` when removing by index 2021-11-23 18:58:57 -07:00
Hugo Locurcio c012fbc8b2
Rename `PROPERTY_USAGE_NOEDITOR` to `PROPERTY_USAGE_NO_EDITOR`
This is consistent with other constants that include `NO`,
such as `PROPERTY_HINT_COLOR_NO_ALPHA`.
2021-11-03 23:06:17 +01:00
Lightning_A c63b18507d Use range iterators for `Map` 2021-09-30 15:09:12 -06:00
Jihyun Yu 8a6fc54ccd Curve2D/Curve3D: exact linear interpolation
While calculating interpolated points, intervals between two baked
points has been assummed to be `baked_interval`. The assumption could
cause significant error in some extreme cases (for example #7088).

To improve accuracy, `baked_dist_cache` is introduced, which stores
distance from starting point for each baked points. `interpolate_baked`
now returns exact linear-interpolated position along baked points.
2021-08-21 16:57:59 +09:00
Aaron Franke 430ad75963
Some work on double support 2021-08-09 17:43:48 -05:00
Rémi Verschelde ac3322b0af
Use const references where possible for List range iterators 2021-07-25 12:22:25 +02:00
Aaron Franke 4e6efd1b07
Use C++ iterators for Lists in many situations 2021-07-23 17:38:28 -04:00