| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/resource.h" |
| 34 |
#include "core/templates/rb_map.h" |
| 35 |
|
| 36 |
|
| 37 |
class Curve : public Resource { |
| 38 |
GDCLASS(Curve, Resource); |
| 39 |
|
| 40 |
public: |
| 41 |
static const char *SIGNAL_RANGE_CHANGED; |
| 42 |
static const char *SIGNAL_DOMAIN_CHANGED; |
| 43 |
|
| 44 |
enum TangentMode { |
| 45 |
TANGENT_FREE = 0, |
| 46 |
TANGENT_LINEAR, |
| 47 |
TANGENT_MODE_COUNT |
| 48 |
}; |
| 49 |
|
| 50 |
struct Point { |
| 51 |
Vector2 position; |
| 52 |
real_t left_tangent = 0.0; |
| 53 |
real_t right_tangent = 0.0; |
| 54 |
TangentMode left_mode = TANGENT_FREE; |
| 55 |
TangentMode right_mode = TANGENT_FREE; |
| 56 |
|
| 57 |
Point() { |
| 58 |
} |
| 59 |
|
| 60 |
Point(const Vector2 &p_position, |
| 61 |
real_t p_left = 0.0, |
| 62 |
real_t p_right = 0.0, |
| 63 |
TangentMode p_left_mode = TANGENT_FREE, |
| 64 |
TangentMode p_right_mode = TANGENT_FREE) { |
| 65 |
position = p_position; |
| 66 |
left_tangent = p_left; |
| 67 |
right_tangent = p_right; |
| 68 |
left_mode = p_left_mode; |
| 69 |
right_mode = p_right_mode; |
| 70 |
} |
| 71 |
}; |
| 72 |
|
| 73 |
Curve(); |
| 74 |
|
| 75 |
int get_point_count() const { return _points.size(); } |
| 76 |
|
| 77 |
void set_point_count(int p_count); |
| 78 |
|
| 79 |
int add_point(Vector2 p_position, |
| 80 |
real_t p_left_tangent = 0, |
| 81 |
real_t p_right_tangent = 0, |
| 82 |
TangentMode p_left_mode = TANGENT_FREE, |
| 83 |
TangentMode p_right_mode = TANGENT_FREE); |
| 84 |
int add_point_no_update(Vector2 p_position, |
| 85 |
real_t p_left_tangent = 0, |
| 86 |
real_t p_right_tangent = 0, |
| 87 |
TangentMode p_left_mode = TANGENT_FREE, |
| 88 |
TangentMode p_right_mode = TANGENT_FREE); |
| 89 |
void remove_point(int p_index); |
| 90 |
void clear_points(); |
| 91 |
|
| 92 |
int get_index(real_t p_offset) const; |
| 93 |
|
| 94 |
void set_point_value(int p_index, real_t p_position); |
| 95 |
int set_point_offset(int p_index, real_t p_offset); |
| 96 |
Vector2 get_point_position(int p_index) const; |
| 97 |
|
| 98 |
Point get_point(int p_index) const; |
| 99 |
|
| 100 |
real_t get_min_value() const { return _min_value; } |
| 101 |
void set_min_value(real_t p_min); |
| 102 |
real_t get_max_value() const { return _max_value; } |
| 103 |
void set_max_value(real_t p_max); |
| 104 |
real_t get_value_range() const { return _max_value - _min_value; } |
| 105 |
|
| 106 |
real_t get_min_domain() const { return _min_domain; } |
| 107 |
void set_min_domain(real_t p_min); |
| 108 |
real_t get_max_domain() const { return _max_domain; } |
| 109 |
void set_max_domain(real_t p_max); |
| 110 |
real_t get_domain_range() const { return _max_domain - _min_domain; } |
| 111 |
|
| 112 |
Array get_limits() const; |
| 113 |
void set_limits(const Array &p_input); |
| 114 |
|
| 115 |
real_t sample(real_t p_offset) const; |
| 116 |
real_t sample_local_nocheck(int p_index, real_t p_local_offset) const; |
| 117 |
|
| 118 |
void clean_dupes(); |
| 119 |
|
| 120 |
void set_point_left_tangent(int p_index, real_t p_tangent); |
| 121 |
void set_point_right_tangent(int p_index, real_t p_tangent); |
| 122 |
void set_point_left_mode(int p_index, TangentMode p_mode); |
| 123 |
void set_point_right_mode(int p_index, TangentMode p_mode); |
| 124 |
|
| 125 |
real_t get_point_left_tangent(int p_index) const; |
| 126 |
real_t get_point_right_tangent(int p_index) const; |
| 127 |
TangentMode get_point_left_mode(int p_index) const; |
| 128 |
TangentMode get_point_right_mode(int p_index) const; |
| 129 |
|
| 130 |
void update_auto_tangents(int p_index); |
| 131 |
|
| 132 |
Array get_data() const; |
| 133 |
void set_data(Array p_input); |
| 134 |
|
| 135 |
void bake(); |
| 136 |
void _bake() const; |
| 137 |
int get_bake_resolution() const { return _bake_resolution; } |
| 138 |
void set_bake_resolution(int p_resolution); |
| 139 |
real_t sample_baked(real_t p_offset) const; |
| 140 |
|
| 141 |
void ensure_default_setup(real_t p_min, real_t p_max); |
| 142 |
|
| 143 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 144 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 145 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 146 |
|
| 147 |
protected: |
| 148 |
static void _bind_methods(); |
| 149 |
|
| 150 |
private: |
| 151 |
void mark_dirty(); |
| 152 |
int _add_point(Vector2 p_position, |
| 153 |
real_t p_left_tangent = 0, |
| 154 |
real_t p_right_tangent = 0, |
| 155 |
TangentMode p_left_mode = TANGENT_FREE, |
| 156 |
TangentMode p_right_mode = TANGENT_FREE, |
| 157 |
bool p_mark_dirty = true); |
| 158 |
void _remove_point(int p_index, bool p_mark_dirty = true); |
| 159 |
|
| 160 |
LocalVector<Point> _points; |
| 161 |
mutable bool _baked_cache_dirty = false; |
| 162 |
mutable Vector<real_t> _baked_cache; |
| 163 |
int _bake_resolution = 100; |
| 164 |
real_t _min_value = 0.0; |
| 165 |
real_t _max_value = 1.0; |
| 166 |
real_t _min_domain = 0.0; |
| 167 |
real_t _max_domain = 1.0; |
| 168 |
}; |
| 169 |
|
| 170 |
VARIANT_ENUM_CAST(Curve::TangentMode) |
| 171 |
|
| 172 |
class Curve2D : public Resource { |
| 173 |
GDCLASS(Curve2D, Resource); |
| 174 |
|
| 175 |
struct Point { |
| 176 |
Vector2 in; |
| 177 |
Vector2 out; |
| 178 |
Vector2 position; |
| 179 |
}; |
| 180 |
|
| 181 |
LocalVector<Point> points; |
| 182 |
|
| 183 |
struct BakedPoint { |
| 184 |
real_t ofs = 0.0; |
| 185 |
Vector2 point; |
| 186 |
}; |
| 187 |
|
| 188 |
mutable bool baked_cache_dirty = false; |
| 189 |
mutable PackedVector2Array baked_point_cache; |
| 190 |
mutable PackedVector2Array baked_forward_vector_cache; |
| 191 |
mutable Vector<real_t> baked_dist_cache; |
| 192 |
mutable real_t baked_max_ofs = 0.0; |
| 193 |
|
| 194 |
void mark_dirty(); |
| 195 |
|
| 196 |
static Vector2 _calculate_tangent(const Vector2 &p_begin, const Vector2 &p_control_1, const Vector2 &p_control_2, const Vector2 &p_end, const real_t p_t); |
| 197 |
void _bake() const; |
| 198 |
|
| 199 |
real_t bake_interval = 5.0; |
| 200 |
|
| 201 |
struct Interval { |
| 202 |
int idx; |
| 203 |
real_t frac; |
| 204 |
}; |
| 205 |
Interval _find_interval(real_t p_offset) const; |
| 206 |
Vector2 _sample_baked(Interval p_interval, bool p_cubic) const; |
| 207 |
Transform2D _sample_posture(Interval p_interval) const; |
| 208 |
|
| 209 |
void _bake_segment2d(RBMap<real_t, Vector2> &r_bake, real_t p_begin, real_t p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, real_t p_tol) const; |
| 210 |
void _bake_segment2d_even_length(RBMap<real_t, Vector2> &r_bake, real_t p_begin, real_t p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, real_t p_length) const; |
| 211 |
Dictionary _get_data() const; |
| 212 |
void _set_data(const Dictionary &p_data); |
| 213 |
|
| 214 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 215 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 216 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 217 |
|
| 218 |
void _add_point(const Vector2 &p_position, const Vector2 &p_in = Vector2(), const Vector2 &p_out = Vector2(), int p_atpos = -1); |
| 219 |
void _remove_point(int p_index); |
| 220 |
|
| 221 |
Vector<RBMap<real_t, Vector2>> _tessellate_even_length(int p_max_stages = 5, real_t p_length = 0.2) const; |
| 222 |
|
| 223 |
protected: |
| 224 |
static void _bind_methods(); |
| 225 |
|
| 226 |
public: |
| 227 |
int get_point_count() const; |
| 228 |
void set_point_count(int p_count); |
| 229 |
void add_point(const Vector2 &p_position, const Vector2 &p_in = Vector2(), const Vector2 &p_out = Vector2(), int p_atpos = -1); |
| 230 |
void set_point_position(int p_index, const Vector2 &p_position); |
| 231 |
Vector2 get_point_position(int p_index) const; |
| 232 |
void set_point_in(int p_index, const Vector2 &p_in); |
| 233 |
Vector2 get_point_in(int p_index) const; |
| 234 |
void set_point_out(int p_index, const Vector2 &p_out); |
| 235 |
Vector2 get_point_out(int p_index) const; |
| 236 |
void remove_point(int p_index); |
| 237 |
void clear_points(); |
| 238 |
|
| 239 |
Vector2 sample(int p_index, real_t p_offset) const; |
| 240 |
Vector2 samplef(real_t p_findex) const; |
| 241 |
|
| 242 |
void set_bake_interval(real_t p_tolerance); |
| 243 |
real_t get_bake_interval() const; |
| 244 |
|
| 245 |
real_t get_baked_length() const; |
| 246 |
Vector2 sample_baked(real_t p_offset, bool p_cubic = false) const; |
| 247 |
Transform2D sample_baked_with_rotation(real_t p_offset, bool p_cubic = false) const; |
| 248 |
PackedVector2Array get_points() const; |
| 249 |
PackedVector2Array get_baked_points() const; |
| 250 |
Vector2 get_closest_point(const Vector2 &p_to_point) const; |
| 251 |
real_t get_closest_offset(const Vector2 &p_to_point) const; |
| 252 |
|
| 253 |
PackedVector2Array tessellate(int p_max_stages = 5, real_t p_tolerance = 4) const; |
| 254 |
PackedVector2Array tessellate_even_length(int p_max_stages = 5, real_t p_length = 20.0) const; |
| 255 |
}; |
| 256 |
|
| 257 |
class Curve3D : public Resource { |
| 258 |
GDCLASS(Curve3D, Resource); |
| 259 |
|
| 260 |
struct Point { |
| 261 |
Vector3 in; |
| 262 |
Vector3 out; |
| 263 |
Vector3 position; |
| 264 |
real_t tilt = 0.0; |
| 265 |
}; |
| 266 |
|
| 267 |
LocalVector<Point> points; |
| 268 |
#ifdef TOOLS_ENABLED |
| 269 |
|
| 270 |
mutable Vector<size_t> points_in_cache; |
| 271 |
#endif |
| 272 |
|
| 273 |
bool closed = false; |
| 274 |
|
| 275 |
mutable bool baked_cache_dirty = false; |
| 276 |
mutable PackedVector3Array baked_point_cache; |
| 277 |
mutable Vector<real_t> baked_tilt_cache; |
| 278 |
mutable PackedVector3Array baked_up_vector_cache; |
| 279 |
mutable PackedVector3Array baked_forward_vector_cache; |
| 280 |
mutable Vector<real_t> baked_dist_cache; |
| 281 |
mutable real_t baked_max_ofs = 0.0; |
| 282 |
|
| 283 |
void mark_dirty(); |
| 284 |
|
| 285 |
static Vector3 _calculate_tangent(const Vector3 &p_begin, const Vector3 &p_control_1, const Vector3 &p_control_2, const Vector3 &p_end, const real_t p_t); |
| 286 |
void _bake() const; |
| 287 |
|
| 288 |
struct Interval { |
| 289 |
int idx; |
| 290 |
real_t frac; |
| 291 |
}; |
| 292 |
Interval _find_interval(real_t p_offset) const; |
| 293 |
Vector3 _sample_baked(Interval p_interval, bool p_cubic) const; |
| 294 |
real_t _sample_baked_tilt(Interval p_interval) const; |
| 295 |
Basis _sample_posture(Interval p_interval, bool p_apply_tilt = false) const; |
| 296 |
Basis _compose_posture(int p_index) const; |
| 297 |
|
| 298 |
real_t bake_interval = 0.2; |
| 299 |
bool up_vector_enabled = true; |
| 300 |
|
| 301 |
void _bake_segment3d(RBMap<real_t, Vector3> &r_bake, real_t p_begin, real_t p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, real_t p_tol) const; |
| 302 |
void _bake_segment3d_even_length(RBMap<real_t, Vector3> &r_bake, real_t p_begin, real_t p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, real_t p_length) const; |
| 303 |
Dictionary _get_data() const; |
| 304 |
void _set_data(const Dictionary &p_data); |
| 305 |
|
| 306 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 307 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 308 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 309 |
|
| 310 |
void _add_point(const Vector3 &p_position, const Vector3 &p_in = Vector3(), const Vector3 &p_out = Vector3(), int p_atpos = -1); |
| 311 |
void _remove_point(int p_index); |
| 312 |
|
| 313 |
Vector<RBMap<real_t, Vector3>> _tessellate_even_length(int p_max_stages = 5, real_t p_length = 0.2) const; |
| 314 |
|
| 315 |
protected: |
| 316 |
static void _bind_methods(); |
| 317 |
|
| 318 |
public: |
| 319 |
#ifdef TOOLS_ENABLED |
| 320 |
|
| 321 |
Basis get_point_baked_posture(int p_index, bool p_apply_tilt = false) const; |
| 322 |
#endif |
| 323 |
|
| 324 |
int get_point_count() const; |
| 325 |
void set_point_count(int p_count); |
| 326 |
void add_point(const Vector3 &p_position, const Vector3 &p_in = Vector3(), const Vector3 &p_out = Vector3(), int p_atpos = -1); |
| 327 |
void set_point_position(int p_index, const Vector3 &p_position); |
| 328 |
Vector3 get_point_position(int p_index) const; |
| 329 |
void set_point_tilt(int p_index, real_t p_tilt); |
| 330 |
real_t get_point_tilt(int p_index) const; |
| 331 |
void set_point_in(int p_index, const Vector3 &p_in); |
| 332 |
Vector3 get_point_in(int p_index) const; |
| 333 |
void set_point_out(int p_index, const Vector3 &p_out); |
| 334 |
Vector3 get_point_out(int p_index) const; |
| 335 |
void remove_point(int p_index); |
| 336 |
void clear_points(); |
| 337 |
|
| 338 |
Vector3 sample(int p_index, real_t p_offset) const; |
| 339 |
Vector3 samplef(real_t p_findex) const; |
| 340 |
|
| 341 |
void set_closed(bool p_closed); |
| 342 |
bool is_closed() const; |
| 343 |
void set_bake_interval(real_t p_tolerance); |
| 344 |
real_t get_bake_interval() const; |
| 345 |
void set_up_vector_enabled(bool p_enable); |
| 346 |
bool is_up_vector_enabled() const; |
| 347 |
|
| 348 |
real_t get_baked_length() const; |
| 349 |
Vector3 sample_baked(real_t p_offset, bool p_cubic = false) const; |
| 350 |
Transform3D sample_baked_with_rotation(real_t p_offset, bool p_cubic = false, bool p_apply_tilt = false) const; |
| 351 |
real_t sample_baked_tilt(real_t p_offset) const; |
| 352 |
Vector3 sample_baked_up_vector(real_t p_offset, bool p_apply_tilt = false) const; |
| 353 |
PackedVector3Array get_baked_points() const; |
| 354 |
Vector<real_t> get_baked_tilts() const; |
| 355 |
PackedVector3Array get_baked_up_vectors() const; |
| 356 |
Vector<real_t> get_baked_dist_cache() const; |
| 357 |
Vector3 get_closest_point(const Vector3 &p_to_point) const; |
| 358 |
real_t get_closest_offset(const Vector3 &p_to_point) const; |
| 359 |
PackedVector3Array get_points() const; |
| 360 |
|
| 361 |
PackedVector3Array tessellate(int p_max_stages = 5, real_t p_tolerance = 4) const; |
| 362 |
PackedVector3Array tessellate_even_length(int p_max_stages = 5, real_t p_length = 0.2) const; |
| 363 |
}; |