2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* curve.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef CURVE_H
|
|
|
|
#define CURVE_H
|
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/io/resource.h"
|
2014-07-06 14:49:27 +00:00
|
|
|
|
2017-04-30 14:27:10 +00:00
|
|
|
// y(x) curve
|
|
|
|
class Curve : public Resource {
|
2019-03-19 18:35:57 +00:00
|
|
|
GDCLASS(Curve, Resource);
|
|
|
|
|
2017-04-30 14:27:10 +00:00
|
|
|
public:
|
|
|
|
static const int MIN_X = 0.f;
|
|
|
|
static const int MAX_X = 1.f;
|
|
|
|
|
2017-06-26 21:39:35 +00:00
|
|
|
static const char *SIGNAL_RANGE_CHANGED;
|
|
|
|
|
|
|
|
enum TangentMode {
|
|
|
|
TANGENT_FREE = 0,
|
|
|
|
TANGENT_LINEAR,
|
|
|
|
TANGENT_MODE_COUNT
|
|
|
|
};
|
|
|
|
|
2017-04-30 14:27:10 +00:00
|
|
|
struct Point {
|
|
|
|
Vector2 pos;
|
|
|
|
real_t left_tangent;
|
|
|
|
real_t right_tangent;
|
2017-06-26 21:39:35 +00:00
|
|
|
TangentMode left_mode;
|
|
|
|
TangentMode right_mode;
|
2017-04-30 14:27:10 +00:00
|
|
|
|
|
|
|
Point() {
|
|
|
|
left_tangent = 0;
|
|
|
|
right_tangent = 0;
|
2017-06-26 21:39:35 +00:00
|
|
|
left_mode = TANGENT_FREE;
|
|
|
|
right_mode = TANGENT_FREE;
|
2017-04-30 14:27:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 00:42:38 +00:00
|
|
|
Point(Vector2 p_pos,
|
|
|
|
real_t p_left = 0,
|
|
|
|
real_t p_right = 0,
|
|
|
|
TangentMode p_left_mode = TANGENT_FREE,
|
|
|
|
TangentMode p_right_mode = TANGENT_FREE) {
|
|
|
|
pos = p_pos;
|
|
|
|
left_tangent = p_left;
|
|
|
|
right_tangent = p_right;
|
|
|
|
left_mode = p_left_mode;
|
|
|
|
right_mode = p_right_mode;
|
2017-04-30 14:27:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Curve();
|
|
|
|
|
|
|
|
int get_point_count() const { return _points.size(); }
|
|
|
|
|
2017-06-28 00:42:38 +00:00
|
|
|
int add_point(Vector2 p_pos,
|
|
|
|
real_t left_tangent = 0,
|
|
|
|
real_t right_tangent = 0,
|
|
|
|
TangentMode left_mode = TANGENT_FREE,
|
|
|
|
TangentMode right_mode = TANGENT_FREE);
|
|
|
|
|
2017-04-30 14:27:10 +00:00
|
|
|
void remove_point(int p_index);
|
|
|
|
void clear_points();
|
|
|
|
|
|
|
|
int get_index(real_t offset) const;
|
|
|
|
|
|
|
|
void set_point_value(int p_index, real_t pos);
|
|
|
|
int set_point_offset(int p_index, float offset);
|
2017-09-10 13:37:49 +00:00
|
|
|
Vector2 get_point_position(int p_index) const;
|
2017-04-30 14:27:10 +00:00
|
|
|
|
2017-06-28 00:42:38 +00:00
|
|
|
Point get_point(int p_index) const;
|
|
|
|
|
2017-06-26 21:39:35 +00:00
|
|
|
float get_min_value() const { return _min_value; }
|
|
|
|
void set_min_value(float p_min);
|
|
|
|
|
|
|
|
float get_max_value() const { return _max_value; }
|
|
|
|
void set_max_value(float p_max);
|
|
|
|
|
2017-04-30 14:27:10 +00:00
|
|
|
real_t interpolate(real_t offset) const;
|
|
|
|
real_t interpolate_local_nocheck(int index, real_t local_offset) const;
|
|
|
|
|
|
|
|
void clean_dupes();
|
|
|
|
|
|
|
|
void set_point_left_tangent(int i, real_t tangent);
|
|
|
|
void set_point_right_tangent(int i, real_t tangent);
|
2017-06-26 21:39:35 +00:00
|
|
|
void set_point_left_mode(int i, TangentMode p_mode);
|
|
|
|
void set_point_right_mode(int i, TangentMode p_mode);
|
|
|
|
|
2017-04-30 14:27:10 +00:00
|
|
|
real_t get_point_left_tangent(int i) const;
|
|
|
|
real_t get_point_right_tangent(int i) const;
|
2017-06-26 21:39:35 +00:00
|
|
|
TangentMode get_point_left_mode(int i) const;
|
|
|
|
TangentMode get_point_right_mode(int i) const;
|
|
|
|
|
|
|
|
void update_auto_tangents(int i);
|
2017-04-30 14:27:10 +00:00
|
|
|
|
|
|
|
Array get_data() const;
|
|
|
|
void set_data(Array input);
|
|
|
|
|
|
|
|
void bake();
|
|
|
|
int get_bake_resolution() const { return _bake_resolution; }
|
2017-08-11 19:10:05 +00:00
|
|
|
void set_bake_resolution(int p_resolution);
|
2017-04-30 14:27:10 +00:00
|
|
|
real_t interpolate_baked(real_t offset);
|
|
|
|
|
2018-07-06 23:21:13 +00:00
|
|
|
void ensure_default_setup(float p_min, float p_max);
|
|
|
|
|
2017-04-30 14:27:10 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void mark_dirty();
|
|
|
|
|
|
|
|
Vector<Point> _points;
|
|
|
|
bool _baked_cache_dirty;
|
|
|
|
Vector<real_t> _baked_cache;
|
|
|
|
int _bake_resolution;
|
2017-06-26 21:39:35 +00:00
|
|
|
float _min_value;
|
|
|
|
float _max_value;
|
2019-06-21 14:06:59 +00:00
|
|
|
int _minmax_set_once; // Encodes whether min and max have been set a first time, first bit for min and second for max.
|
2017-04-30 14:27:10 +00:00
|
|
|
};
|
|
|
|
|
2017-06-26 21:39:35 +00:00
|
|
|
VARIANT_ENUM_CAST(Curve::TangentMode)
|
|
|
|
|
2014-07-06 14:49:27 +00:00
|
|
|
class Curve2D : public Resource {
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(Curve2D, Resource);
|
2014-07-06 14:49:27 +00:00
|
|
|
|
|
|
|
struct Point {
|
|
|
|
Vector2 in;
|
|
|
|
Vector2 out;
|
|
|
|
Vector2 pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Point> points;
|
|
|
|
|
|
|
|
struct BakedPoint {
|
|
|
|
float ofs;
|
|
|
|
Vector2 point;
|
|
|
|
};
|
|
|
|
|
|
|
|
mutable bool baked_cache_dirty;
|
2020-02-17 21:06:54 +00:00
|
|
|
mutable PackedVector2Array baked_point_cache;
|
2014-07-06 14:49:27 +00:00
|
|
|
mutable float baked_max_ofs;
|
|
|
|
|
|
|
|
void _bake() const;
|
|
|
|
|
|
|
|
float bake_interval;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float 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, float p_tol) const;
|
2014-07-06 14:49:27 +00:00
|
|
|
Dictionary _get_data() const;
|
|
|
|
void _set_data(const Dictionary &p_data);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
int get_point_count() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_point(const Vector2 &p_pos, const Vector2 &p_in = Vector2(), const Vector2 &p_out = Vector2(), int p_atpos = -1);
|
2017-09-10 13:37:49 +00:00
|
|
|
void set_point_position(int p_index, const Vector2 &p_pos);
|
|
|
|
Vector2 get_point_position(int p_index) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_point_in(int p_index, const Vector2 &p_in);
|
2014-07-06 14:49:27 +00:00
|
|
|
Vector2 get_point_in(int p_index) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_point_out(int p_index, const Vector2 &p_out);
|
2014-07-06 14:49:27 +00:00
|
|
|
Vector2 get_point_out(int p_index) const;
|
|
|
|
void remove_point(int p_index);
|
2016-12-03 20:35:59 +00:00
|
|
|
void clear_points();
|
2014-07-06 14:49:27 +00:00
|
|
|
|
|
|
|
Vector2 interpolate(int p_index, float p_offset) const;
|
|
|
|
Vector2 interpolatef(real_t p_findex) const;
|
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
void set_bake_interval(float p_tolerance);
|
2014-07-06 14:49:27 +00:00
|
|
|
float get_bake_interval() const;
|
|
|
|
|
|
|
|
float get_baked_length() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 interpolate_baked(float p_offset, bool p_cubic = false) const;
|
2020-02-17 21:06:54 +00:00
|
|
|
PackedVector2Array get_baked_points() const; //useful for going through
|
2018-04-24 23:28:17 +00:00
|
|
|
Vector2 get_closest_point(const Vector2 &p_to_point) const;
|
|
|
|
float get_closest_offset(const Vector2 &p_to_point) const;
|
2014-07-06 14:49:27 +00:00
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
PackedVector2Array tessellate(int p_max_stages = 5, float p_tolerance = 4) const; //useful for display
|
2014-07-06 14:49:27 +00:00
|
|
|
|
|
|
|
Curve2D();
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class Curve3D : public Resource {
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(Curve3D, Resource);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
struct Point {
|
|
|
|
Vector3 in;
|
|
|
|
Vector3 out;
|
|
|
|
Vector3 pos;
|
|
|
|
float tilt;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point() { tilt = 0; }
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Point> points;
|
|
|
|
|
|
|
|
struct BakedPoint {
|
|
|
|
float ofs;
|
|
|
|
Vector3 point;
|
|
|
|
};
|
|
|
|
|
|
|
|
mutable bool baked_cache_dirty;
|
2020-02-17 21:06:54 +00:00
|
|
|
mutable PackedVector3Array baked_point_cache;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
mutable PackedFloat32Array baked_tilt_cache;
|
2020-02-17 21:06:54 +00:00
|
|
|
mutable PackedVector3Array baked_up_vector_cache;
|
2014-02-10 01:10:30 +00:00
|
|
|
mutable float baked_max_ofs;
|
|
|
|
|
|
|
|
void _bake() const;
|
|
|
|
|
|
|
|
float bake_interval;
|
2018-05-18 22:14:25 +00:00
|
|
|
bool up_vector_enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float 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, float p_tol) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
Dictionary _get_data() const;
|
|
|
|
void _set_data(const Dictionary &p_data);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
int get_point_count() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_point(const Vector3 &p_pos, const Vector3 &p_in = Vector3(), const Vector3 &p_out = Vector3(), int p_atpos = -1);
|
2017-09-10 13:37:49 +00:00
|
|
|
void set_point_position(int p_index, const Vector3 &p_pos);
|
|
|
|
Vector3 get_point_position(int p_index) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
void set_point_tilt(int p_index, float p_tilt);
|
|
|
|
float get_point_tilt(int p_index) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_point_in(int p_index, const Vector3 &p_in);
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 get_point_in(int p_index) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_point_out(int p_index, const Vector3 &p_out);
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 get_point_out(int p_index) const;
|
|
|
|
void remove_point(int p_index);
|
2016-12-03 20:35:59 +00:00
|
|
|
void clear_points();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector3 interpolate(int p_index, float p_offset) const;
|
|
|
|
Vector3 interpolatef(real_t p_findex) const;
|
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
void set_bake_interval(float p_tolerance);
|
2014-02-10 01:10:30 +00:00
|
|
|
float get_bake_interval() const;
|
2018-05-18 22:14:25 +00:00
|
|
|
void set_up_vector_enabled(bool p_enable);
|
|
|
|
bool is_up_vector_enabled() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float get_baked_length() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 interpolate_baked(float p_offset, bool p_cubic = false) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
float interpolate_baked_tilt(float p_offset) const;
|
2018-05-18 22:14:25 +00:00
|
|
|
Vector3 interpolate_baked_up_vector(float p_offset, bool p_apply_tilt = false) const;
|
2020-02-17 21:06:54 +00:00
|
|
|
PackedVector3Array get_baked_points() const; //useful for going through
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
PackedFloat32Array get_baked_tilts() const; //useful for going through
|
2020-02-17 21:06:54 +00:00
|
|
|
PackedVector3Array get_baked_up_vectors() const;
|
2018-04-24 23:28:17 +00:00
|
|
|
Vector3 get_closest_point(const Vector3 &p_to_point) const;
|
|
|
|
float get_closest_offset(const Vector3 &p_to_point) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
PackedVector3Array tessellate(int p_max_stages = 5, float p_tolerance = 4) const; //useful for display
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Curve3D();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CURVE_H
|