Blender V5.3
action_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9/* System includes ----------------------------------------------------- */
10
11#include <cfloat>
12#include <cstdlib>
13#include <cstring>
14
15#include "BLI_listbase.hh"
16#include "BLI_math_vector_c.hh"
17#include "BLI_memory_utils.hh"
18#include "BLI_utildefines.hh"
19
20/* Types --------------------------------------------------------------- */
21
22#include "DNA_anim_types.h"
23#include "DNA_modifier_types.h"
24#include "DNA_node_types.h"
25#include "DNA_object_types.h"
26#include "DNA_scene_types.h"
27#include "DNA_screen_types.h"
28
30#include "BKE_pointcache.h"
31#include "BKE_scene_runtime.hh"
32
33#include "ANIM_action.hh"
34
35/* Everything from source (BIF, BDR, BSE) ------------------------------ */
36
37#include "GPU_immediate.hh"
38#include "GPU_matrix.hh"
39#include "GPU_state.hh"
40
41#include "UI_interface.hh"
42#include "UI_resources.hh"
43#include "UI_view2d.hh"
44
45#include "ED_anim_api.hh"
46#include "ED_keyframes_draw.hh"
47
48#include "MOD_nodes.hh"
49
50#include "action_intern.hh"
51
52namespace blender {
53
54/* -------------------------------------------------------------------- */
57
59 bAnimContext *ac,
60 ARegion *region,
61 const ListBaseT<bAnimListElem> &anim_data)
62{
63 bAnimListElem *ale;
64 View2D *v2d = &region->v2d;
65 /* need to do a view-sync here, so that the keys area doesn't jump around (it must copy this) */
66 ui::view2d_sync(nullptr, ac->area, v2d, V2D_LOCK_COPY);
67
68 const float channel_step = ANIM_UI_get_channel_step();
69 /* Loop through channels, and set up drawing depending on their type. */
70 { /* first pass: just the standard GL-drawing for backdrop + text */
71 size_t channel_index = 0;
72 float ymax = ANIM_UI_get_first_channel_top(v2d);
73
74 for (ale = anim_data.first(); ale; ale = ale->next, ymax -= channel_step, channel_index++) {
75 const float ymin = ymax - ANIM_UI_get_channel_height();
76
77 /* check if visible */
78 if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
79 IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax))
80 {
81 /* draw all channels using standard channel-drawing API */
82 ANIM_channel_draw(ac, ale, ymin, ymax, channel_index);
83 }
84 }
85 }
86 { /* second pass: widgets */
87 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
88 size_t channel_index = 0;
89 float ymax = ANIM_UI_get_first_channel_top(v2d);
90
91 for (ale = anim_data.first(); ale; ale = ale->next, ymax -= channel_step, channel_index++) {
92 const float ymin = ymax - ANIM_UI_get_channel_height();
93
94 /* check if visible */
95 if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
96 IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax))
97 {
98 /* draw all channels using standard channel-drawing API */
99 rctf channel_rect;
100 BLI_rctf_init(&channel_rect, 0, v2d->cur.xmax, ymin, ymax);
101 ANIM_channel_draw_widgets(C, ac, ale, block, &channel_rect, channel_index);
102 }
103 }
104
105 block_end(C, block);
106 block_draw(C, block);
107 }
108}
109
111
112/* -------------------------------------------------------------------- */
115
116/* extra padding for lengths (to go under scrollers) */
117#define EXTRA_SCROLL_PAD 100.0f
118
119/* Draw manually set intended playback frame ranges for actions. */
120static void draw_channel_action_ranges(ListBaseT<bAnimListElem> *anim_data, View2D *v2d)
121{
122 /* Variables for coalescing the Y region of one action. */
123 bAction *cur_action = nullptr;
124 AnimData *cur_adt = nullptr;
125 float cur_ymax;
126
127 /* Walk through channels, grouping contiguous spans referencing the same action. */
129 const float ystep = ANIM_UI_get_channel_step();
130 float ymin = ymax - ystep;
131
132 for (bAnimListElem *ale = anim_data->first(); ale; ale = ale->next, ymax = ymin, ymin -= ystep) {
133 bAction *action = nullptr;
134 AnimData *adt = nullptr;
135
136 /* check if visible */
137 if (IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
138 IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax))
139 {
140 /* check if anything to show for this channel */
141 if (ale->datatype != ALE_NONE) {
142 action = ANIM_channel_action_get(ale);
143
144 if (action) {
145 adt = ale->adt;
146 }
147 }
148 }
149
150 /* Extend the current region, or flush and restart. */
151 if (action != cur_action || adt != cur_adt) {
152 if (cur_action) {
153 ANIM_draw_action_framerange(cur_adt, cur_action, v2d, ymax, cur_ymax);
154 }
155
156 cur_action = action;
157 cur_adt = adt;
158 cur_ymax = ymax;
159 }
160 }
161
162 /* Flush the last region. */
163 if (cur_action) {
164 ANIM_draw_action_framerange(cur_adt, cur_action, v2d, ymax, cur_ymax);
165 }
166}
167
169 ListBaseT<bAnimListElem> &anim_data,
170 View2D *v2d,
171 uint pos)
172{
173 uchar col1[4], col2[4];
174 uchar col1a[4], col2a[4];
175 uchar col1b[4], col2b[4];
176 uchar col_summary[4];
177
178 /* get theme colors */
182
185
188
189 float ymax = ANIM_UI_get_first_channel_top(v2d);
190 const float channel_step = ANIM_UI_get_channel_step();
191 bAnimListElem *ale;
192 for (ale = anim_data.first(); ale; ale = ale->next, ymax -= channel_step) {
193 const float ymin = ymax - ANIM_UI_get_channel_height();
194
195 /* check if visible */
196 if (!(IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
197 IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax)))
198 {
199 continue;
200 }
202 int sel = 0;
203
204 /* determine if any need to draw channel */
205 if (ale->datatype == ALE_NONE) {
206 continue;
207 }
208 /* determine if channel is selected */
209 if (acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT)) {
211 }
212
214 switch (ale->type) {
215 case ANIMTYPE_SUMMARY: {
217 /* Only draw the summary line backdrop when it is expanded. If the entire dope sheet is
218 * just one line, there is no need for any distinction between lines, and the red-ish
219 * color is only going to be a distraction. */
220 continue;
221 }
223 break;
224 }
226 case ANIMTYPE_SCENE:
227 case ANIMTYPE_OBJECT: {
228 immUniformColor3ubvAlpha(col1b, sel ? col1[3] : col1b[3]);
229 break;
230 }
233 case ANIMTYPE_DSSKEY:
234 case ANIMTYPE_DSWOR: {
235 immUniformColor3ubvAlpha(col2b, sel ? col1[3] : col2b[3]);
236 break;
237 }
238 case ANIMTYPE_GROUP:
239 immUniformColor4ubv(sel ? col1a : col2a);
240 break;
241 default: {
242 immUniformColor4ubv(sel ? col1 : col2);
243 }
244 }
245
246 /* draw region twice: firstly backdrop, then the current range */
247 immRectf(pos, v2d->cur.xmin, ymin, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymax);
248 }
249 else if (ac->datatype == ANIMCONT_GPENCIL) {
250 uchar *color;
251 switch (ale->type) {
252 case ANIMTYPE_SUMMARY:
253 color = col_summary;
254 break;
255
257 color = sel ? col1a : col2a;
258 break;
259
261 color = col2b;
262 color[3] = sel ? col1[3] : col2b[3];
263 break;
264
265 default:
266 color = sel ? col1 : col2;
267 break;
268 }
269
270 /* Color overlay on frames between the start/end frames. */
272 immRectf(pos, ac->scene->r.sfra, ymin, ac->scene->r.efra, ymax);
273
274 /* Color overlay outside the start/end frame range get a more transparent overlay. */
275 immUniformColor3ubvAlpha(color, std::min(255, color[3] / 2));
276 immRectf(pos, v2d->cur.xmin, ymin, ac->scene->r.sfra, ymax);
277 immRectf(pos, ac->scene->r.efra, ymin, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymax);
278 }
279 else if (ac->datatype == ANIMCONT_MASK) {
280 /* TODO: this is a copy of gpencil. */
281 uchar *color;
282 if (ale->type == ANIMTYPE_SUMMARY) {
283 color = col_summary;
284 }
285 else {
286 color = sel ? col1 : col2;
287 }
288
289 /* Color overlay on frames between the start/end frames. */
291 immRectf(pos, ac->scene->r.sfra, ymin, ac->scene->r.efra, ymax);
292
293 /* Color overlay outside the start/end frame range get a more transparent overlay. */
294 immUniformColor3ubvAlpha(color, std::min(255, color[3] / 2));
295 immRectf(pos, v2d->cur.xmin, ymin, ac->scene->r.sfra, ymax);
296 immRectf(pos, ac->scene->r.efra, ymin, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymax);
297 }
298
299 /* Alpha-over the channel color, if it's there. */
300 {
301 const bool show_group_colors = U.animation_flag & USER_ANIM_SHOW_CHANNEL_GROUP_COLORS;
302 uint8_t color[3];
303 if (show_group_colors && acf->get_channel_color && acf->get_channel_color(ale, color)) {
305 immRectf(pos, v2d->cur.xmin, ymin, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymax);
306 }
307 }
308 }
309}
310
312 View2D *v2d,
313 SpaceAction *saction,
314 const ListBaseT<bAnimListElem> &anim_data)
315{
316 /* Draw keyframes
317 * 1) Only channels that are visible in the Action Editor get drawn/evaluated.
318 * This is to try to optimize this for heavier data sets
319 * 2) Keyframes which are out of view horizontally are disregarded
320 */
321 int action_flag = saction->flag;
322 bDopeSheet *ads = &saction->ads;
323
324 if (saction->mode == SACTCONT_TIMELINE) {
325 action_flag &= ~SACTION_SHOW_INTERPOLATION;
326 }
327
328 const float channel_step = ANIM_UI_get_channel_step();
329 float ymax = ANIM_UI_get_first_channel_top(v2d);
330
332
333 const float scale_factor = ANIM_UI_get_keyframe_scale_factor();
334
335 bAnimListElem *ale;
336 for (ale = anim_data.first(); ale; ale = ale->next, ymax -= channel_step) {
337 const float ymin = ymax - ANIM_UI_get_channel_height();
338 float ycenter = (ymin + ymax) / 2.0f;
339
340 /* check if visible */
341 if (!(IN_RANGE(ymin, v2d->cur.ymin, v2d->cur.ymax) ||
342 IN_RANGE(ymax, v2d->cur.ymin, v2d->cur.ymax)))
343 {
344 continue;
345 }
346
347 /* check if anything to show for this channel */
348 if (ale->datatype == ALE_NONE) {
349 continue;
350 }
351
352 /* Add channels to list to draw later. */
353 switch (ale->datatype) {
354 case ALE_ALL:
356 draw_list, static_cast<bAnimContext *>(ale->data), ycenter, scale_factor, action_flag);
357 break;
358 case ALE_SCE:
359 ED_add_scene_channel(draw_list,
360 ads,
361 static_cast<Scene *>(ale->key_data),
362 ycenter,
363 scale_factor,
364 action_flag);
365 break;
366 case ALE_OB:
367 ED_add_object_channel(draw_list,
368 ads,
369 static_cast<Object *>(ale->key_data),
370 ycenter,
371 scale_factor,
372 action_flag);
373 break;
376 ac,
377 ale,
378 static_cast<bAction *>(ale->key_data),
379 ycenter,
380 scale_factor,
381 action_flag);
382 break;
383 case ALE_ACTION_SLOT:
385 ac,
386 ale,
387 static_cast<bAction *>(ale->key_data)->wrap(),
388 *static_cast<animrig::Slot *>(ale->data),
389 ycenter,
390 scale_factor,
391 action_flag);
392 break;
393 case ALE_ACT:
395 break;
396 case ALE_GROUP:
398 ale,
399 static_cast<bActionGroup *>(ale->data),
400 ycenter,
401 scale_factor,
402 action_flag);
403 break;
404 case ALE_FCURVE: {
405 ED_add_fcurve_channel(draw_list,
406 ale,
407 static_cast<FCurve *>(ale->key_data),
408 ycenter,
409 scale_factor,
410 action_flag);
411 break;
412 }
415 ads,
416 static_cast<const GreasePencilLayer *>(ale->data),
417 ycenter,
418 scale_factor,
419 action_flag);
420 break;
423 draw_list,
424 ads,
425 static_cast<const GreasePencilLayerTreeGroup *>(ale->data),
426 ycenter,
427 scale_factor,
428 action_flag);
429 break;
432 ac,
433 ale,
434 static_cast<const GreasePencil *>(ale->data),
435 ycenter,
436 scale_factor,
437 action_flag);
438 break;
439 case ALE_GPFRAME:
441 ads,
442 static_cast<bGPDlayer *>(ale->data),
443 ycenter,
444 scale_factor,
445 action_flag);
446 break;
447 case ALE_MASKLAY:
449 ads,
450 static_cast<MaskLayer *>(ale->data),
451 ycenter,
452 scale_factor,
453 action_flag);
454 break;
455 case ALE_NONE:
456 case ALE_NLASTRIP:
457 break;
458 }
459 }
460
461 /* Drawing happens in here. */
462 ED_channel_list_flush(draw_list, v2d);
463 ED_channel_list_free(draw_list);
464}
465
467 SpaceAction *saction,
468 ARegion *region,
469 ListBaseT<bAnimListElem> *anim_data)
470{
471 View2D *v2d = &region->v2d;
472
473 /* Draw the manual frame ranges for actions in the background of the dope-sheet.
474 * The action editor has already drawn the range for its action so it's not needed. */
475 if (ac->datatype == ANIMCONT_DOPESHEET) {
476 draw_channel_action_ranges(anim_data, v2d);
477 }
478
479 /* Draw the background strips. */
480 GPUVertFormat *format = immVertexFormat();
481 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
482
484
486
487 /* first backdrop strips */
488 draw_backdrops(ac, *anim_data, v2d, pos);
489
491
492 /* black line marking 'current frame' for Time-Slide transform mode */
493 if (saction->flag & SACTION_MOVING) {
494 immUniformColor3f(0.0f, 0.0f, 0.0f);
495
497 immVertex2f(pos, saction->timeslide, v2d->cur.ymin - EXTRA_SCROLL_PAD);
498 immVertex2f(pos, saction->timeslide, v2d->cur.ymax);
499 immEnd();
500 }
502
503 draw_keyframes(ac, v2d, saction, *anim_data);
504
505 /* free temporary channels used for drawing */
506 ANIM_animdata_freelist(anim_data);
507}
508
510
511/* -------------------------------------------------------------------- */
514
515static bool timeline_cache_is_hidden_by_setting(const SpaceAction *saction, const PTCacheID *pid)
516{
517 switch (pid->type) {
519 if ((saction->cache_display & TIME_CACHE_SOFTBODY) == 0) {
520 return true;
521 }
522 break;
524 if ((saction->cache_display & TIME_CACHE_PARTICLES) == 0) {
525 return true;
526 }
527 break;
529 if ((saction->cache_display & TIME_CACHE_CLOTH) == 0) {
530 return true;
531 }
532 break;
535 if ((saction->cache_display & TIME_CACHE_SMOKE) == 0) {
536 return true;
537 }
538 break;
540 if ((saction->cache_display & TIME_CACHE_DYNAMICPAINT) == 0) {
541 return true;
542 }
543 break;
545 if ((saction->cache_display & TIME_CACHE_RIGIDBODY) == 0) {
546 return true;
547 }
548 break;
549 }
550 return false;
551}
552
553static void timeline_cache_color_get(PTCacheID *pid, float color[4])
554{
555 switch (pid->type) {
557 color[0] = 1.0;
558 color[1] = 0.4;
559 color[2] = 0.02;
560 color[3] = 0.1;
561 break;
563 color[0] = 1.0;
564 color[1] = 0.1;
565 color[2] = 0.02;
566 color[3] = 0.1;
567 break;
569 color[0] = 0.1;
570 color[1] = 0.1;
571 color[2] = 0.75;
572 color[3] = 0.1;
573 break;
576 color[0] = 0.2;
577 color[1] = 0.2;
578 color[2] = 0.2;
579 color[3] = 0.1;
580 break;
582 color[0] = 1.0;
583 color[1] = 0.1;
584 color[2] = 0.75;
585 color[3] = 0.1;
586 break;
588 color[0] = 1.0;
589 color[1] = 0.6;
590 color[2] = 0.0;
591 color[3] = 0.1;
592 break;
593 default:
594 color[0] = 1.0;
595 color[1] = 0.0;
596 color[2] = 1.0;
597 color[3] = 0.1;
598 BLI_assert(0);
599 break;
600 }
601}
602
604 float color[4],
605 float color_state[4])
606{
607 if (cache->flag & PTCACHE_BAKED) {
608 color[3] = color_state[3] = 1.0f;
609 }
610 else if (cache->flag & PTCACHE_OUTDATED) {
611 color[3] = color_state[3] = 0.7f;
612 mul_v3_fl(color_state, 0.5f);
613 }
614 else {
615 color[3] = color_state[3] = 0.7f;
616 }
617}
618
620 int search_start_frame,
621 int *r_segment_start,
622 int *r_segment_end)
623{
624 int offset = cache->startframe;
625 int current = search_start_frame;
626
627 /* Find segment start frame. */
628 while (true) {
629 if (current > cache->endframe) {
630 return false;
631 }
632 if (cache->cached_frames[current - offset]) {
633 *r_segment_start = current;
634 break;
635 }
636 current++;
637 }
638
639 /* Find segment end frame. */
640 while (true) {
641 if (current > cache->endframe) {
642 *r_segment_end = current - 1;
643 return true;
644 }
645 if (!cache->cached_frames[current - offset]) {
646 *r_segment_end = current - 1;
647 return true;
648 }
649 current++;
650 }
651}
652
654{
655 uint count = 0;
656
657 int current = cache->startframe;
658 int segment_start;
659 int segment_end;
660 while (timeline_cache_find_next_cached_segment(cache, current, &segment_start, &segment_end)) {
661 count++;
662 current = segment_end + 1;
663 }
664
665 return count;
666}
667
669{
670 uint segments_count = timeline_cache_segments_count(cache);
671 if (segments_count == 0) {
672 return;
673 }
674
675 immBeginAtMost(GPU_PRIM_TRIS, segments_count * 6);
676
677 int current = cache->startframe;
678 int segment_start;
679 int segment_end;
680 while (timeline_cache_find_next_cached_segment(cache, current, &segment_start, &segment_end)) {
681 immRectf_fast(pos_id, segment_start, 0, segment_end + 1.0f, 1.0f);
682 current = segment_end + 1;
683 }
684
685 immEnd();
686}
687
688static void timeline_cache_draw_single(PTCacheID *pid, float y_offset, float height, uint pos_id)
689{
692 GPU_matrix_scale_2f(1.0, height);
693
696
697 /* Mix in the background color to tone it down a bit. */
698 ColorTheme4f background;
700
701 interp_v3_v3v3(color, color, background, 0.6f);
702
703 /* Highlight the frame range of the simulation. */
704 immUniform4fv("color1", color);
705 immUniform4fv("color2", color);
706 immRectf(pos_id, float(pid->cache->startframe), 0.0, float(pid->cache->endframe), 1.0);
707
708 /* Now show the cached frames on top. */
709 ColorTheme4f color_state;
710 copy_v4_v4(color_state, color);
711
713
714 immUniform4fv("color1", color);
715 immUniform4fv("color2", color_state);
716
718
720}
721
726
728 const bool all_simulations_baked,
729 float *y_offset,
730 const float line_height,
731 const uint pos_id)
732{
733 if (cache_ranges.is_empty()) {
734 return;
735 }
736
737 bool has_bake = false;
738
739 for (const CacheRange &sim_range : cache_ranges) {
740 switch (sim_range.status) {
743 break;
745 has_bake = true;
746 break;
747 }
748 }
749
750 Set<int> status_change_frames_set;
751 for (const CacheRange &sim_range : cache_ranges) {
752 status_change_frames_set.add(sim_range.frames.first());
753 status_change_frames_set.add(sim_range.frames.one_after_last());
754 }
755 Vector<int> status_change_frames;
756 status_change_frames.extend(status_change_frames_set.begin(), status_change_frames_set.end());
757 std::ranges::sort(status_change_frames);
758 const OffsetIndices<int> frame_ranges = status_change_frames.as_span();
759
761 GPU_matrix_translate_2f(0.0, float(V2D_SCROLL_HANDLE_HEIGHT) + *y_offset);
762 GPU_matrix_scale_2f(1.0, line_height);
763
764 ColorTheme4f base_color;
766 ColorTheme4f invalid_color = base_color;
767 mul_v3_fl(invalid_color, 0.5f);
768 invalid_color.a *= 0.7f;
769 ColorTheme4f valid_color = base_color;
770 valid_color.a *= 0.7f;
771 ColorTheme4f baked_color = base_color;
772
773 float max_used_height = 1.0f;
774 for (const int range_i : frame_ranges.index_range()) {
775 const IndexRange frame_range = frame_ranges[range_i];
776 const int start_frame = frame_range.first();
777 const int end_frame = frame_range.last();
778
779 bool has_bake_at_frame = false;
780 bool has_valid_at_frame = false;
781 bool has_invalid_at_frame = false;
782 for (const CacheRange &sim_range : cache_ranges) {
783 if (sim_range.frames.contains(start_frame)) {
784 switch (sim_range.status) {
786 has_invalid_at_frame = true;
787 break;
789 has_valid_at_frame = true;
790 break;
792 has_bake_at_frame = true;
793 break;
794 }
795 }
796 }
797 if (!(has_bake_at_frame || has_valid_at_frame || has_invalid_at_frame)) {
798 continue;
799 }
800
801 if (all_simulations_baked) {
802 immUniform4fv("color1", baked_color);
803 immUniform4fv("color2", baked_color);
805 immRectf_fast(pos_id, start_frame, 0, end_frame + 1.0f, 1.0f);
806 immEnd();
807 }
808 else {
809 if (has_valid_at_frame || has_invalid_at_frame) {
810 immUniform4fv("color1", valid_color);
811 immUniform4fv("color2", has_invalid_at_frame ? invalid_color : valid_color);
813 const float top = has_bake ? 2.0f : 1.0f;
814 immRectf_fast(pos_id, start_frame, 0.0f, end_frame + 1.0f, top);
815 immEnd();
816 max_used_height = top;
817 }
818 if (has_bake_at_frame) {
819 immUniform4fv("color1", baked_color);
820 immUniform4fv("color2", baked_color);
822 immRectf_fast(pos_id, start_frame, 0, end_frame + 1.0f, 1.0f);
823 immEnd();
824 }
825 }
826 }
828
829 *y_offset += max_used_height * 2;
830}
831
832/* Draw the interactive compositor playback cache markers. */
834 const Vector<bke::compositor::Cache::FrameRange> cached_frame_ranges,
835 const float y_offset,
836 const float line_height,
837 const uint pos_id)
838{
839
842 GPU_matrix_scale_2f(1.0, line_height);
843
846
847 for (const bke::compositor::Cache::FrameRange &range : cached_frame_ranges) {
848 immUniform4fv("color1", color);
849 immUniform4fv("color2", color);
851 immRectf_fast(pos_id, range.start, 0.0f, range.end + 1.0f, 1.0f);
852 immEnd();
853 }
855}
856
857void timeline_draw_cache(const SpaceAction *saction, const Object *ob, const Scene *scene)
858{
859 if (!flag_is_set(saction->cache_display, TIME_CACHE_DISPLAY)) {
860 return;
861 }
862
863 uint pos_id = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
866
867 BLI_SCOPED_DEFER([]() {
870 });
871
872 const float cache_draw_height = 4.0f * UI_SCALE_FAC * U.pixelsize;
873 immUniform1i("size1", cache_draw_height * 2.0f);
874 immUniform1i("size2", cache_draw_height);
875
876 float y_offset = 0.0f;
877 if (saction->cache_display & TIME_CACHE_COMPOSITOR) {
878 const Vector<bke::compositor::Cache::FrameRange> cached_frame_ranges =
880 if (!cached_frame_ranges.is_empty()) {
881 timeline_cache_draw_compositor(cached_frame_ranges, y_offset, cache_draw_height, pos_id);
882 y_offset += cache_draw_height;
883 }
884 }
885
886 if (ob == nullptr) {
887 return;
888 }
889
890 /* Iterate over point-caches on the active object, and draw each one's range. */
891 ListBaseT<PTCacheID> pidlist;
892 BKE_ptcache_ids_from_object(&pidlist, const_cast<Object *>(ob), const_cast<Scene *>(scene), 0);
893 for (PTCacheID &pid : pidlist) {
894 if (timeline_cache_is_hidden_by_setting(saction, &pid)) {
895 continue;
896 }
897
898 if (pid.cache->cached_frames == nullptr) {
899 continue;
900 }
901
902 timeline_cache_draw_single(&pid, y_offset, cache_draw_height, pos_id);
903
904 y_offset += cache_draw_height;
905 }
906 pidlist.free_no_destruct();
907
909 Vector<CacheRange> cache_ranges;
910 bool all_simulations_baked = true;
911 for (ModifierData &md : ob->modifiers) {
912 if (md.type != eModifierType_Nodes) {
913 continue;
914 }
915 const NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(&md);
916 if (nmd->node_group == nullptr || ID_MISSING(nmd->node_group)) {
917 continue;
918 }
919 if (!nmd->runtime->cache) {
920 continue;
921 }
922 if (nmd->node_group->nested_node_refs_num == 0) {
923 /* Skip when there are no bake nodes or simulations. */
924 continue;
925 }
926 const bke::bake::ModifierCache &modifier_cache = *nmd->runtime->cache;
927 {
928 std::lock_guard lock{modifier_cache.mutex};
929 for (const auto item : modifier_cache.simulation_cache_by_id.items()) {
930 const bke::bake::SimulationNodeCache &node_cache = *item.value;
931 if (node_cache.bake.frames.is_empty()) {
932 all_simulations_baked = false;
933 continue;
934 }
936 all_simulations_baked = false;
937 }
938 cache_ranges.append({node_cache.bake.frame_range(), node_cache.cache_status});
939 }
940 for (const auto item : modifier_cache.bake_cache_by_id.items()) {
941 const NodesModifierBake *bake = nmd->find_bake(item.key);
942 if (!bake) {
943 continue;
944 }
945 if (bake->bake_mode == NODES_MODIFIER_BAKE_MODE_STILL) {
946 continue;
947 }
948 const bke::bake::BakeNodeCache &node_cache = *item.value;
949 if (node_cache.bake.frames.is_empty()) {
950 continue;
951 }
952 cache_ranges.append({node_cache.bake.frame_range(), bke::bake::CacheStatus::Baked});
953 }
954 }
955 }
957 cache_ranges, all_simulations_baked, &y_offset, cache_draw_height, pos_id);
958 }
959}
960
962
963} // namespace blender
Functions and classes to work with Actions.
#define PTCACHE_TYPE_SMOKE_HIGHRES
#define PTCACHE_TYPE_CLOTH
#define PTCACHE_TYPE_DYNAMICPAINT
#define PTCACHE_TYPE_PARTICLES
#define PTCACHE_TYPE_SOFTBODY
#define PTCACHE_TYPE_SMOKE_DOMAIN
#define PTCACHE_TYPE_RIGIDBODY
#define BLI_SCOPED_DEFER(function_to_defer)
#define ID_MISSING(_id)
Definition DNA_ID.h:695
Object is a sort of wrapper for general info.
#define UI_SCALE_FAC
#define C
Definition RandGen.cpp:29
#define V2D_LOCK_COPY
Definition UI_view2d.hh:110
#define V2D_SCROLL_HANDLE_HEIGHT
Definition UI_view2d.hh:92
#define EXTRA_SCROLL_PAD
volatile int lock
#define BLI_assert_unreachable()
#define IN_RANGE(a, b, c)
#define ELEM(...)
ChannelStorageType a
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
Iterator begin() const
Definition BLI_set.hh:499
Iterator end() const
Definition BLI_set.hh:509
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr bool is_empty() const
Definition BLI_span.hh:264
void append(const T &value)
bool is_empty() const
void extend(Span< T > array)
Span< T > as_span() const
void get_color_4ubv(int colorid, unsigned char col[4])
void get_color_4fv(int colorid, float col[4])
void view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
Definition view2d.cc:850
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float ymaxc, size_t channel_index)
short ANIM_channel_setting_get(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting)
void draw_channel_names(bContext *C, bAnimContext *ac, ARegion *region, const ListBaseT< bAnimListElem > &anim_data)
void ED_add_grease_pencil_datablock_channel(ChannelDrawList *channel_list, bAnimContext *ac, bAnimListElem *ale, const GreasePencil *grease_pencil, const float ypos, const float yscale_fac, int saction_flag)
void immEnd()
const bAnimChannelType * ANIM_channel_get_typeinfo(const bAnimListElem *ale)
void immUniformColor3f(float r, float g, float b)
ChannelDrawList * ED_channel_draw_list_create()
unsigned int uint
Definition BKE_text.h:55
@ ANIMCONT_SHAPEKEY
@ ANIMCONT_ACTION
@ ANIMCONT_DOPESHEET
@ ANIMCONT_GPENCIL
static void timeline_cache_draw_geometry_nodes(const Span< CacheRange > cache_ranges, const bool all_simulations_baked, float *y_offset, const float line_height, const uint pos_id)
void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *region, ListBaseT< bAnimListElem > *anim_data)
void ANIM_draw_action_framerange(AnimData *adt, bAction *action, View2D *v2d, float ymin, float ymax)
Definition anim_draw.cc:212
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
GPUVertFormat * immVertexFormat()
void immBegin(GPUPrimType, uint vertex_len)
static void draw_backdrops(bAnimContext *ac, ListBaseT< bAnimListElem > &anim_data, View2D *v2d, uint pos)
static bool timeline_cache_find_next_cached_segment(PointCache *cache, int search_start_frame, int *r_segment_start, int *r_segment_end)
@ TH_GROUP_ACTIVE
@ TH_DOPESHEET_CHANNELSUBOB
@ TH_DOPESHEET_CHANNELOB
@ TH_SIMULATED_FRAMES
@ TH_CHANNEL_SELECT
@ USER_ANIM_SHOW_CHANNEL_GROUP_COLORS
@ ANIMTYPE_GREASE_PENCIL_LAYER_GROUP
@ ANIMTYPE_GREASE_PENCIL_DATABLOCK
@ ANIMTYPE_OBJECT
@ ANIMTYPE_SUMMARY
@ ANIMTYPE_FILLACT_LAYERED
@ ANIMTYPE_ACTION_SLOT
@ ANIMTYPE_FILLACTD
@ ANIMTYPE_DSSKEY
static bool timeline_cache_is_hidden_by_setting(const SpaceAction *saction, const PTCacheID *pid)
void ED_add_mask_layer_channel(ChannelDrawList *channel_list, bDopeSheet *ads, MaskLayer *masklay, float ypos, float yscale_fac, int saction_flag)
static void timeline_cache_draw_single(PTCacheID *pid, float y_offset, float height, uint pos_id)
void immUnbindProgram()
MINLINE void mul_v3_fl(float r[3], float f)
void GPU_matrix_scale_2f(float x, float y)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
float ANIM_UI_get_channel_height()
@ TIME_CACHE_DYNAMICPAINT
@ TIME_CACHE_SIMULATION_NODES
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void ED_add_grease_pencil_layer_group_channel(ChannelDrawList *channel_list, bDopeSheet *ads, const GreasePencilLayerTreeGroup *layer_group, const float ypos, const float yscale_fac, int saction_flag)
float ANIM_UI_get_first_channel_top(View2D *v2d)
@ ACHANNEL_SETTING_EXPAND
@ ACHANNEL_SETTING_SELECT
void immUniformThemeColor(int color_id)
@ ALE_GREASE_PENCIL_GROUP
@ ALE_ACTION_LAYERED
@ ALE_GREASE_PENCIL_DATA
@ ALE_ACTION_SLOT
@ ALE_GREASE_PENCIL_CEL
void ED_add_fcurve_channel(ChannelDrawList *channel_list, bAnimListElem *ale, FCurve *fcu, float ypos, float yscale_fac, int saction_flag)
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
static void draw_keyframes(bAnimContext *ac, View2D *v2d, SpaceAction *saction, const ListBaseT< bAnimListElem > &anim_data)
void ED_add_scene_channel(ChannelDrawList *channel_list, bDopeSheet *ads, Scene *sce, float ypos, float yscale_fac, int saction_flag)
@ NODES_MODIFIER_BAKE_MODE_STILL
void immUniform4fv(const char *name, const float data[4])
void ED_add_summary_channel(ChannelDrawList *channel_list, bAnimContext *ac, float ypos, float yscale_fac, int saction_flag)
unsigned char uint8_t
Definition BKE_text.h:79
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void BKE_ptcache_ids_from_object(ListBaseT< PTCacheID > *lb, struct Object *ob, struct Scene *scene, int duplis)
void ANIM_channel_draw_widgets(const bContext *C, bAnimContext *ac, bAnimListElem *ale, ui::Block *block, const rctf *rect, size_t channel_index)
void GPU_matrix_translate_2f(float x, float y)
bAction * ANIM_channel_action_get(const bAnimListElem *ale)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
static void timeline_cache_draw_compositor(const Vector< bke::compositor::Cache::FrameRange > cached_frame_ranges, const float y_offset, const float line_height, const uint pos_id)
void ED_channel_list_free(ChannelDrawList *channel_list)
float ANIM_UI_get_channel_skip()
static void timeline_cache_color_get(PTCacheID *pid, float color[4])
void ED_add_action_slot_channel(ChannelDrawList *channel_list, bAnimContext *ac, bAnimListElem *ale, animrig::Action &action, animrig::Slot &slot, const float ypos, const float yscale_fac, int saction_flag)
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
static void timeline_cache_modify_color_based_on_state(PointCache *cache, float color[4], float color_state[4])
void ED_channel_list_flush(ChannelDrawList *channel_list, View2D *v2d)
void immRectf_fast(uint pos, float x1, float y1, float x2, float y2)
void ED_add_object_channel(ChannelDrawList *channel_list, bDopeSheet *ads, Object *ob, float ypos, float yscale_fac, int saction_flag)
float ANIM_UI_get_keyframe_scale_factor()
static uint timeline_cache_segments_count(PointCache *cache)
static void draw_channel_action_ranges(ListBaseT< bAnimListElem > *anim_data, View2D *v2d)
MINLINE void copy_v4_v4(float r[4], const float a[4])
ColorTheme4< float > ColorTheme4f
@ SACTION_SHOW_INTERPOLATION
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
void immUniform1i(const char *name, int x)
void ED_add_action_layered_channel(ChannelDrawList *channel_list, bAnimContext *ac, bAnimListElem *ale, bAction *action, const float ypos, const float yscale_fac, int saction_flag)
void timeline_draw_cache(const SpaceAction *saction, const Object *ob, const Scene *scene)
void immUniformColor4ubv(const unsigned char rgba[4])
void immUniformColor3ubvAlpha(const unsigned char rgb[3], unsigned char a)
void GPU_matrix_pop()
void ED_add_action_group_channel(ChannelDrawList *channel_list, bAnimListElem *ale, bActionGroup *agrp, float ypos, float yscale_fac, int saction_flag)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
void ED_add_grease_pencil_layer_legacy_channel(ChannelDrawList *channel_list, bDopeSheet *ads, bGPDlayer *gpl, float ypos, float yscale_fac, int saction_flag)
float ANIM_UI_get_channel_step()
static void timeline_cache_draw_cached_segments(PointCache *cache, uint pos_id)
void ED_add_grease_pencil_cels_channel(ChannelDrawList *channel_list, bDopeSheet *ads, const GreasePencilLayer *layer, const float ypos, const float yscale_fac, int saction_flag)
void GPU_matrix_push()
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
bke::bake::CacheStatus status
NodesModifierRuntime * runtime
std::shared_ptr< bke::bake::ModifierCache > cache
Definition MOD_nodes.hh:64
ListBaseT< ModifierData > modifiers
struct PointCache * cache
bke::SceneRuntime * runtime
struct RenderData r
eAnimEdit_Context mode
eTimeline_Cache_Flag cache_display
bool(*) has_setting(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting)
bool(*) get_channel_color(const bAnimListElem *ale, uint8_t r_color[3])
eAnimCont_Types datatype
eAnim_ChannelType type
bAnimListElem * next
Map< int, std::unique_ptr< SimulationNodeCache > > simulation_cache_by_id
Map< int, std::unique_ptr< BakeNodeCache > > bake_cache_by_id
Vector< std::unique_ptr< FrameCache > > frames