Blender V5.3
MOD_grease_pencil_time.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_index_range.hh"
10#include "BLI_map.hh"
11#include "BLI_span.hh"
12#include "BLI_string.hh"
13#include "BLI_string_utf8.hh"
14
15#include "DNA_modifier_types.h"
16#include "DNA_scene_types.h"
17
18#include "BKE_curves.hh"
19#include "BKE_geometry_set.hh"
20#include "BKE_grease_pencil.hh"
21#include "BKE_instances.hh"
22#include "BKE_modifier.hh"
23#include "BKE_screen.hh"
24
25#include "BLO_read_write.hh"
26
28
29#include "UI_interface.hh"
31#include "UI_resources.hh"
32
33#include "BLT_translation.hh"
34
35#include "WM_api.hh"
36#include "WM_types.hh"
37
38#include "RNA_access.hh"
39#include "RNA_prototypes.hh"
40
42#include "MOD_ui_common.hh"
43
44namespace blender {
45
46static void init_data(ModifierData *md)
47{
48 auto *tmd = reinterpret_cast<GreasePencilTimeModifierData *>(md);
49
51 modifier::greasepencil::init_influence_data(&tmd->influence, false);
52
53 GreasePencilTimeModifierSegment *segment = MEM_new<GreasePencilTimeModifierSegment>(__func__);
54 STRNCPY_UTF8(segment->name, DATA_("Segment"));
55 tmd->segments_array = segment;
56 tmd->segments_num = 1;
57}
58
59static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
60{
61 const auto *tmd = reinterpret_cast<const GreasePencilTimeModifierData *>(md);
62 auto *tmmd = reinterpret_cast<GreasePencilTimeModifierData *>(target);
63
65
66 BKE_modifier_copydata_generic(md, target, flag);
67 modifier::greasepencil::copy_influence_data(&tmd->influence, &tmmd->influence, flag);
68
69 tmmd->segments_array = static_cast<GreasePencilTimeModifierSegment *>(
70 MEM_dupalloc(tmd->segments_array));
71}
72
73static void free_data(ModifierData *md)
74{
75 auto *tmd = reinterpret_cast<GreasePencilTimeModifierData *>(md);
77
78 MEM_SAFE_DELETE(tmd->segments_array);
79}
80
81static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
82{
83 auto *tmd = reinterpret_cast<GreasePencilTimeModifierData *>(md);
84 modifier::greasepencil::foreach_influence_ID_link(&tmd->influence, ob, walk, user_data);
85}
86
87struct FrameRange {
88 /* Start frame. */
89 int sfra;
90 /* End frame (unlimited range when undefined). */
91 int efra;
92
93 bool is_empty() const
94 {
95 return efra < sfra;
96 }
97
98 bool is_single_frame() const
99 {
100 return efra == sfra;
101 }
102
103 int duration() const
104 {
105 return std::max(efra + 1 - sfra, 0);
106 }
107
108 FrameRange drop_front(const int n) const
109 {
110 BLI_assert(n >= 0);
111 return FrameRange{std::min(sfra + n, efra), efra};
112 }
113
114 FrameRange drop_back(const int n) const
115 {
116 BLI_assert(n >= 0);
117 return FrameRange{sfra, std::max(efra - n, sfra)};
118 }
119
120 FrameRange shift(const int n) const
121 {
122 return FrameRange{sfra + n, efra + n};
123 }
124};
125
131static IndexRange find_key_range(const Span<int> sorted_keys, const FrameRange &frame_range)
132{
133 IndexRange result = sorted_keys.index_range();
134 for (const int i : result.index_range()) {
135 const int irev = result.size() - 1 - i;
136 if (sorted_keys[result[irev]] <= frame_range.sfra) {
137 /* Found first key affecting the frame range, drop any earlier keys. */
138 result = result.drop_front(irev);
139 break;
140 }
141 }
142 for (const int i : result.index_range()) {
143 if (sorted_keys[result[i]] > frame_range.efra) {
144 /* Found first key outside the frame range, drop this and later keys. */
145 result = result.take_front(i);
146 break;
147 }
148 }
149 return result;
150}
151
153 private:
154 float offset_;
155 float scale_;
156 bool use_loop_;
157
158 public:
160 : offset_(tmd.offset),
161 scale_(tmd.frame_scale),
162 use_loop_(tmd.flag & MOD_GREASE_PENCIL_TIME_KEEP_LOOP)
163 {
164 }
165
166 float offset() const
167 {
168 return offset_;
169 }
170 float scale() const
171 {
172 return scale_;
173 }
174 bool use_loop() const
175 {
176 return use_loop_;
177 }
178
179 float to_scene_time(const float local_frame) const
180 {
181 return float(local_frame - offset_) / scale_;
182 }
183 float to_local_time(const float scene_frame) const
184 {
185 return scene_frame * scale_ + offset_;
186 }
187
188 /* Compute scene frame number on or after the local frame. */
189 int scene_frame_before_local_frame(const int local_frame) const
190 {
191 return int(math::floor(to_scene_time(local_frame)));
192 }
193 /* Compute scene frame number on or after the local frame. */
194 int scene_frame_after_local_frame(const int local_frame) const
195 {
196 return int(math::ceil(to_scene_time(local_frame)));
197 }
198
199 /* Compute local frame number on or before the scene frame. */
200 int local_frame_before_scene_frame(const int scene_frame) const
201 {
202 return int(math::floor(to_local_time(scene_frame)));
203 }
204 /* Compute local frame number on or after the scene frame. */
205 int local_frame_after_scene_frame(const int scene_frame) const
206 {
207 return int(math::ceil(to_local_time(scene_frame)));
208 }
209};
210
211/* Determine how many times the source range must be repeated to cover the destination range. */
212static void calculate_repetitions(const TimeMapping &mapping,
213 const FrameRange &gp_src,
214 const FrameRange &scene_dst,
215 int &r_start,
216 int &r_count)
217{
218 if (!mapping.use_loop()) {
219 r_start = 0;
220 r_count = 1;
221 return;
222 }
223 const int duration = gp_src.duration();
224 if (duration <= 0) {
225 r_start = 0;
226 r_count = 0;
227 return;
228 }
229 const FrameRange gp_dst = {mapping.local_frame_before_scene_frame(scene_dst.sfra),
230 mapping.local_frame_after_scene_frame(scene_dst.efra)};
231 r_start = math::floor(float(gp_dst.sfra - gp_src.sfra) / float(duration));
232 r_count = math::floor(float(gp_dst.efra - gp_src.sfra) / float(duration)) + 1 - r_start;
233}
234
235static void insert_keys_forward(const TimeMapping &mapping,
236 const Map<int, GreasePencilFrame> &frames,
237 const Span<int> sorted_keys,
238 const FrameRange gp_src_range,
239 const FrameRange gp_dst_range,
240 Map<int, GreasePencilFrame> &dst_frames)
241{
242 const int offset = gp_dst_range.sfra - gp_src_range.sfra;
243 for (const int i : sorted_keys.index_range()) {
244 const int gp_key = sorted_keys[i];
245 const int gp_insert_key = std::max(gp_key, gp_src_range.sfra);
246 if (gp_insert_key > gp_src_range.efra) {
247 continue;
248 }
249
250 const int scene_key = mapping.scene_frame_after_local_frame(gp_insert_key + offset);
251 dst_frames.add_overwrite(scene_key, frames.lookup(gp_key));
252 }
253}
254
255/* Insert keys in reverse order. */
256static void insert_keys_reverse(const TimeMapping &mapping,
257 const Map<int, GreasePencilFrame> &frames,
258 const Span<int> sorted_keys,
259 const FrameRange gp_src_range,
260 const FrameRange gp_dst_range,
261 Map<int, GreasePencilFrame> &dst_frames)
262{
263 const int offset = gp_dst_range.sfra - gp_src_range.sfra;
264 for (const int i : sorted_keys.index_range()) {
265 /* In reverse mode keys need to be inserted in reverse order to ensure "earlier" frames can
266 * overwrite "later" frames. */
267 const int irev = sorted_keys.size() - 1 - i;
268 /* This finds the correct scene frame starting at the end of the frame interval. */
269 const int gp_key = sorted_keys[irev];
270 /* The insertion scene time is the end of the keyframe interval instead of the start.
271 * This is the frame after the end frame (efra) to cover the full extent of the end frame
272 * interval. */
273 const int gp_end_key = (irev < sorted_keys.size() - 1) ?
274 std::min(sorted_keys[irev + 1], gp_src_range.efra + 1) :
275 gp_src_range.efra + 1;
276 if (gp_end_key < gp_src_range.sfra) {
277 return;
278 }
279
280 /* Reverse key frame inside the range. */
281 const int gp_key_rev = gp_src_range.efra + 1 - (gp_end_key - gp_src_range.sfra);
282 const int scene_key = mapping.scene_frame_after_local_frame(gp_key_rev + offset);
283 dst_frames.add_overwrite(scene_key, frames.lookup(gp_key));
284 }
285}
286
287static void fill_scene_range_fixed(const TimeMapping &mapping,
288 const Map<int, GreasePencilFrame> &frames,
289 const Span<int> sorted_keys,
290 const int gp_src_frame,
291 const FrameRange scene_dst_range,
292 Map<int, GreasePencilFrame> &dst_frames)
293{
294 const FrameRange gp_src_range = {gp_src_frame, gp_src_frame};
295 const FrameRange gp_dst_range = {mapping.local_frame_before_scene_frame(scene_dst_range.sfra),
296 mapping.local_frame_after_scene_frame(scene_dst_range.efra)};
297
298 const Span<int> src_keys = sorted_keys.slice(find_key_range(sorted_keys, gp_src_range));
299 insert_keys_forward(mapping, frames, src_keys, gp_src_range, gp_dst_range, dst_frames);
300}
301
302static void fill_scene_range_forward(const TimeMapping &mapping,
303 const Map<int, GreasePencilFrame> &frames,
304 const Span<int> sorted_keys,
305 const FrameRange gp_src_range,
306 const FrameRange scene_dst_range,
307 Map<int, GreasePencilFrame> &dst_frames)
308{
309 int repeat_start = 0, repeat_count = 1;
310 calculate_repetitions(mapping, gp_src_range, scene_dst_range, repeat_start, repeat_count);
311
312 const Span<int> src_keys = sorted_keys.slice(find_key_range(sorted_keys, gp_src_range));
313 FrameRange gp_dst_range = gp_src_range.shift(repeat_start * gp_src_range.duration());
314 for ([[maybe_unused]] const int repeat_i : IndexRange(repeat_count)) {
315 insert_keys_forward(mapping, frames, src_keys, gp_src_range, gp_dst_range, dst_frames);
316 gp_dst_range = gp_dst_range.shift(gp_src_range.duration());
317 }
318}
319
320static void fill_scene_range_reverse(const TimeMapping &mapping,
321 const Map<int, GreasePencilFrame> &frames,
322 const Span<int> sorted_keys,
323 const FrameRange gp_src_range,
324 const FrameRange scene_dst_range,
325 Map<int, GreasePencilFrame> &dst_frames)
326{
327 int repeat_start = 0, repeat_count = 1;
328 calculate_repetitions(mapping, gp_src_range, scene_dst_range, repeat_start, repeat_count);
329
330 const Span<int> src_keys = sorted_keys.slice(find_key_range(sorted_keys, gp_src_range));
331 FrameRange gp_dst_range = gp_src_range.shift(repeat_start * gp_src_range.duration());
332 for ([[maybe_unused]] const int repeat_i : IndexRange(repeat_count)) {
333 insert_keys_reverse(mapping, frames, src_keys, gp_src_range, gp_dst_range, dst_frames);
334 gp_dst_range = gp_dst_range.shift(gp_src_range.duration());
335 }
336}
337
338static void fill_scene_range_ping_pong(const TimeMapping &mapping,
339 const Map<int, GreasePencilFrame> &frames,
340 const Span<int> sorted_keys,
341 const FrameRange gp_src_range,
342 const FrameRange scene_dst_range,
343 Map<int, GreasePencilFrame> &dst_frames)
344{
345 /* Double interval for ping-pong mode, start and end frame only appear once. */
346 const FrameRange gp_src_range_ping = {gp_src_range.sfra, gp_src_range.efra - 1};
347 const FrameRange gp_src_range_pong = {gp_src_range.sfra + 1, gp_src_range.efra};
348 const FrameRange gp_range_full = {gp_src_range.sfra,
349 2 * gp_src_range.efra - gp_src_range.sfra - 1};
350 int repeat_start = 0, repeat_count = 1;
351 calculate_repetitions(mapping, gp_range_full, scene_dst_range, repeat_start, repeat_count);
352
353 const Span<int> src_keys = sorted_keys.slice(find_key_range(sorted_keys, gp_src_range));
354 FrameRange gp_dst_range = gp_src_range.shift(repeat_start * gp_range_full.duration());
355 for ([[maybe_unused]] const int repeat_i : IndexRange(repeat_count)) {
356 /* Ping. */
357 insert_keys_forward(mapping, frames, src_keys, gp_src_range, gp_dst_range, dst_frames);
358 gp_dst_range = gp_dst_range.shift(gp_src_range_ping.duration());
359 /* Pong. */
360 insert_keys_reverse(mapping, frames, src_keys, gp_src_range, gp_dst_range, dst_frames);
361 gp_dst_range = gp_dst_range.shift(gp_src_range_pong.duration());
362 }
363}
364
365static void fill_scene_range_chain(const TimeMapping &mapping,
366 const Map<int, GreasePencilFrame> &frames,
367 const Span<int> sorted_keys,
369 const FrameRange gp_src_range,
370 const FrameRange scene_dst_range,
371 Map<int, GreasePencilFrame> &dst_frames)
372{
373 using Segment = GreasePencilTimeModifierSegment;
374
375 if (segments.is_empty()) {
376 return;
377 }
378 /* Segment settings tolerate start frame after end frame. */
379 auto segment_base_range = [](const Segment &segment) {
380 return FrameRange{std::min(segment.segment_start, segment.segment_end),
381 std::max(segment.segment_start, segment.segment_end)};
382 };
383 auto segment_full_range = [](const Segment &segment) {
384 const FrameRange base_range = FrameRange{std::min(segment.segment_start, segment.segment_end),
385 std::max(segment.segment_start, segment.segment_end)};
386 const int base_duration = (segment.segment_mode == MOD_GREASE_PENCIL_TIME_SEG_MODE_PINGPONG ?
387 base_range.duration() * 2 - 2 :
388 base_range.duration());
389 return FrameRange{base_range.sfra,
390 base_range.sfra + segment.segment_repeat * base_duration - 1};
391 };
392 /* Find src range by adding up all segments. */
393 const FrameRange gp_range_full = [&]() {
394 int duration = segment_full_range(segments.first()).duration();
395 for (const Segment &segment : segments.drop_front(1)) {
396 duration += segment_full_range(segment).duration();
397 }
398 /* Same start as the source range. */
399 return FrameRange{gp_src_range.sfra, gp_src_range.sfra + duration - 1};
400 }();
401 int repeat_start = 0, repeat_count = 1;
402 calculate_repetitions(mapping, gp_range_full, scene_dst_range, repeat_start, repeat_count);
403
404 const Span<int> src_keys = sorted_keys;
405
406 FrameRange gp_dst_range = gp_src_range.shift(repeat_start * gp_range_full.duration());
407 for ([[maybe_unused]] const int repeat_i : IndexRange(repeat_count)) {
408 for (const Segment &segment : segments) {
409 const FrameRange segment_src_range = segment_base_range(segment);
410 for ([[maybe_unused]] const int segment_repeat_i : IndexRange(segment.segment_repeat)) {
411 switch (GreasePencilTimeModifierSegmentMode(segment.segment_mode)) {
414 mapping, frames, src_keys, segment_src_range, gp_dst_range, dst_frames);
415 gp_dst_range = gp_dst_range.shift(segment_src_range.duration());
416 break;
419 mapping, frames, src_keys, segment_src_range, gp_dst_range, dst_frames);
420 gp_dst_range = gp_dst_range.shift(segment_src_range.duration());
421 break;
423 /* Ping. */
424 const FrameRange segment_src_range_ping = {segment_src_range.sfra,
425 segment_src_range.efra - 1};
427 mapping, frames, src_keys, segment_src_range_ping, gp_dst_range, dst_frames);
428 gp_dst_range = gp_dst_range.shift(segment_src_range_ping.duration());
429 /* Pong. */
430 const FrameRange segment_src_range_pong = {segment_src_range.sfra + 1,
431 segment_src_range.efra};
433 mapping, frames, src_keys, segment_src_range_pong, gp_dst_range, dst_frames);
434 gp_dst_range = gp_dst_range.shift(segment_src_range_pong.duration());
435 break;
436 }
437 }
438 }
439 }
440 }
441}
442
444 const Scene &eval_scene,
445 const Map<int, GreasePencilFrame> &frames,
446 const Span<int> sorted_keys,
447 const FrameRange scene_dst_range,
448 Map<int, GreasePencilFrame> &dst_frames)
449{
450 const TimeMapping mapping(tmd);
451 const auto mode = GreasePencilTimeModifierMode(tmd.mode);
452 const bool use_custom_range = tmd.flag & MOD_GREASE_PENCIL_TIME_CUSTOM_RANGE;
453
454 const FrameRange scene_range = FrameRange{eval_scene.r.sfra, eval_scene.r.efra};
455 const FrameRange custom_range = use_custom_range ? FrameRange{tmd.sfra, tmd.efra} : scene_range;
456
457 switch (mode) {
460 tmd, frames, sorted_keys, custom_range, scene_dst_range, dst_frames);
461 break;
464 tmd, frames, sorted_keys, custom_range, scene_dst_range, dst_frames);
465 break;
467 fill_scene_range_fixed(tmd, frames, sorted_keys, tmd.offset, scene_dst_range, dst_frames);
468 break;
471 tmd, frames, sorted_keys, custom_range, scene_dst_range, dst_frames);
472 break;
475 tmd, frames, sorted_keys, tmd.segments(), scene_range, scene_dst_range, dst_frames);
476 break;
477 }
478}
479
481 const ModifierEvalContext *ctx,
482 bke::GeometrySet *geometry_set)
483{
486
487 auto *tmd = reinterpret_cast<GreasePencilTimeModifierData *>(md);
488 const Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
489 /* Just include the current frame for now. The method can be applied to arbitrary ranges. */
490 const FrameRange dst_keyframe_range = {scene->r.cfra, scene->r.cfra};
491
492 if (!geometry_set->has_grease_pencil()) {
493 return;
494 }
496
497 IndexMaskMemory mask_memory;
499 grease_pencil, tmd->influence, mask_memory);
500
501 const Span<Layer *> layers_for_write = grease_pencil.layers_for_write();
502 layer_mask.foreach_index([&](const int64_t layer_i) {
503 Layer &layer = *layers_for_write[layer_i];
504 const Span<int> sorted_keys = layer.sorted_keys();
505 const Map<int, GreasePencilFrame> &src_frames = layer.frames();
506
508 fill_scene_timeline(*tmd, *scene, src_frames, sorted_keys, dst_keyframe_range, new_frames);
509 layer.frames_for_write() = std::move(new_frames);
510 layer.tag_frames_map_keys_changed();
511 });
512}
513
514static void panel_draw(const bContext *C, Panel *panel)
515{
516 ui::Layout &layout = *panel->layout;
517
518 PointerRNA ob_ptr;
520 auto *tmd = static_cast<GreasePencilTimeModifierData *>(ptr->data);
521 const auto mode = GreasePencilTimeModifierMode(RNA_enum_get(ptr, "mode"));
522 const bool use_fixed_offset = (mode == MOD_GREASE_PENCIL_TIME_MODE_FIX);
523 const bool use_custom_range = !ELEM(
525 ui::Layout *row, *col;
526
527 layout.use_property_split_set(true);
528
529 layout.prop(ptr, "mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
530
531 col = &layout.column(false);
532
533 const char *text = use_fixed_offset ? IFACE_("Frame") : IFACE_("Frame Offset");
534 col->prop(ptr, "offset", UI_ITEM_NONE, text, ICON_NONE);
535
536 row = &col->row(false);
537 row->active_set(!use_fixed_offset);
538 row->prop(ptr, "frame_scale", UI_ITEM_NONE, IFACE_("Scale"), ICON_NONE);
539
540 row = &layout.row(false);
541 row->active_set(!use_fixed_offset);
542 row->prop(ptr, "use_keep_loop", UI_ITEM_NONE, std::nullopt, ICON_NONE);
543
545 row = &layout.row(false);
546 row->use_property_split_set(false);
547
549 const_cast<bContext *>(C),
550 "MOD_UL_grease_pencil_time_modifier_segments",
551 "",
552 ptr,
553 "segments",
554 ptr,
555 "segment_active_index",
556 nullptr,
557 3,
558 10,
559 0,
561
562 col = &row->column(false);
563
564 ui::Layout *sub = &col->column(true);
565 sub->op("OBJECT_OT_grease_pencil_time_modifier_segment_add", "", ICON_ADD);
566 sub->op("OBJECT_OT_grease_pencil_time_modifier_segment_remove", "", ICON_REMOVE);
567 col->separator();
568 sub = &col->column(true);
569 PointerRNA op_ptr = layout.op(
570 "OBJECT_OT_grease_pencil_time_modifier_segment_move", "", ICON_TRIA_UP);
571 RNA_enum_set(&op_ptr, "type", /* ed::object::DashSegmentMoveDirection::Up */ -1);
572 op_ptr = layout.op("OBJECT_OT_grease_pencil_time_modifier_segment_move", "", ICON_TRIA_DOWN);
573 RNA_enum_set(&op_ptr, "type", /* ed::object::DashSegmentMoveDirection::Down */ 1);
574
575 if (tmd->segments().index_range().contains(tmd->segment_active_index)) {
577 ptr->owner_id,
578 RNA_GreasePencilTimeModifierSegment,
579 &tmd->segments()[tmd->segment_active_index]);
580
581 sub = &layout.column(true);
582 sub->prop(&segment_ptr, "segment_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
583 sub = &layout.column(true);
584 sub->prop(&segment_ptr, "segment_start", UI_ITEM_NONE, std::nullopt, ICON_NONE);
585 sub->prop(&segment_ptr, "segment_end", UI_ITEM_NONE, std::nullopt, ICON_NONE);
586 sub->prop(&segment_ptr, "segment_repeat", UI_ITEM_NONE, std::nullopt, ICON_NONE);
587 }
588 }
589
590 ui::PanelLayout custom_range_panel_layout = layout.panel_prop(C, ptr, "open_custom_range_panel");
591 if (ui::Layout *header = custom_range_panel_layout.header) {
592 header->use_property_split_set(false);
593 header->active_set(use_custom_range);
594 header->prop(ptr, "use_custom_frame_range", UI_ITEM_NONE, std::nullopt, ICON_NONE);
595 }
596 if (ui::Layout *body = custom_range_panel_layout.body) {
597 body->use_property_split_set(true);
598 body->active_set(use_custom_range && RNA_boolean_get(ptr, "use_custom_frame_range"));
599
600 col = &body->column(true);
601 col->prop(ptr, "frame_start", UI_ITEM_NONE, IFACE_("Frame Start"), ICON_NONE);
602 col->prop(ptr, "frame_end", UI_ITEM_NONE, IFACE_("End"), ICON_NONE);
603 }
604
605 if (ui::Layout *influence_panel = layout.panel_prop(
606 C, ptr, "open_influence_panel", IFACE_("Influence")))
607 {
609 }
610
611 modifier_error_message_draw(layout, ptr);
612}
613
614static void segment_list_item_draw(uiList * /*ui_list*/,
615 const bContext * /*C*/,
616 ui::Layout &layout,
617 PointerRNA * /*idataptr*/,
618 PointerRNA *itemptr,
619 int /*icon*/,
620 PointerRNA * /*active_dataptr*/,
621 const char * /*active_propname*/,
622 int /*index*/,
623 int /*flt_flag*/)
624{
625 ui::Layout &row = layout.row(true);
626 row.prop(itemptr, "name", ui::ITEM_R_NO_BG, "", ICON_NONE);
627}
628
629static void panel_register(ARegionType *region_type)
630{
632
633 uiListType *list_type = MEM_new_zeroed<uiListType>("Grease Pencil Time modifier segments");
634 STRNCPY_UTF8(list_type->idname, "MOD_UL_grease_pencil_time_modifier_segments");
636 WM_uilisttype_add(list_type);
637}
638
639static void blend_write(BlendWriter *writer, const ID * /*id_owner*/, const ModifierData *md)
640{
641 const auto *tmd = reinterpret_cast<const GreasePencilTimeModifierData *>(md);
642
643 writer->write_struct(tmd);
644 modifier::greasepencil::write_influence_data(writer, &tmd->influence);
645
646 writer->write_struct_array(tmd->segments_num, tmd->segments_array);
647}
648
649static void blend_read(BlendDataReader *reader, ModifierData *md)
650{
651 auto *tmd = reinterpret_cast<GreasePencilTimeModifierData *>(md);
652
653 modifier::greasepencil::read_influence_data(reader, &tmd->influence);
654
655 BLO_read_array_and_validate_size(reader, &tmd->segments_array, &tmd->segments_num);
656}
657
659 /*idname*/ "GreasePencilTime",
660 /*name*/ N_("TimeOffset"),
661 /*struct_name*/ "GreasePencilTimeModifierData",
662 /*struct_size*/ sizeof(GreasePencilTimeModifierData),
663 /*srna*/ &RNA_GreasePencilTimeModifier,
667 /*icon*/ ICON_MOD_TIME,
668
669 /*copy_data*/ copy_data,
670
671 /*deform_verts*/ nullptr,
672 /*deform_matrices*/ nullptr,
673 /*deform_verts_EM*/ nullptr,
674 /*deform_matrices_EM*/ nullptr,
675 /*modify_mesh*/ nullptr,
676 /*modify_geometry_set*/ modify_geometry_set,
677
678 /*init_data*/ init_data,
679 /*required_data_mask*/ nullptr,
680 /*free_data*/ free_data,
681 /*is_disabled*/ nullptr,
682 /*update_depsgraph*/ nullptr,
683 /*depends_on_time*/ nullptr,
684 /*depends_on_normals*/ nullptr,
685 /*foreach_ID_link*/ foreach_ID_link,
686 /*foreach_tex_link*/ nullptr,
687 /*free_runtime_data*/ nullptr,
688 /*panel_register*/ panel_register,
689 /*blend_write*/ blend_write,
690 /*blend_read*/ blend_read,
691};
692
693Span<GreasePencilTimeModifierSegment> GreasePencilTimeModifierData::segments() const
694{
695 return {this->segments_array, this->segments_num};
696}
697
698MutableSpan<GreasePencilTimeModifierSegment> GreasePencilTimeModifierData::segments()
699{
700 return {this->segments_array, this->segments_num};
701}
702
703} // namespace blender
Low-level operations for curves.
Low-level operations for grease pencil.
#define STRNCPY_UTF8(dst, src)
#define IFACE_(msgid)
#define DATA_(msgid)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define ELEM(...)
constexpr IndexRange()=default
bool add_overwrite(const Key &key, const Value &value)
Definition BLI_map.hh:325
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
constexpr Span drop_front(int64_t n) const
Definition BLI_span.hh:175
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define layer
T floor(const T &a)
T ceil(const T &a)
void read_influence_data(BlendDataReader *reader, GreasePencilModifierInfluenceData *influence_data)
void init_influence_data(GreasePencilModifierInfluenceData *influence_data, const bool has_custom_curve)
void write_influence_data(BlendWriter *writer, const GreasePencilModifierInfluenceData *influence_data)
void draw_layer_filter_settings(const bContext *, ui::Layout &layout, PointerRNA *ptr)
IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil, const GreasePencilModifierInfluenceData &influence_data, IndexMaskMemory &memory)
void free_influence_data(GreasePencilModifierInfluenceData *influence_data)
void foreach_influence_ID_link(GreasePencilModifierInfluenceData *influence_data, Object *ob, IDWalkFunc walk, void *user_data)
void copy_influence_data(const GreasePencilModifierInfluenceData *influence_data_src, GreasePencilModifierInfluenceData *influence_data_dst, const int)
void template_uilist(Layout *layout, const bContext *C, const char *listtype_name, const char *list_id, PointerRNA *dataptr, StringRefNull propname, PointerRNA *active_dataptr, StringRefNull active_propname, const char *item_dyntip_propname, int rows, int maxrows, int layout_type, enum TemplateListFlags flags)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
__int64 int64_t
Definition BKE_text.h:90
static void fill_scene_timeline(const GreasePencilTimeModifierData &tmd, const Scene &eval_scene, const Map< int, GreasePencilFrame > &frames, const Span< int > sorted_keys, const FrameRange scene_dst_range, Map< int, GreasePencilFrame > &dst_frames)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static void blend_write(BlendWriter *writer, const ID *, const ModifierData *md)
Definition MOD_bevel.cc:454
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
static void fill_scene_range_fixed(const TimeMapping &mapping, const Map< int, GreasePencilFrame > &frames, const Span< int > sorted_keys, const int gp_src_frame, const FrameRange scene_dst_range, Map< int, GreasePencilFrame > &dst_frames)
GreasePencilTimeModifierSegmentMode
@ MOD_GREASE_PENCIL_TIME_SEG_MODE_PINGPONG
@ MOD_GREASE_PENCIL_TIME_SEG_MODE_REVERSE
@ MOD_GREASE_PENCIL_TIME_SEG_MODE_NORMAL
@ eModifierType_GreasePencilTime
static void init_data(ModifierData *md)
void(*)(void *user_data, Object *ob, ID **idpoin, LibraryForeachIDCallbackFlag cb_flag) IDWalkFunc
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
@ MOD_GREASE_PENCIL_TIME_KEEP_LOOP
@ MOD_GREASE_PENCIL_TIME_CUSTOM_RANGE
static void fill_scene_range_chain(const TimeMapping &mapping, const Map< int, GreasePencilFrame > &frames, const Span< int > sorted_keys, const Span< GreasePencilTimeModifierSegment > segments, const FrameRange gp_src_range, const FrameRange scene_dst_range, Map< int, GreasePencilFrame > &dst_frames)
static void modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set)
void modifier_error_message_draw(ui::Layout &layout, PointerRNA *ptr)
static void calculate_repetitions(const TimeMapping &mapping, const FrameRange &gp_src, const FrameRange &scene_dst, int &r_start, int &r_count)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ MOD_GREASE_PENCIL_TIME_MODE_REVERSE
@ MOD_GREASE_PENCIL_TIME_MODE_PINGPONG
@ MOD_GREASE_PENCIL_TIME_MODE_FIX
@ MOD_GREASE_PENCIL_TIME_MODE_NORMAL
@ MOD_GREASE_PENCIL_TIME_MODE_CHAIN
static void free_data(ModifierData *md)
static void segment_list_item_draw(uiList *, const bContext *, ui::Layout &layout, PointerRNA *, PointerRNA *itemptr, int, PointerRNA *, const char *, int, int)
static void panel_register(ARegionType *region_type)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static void fill_scene_range_forward(const TimeMapping &mapping, const Map< int, GreasePencilFrame > &frames, const Span< int > sorted_keys, const FrameRange gp_src_range, const FrameRange scene_dst_range, Map< int, GreasePencilFrame > &dst_frames)
@ eModifierTypeFlag_SupportsMapping
@ eModifierTypeFlag_AcceptsGreasePencil
@ eModifierTypeFlag_EnableInEditmode
@ eModifierTypeFlag_SupportsEditmode
static void fill_scene_range_ping_pong(const TimeMapping &mapping, const Map< int, GreasePencilFrame > &frames, const Span< int > sorted_keys, const FrameRange gp_src_range, const FrameRange scene_dst_range, Map< int, GreasePencilFrame > &dst_frames)
void BLO_read_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size, const int elems=1)
static void blend_read(BlendDataReader *, ModifierData *md)
bool WM_uilisttype_add(uiListType *ult)
ModifierTypeInfo modifierType_GreasePencilTime
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
static void panel_draw(const bContext *, Panel *panel)
static void insert_keys_forward(const TimeMapping &mapping, const Map< int, GreasePencilFrame > &frames, const Span< int > sorted_keys, const FrameRange gp_src_range, const FrameRange gp_dst_range, Map< int, GreasePencilFrame > &dst_frames)
static void fill_scene_range_reverse(const TimeMapping &mapping, const Map< int, GreasePencilFrame > &frames, const Span< int > sorted_keys, const FrameRange gp_src_range, const FrameRange scene_dst_range, Map< int, GreasePencilFrame > &dst_frames)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
static IndexRange find_key_range(const Span< int > sorted_keys, const FrameRange &frame_range)
static void insert_keys_reverse(const TimeMapping &mapping, const Map< int, GreasePencilFrame > &frames, const Span< int > sorted_keys, const FrameRange gp_src_range, const FrameRange gp_dst_range, Map< int, GreasePencilFrame > &dst_frames)
void BKE_modifier_copydata_generic(const ModifierData *md, ModifierData *md_dst, int flag)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_array(const int64_t array_size, const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
FrameRange shift(const int n) const
FrameRange drop_back(const int n) const
FrameRange drop_front(const int n) const
GreasePencilTimeModifierSegment * segments_array
ui::Layout * layout
struct RenderData r
int scene_frame_before_local_frame(const int local_frame) const
int local_frame_after_scene_frame(const int scene_frame) const
int local_frame_before_scene_frame(const int scene_frame) const
int scene_frame_after_local_frame(const int local_frame) const
float to_local_time(const float scene_frame) const
TimeMapping(const GreasePencilTimeModifierData &tmd)
float to_scene_time(const float local_frame) const
GreasePencil * get_grease_pencil_for_write()
char idname[BKE_ST_MAXNAME]
uiListDrawItemFunc draw_item
void use_property_split_set(bool is_sep)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
PanelLayout panel_prop(const bContext *C, PointerRNA *open_prop_owner, StringRefNull open_prop_name)
Layout & row(bool align)
#define N_(msgid)