70 last = replace ? last + 1 : last;
104 float viewport_size[4];
136 for (i = 0, fed = env->
data; i < env->totvert; i++, fed++) {
199 const float line_length = 0.7f;
220 for (
const int i : index_range) {
290 immUniform4f(
"outlineColor", hcolor[0], hcolor[1], hcolor[2], 1.0f);
296 for (
const int i : index_range) {
335 const bool sel_handle_only,
355 const BezTriple *left_bezt = active_keyframe_index > 0 ? &fcu->
bezt[active_keyframe_index - 1] :
386 bool sel_handle_only)
462 for (
int sel = 0; sel < 2; sel++) {
467 for (
const int i : index_range) {
555 scale[1] /= hsize / unit_scale;
559 last = (first) ? (first + (fcu->
totvert - 1)) : (
nullptr);
599 const bool use_nla_remap,
600 const bool draw_extrapolation)
611 FCurve fcurve_for_draw = *fcu_;
612 fcurve_for_draw.
driver =
nullptr;
617 ac->
scene,
id, &fcurve_for_draw, mapping_flag, &offset);
634 float pixels_per_sample = 1.5f;
647 samplefreq = std::max(samplefreq, 0.1f);
651 samplefreq = std::max(samplefreq, 0.00001f);
662 if (!draw_extrapolation) {
671 if (fcu_end < fcu_start) {
672 std::swap(fcu_start, fcu_end);
676 stime =
max_ff(stime, fcu_start);
677 etime =
min_ff(etime, fcu_end);
680 const int total_samples =
roundf((etime - stime) / samplefreq);
681 if (total_samples <= 0) {
698 for (
int i = 0; i < total_samples; i++) {
699 const float ctime = stime + i * samplefreq;
700 float eval_time = eval_start + i * eval_freq;
709 eval_time = std::min(eval_time, eval_end);
732 const bool draw_extrapolation)
734 if (!draw_extrapolation && fcu->
totvert == 1) {
739 FPoint *fpt = prevfpt + 1;
742 float unit_scale, offset;
746 const bool extrap_left = draw_extrapolation && prevfpt->
vec[0] > v2d->
cur.
xmin;
751 const bool extrap_right = draw_extrapolation && (prevfpt +
b - 1)->vec[0] < v2d->
cur.
xmax;
773 v[1] = prevfpt->
vec[1];
777 fac = (prevfpt->
vec[0] - fpt->
vec[0]) / (prevfpt->
vec[0] -
v[0]);
781 v[1] = prevfpt->
vec[1] - fac * (prevfpt->
vec[1] - fpt->
vec[1]);
808 v[1] = prevfpt->
vec[1];
813 fac = (prevfpt->
vec[0] - fpt->
vec[0]) / (prevfpt->
vec[0] -
v[0]);
817 v[1] = prevfpt->
vec[1] - fac * (prevfpt->
vec[1] - fpt->
vec[1]);
830 const float2 pixels_per_unit)
832 const float points_per_pixel = 0.25f;
833 const int resolution_x = int(((bezt->
vec[1][0] - prevbezt->
vec[1][0]) * pixels_per_unit[0]) *
837 const float min_y = std::min(
838 {bezt->
vec[1][1], bezt->
vec[2][1], prevbezt->
vec[1][1], prevbezt->
vec[0][1]});
839 const float max_y = std::max(
840 {bezt->
vec[1][1], bezt->
vec[2][1], prevbezt->
vec[1][1], prevbezt->
vec[0][1]});
841 const int resolution_y = int(((max_y - min_y) * pixels_per_unit[1]) * points_per_pixel);
846 return resolution_x + resolution_y;
858 if (resolution < 2) {
859 curve_vertices.
append({prevbezt->
vec[1][0], prevbezt->
vec[1][1]});
865 resolution =
min_ii(64, resolution);
867 float prev_key[2], prev_handle[2], bez_handle[2], bez_key[2];
873 prev_key[0] = prevbezt->
vec[1][0];
874 prev_key[1] = prevbezt->
vec[1][1];
875 prev_handle[0] = prevbezt->
vec[2][0];
876 prev_handle[1] = prevbezt->
vec[2][1];
878 bez_handle[0] = bezt->
vec[0][0];
879 bez_handle[1] = bezt->
vec[0][1];
880 bez_key[0] = bezt->
vec[1][0];
881 bez_key[1] = bezt->
vec[1][1];
896 bezier_diff_points + 1,
900 for (
float *fp = bezier_diff_points; resolution; resolution--, fp += 2) {
902 const float y = *(fp + 1);
905 MEM_delete(bezier_diff_points);
909 const float v2d_xmin,
913 float vertex_position[2];
914 vertex_position[0] = v2d_xmin;
922 vertex_position[1] = bezt->
vec[1][1];
927 float fac = (bezt->
vec[1][0] - next_bezt->
vec[1][0]) / (bezt->
vec[1][0] - vertex_position[0]);
931 vertex_position[1] = bezt->
vec[1][1] - fac * (bezt->
vec[1][1] - next_bezt->
vec[1][1]);
935 float fac = (bezt->
vec[0][0] - bezt->
vec[1][0]) / (bezt->
vec[1][0] - vertex_position[0]);
939 vertex_position[1] = bezt->
vec[1][1] - fac * (bezt->
vec[0][1] - bezt->
vec[1][1]);
942 curve_vertices.
append(vertex_position);
946 const float v2d_xmax,
949 float vertex_position[2];
950 vertex_position[0] = v2d_xmax;
958 vertex_position[1] = bezt->
vec[1][1];
963 float fac = (bezt->
vec[1][0] - prev_bezt->
vec[1][0]) / (bezt->
vec[1][0] - vertex_position[0]);
967 vertex_position[1] = bezt->
vec[1][1] - fac * (bezt->
vec[1][1] - prev_bezt->
vec[1][1]);
971 float fac = (bezt->
vec[2][0] - bezt->
vec[1][0]) / (bezt->
vec[1][0] - vertex_position[0]);
975 vertex_position[1] = bezt->
vec[1][1] - fac * (bezt->
vec[2][1] - bezt->
vec[1][1]);
978 curve_vertices.
append(vertex_position);
988 const float2 pixels_per_unit = {window_width / v2d_frame_range,
989 (window_height / v2d_value_range) * unit_scale};
990 return pixels_per_unit;
1005 {
bounds.ymin, right_key->
vec[1][1], right_key->
vec[0][1], left_key->
vec[2][1]});
1007 {
bounds.ymax, right_key->
vec[1][1], right_key->
vec[0][1], left_key->
vec[2][1]});
1019 if (!draw_extrapolation && fcu->
totvert == 1) {
1034 if (draw_extrapolation && fcu->
bezt[0].
vec[1][0] > v2d->
cur.
xmin) {
1047 const float pixel_width = v2d_frame_range / window_width;
1048 const float samples_per_pixel = 0.66f;
1049 const float evaluation_step = pixel_width / samples_per_pixel;
1053 first_key->
vec[1][0], first_key->
vec[1][0], first_key->
vec[1][1], first_key->
vec[1][1]};
1055 bool has_skipped_keys =
false;
1056 const float min_pixel_distance = 3.0f;
1059 for (
const int i : index_range.
drop_front(1)) {
1065 if (pixel_distance >= min_pixel_distance && has_skipped_keys) {
1071 has_skipped_keys =
false;
1073 prevbezt->
vec[1][0], prevbezt->
vec[1][0], prevbezt->
vec[1][1], prevbezt->
vec[1][1]};
1079 if (pixel_distance < min_pixel_distance) {
1081 has_skipped_keys =
true;
1085 switch (prevbezt->
ipo) {
1090 curve_vertices.
append({prevbezt->
vec[1][0], prevbezt->
vec[1][1]});
1091 curve_vertices.
append({bezt->
vec[1][0], prevbezt->
vec[1][1]});
1096 curve_vertices.
append({prevbezt->
vec[1][0], prevbezt->
vec[1][1]});
1107 curve_vertices.
append(prevbezt->
vec[1]);
1108 float current_frame = prevbezt->
vec[1][0] + evaluation_step;
1109 while (current_frame < bezt->vec[1][0]) {
1111 current_frame += evaluation_step;
1129 if (curve_vertices.
size() < 2) {
1180 float viewport_size[4];
1230 draw_extrapolation);
1239 else if (fcu->
fpt) {
1262 switch (fcm->
type) {
1275 ac->
scene, ale->
id, fcu, mapping_flag, &offset);
1337 float viewport_size[4];
1459 float viewport_size[4];
1470 const bool draw_extrapolation =
false;
1493 ListBaseT<bAnimListElem> anim_data = {
nullptr,
nullptr};
1508 const FCurve *fcu =
static_cast<FCurve *
>(ale.key_data);
1510 ale_active_fcurve = &ale;
1518 if (ale_active_fcurve !=
nullptr) {
1535 const ListBaseT<bAnimListElem> &anim_data)
1545 size_t channel_index = 0;
1548 for (ale = anim_data.first(); ale; ale = ale->
next, ymax -= channel_step, channel_index++) {
1562 size_t channel_index = 0;
1568 for (ale = anim_data.first(); ale; ale = ale->
next, ymax -= channel_step, channel_index++) {
1582 block_end(
C, block);
1583 block_draw(
C, block);
#define FCURVE_ACTIVE_KEYFRAME_NONE
#define BEZT_ISSEL_ANY(bezt)
#define IN_RANGE(a, b, c)
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr IndexRange()=default
constexpr IndexRange drop_front(int64_t n) const
void append(const T &value)
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
float3x3 scale(float3x3 mat, float2 scale)
void get_color_3fv(int colorid, float col[3])
void get_color_4fv(int colorid, float col[4])
float get_value_f(int colorid)
void get_color_shade_4fv(int colorid, int offset, float col[4])
float view2d_scale_get_x(const View2D *v2d)
void view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
MINLINE float min_ff(float a, float b)
void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float ymaxc, size_t channel_index)
static void draw_fcurve(bAnimContext *ac, SpaceGraph *sipo, ARegion *region, bAnimListElem *ale)
bool BKE_fcurve_calc_range(const FCurve *fcu, float *r_min, float *r_max, bool selected_keys_only)
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
void immUniformColor3f(float r, float g, float b)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
void graph_draw_ghost_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region)
void immUniform2f(const char *name, float x, float y)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
static void draw_fcurve_vertices(ARegion *region, FCurve *fcu, bool do_handles, bool sel_handle_only)
static bool draw_fcurve_handles_check(const SpaceGraph *sipo, const FCurve *fcu)
GPUVertFormat * immVertexFormat()
static void add_extrapolation_point_right(const FCurve *fcu, const float v2d_xmax, Vector< float2 > &curve_vertices)
void GPU_point_size(float size)
static void draw_fcurve_active_handle_vertices(const FCurve *fcu, const bool sel_handle_only, const uint pos)
void immBegin(GPUPrimType, uint vertex_len)
float ANIM_nla_tweakedit_remap(bAnimListElem *ale, const float cframe, const eNlaTime_ConvertModes mode)
static void draw_fcurve_handle_vertices(FCurve *fcu, View2D *v2d, bool sel_handle_only, uint pos)
void GPU_line_smooth(bool enable)
static void expand_key_bounds(const BezTriple *left_key, const BezTriple *right_key, rctf &bounds)
@ TH_HANDLE_VERTEX_SELECT
ATTR_WARN_UNUSED_RESULT const BMVert * v
void immUniformColor4fv(const float rgba[4])
@ USER_ANIM_HIGH_QUALITY_DRAWING
@ USER_ANIM_ONLY_SHOW_SELECTED_CURVE_KEYS
bool ANIM_nla_mapping_allowed(const bAnimListElem *ale)
static void draw_fcurve_modifier_controls_envelope(FModifier *fcm, View2D *v2d, bAnimListElem *ale_nla_remap)
void ANIM_nla_mapping_apply_if_needed_fcurve(bAnimListElem *ale, FCurve *fcu, const bool restore, const bool only_keys)
static void draw_fcurve_selected_keyframe_vertices(FCurve *fcu, bool sel, uint pos, const IndexRange index_range)
void GPU_line_width(float width)
void GPU_matrix_scale_2f(float x, float y)
float ANIM_UI_get_channel_height()
static float fcurve_display_alpha(const FCurve *fcu)
float GPU_line_width_get()
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
@ FMODIFIER_TYPE_ENVELOPE
AnimData * BKE_animdata_from_id(const ID *id)
static IndexRange get_bounding_bezt_index_range(const FCurve *fcu, const float min, const float max)
float ANIM_UI_get_first_channel_top(View2D *v2d)
static float calculate_pixel_distance(const rctf &bounds, const float2 pixels_per_unit)
bool BKE_fcurve_is_protected(const FCurve &fcu)
void immUniformThemeColor(int color_id)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
static int calculate_bezt_draw_resolution(BezTriple *bezt, BezTriple *prevbezt, const float2 pixels_per_unit)
static void add_extrapolation_point_left(const FCurve *fcu, const float v2d_xmin, Vector< float2 > &curve_vertices)
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
size_t ANIM_animdata_filter(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
void immVertex2f(uint attr_id, float x, float y)
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_CURVE_VISIBLE
void GPU_viewport_size_get_f(float coords[4])
void immAttr4fv(uint attr_id, const float data[4])
static void draw_fcurve_samples(ARegion *region, const FCurve *fcu, const float unit_scale)
static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, const uint shdr_pos, const bool draw_extrapolation)
@ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
@ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA
@ GPU_SHADER_3D_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_COLOR
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_3D_FLAT_COLOR
void immUniform4fv(const char *name, const float data[4])
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
static void draw_cross(float position[2], const float scale[2], uint attr_id)
void immUniformThemeColorShade(int color_id, int offset)
static void set_fcurve_vertex_color(FCurve *fcu, bool sel)
FModifier * find_active_fmodifier(ListBaseT< FModifier > *modifiers)
void GPU_program_point_size(bool enable)
void ANIM_channel_draw_widgets(const bContext *C, bAnimContext *ac, bAnimListElem *ale, ui::Block *block, const rctf *rect, size_t channel_index)
@ SIPO_NO_DRAW_EXTRAPOLATION
void GPU_matrix_translate_2f(float x, float y)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region, const ListBaseT< bAnimListElem > &anim_data)
static void draw_fcurve_curve(bAnimContext *ac, ID *id, const FCurve *fcu_, View2D *v2d, uint pos, const bool use_nla_remap, const bool draw_extrapolation)
void graph_draw_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region, short sel)
void BKE_fcurve_correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2])
void immUniform4f(const char *name, float x, float y, float z, float w)
int BKE_fcurve_active_keyframe_index(const FCurve *fcu)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
MINLINE float max_ff(float a, float b)
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
bool BKE_fcurve_are_keyframes_usable(const FCurve &fcu)
float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag, float *r_offset)
void GPU_matrix_translate_2fv(const float vec[2])
void immUniform2fv(const char *name, const float data[2])
static void add_bezt_vertices(BezTriple *bezt, BezTriple *prevbezt, int resolution, Vector< float2 > &curve_vertices)
void immUniformColor3fv(const float rgb[3])
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
void GPU_blend(GPUBlend blend)
void immUniform1i(const char *name, int x)
void immVertex2fv(uint attr_id, const float data[2])
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
void immUniformColor3fvAlpha(const float rgb[3], float a)
MINLINE int min_ii(int a, int b)
MINLINE int clamp_i(int value, int min, int max)
@ FCURVE_EXTRAPOLATE_CONSTANT
static void draw_fcurve_selected_handle_vertices(FCurve *fcu, View2D *v2d, bool sel, bool sel_handle_only, uint pos)
static void draw_fcurve_handles(SpaceGraph *sipo, ARegion *region, const FCurve *fcu)
float ANIM_UI_get_channel_step()
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
static void draw_fcurve_curve_keys(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, uint pos, const bool draw_extrapolation)
static void draw_fcurve_keyframe_vertices(FCurve *fcu, View2D *v2d, const uint pos)
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
static float2 calculate_pixels_per_unit(View2D *v2d, const float unit_scale)
float evaluate_fcurve(const FCurve *fcu, float evaltime)
short ANIM_get_normalization_flags(SpaceLink *space_link)
static void draw_fcurve_active_vertex(const FCurve *fcu, const View2D *v2d, const uint pos)
eBezTriple_Interpolation ipo
ListBaseT< FModifier > modifiers
bke::FCurveRuntime * runtime
ListBaseT< FCurve > ghost_curves
SpaceGraph_Runtime runtime