Blender V5.3
scene.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/* Allow using deprecated functionality for .blend file I/O. */
10#define DNA_DEPRECATED_ALLOW
11
12#include <cstddef>
13#include <cstdio>
14#include <cstring>
15#include <optional>
16
17#include "MEM_guardedalloc.h"
18
19#include "DNA_anim_types.h"
20#include "DNA_brush_types.h"
25#include "DNA_linestyle_types.h"
26#include "DNA_mask_types.h"
27#include "DNA_material_types.h"
28#include "DNA_mesh_types.h"
29#include "DNA_node_types.h"
30#include "DNA_object_types.h"
31#include "DNA_rigidbody_types.h"
32#include "DNA_scene_types.h"
33#include "DNA_screen_types.h"
34#include "DNA_sequence_types.h"
35#include "DNA_sound_types.h"
36#include "DNA_space_types.h"
37#include "DNA_text_types.h"
38#include "DNA_userdef_types.h"
39#include "DNA_vfont_types.h"
40#include "DNA_view3d_types.h"
42#include "DNA_world_types.h"
43
44#include "BLI_function_ref.hh"
45#include "BLI_listbase.hh"
46#include "BLI_math_base_c.hh"
48#include "BLI_path_utils.hh"
49#include "BLI_string_utf8.hh"
50#include "BLI_string_utils.hh"
51#include "BLI_threads.hh"
52#include "BLI_utildefines.hh"
53
54#include "BLO_readfile.hh"
55
56#include "BLT_translation.hh"
57
58#include "BKE_action.hh"
59#include "BKE_anim_data.hh"
60#include "BKE_animsys.hh"
61#include "BKE_bpath.hh"
62#include "BKE_callbacks.hh"
63#include "BKE_collection.hh"
64#include "BKE_colortools.hh"
65#include "BKE_curveprofile.h"
66#include "BKE_duplilist.hh"
67#include "BKE_editmesh.hh"
68#include "BKE_effect.h"
69#include "BKE_fcurve.hh"
70#include "BKE_idprop.hh"
71#include "BKE_idtype.hh"
72#include "BKE_image.hh"
73#include "BKE_image_format.hh"
74#include "BKE_layer.hh"
75#include "BKE_lib_id.hh"
76#include "BKE_lib_query.hh"
77#include "BKE_lib_remap.hh"
78#include "BKE_main.hh"
79#include "BKE_mesh_types.hh"
81#include "BKE_node_runtime.hh"
82#include "BKE_paint.hh"
83#include "BKE_paint_types.hh"
84#include "BKE_pointcache.h"
85#include "BKE_preview_image.hh"
86#include "BKE_rigidbody.h"
87#include "BKE_scene.hh"
88#include "BKE_scene_runtime.hh"
89#include "BKE_screen.hh"
90#include "BKE_sound.hh"
91#include "BKE_unit.hh"
92#include "BKE_workspace.hh"
93
94#include "ANIM_action.hh"
95
96#include "DEG_depsgraph.hh"
100
101#include "NOD_eval_log.hh"
102
103#include "RE_engine.h"
104
105#include "RNA_access.hh"
106
107#include "SEQ_iterator.hh"
108#include "SEQ_sequencer.hh"
109
110#include "BLO_read_write.hh"
111
112#include "IMB_colormanagement.hh"
113#include "IMB_imbuf.hh"
114
115#include "DRW_engine.hh"
116
117#include "bmesh.hh"
118#include "versioning_common.hh"
119
120namespace blender {
121
122/* -------------------------------------------------------------------- */
125
126using bke::CompositorRuntime;
127using bke::SceneRuntime;
128using bke::SequencerRuntime;
129
136
141
143
144{
145 CurveMapping *cumap = BKE_curvemapping_add(1, 0, 0, 1, 1);
146
148 cumap->preset = CURVE_PRESET_LINE;
149
151 BKE_curvemapping_changed(cumap, false);
153
154 return cumap;
155}
156
158{
159 CurveMapping *cumap = BKE_curvemapping_add(1, 0, 0, 1, 1);
162
163 return cumap;
164}
165
174
175static void scene_init_data(ID *id)
176{
177 Scene *scene = id_cast<Scene *>(id);
178 const char *colorspace_name;
179 SceneRenderView *srv;
180 CurveMapping *mblur_shutter_curve;
181
182 INIT_DEFAULT_STRUCT_AFTER(scene, id);
183
184 STRNCPY(scene->r.bake.filepath, U.renderdir);
185
186 mblur_shutter_curve = &scene->r.mblur_shutter_curve;
187 BKE_curvemapping_set_defaults(mblur_shutter_curve, 1, 0.0f, 0.0f, 1.0f, 1.0f, HD_AUTO);
188 BKE_curvemapping_init(mblur_shutter_curve);
189 BKE_curvemap_reset(mblur_shutter_curve->cm,
190 &mblur_shutter_curve->clipr,
193
194 scene->toolsettings = MEM_new<ToolSettings>(__func__);
195 /* Unlike other Paint structs, the `ImagePaintSettings` is default allocated, so it needs to be
196 * explicitly initialized when a new scene is created to ensure runtime data is in a consistent
197 * state. */
198 BKE_paint_init(nullptr, scene, PaintMode::Texture2D, false);
199
200 scene->toolsettings->autokey_mode = U.autokey_mode;
201
205
206 /* Grease pencil multi-frame falloff curve. */
207 scene->toolsettings->gp_sculpt.cur_falloff = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
208 CurveMapping *gp_falloff_curve = scene->toolsettings->gp_sculpt.cur_falloff;
209 BKE_curvemapping_init(gp_falloff_curve);
210 BKE_curvemap_reset(gp_falloff_curve->cm,
211 &gp_falloff_curve->clipr,
214
215 scene->toolsettings->gp_sculpt.cur_primitive = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
216 CurveMapping *gp_primitive_curve = scene->toolsettings->gp_sculpt.cur_primitive;
217 BKE_curvemapping_init(gp_primitive_curve);
218 BKE_curvemap_reset(gp_primitive_curve->cm,
219 &gp_primitive_curve->clipr,
222
224 scene->unit.scale_length = 1.0f;
228 scene->unit.temperature_unit = uchar(
230
231 {
233 pset = &scene->toolsettings->particle;
234 for (size_t i = 1; i < ARRAY_SIZE(pset->brush); i++) {
235 pset->brush[i] = pset->brush[0];
236 }
237 pset->brush[PE_BRUSH_CUT].strength = 1.0f;
238 }
239
241
242 STRNCPY(scene->r.pic, U.renderdir);
243
244 /* NOTE: in header_info.c the scene copy happens...,
245 * if you add more to renderdata it has to be checked there. */
246
247 /* multiview - stereo */
249 srv = scene->r.views.first();
251
253 srv = scene->r.views.last();
255
256 /* color management */
258
262 colorspace_name);
263
266
267 /* Curve Profile */
269
270 /* Sequencer */
272
273 for (size_t i = 0; i < ARRAY_SIZE(scene->orientation_slots); i++) {
274 scene->orientation_slots[i].index_custom = -1;
275 }
276
277 /* Master Collection */
279
280 BKE_view_layer_add(nullptr, scene, DATA_("ViewLayer"), nullptr, VIEWLAYER_ADD_NEW);
281
282 scene->runtime = MEM_new<SceneRuntime>(__func__);
283}
284
285static void scene_copy_data(Main *bmain,
286 std::optional<Library *> owner_library,
287 ID *id_dst,
288 const ID *id_src,
289 const int flag)
290{
291 Scene *scene_dst = id_cast<Scene *>(id_dst);
292 const Scene *scene_src = id_cast<const Scene *>(id_src);
293 /* Never handle user-count here for own sub-data. */
294 const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
295 /* Always need allocation of the embedded ID data. */
296 const int flag_embedded_id_data = flag_subdata & ~LIB_ID_CREATE_NO_ALLOCATE;
297
298 scene_dst->ed = nullptr;
299 scene_dst->depsgraph_hash = nullptr;
300 scene_dst->fps_info = nullptr;
301
302 /* Master Collection */
303 if (scene_src->master_collection) {
304 BKE_id_copy_in_lib(bmain,
305 owner_library,
306 &scene_src->master_collection->id,
307 &scene_dst->id,
308 reinterpret_cast<ID **>(&scene_dst->master_collection),
309 flag_embedded_id_data);
310 }
311
312 /* View Layers */
313 if (bmain) {
314 for (ViewLayer &view_layer : scene_src->view_layers) {
315 BKE_view_layer_synced_ensure(*bmain, scene_src, &view_layer);
316 }
317 }
318 BLI_duplicatelist(&scene_dst->view_layers, &scene_src->view_layers);
319 for (ViewLayer *view_layer_src = scene_src->view_layers.first(),
320 *view_layer_dst = scene_dst->view_layers.first();
321 view_layer_src;
322 view_layer_src = view_layer_src->next, view_layer_dst = view_layer_dst->next)
323 {
324 BKE_view_layer_copy_data(scene_dst, scene_src, view_layer_dst, view_layer_src, flag_subdata);
325 }
326
327 BKE_copy_time_markers(scene_dst->markers, scene_src->markers, flag);
328
329 BLI_duplicatelist(&(scene_dst->transform_spaces), &(scene_src->transform_spaces));
330 BLI_duplicatelist(&(scene_dst->r.views), &(scene_src->r.views));
331 BKE_keyingsets_copy(&(scene_dst->keyingsets), &(scene_src->keyingsets));
332
333 if (scene_src->rigidbody_world) {
335 flag_subdata);
336 }
337
338 /* copy color management settings */
340 &scene_src->display_settings);
344
345 BKE_image_format_copy(&scene_dst->r.im_format, &scene_src->r.im_format);
346 BKE_image_format_copy(&scene_dst->r.bake.im_format, &scene_src->r.bake.im_format);
347
349
350 /* tool settings */
351 scene_dst->toolsettings = BKE_toolsettings_copy(scene_src->toolsettings, flag_subdata);
352
353 if (scene_src->display.shading.prop) {
354 scene_dst->display.shading.prop = IDP_CopyProperty(scene_src->display.shading.prop);
355 }
356
357 /* sequencer data */
358 if (scene_src->ed) {
359 scene_dst->ed = MEM_new<Editing>(__func__);
360 scene_dst->ed->cache_flag = scene_src->ed->cache_flag;
361 scene_dst->ed->show_missing_media_flag = scene_src->ed->show_missing_media_flag;
362 scene_dst->ed->proxy_storage = scene_src->ed->proxy_storage;
363 STRNCPY(scene_dst->ed->proxy_dir, scene_src->ed->proxy_dir);
365 scene_src,
366 scene_dst,
367 &scene_dst->ed->seqbase,
368 &scene_src->ed->seqbase,
369 /* NOTE: Never use #StripDuplicate::Data here (would generate
370 * recursive ID duplication not, supported at all here). */
372 flag_subdata);
373 BLI_duplicatelist(&scene_dst->ed->channels, &scene_src->ed->channels);
374 }
375
376 if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
377 BKE_previewimg_id_copy(&scene_dst->id, &scene_src->id);
378 }
379 else {
380 scene_dst->preview = nullptr;
381 }
382
383 BKE_scene_copy_data_eevee(scene_dst, scene_src);
384
385 bke::compositor::copy_effects(*scene_dst, *scene_src, flag_subdata);
386
387 scene_dst->runtime = MEM_new<SceneRuntime>(__func__);
388}
389
390static void scene_free_data(ID *id)
391{
392 Scene *scene = id_cast<Scene *>(id);
393 const bool do_id_user = false;
394
395 seq::editing_free(scene, do_id_user);
396
398
400 "Pointer should not be valid after blend file reading.");
401
402 if (scene->rigidbody_world) {
403 /* Prevent rigidbody freeing code to follow other IDs pointers, this should never be allowed
404 * nor necessary from here, and with new undo code, those pointers may be fully invalid or
405 * worse, pointing to data actually belonging to new BMain! */
406 scene->rigidbody_world->constraints = nullptr;
407 scene->rigidbody_world->group = nullptr;
409 }
410
411 BKE_free_time_markers(scene->markers, do_id_user);
412 scene->transform_spaces.free_no_destruct();
413 scene->r.views.free_no_destruct();
414
416 scene->toolsettings = nullptr;
417
419
420 MEM_SAFE_DELETE_VOID(scene->fps_info);
421
423
427
428 BKE_previewimg_id_free(&scene->id);
430
431 for (ViewLayer &view_layer : scene->view_layers.items_mutable()) {
432 BLI_remlink(&scene->view_layers, &view_layer);
433 BKE_view_layer_free_ex(&view_layer, do_id_user);
434 }
435
436 /* Master Collection */
437 /* TODO: what to do with do_id_user? it's also true when just
438 * closing the file which seems wrong? should decrement users
439 * for objects directly in the master collection? then other
440 * collections in the scene need to do it too? */
441 if (scene->master_collection) {
444 MEM_delete(scene->master_collection);
445 scene->master_collection = nullptr;
446 }
447
448 if (scene->display.shading.prop) {
450 scene->display.shading.prop = nullptr;
451 }
452
454
455 /* These are freed on `do_versions`. */
456 BLI_assert(scene->layer_properties == nullptr);
457
458 MEM_delete(scene->runtime);
459}
460
462 ID **id_pointer,
463 void *user_data,
464 const LibraryForeachIDCallbackFlag cb_flag)
465{
466 LibraryForeachIDData *data = static_cast<LibraryForeachIDData *>(user_data);
468 data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
469}
470
476 /* Undo when preserving tool-settings from old scene, we also want to try to preserve that ID
477 * pointer from its old scene's value. */
479 /* Undo when preserving tool-settings from old scene, we want to keep the new value of that ID
480 * pointer. */
482};
483
485 ID **id_p,
487 BlendLibReader *reader,
488 ID **id_old_p,
489 const uint cb_flag)
490{
491 switch (action) {
493 ID *id_old = *id_old_p;
494 /* Old data has not been remapped to new values of the pointers, if we want to keep the old
495 * pointer here we need its new address. */
496 ID *id_old_new = id_old != nullptr ? BLO_read_get_new_id_address_from_session_uid(
497 reader, id_old->session_uid) :
498 nullptr;
499 /* The new address may be the same as the old one, in which case there is nothing to do. */
500 if (id_old_new == id_old) {
501 break;
502 }
503 if (id_old_new != nullptr) {
504 BLI_assert(id_old == id_old_new->orig_id);
505 *id_old_p = id_old_new;
506 if (cb_flag & IDWALK_CB_USER) {
507 id_us_plus_no_lib(id_old_new);
508 id_us_min(id_old);
509 }
510 break;
511 }
512
513 /* We failed to find a new valid pointer for the previous ID, just keep the current one as
514 * if we had been under #SCENE_FOREACH_UNDO_NO_RESTORE case.
515 *
516 * There is a nasty twist here though: a previous call to 'undo_preserve' on the Scene ID may
517 * have modified it, even though the undo step detected it as unmodified. In such case, the
518 * value of `*id_p` may end up also pointing to an invalid (no more in newly read Main) ID,
519 * so it also needs to be checked from its `session_uid`. */
520 ID *id = *id_p;
521 ID *id_new = id != nullptr ?
523 nullptr;
524 if (id_new != id) {
525 *id_p = id_new;
526 if (cb_flag & IDWALK_CB_USER) {
527 id_us_plus_no_lib(id_new);
528 id_us_min(id);
529 }
530 }
531 std::swap(*id_p, *id_old_p);
532 break;
533 }
535 /* Counteract the swap of the whole ToolSettings container struct. */
536 std::swap(*id_p, *id_old_p);
537 break;
538 }
539}
540
546#define BKE_LIB_FOREACHID_UNDO_PRESERVE_PROCESS_IDSUPER_P( \
547 _data, _id_p, _do_undo_restore, _action, _reader, _id_old_p, _cb_flag) \
548 { \
549 if (_do_undo_restore) { \
550 scene_foreach_toolsettings_id_pointer_process( \
551 (ID **)(_id_p), _action, _reader, (ID **)(_id_old_p), _cb_flag); \
552 } \
553 else { \
554 BLI_assert((_data) != nullptr); \
555 BKE_LIB_FOREACHID_PROCESS_IDSUPER_P(_data, _id_p, _cb_flag); \
556 } \
557 } \
558 (void)0
559
560#define BKE_LIB_FOREACHID_UNDO_PRESERVE_PROCESS_FUNCTION_CALL( \
561 _data, _do_undo_restore, _func_call) \
562 { \
563 if (_do_undo_restore) { \
564 _func_call; \
565 } \
566 else { \
567 BLI_assert((_data) != nullptr); \
568 BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(_data, _func_call); \
569 } \
570 } \
571 (void)0
572
574 Paint *paint,
575 const bool do_undo_restore,
576 BlendLibReader *reader,
577 Paint *paint_old)
578{
579 /* `paint` may be nullptr in 'undo_preserve' case, when the relevant sub-data does not exist in
580 * newly read toolsettings, but does exist in old existing ones.
581 *
582 * This function should never be called in case the old toolsettings do not have the relevant
583 * `paint_old` data. */
584 BLI_assert(paint_old != nullptr);
585
586 Brush *brush_tmp = nullptr;
587 Brush **brush_p = paint ? &paint->brush : &brush_tmp;
589 brush_p,
590 do_undo_restore,
592 reader,
593 &paint_old->brush,
595
596 Palette *palette_tmp = nullptr;
597 Palette **palette_p = paint ? &paint->palette : &palette_tmp;
599 palette_p,
600 do_undo_restore,
602 reader,
603 &paint_old->palette,
605}
606
608 ToolSettings *toolsett,
609 const bool do_undo_restore,
610 BlendLibReader *reader,
611 ToolSettings *toolsett_old)
612{
613 /* In regular foreach_id case, only one set of data is processed, both pointers are expected to
614 * be the same.
615 *
616 * In undo_preserve case, both pointers may be different (see #lib_link_all for why they may be
617 * the same in some cases). */
618 BLI_assert(do_undo_restore || (toolsett == toolsett_old));
619 BLI_assert(!ELEM(nullptr, toolsett, toolsett_old));
620
621 /* NOTE: In 'undo_preserve' case, the 'old' data is the source of truth here, since it is the one
622 * that will be re-used in newly read Main and therefore needs valid, existing in new Main, ID
623 * pointers. */
624
626 &toolsett->particle.scene,
627 do_undo_restore,
629 reader,
630 &toolsett_old->particle.scene,
633 &toolsett->particle.object,
634 do_undo_restore,
636 reader,
637 &toolsett_old->particle.object,
640 &toolsett->particle.shape_object,
641 do_undo_restore,
643 reader,
644 &toolsett_old->particle.shape_object,
646
648 data, &toolsett->imapaint.paint, do_undo_restore, reader, &toolsett_old->imapaint.paint);
650 &toolsett->imapaint.stencil,
651 do_undo_restore,
653 reader,
654 &toolsett_old->imapaint.stencil,
657 &toolsett->imapaint.clone,
658 do_undo_restore,
660 reader,
661 &toolsett_old->imapaint.clone,
664 &toolsett->imapaint.canvas,
665 do_undo_restore,
667 reader,
668 &toolsett_old->imapaint.canvas,
670
671 /* These two Object pointers should just follow the normal Undo behavior. See #153065. */
673 &toolsett->anim_mirror_object,
674 do_undo_restore,
676 reader,
677 &toolsett_old->anim_mirror_object,
680 &toolsett->anim_relative_object,
681 do_undo_restore,
683 reader,
684 &toolsett_old->anim_relative_object,
686
687 Paint *paint, *paint_old;
688
689 if (toolsett_old->vpaint) {
690 paint = toolsett->vpaint ? &toolsett->vpaint->paint : nullptr;
691 paint_old = &toolsett_old->vpaint->paint;
693 data,
694 do_undo_restore,
695 scene_foreach_paint(data, paint, do_undo_restore, reader, paint_old));
696 }
697 if (toolsett_old->wpaint) {
698 paint = toolsett->wpaint ? &toolsett->wpaint->paint : nullptr;
699 paint_old = &toolsett_old->wpaint->paint;
701 data,
702 do_undo_restore,
703 scene_foreach_paint(data, paint, do_undo_restore, reader, paint_old));
704 }
705 if (toolsett_old->sculpt) {
706 paint = toolsett->sculpt ? &toolsett->sculpt->paint : nullptr;
707 paint_old = &toolsett_old->sculpt->paint;
709 data,
710 do_undo_restore,
711 scene_foreach_paint(data, paint, do_undo_restore, reader, paint_old));
712
713 /* WARNING: Handling this object pointer is fairly intricated, to support both 'regular'
714 * foreach_id processing (in which case both sets of data, current and old, are the same), and
715 * the restore-after-undo cases. It does not have a helper, because so far it is the only case
716 * of having to deal with non-'paint' data in a sub-toolsett struct. */
717 Object *gravity_object = toolsett->sculpt ? toolsett->sculpt->gravity_object : nullptr;
718 Object *gravity_object_old = toolsett_old->sculpt->gravity_object;
720 &gravity_object,
721 do_undo_restore,
723 reader,
724 &gravity_object_old,
726 if (toolsett->sculpt) {
727 toolsett->sculpt->gravity_object = gravity_object;
728 }
729 /* Do not re-assign `gravity_object_old` object if both current and old data are the same
730 * (foreach_id case), that would nullify assignment above, making remapping cases fail. */
731 if (toolsett_old != toolsett) {
732 toolsett_old->sculpt->gravity_object = gravity_object_old;
733 }
734 }
735 if (toolsett_old->gp_paint) {
736 paint = toolsett->gp_paint ? &toolsett->gp_paint->paint : nullptr;
737 paint_old = &toolsett_old->gp_paint->paint;
739 data,
740 do_undo_restore,
741 scene_foreach_paint(data, paint, do_undo_restore, reader, paint_old));
742 }
743 if (toolsett_old->gp_vertexpaint) {
744 paint = toolsett->gp_vertexpaint ? &toolsett->gp_vertexpaint->paint : nullptr;
745 paint_old = &toolsett_old->gp_vertexpaint->paint;
747 data,
748 do_undo_restore,
749 scene_foreach_paint(data, paint, do_undo_restore, reader, paint_old));
750 }
751 if (toolsett_old->gp_sculptpaint) {
752 paint = toolsett->gp_sculptpaint ? &toolsett->gp_sculptpaint->paint : nullptr;
753 paint_old = &toolsett_old->gp_sculptpaint->paint;
755 data,
756 do_undo_restore,
757 scene_foreach_paint(data, paint, do_undo_restore, reader, paint_old));
758 }
759 if (toolsett_old->gp_weightpaint) {
760 paint = toolsett->gp_weightpaint ? &toolsett->gp_weightpaint->paint : nullptr;
761 paint_old = &toolsett_old->gp_weightpaint->paint;
763 data,
764 do_undo_restore,
765 scene_foreach_paint(data, paint, do_undo_restore, reader, paint_old));
766 }
767 if (toolsett_old->curves_sculpt) {
768 paint = toolsett->curves_sculpt ? &toolsett->curves_sculpt->paint : nullptr;
769 paint_old = &toolsett_old->curves_sculpt->paint;
771 data,
772 do_undo_restore,
773 scene_foreach_paint(data, paint, do_undo_restore, reader, paint_old));
774 }
775
777 data,
779 do_undo_restore,
781 reader,
782 &toolsett_old->gp_sculpt.guide.reference_object,
784}
785
786#undef BKE_LIB_FOREACHID_UNDO_PRESERVE_PROCESS_IDSUPER
787#undef BKE_LIB_FOREACHID_UNDO_PRESERVE_PROCESS_FUNCTION_CALL
788
790 ListBaseT<LayerCollection> *lb,
791 const bool is_master)
792{
793 const int data_flags = BKE_lib_query_foreachid_process_flags_get(data);
794
795 for (LayerCollection &lc : *lb) {
796 if ((data_flags & IDWALK_NO_ORIG_POINTERS_ACCESS) == 0 && lc.collection != nullptr) {
797 BLI_assert(is_master == ((lc.collection->id.flag & ID_FLAG_EMBEDDED_DATA) != 0));
798 }
802 scene_foreach_layer_collection(data, &lc.layer_collections, false);
803 }
804}
805
806static bool strip_foreach_member_id_cb(Strip *strip, void *user_data)
807{
808 LibraryForeachIDData *data = static_cast<LibraryForeachIDData *>(user_data);
809
810/* Only for deprecated data. */
811#define FOREACHID_PROCESS_ID_NOCHECK(_data, _id_super, _cb_flag) \
812 { \
813 BKE_lib_query_foreachid_process((_data), reinterpret_cast<ID **>(&(_id_super)), (_cb_flag)); \
814 if (BKE_lib_query_foreachid_iter_stop(_data)) { \
815 return false; \
816 } \
817 } \
818 ((void)0)
819
820#define FOREACHID_PROCESS_IDSUPER(_data, _id_super, _cb_flag) \
821 { \
822 CHECK_TYPE(&((_id_super)->id), ID *); \
823 FOREACHID_PROCESS_ID_NOCHECK(_data, _id_super, _cb_flag); \
824 } \
825 ((void)0)
826
828 FOREACHID_PROCESS_IDSUPER(data, strip->scene_camera, IDWALK_CB_NOP);
832 IDP_foreach_property(strip->prop, IDP_TYPE_FILTER_ID, [&](IDProperty *prop) {
833 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
834 });
835 IDP_foreach_property(strip->system_properties, IDP_TYPE_FILTER_ID, [&](IDProperty *prop) {
836 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
837 });
838 if (strip->type == STRIP_TYPE_COMPOSITOR && strip->effectdata) {
839 CompositorEffectVars *comp_data = static_cast<CompositorEffectVars *>(strip->effectdata);
842 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
843 });
844 }
845 /* TODO: This could use `seq::foreach_strip_modifier_id`, but because `FOREACHID_PROCESS_IDSUPER`
846 * doesn't take IDs but "ID supers", it makes it a bit more cumbersome. */
847 for (StripModifierData &smd : strip->modifiers) {
850 auto *modifier_data = reinterpret_cast<SequencerCompositorModifierData *>(&smd);
851 FOREACHID_PROCESS_IDSUPER(data, modifier_data->node_group, IDWALK_CB_USER);
852 }
854 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
855 });
856 }
857
858 if (strip->type == STRIP_TYPE_TEXT && strip->effectdata) {
859 TextVars *text_data = static_cast<TextVars *>(strip->effectdata);
861 }
862
863#undef FOREACHID_PROCESS_IDSUPER
864#undef FOREACHID_PROCESS_ID_NOCHECK
865
866 return true;
867}
868
870{
871 Scene *scene = reinterpret_cast<Scene *>(id);
873
881
883
884 if (scene->nodetree) {
885 /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
888 }
889 if (scene->ed) {
892 }
893
896
897 /* This pointer can be nullptr during old files reading, better be safe than sorry. */
898 if (scene->master_collection != nullptr) {
901 }
902
903 for (ViewLayer &view_layer : scene->view_layers) {
907 data,
909 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
910 }));
912 data,
914 view_layer.system_properties, IDP_TYPE_FILTER_ID, [&](IDProperty *prop) {
915 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
916 }));
917
918 /* FIXME: Although ideally this should always have access to synced data, this is not always
919 * the case (FOREACH_ID can be called in context where re-syncing is blocked, while effectively
920 * modifying the view-layer or collections data, see e.g. #id_delete code which remaps all
921 * deleted ID usages to null).
922 *
923 * There is no obvious solution to this problem, so for now working around with some 'band-aid'
924 * special code and asserts.
925 *
926 * In the future, there may be need for a new `IDWALK_CB` flag to mark existing pointer values
927 * as unsafe to access in such cases. */
929 const bool is_synced = bmain ? BKE_view_layer_synced_ensure(*bmain, scene, &view_layer) :
930 BKE_view_layer_is_synced(view_layer);
931 if (!is_synced) {
932 BLI_assert_msg((flag & IDWALK_RECURSE) == 0,
933 "foreach_id should never recurse in case it cannot ensure that all "
934 "view-layers are in synced with their collections");
935 }
936 for (Base &base : *BKE_view_layer_object_bases_unsynced_get(&view_layer)) {
938 data,
939 base.object,
941 }
942
945
946 for (FreestyleModuleConfig &fmc : view_layer.freestyle_config.modules) {
948 }
949
950 for (FreestyleLineSet &fls : view_layer.freestyle_config.linesets) {
953 }
954 }
955
956 for (TimeMarker &marker : scene->markers) {
960 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
961 }));
962 }
963
964 ToolSettings *toolsett = scene->toolsettings;
965 if (toolsett) {
967 data, scene_foreach_toolsettings(data, toolsett, false, nullptr, toolsett));
968 }
969
970 if (scene->rigidbody_world) {
972 data,
975 }
976
978 for (Base &base_legacy : scene->base.items_mutable()) {
980 }
981
982 for (SceneRenderLayer &srl : scene->r.layers) {
984 for (FreestyleModuleConfig &fmc : srl.freestyleConfig.modules) {
986 }
987 for (FreestyleLineSet &fls : srl.freestyleConfig.linesets) {
990 }
991 }
992 }
993}
994
995static bool strip_foreach_path_callback(Strip *strip, void *user_data)
996{
997 if (STRIP_HAS_PATH(strip)) {
998 StripElem *se = strip->data->stripdata;
999 BPathForeachPathData *bpath_data = static_cast<BPathForeachPathData *>(user_data);
1000
1001 if (ELEM(strip->type, STRIP_TYPE_MOVIE, STRIP_TYPE_SOUND) && se) {
1003 strip->data->dirpath,
1004 sizeof(strip->data->dirpath),
1005 se->filename,
1006 sizeof(se->filename));
1007 }
1008 else if ((strip->type == STRIP_TYPE_IMAGE) && se) {
1009 /* NOTE: An option not to loop over all strips could be useful? */
1010 uint len = uint(strip->data->stripdata_num);
1011 uint i;
1012
1013 if (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE) {
1014 /* only operate on one path */
1015 len = std::min(1u, len);
1016 }
1017
1018 for (i = 0; i < len; i++, se++) {
1020 strip->data->dirpath,
1021 sizeof(strip->data->dirpath),
1022 se->filename,
1023 sizeof(se->filename));
1024 }
1025 }
1026 else {
1027 /* simple case */
1029 bpath_data, strip->data->dirpath, sizeof(strip->data->dirpath));
1030 }
1031 }
1032 return true;
1033}
1034
1035static void scene_foreach_path(ID *id, BPathForeachPathData *bpath_data)
1036{
1037 Scene *scene = id_cast<Scene *>(id);
1038 if (scene->ed != nullptr) {
1040 }
1041}
1042
1044{
1045 Scene *scene = id_cast<Scene *>(id);
1046
1048 fn.single(paint.unified_paint_settings.color);
1049 fn.single(paint.unified_paint_settings.secondary_color);
1050 });
1051}
1052
1054{
1055 Scene *scene = id_cast<Scene *>(id);
1056
1058 BKE_paint_foreach_asset_weak_reference(paint, fn);
1059 });
1060}
1061
1062static void scene_foreach_cache(ID *id,
1063 IDTypeForeachCacheFunctionCallback function_callback,
1064 void *user_data)
1065{
1066 Scene *scene = id_cast<Scene *>(id);
1067 if (scene->ed != nullptr) {
1068 IDCacheKey key;
1069 key.id_session_uid = id->session_uid;
1070 /* Preserve VSE thumbnail cache across global undo steps. */
1071 key.identifier = offsetof(Editing, runtime) + offsetof(seq::EditingRuntime, thumbnail_cache);
1072 function_callback(
1073 id, &key, reinterpret_cast<void **>(&scene->ed->runtime->thumbnail_cache), 0, user_data);
1074 }
1075}
1076
1078 const bNodeTree &compositing_node_group,
1079 BlendWriter *writer)
1080{
1081 bNodeTree *temp_nodetree_copy = bke::node_tree_copy_tree_ex(
1082 compositing_node_group, nullptr, false);
1083
1084 temp_nodetree_copy->id.flag |= ID_FLAG_EMBEDDED_DATA;
1085 temp_nodetree_copy->owner_id = &scene.id;
1086 temp_nodetree_copy->id.lib = scene.id.lib;
1087 /* Set deprecated chunksize for forward compatibility. */
1088 temp_nodetree_copy->chunksize = 256;
1089
1090 /* The Composite node was replaced by the Group Output node in 5.0, so we add one to ensure
1091 * forward compatibility. */
1092 bNodeSocket *group_output_first_input = nullptr;
1093 bNode *composite_node = nullptr;
1094 bNodeSocket *composite_input = nullptr;
1095 bke::bNodeType ntype;
1096 for (bNode &node : temp_nodetree_copy->nodes.items_mutable()) {
1097 if (node.is_type("NodeGroupOutput"_ustr) && (node.flag & NODE_DO_OUTPUT)) {
1098 composite_node = &version_node_add_unknown(*temp_nodetree_copy,
1099 ntype,
1100 "CompositorNodeComposite",
1102 "Composite",
1103 "Final render output",
1104 "COMPOSITE",
1106 140.0f,
1107 100.0f,
1108 true);
1109 composite_input = &version_node_add_socket(
1110 *temp_nodetree_copy, *composite_node, SOCK_IN, "NodeSocketColor", "Image");
1111
1112 composite_node->location[0] = node.location[0] - 20.0f;
1113 composite_node->location[1] = node.location[1];
1114 group_output_first_input = node.inputs.first();
1115 break;
1116 }
1117 }
1118
1119 bNodeLink *ngroup_input_link = nullptr;
1120 for (bNodeLink &link : temp_nodetree_copy->links.items_reversed_mutable()) {
1121 if (link.tosock && link.tosock == group_output_first_input) {
1122 ngroup_input_link = &link;
1123 break;
1124 }
1125 }
1126 if (ngroup_input_link) {
1127 version_node_add_link(*temp_nodetree_copy,
1128 *ngroup_input_link->fromnode,
1129 *ngroup_input_link->fromsock,
1130 *composite_node,
1131 *composite_input);
1132 }
1133
1134 BLO_Write_IDBuffer temp_embedded_id_buffer{temp_nodetree_copy->id, writer};
1135 bNodeTree *temp_nodetree = reinterpret_cast<bNodeTree *>(temp_embedded_id_buffer.get());
1136 writer->write_embedded_id_struct(scene.nodetree, temp_nodetree);
1137
1138 /* Todo(#140111): Forward compatibility support will be removed in 6.0. Do not write an embedded
1139 * nodetree at `scene->nodetree` anymore. */
1140 bke::node_tree_blend_write(writer, temp_nodetree);
1141
1142 bke::node_tree_free_embedded_tree(temp_nodetree_copy);
1143 MEM_delete(temp_nodetree_copy);
1144 temp_nodetree_copy = nullptr;
1145 MEM_delete_void(reinterpret_cast<void *>(scene.nodetree));
1146 scene.nodetree = nullptr;
1147 scene.compositing_node_group = nullptr;
1148}
1149
1150static void scene_blend_write(BlendWriter *writer, ID *id, const void *id_address)
1151{
1152 Scene *sce = id_cast<Scene *>(id);
1153 const bool is_write_undo = writer->is_undo();
1154
1155 if (is_write_undo) {
1156 /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
1157 /* XXX This UI data should not be stored in Scene at all... */
1158 sce->cursor = View3DCursor{};
1159 }
1160
1161 /* Todo(#140111): Forward compatibility support will be removed in 6.0. */
1162 if (!is_write_undo) {
1163 for (const SceneCompositorEffect &effect : sce->compositor_effects) {
1165 sce->compositing_node_group = effect.node_group;
1166 break;
1167 }
1168 }
1169 }
1170
1171 /* Todo(#140111): Forward compatibility support will be removed in 6.0. Do not initialize the
1172 * address of `scene->nodetree` anymore. */
1173 if (sce->compositing_node_group && !is_write_undo) {
1174 /* #Scene::nodetree is written for forward compatibility.
1175 * The pointer must be valid before writing the scene. */
1176 /* We need a valid, unique (within that Scene ID) memory address as 'UID' of the written
1177 * embedded node tree. The simplest and safest solution to obtain this is to actually allocate
1178 * a dummy byte. */
1179 sce->nodetree = reinterpret_cast<bNodeTree *>(MEM_new_uninitialized(1, "dummy pointer"));
1180 }
1181
1182 /* Todo(#140111): Forward compatibility support will be removed in 6.0. Remove mapping between
1183 * `scene->use_nodes` and `scene->r.scemode`. */
1184 if (sce->compositing_node_group && sce->r.scemode & R_DOCOMP) {
1185 sce->use_nodes = true;
1186 }
1187
1188 /* write LibData */
1189 writer->write_id_struct(id_address, sce);
1190 BKE_id_blend_write(writer, &sce->id);
1191
1193
1194 /* direct data */
1195 ToolSettings *ts = sce->toolsettings;
1196
1197 writer->write_struct(ts);
1198
1201 }
1202
1205 }
1206
1209 }
1210
1211 if (ts->vpaint) {
1212 writer->write_struct(ts->vpaint);
1213 BKE_paint_blend_write(writer, &ts->vpaint->paint);
1214 }
1215 if (ts->wpaint) {
1216 writer->write_struct(ts->wpaint);
1217 BKE_paint_blend_write(writer, &ts->wpaint->paint);
1218 }
1219 if (ts->sculpt) {
1220 writer->write_struct(ts->sculpt);
1223 }
1226 }
1227
1228 BKE_paint_blend_write(writer, &ts->sculpt->paint);
1229 }
1232 }
1233 if (ts->gp_paint) {
1234 writer->write_struct(ts->gp_paint);
1235 BKE_paint_blend_write(writer, &ts->gp_paint->paint);
1236 }
1237 if (ts->gp_vertexpaint) {
1238 writer->write_struct(ts->gp_vertexpaint);
1240 }
1241 if (ts->gp_sculptpaint) {
1242 writer->write_struct(ts->gp_sculptpaint);
1244 }
1245 if (ts->gp_weightpaint) {
1246 writer->write_struct(ts->gp_weightpaint);
1248 }
1249 if (ts->curves_sculpt) {
1250 writer->write_struct(ts->curves_sculpt);
1252 }
1253 /* write grease-pencil custom ipo curve to file */
1254 if (ts->gp_interpolate.custom_ipo) {
1256 }
1257 /* write grease-pencil multi-frame falloff curve to file */
1258 if (ts->gp_sculpt.cur_falloff) {
1260 }
1261 /* write grease-pencil primitive curve to file */
1262 if (ts->gp_sculpt.cur_primitive) {
1264 }
1265 /* Write the curve profile to the file. */
1268 }
1269 if (ts->sequencer_tool_settings) {
1271 }
1272
1273 BKE_paint_blend_write(writer, &ts->imapaint.paint);
1274
1275 Editing *ed = sce->ed;
1276 if (ed) {
1277 writer->write_struct(ed);
1278
1279 seq::blend_write(writer, &ed->seqbase);
1280 for (SeqTimelineChannel &channel : ed->channels) {
1281 writer->write_struct(&channel);
1282 }
1283 /* new; meta stack too, even when its nasty restore code */
1284 for (MetaStack &ms : ed->metastack) {
1285 writer->write_struct(&ms);
1286 }
1287 }
1288
1289 /* writing dynamic list of TimeMarkers to the blend file */
1291
1292 /* writing dynamic list of TransformOrientations to the blend file */
1293 for (TransformOrientation &ts : sce->transform_spaces) {
1294 writer->write_struct(&ts);
1295 }
1296
1297 /* writing MultiView to the blend file */
1298 for (SceneRenderView &srv : sce->r.views) {
1299 writer->write_struct(&srv);
1300 }
1301
1302 if (sce->compositing_node_group && !is_write_undo) {
1304 }
1305
1309
1310 /* writing RigidBodyWorld data to the blend file */
1311 if (sce->rigidbody_world) {
1312 /* Set deprecated pointers to prevent crashes of older Blenders */
1315 writer->write_struct(sce->rigidbody_world);
1316
1317 writer->write_struct(sce->rigidbody_world->shared);
1320 }
1321
1322 BKE_previewimg_blend_write(writer, sce->preview);
1324
1325 for (ViewLayer &view_layer : sce->view_layers) {
1326 BKE_view_layer_blend_write(writer, sce, &view_layer);
1327 }
1328
1329 if (sce->master_collection) {
1330 BLO_Write_IDBuffer temp_embedded_id_buffer{sce->master_collection->id, writer};
1331 Collection *temp_collection = reinterpret_cast<Collection *>(temp_embedded_id_buffer.get());
1332 BKE_collection_blend_write_prepare_nolib(writer, temp_collection);
1333 writer->write_embedded_id_struct(sce->master_collection, temp_collection);
1334 BKE_collection_blend_write_nolib(writer, temp_collection);
1335 }
1336
1338
1339 bke::compositor::write_effects(*sce, *writer);
1340
1341 /* Freed on `do_versions()`. */
1342 BLI_assert(sce->layer_properties == nullptr);
1343}
1344
1345static void direct_link_paint_helper(BlendDataReader *reader, const Scene *scene, Paint **paint)
1346{
1347 /* TODO: is this needed. */
1348 BLO_read_struct(reader, Paint, paint);
1349
1350 if (*paint) {
1351 BKE_paint_blend_read_data(reader, scene, *paint);
1352 }
1353}
1354
1355static void link_recurs_seq(BlendDataReader *reader, ListBaseT<Strip> *lb)
1356{
1357 BLO_read_struct_list(reader, Strip, lb);
1358
1359 for (Strip &strip : lb->items_mutable()) {
1360 /* Sanity check. */
1361 if (!seq::is_valid_strip_channel(&strip)) {
1362 BLI_freelinkN(lb, &strip);
1363 BLO_read_data_reports(reader)->count.sequence_strips_skipped++;
1364 }
1365 else if (strip.seqbase.first()) {
1366 link_recurs_seq(reader, &strip.seqbase);
1367 }
1368 }
1369}
1370
1372{
1373 Scene *sce = id_cast<Scene *>(id);
1374
1375 sce->depsgraph_hash = nullptr;
1376 sce->fps_info = nullptr;
1377
1380
1381 /* set users to one by default, not in lib-link, this will increase it for compo nodes */
1382 id_us_ensure_real(&sce->id);
1383
1384 sce->runtime = MEM_new<SceneRuntime>(__func__);
1385
1386 BLO_read_struct_list(reader, Base, &(sce->base));
1387
1390
1391 BLO_read_struct(reader, Base, &sce->basact);
1392
1394 if (sce->toolsettings) {
1396
1398 if (ups->curve_rand_hue) {
1401 }
1402
1404 if (ups->curve_rand_saturation) {
1407 }
1408
1410 if (ups->curve_rand_value) {
1413 }
1414
1415 direct_link_paint_helper(reader, sce, reinterpret_cast<Paint **>(&sce->toolsettings->sculpt));
1416 direct_link_paint_helper(reader, sce, reinterpret_cast<Paint **>(&sce->toolsettings->vpaint));
1417 direct_link_paint_helper(reader, sce, reinterpret_cast<Paint **>(&sce->toolsettings->wpaint));
1419 reader, sce, reinterpret_cast<Paint **>(&sce->toolsettings->gp_paint));
1421 reader, sce, reinterpret_cast<Paint **>(&sce->toolsettings->gp_vertexpaint));
1423 reader, sce, reinterpret_cast<Paint **>(&sce->toolsettings->gp_sculptpaint));
1425 reader, sce, reinterpret_cast<Paint **>(&sce->toolsettings->gp_weightpaint));
1427 reader, sce, reinterpret_cast<Paint **>(&sce->toolsettings->curves_sculpt));
1428
1430
1431 sce->toolsettings->particle.paintcursor = nullptr;
1432 sce->toolsettings->particle.scene = nullptr;
1433 sce->toolsettings->particle.object = nullptr;
1434 sce->toolsettings->gp_sculpt.paintcursor = nullptr;
1439 }
1440
1441 if (sce->toolsettings->sculpt) {
1445
1449 }
1450
1455 }
1456 }
1457
1458 /* Relink grease pencil interpolation curves. */
1462 }
1463 /* Relink grease pencil multi-frame falloff curve. */
1467 }
1468 /* Relink grease pencil primitive curve. */
1472 }
1473
1474 /* Relink toolsettings curve profile. */
1478 }
1479
1482 }
1483
1484 if (sce->ed) {
1485 BLO_read_struct(reader, Editing, &sce->ed);
1486 Editing *ed = sce->ed;
1487
1488 BLO_read_struct_no_us(reader, Strip, &ed->act_strip);
1489 BLO_read_struct_no_us(reader, Strip, &ed->current_meta_strip);
1490 ed->runtime = MEM_new<seq::EditingRuntime>(__func__);
1491
1492 /* recursive link sequences, lb will be correctly initialized */
1493 link_recurs_seq(reader, &ed->seqbase);
1494
1495 /* Read in sequence member data. */
1496 seq::blend_read(reader, &ed->seqbase);
1497 BLO_read_struct_list(reader, SeqTimelineChannel, &ed->channels);
1498
1499 /* stack */
1500 BLO_read_struct_list(reader, MetaStack, &(ed->metastack));
1501
1502 for (MetaStack &ms : ed->metastack) {
1503 BLO_read_struct(reader, Strip, &ms.parent_strip);
1504
1506 }
1507 }
1508
1509 /* Runtime */
1510 sce->r.mode &= ~R_NO_CAMERA_SWITCH;
1511
1513
1516 BLO_read_struct_list(reader, SceneRenderView, &(sce->r.views));
1517
1518 for (SceneRenderLayer &srl : sce->r.layers) {
1519 BLO_read_struct(reader, IDProperty, &srl.prop);
1520 IDP_BlendDataRead(reader, &srl.prop);
1521 BLO_read_struct_list(reader, FreestyleModuleConfig, &(srl.freestyleConfig.modules));
1522 BLO_read_struct_list(reader, FreestyleLineSet, &(srl.freestyleConfig.linesets));
1523 }
1524
1528
1530 RigidBodyWorld *rbw = sce->rigidbody_world;
1531 if (rbw) {
1533
1534 if (rbw->shared == nullptr) {
1535 /* Link deprecated caches if they exist, so we can use them for versioning.
1536 * We should only do this when rbw->shared == nullptr, because those pointers
1537 * are always set (for compatibility with older Blenders). We mustn't link
1538 * the same pointcache twice. */
1539 BKE_ptcache_blend_read_data(reader, &rbw->ptcaches, &rbw->pointcache, false);
1540
1541 /* make sure simulation starts from the beginning after loading file */
1542 if (rbw->pointcache) {
1543 rbw->ltime = float(rbw->pointcache->startframe);
1544 }
1545 }
1546 else {
1547 /* link caches */
1548 BKE_ptcache_blend_read_data(reader, &rbw->shared->ptcaches, &rbw->shared->pointcache, false);
1549
1550 /* make sure simulation starts from the beginning after loading file */
1551 if (rbw->shared->pointcache) {
1552 rbw->ltime = float(rbw->shared->pointcache->startframe);
1553 }
1554 }
1555
1557 rbw->objects = nullptr;
1558 rbw->numbodies = 0;
1559
1560 /* set effector weights */
1562 if (!rbw->effector_weights) {
1564 }
1565 }
1566
1567 BLO_read_struct(reader, PreviewImage, &sce->preview);
1568 BKE_previewimg_blend_read(reader, sce->preview);
1569
1571
1572 /* insert into global old-new map for reading without UI (link_global accesses it again) */
1573 BLO_read_glob_list(reader, &sce->view_layers);
1574 for (ViewLayer &view_layer : sce->view_layers) {
1575 BKE_view_layer_blend_read_data(reader, &view_layer);
1576 }
1577
1579
1581 IDP_BlendDataRead(reader, &sce->layer_properties);
1582
1583 bke::compositor::read_effects(*sce, *reader);
1584}
1585
1586/* patch for missing scene IDs, can't be in do-versions */
1588{
1589 Scene *sce = reinterpret_cast<Scene *>(id);
1590
1591 for (Base &base_legacy : sce->base.items_mutable()) {
1592 if (base_legacy.object == nullptr) {
1595 RPT_("LIB: object lost from scene: '%s'"),
1596 sce->id.name + 2);
1597 BLI_remlink(&sce->base, &base_legacy);
1598 if (&base_legacy == sce->basact) {
1599 sce->basact = nullptr;
1600 }
1601 MEM_delete(&base_legacy);
1602 }
1603 }
1604
1605 for (ViewLayer &view_layer : sce->view_layers) {
1606 BKE_view_layer_blend_read_after_liblink(reader, id, &view_layer);
1607 }
1608
1609#ifdef USE_SETSCENE_CHECK
1610 if (sce->set != nullptr) {
1612 }
1613#endif
1614 if (ID_IS_LINKED(sce)) {
1615 /* Linked scenes never have NLA tweak mode enabled. This works in concert with code in
1616 * BKE_animdata_blend_read_data, which also ensures that linked AnimData structs are never
1617 * linked in NLA tweak mode. */
1618 sce->flag &= ~SCE_NLA_EDIT_ON;
1619 }
1620}
1621
1622static void scene_undo_preserve(BlendLibReader *reader, ID *id_new, ID *id_old)
1623{
1624 Scene *scene_new = id_cast<Scene *>(id_new);
1625 Scene *scene_old = id_cast<Scene *>(id_old);
1626
1627 std::swap(scene_old->cursor, scene_new->cursor);
1628 if (scene_new->toolsettings != nullptr && scene_old->toolsettings != nullptr) {
1629 /* First try to restore ID pointers that can be and should be preserved (like brushes or
1630 * palettes), and counteract the swap of the whole ToolSettings structs below for the others
1631 * (like object ones). */
1633 nullptr, scene_new->toolsettings, true, reader, scene_old->toolsettings);
1634 dna::shallow_swap(*scene_old->toolsettings, *scene_new->toolsettings);
1635 }
1636}
1637
1638static void scene_lib_override_apply_post(ID *id_dst, ID * /*id_src*/)
1639{
1640 Scene *scene = id_cast<Scene *>(id_dst);
1641
1642 if (scene->rigidbody_world != nullptr) {
1643 PTCacheID pid;
1644 BKE_ptcache_id_from_rigidbody(&pid, nullptr, scene->rigidbody_world);
1645 for (PointCache &point_cache : *pid.ptcaches) {
1646 point_cache.flag |= PTCACHE_FLAG_INFO_DIRTY;
1647 }
1648 }
1649}
1650
1652 .id_code = Scene::id_type,
1653 .id_filter = FILTER_ID_SCE,
1654 .dependencies_id_types = (FILTER_ID_OB | FILTER_ID_WO | FILTER_ID_SCE | FILTER_ID_MC |
1658 .main_listbase_index = INDEX_ID_SCE,
1659 .struct_size = sizeof(Scene),
1660 .name = "Scene",
1661 .name_plural = N_("scenes"),
1662 .translation_context = BLT_I18NCONTEXT_ID_SCENE,
1664 .asset_type_info = nullptr,
1665
1666 .init_data = scene_init_data,
1667 .copy_data = scene_copy_data,
1668 .free_data = scene_free_data,
1669 /* For now default `BKE_lib_id_make_local_generic()` should work, may need more work though to
1670 * support all possible corner cases. */
1671 .make_local = nullptr,
1672 .foreach_id = scene_foreach_id,
1673 .foreach_cache = scene_foreach_cache,
1674 .foreach_path = scene_foreach_path,
1675 .foreach_working_space_color = scene_foreach_working_space_color,
1676 .foreach_asset_weak_reference = scene_foreach_asset_weak_reference,
1677 .owner_pointer_get = nullptr,
1678
1679 .blend_write = scene_blend_write,
1680 .blend_read_data = scene_blend_read_data,
1681 .blend_read_after_liblink = scene_blend_read_after_liblink,
1682
1683 .blend_read_undo_preserve = scene_undo_preserve,
1684
1685 .lib_override_apply_post = scene_lib_override_apply_post,
1686};
1687
1689
1690/* -------------------------------------------------------------------- */
1693
1694double Scene::frames_per_second() const
1695{
1696 return double(this->r.frs_sec) / double(this->r.frs_sec_base);
1697}
1698
1699int Scene::playback_start() const
1700{
1701 if (this->r.flag & SCER_PRV_RANGE) {
1702 return this->r.psfra;
1703 }
1704 return this->r.sfra;
1705}
1706
1707int Scene::playback_end() const
1708{
1709 if (this->r.flag & SCER_PRV_RANGE) {
1710 return this->r.pefra;
1711 }
1712 return this->r.efra;
1713}
1714
1716
1717const char *RE_engine_id_BLENDER_EEVEE = "BLENDER_EEVEE";
1718const char *RE_engine_id_BLENDER_EEVEE_NEXT = "BLENDER_EEVEE_NEXT";
1719const char *RE_engine_id_BLENDER_WORKBENCH = "BLENDER_WORKBENCH";
1720const char *RE_engine_id_CYCLES = "CYCLES";
1721
1723{
1724 std::optional<std::pair<animrig::Action *, animrig::Slot *>> action_and_slot =
1726 if (!action_and_slot) {
1727 return;
1728 }
1729
1730 animrig::Channelbag *channelbag = channelbag_for_action_slot(*action_and_slot->first,
1731 action_and_slot->second->handle);
1732 if (!channelbag) {
1733 return;
1734 }
1735
1736 /* Create a copy of the F-Curve pointers, so iteration is safe while they are removed. */
1737 Vector<FCurve *> fcurves = channelbag->fcurves();
1738
1739 for (FCurve *fcurve : fcurves) {
1740 if (strstr(fcurve->rna_path().c_str(), "sequence_editor.strips_all")) {
1741 channelbag->fcurve_remove(*fcurve);
1742 }
1743 }
1744}
1745
1746ToolSettings *BKE_toolsettings_copy(ToolSettings *toolsettings, const int flag)
1747{
1748 if (toolsettings == nullptr) {
1749 return nullptr;
1750 }
1751 ToolSettings *ts = MEM_dupalloc(toolsettings);
1752 if (toolsettings->vpaint) {
1753 ts->vpaint = MEM_dupalloc(toolsettings->vpaint);
1754 BKE_paint_copy(&toolsettings->vpaint->paint, &ts->vpaint->paint, flag);
1755 }
1756 if (toolsettings->wpaint) {
1757 ts->wpaint = MEM_dupalloc(toolsettings->wpaint);
1758 BKE_paint_copy(&toolsettings->wpaint->paint, &ts->wpaint->paint, flag);
1759 }
1760 if (toolsettings->sculpt) {
1761 ts->sculpt = MEM_dupalloc(toolsettings->sculpt);
1762 BKE_paint_copy(&toolsettings->sculpt->paint, &ts->sculpt->paint, flag);
1763
1764 if (toolsettings->sculpt->automasking_cavity_curve) {
1766 toolsettings->sculpt->automasking_cavity_curve);
1768 }
1769
1770 if (toolsettings->sculpt->automasking_cavity_curve_op) {
1772 toolsettings->sculpt->automasking_cavity_curve_op);
1774 }
1775 }
1776 if (toolsettings->uvsculpt.curve_distance_falloff) {
1778 toolsettings->uvsculpt.curve_distance_falloff);
1780 }
1781 if (toolsettings->gp_paint) {
1782 ts->gp_paint = MEM_dupalloc(toolsettings->gp_paint);
1783 BKE_paint_copy(&toolsettings->gp_paint->paint, &ts->gp_paint->paint, flag);
1784 }
1785 if (toolsettings->gp_vertexpaint) {
1786 ts->gp_vertexpaint = MEM_dupalloc(toolsettings->gp_vertexpaint);
1787 BKE_paint_copy(&toolsettings->gp_vertexpaint->paint, &ts->gp_vertexpaint->paint, flag);
1788 }
1789 if (toolsettings->gp_sculptpaint) {
1790 ts->gp_sculptpaint = MEM_dupalloc(toolsettings->gp_sculptpaint);
1791 BKE_paint_copy(&toolsettings->gp_sculptpaint->paint, &ts->gp_sculptpaint->paint, flag);
1792 }
1793 if (toolsettings->gp_weightpaint) {
1794 ts->gp_weightpaint = MEM_dupalloc(toolsettings->gp_weightpaint);
1795 BKE_paint_copy(&toolsettings->gp_weightpaint->paint, &ts->gp_weightpaint->paint, flag);
1796 }
1797 if (toolsettings->curves_sculpt) {
1798 ts->curves_sculpt = MEM_dupalloc(toolsettings->curves_sculpt);
1799 BKE_paint_copy(&toolsettings->curves_sculpt->paint, &ts->curves_sculpt->paint, flag);
1800 }
1801
1802 /* Color jitter curves in unified paint settings. */
1809
1810 BKE_paint_copy(&toolsettings->imapaint.paint, &ts->imapaint.paint, flag);
1811 ts->particle.paintcursor = nullptr;
1812 ts->particle.scene = nullptr;
1813 ts->particle.object = nullptr;
1814
1815 /* duplicate Grease Pencil interpolation curve */
1817 /* Duplicate Grease Pencil multi-frame falloff. */
1820
1822 toolsettings->custom_bevel_profile_preset);
1823
1825 return ts;
1826}
1827
1829{
1830 if (toolsettings == nullptr) {
1831 return;
1832 }
1833 if (toolsettings->vpaint) {
1834 BKE_paint_free(&toolsettings->vpaint->paint);
1835 MEM_delete(toolsettings->vpaint);
1836 }
1837 if (toolsettings->wpaint) {
1838 BKE_paint_free(&toolsettings->wpaint->paint);
1839 MEM_delete(toolsettings->wpaint);
1840 }
1841 if (toolsettings->sculpt) {
1842 if (toolsettings->sculpt->automasking_cavity_curve) {
1844 }
1845 if (toolsettings->sculpt->automasking_cavity_curve_op) {
1847 }
1848
1849 BKE_paint_free(&toolsettings->sculpt->paint);
1850 MEM_delete(toolsettings->sculpt);
1851 }
1852 if (toolsettings->uvsculpt.curve_distance_falloff) {
1854 }
1855 if (toolsettings->gp_paint) {
1856 BKE_paint_free(&toolsettings->gp_paint->paint);
1857 MEM_delete(toolsettings->gp_paint);
1858 }
1859 if (toolsettings->gp_vertexpaint) {
1860 BKE_paint_free(&toolsettings->gp_vertexpaint->paint);
1861 MEM_delete(toolsettings->gp_vertexpaint);
1862 }
1863 if (toolsettings->gp_sculptpaint) {
1864 BKE_paint_free(&toolsettings->gp_sculptpaint->paint);
1865 MEM_delete(toolsettings->gp_sculptpaint);
1866 }
1867 if (toolsettings->gp_weightpaint) {
1868 BKE_paint_free(&toolsettings->gp_weightpaint->paint);
1869 MEM_delete(toolsettings->gp_weightpaint);
1870 }
1871 if (toolsettings->curves_sculpt) {
1872 BKE_paint_free(&toolsettings->curves_sculpt->paint);
1873 MEM_delete(toolsettings->curves_sculpt);
1874 }
1875 BKE_paint_free(&toolsettings->imapaint.paint);
1876
1877 /* Color jitter curves in unified paint settings. */
1878 if (toolsettings->unified_paint_settings.curve_rand_hue) {
1880 }
1883 }
1884 if (toolsettings->unified_paint_settings.curve_rand_value) {
1886 }
1887
1888 /* free Grease Pencil interpolation curve */
1889 if (toolsettings->gp_interpolate.custom_ipo) {
1891 }
1892 /* free Grease Pencil multi-frame falloff curve */
1893 if (toolsettings->gp_sculpt.cur_falloff) {
1895 }
1896 if (toolsettings->gp_sculpt.cur_primitive) {
1898 }
1899
1900 if (toolsettings->custom_bevel_profile_preset) {
1902 }
1903
1904 if (toolsettings->sequencer_tool_settings) {
1906 }
1907
1908 MEM_delete(toolsettings);
1909}
1910
1911void BKE_scene_copy_data_eevee(Scene *sce_dst, const Scene *sce_src)
1912{
1913 /* Copy eevee data between scenes. */
1914 sce_dst->eevee = dna::shallow_copy(sce_src->eevee);
1915}
1916
1918 Scene *sce,
1919 eSceneCopyMethod type,
1920 eDupli_ID_Flags duplicate_flags,
1921 /*eLibIDDuplicateFlags*/ uint duplicate_options)
1922{
1923 Scene *sce_copy;
1924
1925 /* TODO: this should/could most likely be replaced by call to more generic code at some point...
1926 * But for now, let's keep it well isolated here. */
1927 if (type == SCE_COPY_EMPTY) {
1928 ListBaseT<SceneRenderView> rv;
1929
1930 sce_copy = BKE_scene_add(bmain, sce->id.name + 2);
1931
1932 rv = sce_copy->r.views;
1934 sce_copy->r = dna::shallow_copy(sce->r);
1935 sce_copy->r.views = rv;
1936 sce_copy->unit = sce->unit;
1937 sce_copy->physics_settings = sce->physics_settings;
1938 sce_copy->audio = sce->audio;
1939 BKE_scene_copy_data_eevee(sce_copy, sce);
1940
1941 if (sce->id.properties) {
1942 sce_copy->id.properties = IDP_CopyProperty(sce->id.properties);
1943 }
1944 if (sce->id.system_properties) {
1946 }
1947
1948 BKE_sound_destroy_scene(sce_copy);
1949
1950 /* copy color management settings */
1955
1956 BKE_image_format_copy(&sce_copy->r.im_format, &sce->r.im_format);
1958
1960
1961 /* viewport display settings */
1962 sce_copy->display = sce->display;
1963
1964 /* tool settings */
1966 sce_copy->toolsettings = BKE_toolsettings_copy(sce->toolsettings, 0);
1967
1968 /* grease pencil */
1969 sce_copy->gpd = nullptr;
1970
1971 sce_copy->preview = nullptr;
1972
1973 return sce_copy;
1974 }
1975
1976 /* Scene duplication is always root of duplication currently, and so `is_root_id` is always true.
1977 *
1978 * Keep `is_root_id` around though, as this allows the rest of the duplication code to stay in
1979 * sync with the layout and behavior as the other duplicate functions (see e.g.
1980 * #BKE_collection_duplicate or #BKE_object_duplicate).
1981 *
1982 * TODO: At some point it would be nice to deduplicate this logic and move common behavior into
1983 * generic ID management code, with IDType callbacks for specific duplication behavior only. */
1984 const bool is_subprocess = (duplicate_options & LIB_ID_DUPLICATE_IS_SUBPROCESS) != 0;
1985 const bool is_root_id = (duplicate_options & LIB_ID_DUPLICATE_IS_ROOT_ID) != 0;
1986 const int copy_flags = LIB_ID_COPY_DEFAULT;
1987
1988 if (!is_subprocess) {
1990 }
1991
1992 if (is_root_id) {
1993 /* In case root duplicated ID is linked, assume we want to get a local copy of it and
1994 * duplicate all expected linked data. */
1995 if (ID_IS_LINKED(sce)) {
1996 duplicate_flags = (duplicate_flags | USER_DUP_LINKED_ID);
1997 }
1998 }
1999
2000 if (is_subprocess) {
2001 if (sce->id.newid != nullptr) {
2002 return id_cast<Scene *>(sce->id.newid);
2003 }
2004 sce_copy = id_cast<Scene *>(
2005 BKE_id_copy_for_duplicate(bmain, id_cast<ID *>(sce), duplicate_flags, copy_flags));
2006 }
2007 else {
2008 BLI_assert(sce->id.newid == nullptr);
2009 sce_copy = id_cast<Scene *>(BKE_id_copy(bmain, id_cast<ID *>(sce)));
2010 id_us_min(&sce_copy->id);
2011 /* Usages of the duplicated scene also need to be remapped in new duplicated IDs. */
2012 ID_NEW_SET(sce, sce_copy);
2013
2014 /* In subprocesses, action data is duplicated in `BKE_id_copy_for_duplicate`, match that: */
2015 BKE_animdata_duplicate_id_action(bmain, &sce_copy->id, duplicate_flags);
2016 }
2017 id_us_ensure_real(&sce_copy->id);
2018
2019 /* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks. */
2020
2021 /* Exception for the compositor; Before 5.0, creating a linked copy of the scene created a new
2022 * compositing node tree with a Render Layers node that referred to the new scene.
2023 * To preserve this behavior, we make a full copy when creating a linked copy as well as a full
2024 * copy of the scene.*/
2025 for (SceneCompositorEffect &effect : sce->compositor_effects) {
2027 bmain, reinterpret_cast<ID *>(effect.node_group), duplicate_flags, copy_flags);
2028 }
2029
2030 if (type == SCE_COPY_FULL) {
2031 /* Copy Freestyle LineStyle datablocks. */
2032 for (ViewLayer &view_layer_dst : sce_copy->view_layers) {
2033 for (FreestyleLineSet &lineset : view_layer_dst.freestyle_config.linesets) {
2035 bmain, id_cast<ID *>(lineset.linestyle), duplicate_flags, copy_flags);
2036 }
2037 }
2038
2039 /* Full copy of world (included animations) */
2040 BKE_id_copy_for_duplicate(bmain, id_cast<ID *>(sce->world), duplicate_flags, copy_flags);
2041
2042 /* Full copy of GreasePencil. */
2043 BKE_id_copy_for_duplicate(bmain, id_cast<ID *>(sce->gpd), duplicate_flags, copy_flags);
2044
2045 /* Deep-duplicate collections and objects (using preferences' settings for which sub-data to
2046 * duplicate along the object itself). */
2048 nullptr,
2049 nullptr,
2050 sce_copy->master_collection,
2051 duplicate_flags,
2053
2054 /* Rigid body world collections may not be instantiated as scene's collections, ensure they
2055 * also get properly duplicated. */
2056 if (sce_copy->rigidbody_world != nullptr) {
2057 if (sce_copy->rigidbody_world->group != nullptr) {
2059 nullptr,
2060 nullptr,
2061 sce_copy->rigidbody_world->group,
2062 duplicate_flags,
2064 }
2065 if (sce_copy->rigidbody_world->constraints != nullptr) {
2067 nullptr,
2068 nullptr,
2069 sce_copy->rigidbody_world->constraints,
2070 duplicate_flags,
2072 }
2073 }
2074
2075 /* Duplicate receiver and blocker collections from the light linking settings.
2076 * If light linking used a collection from a scene collection, the light linking will end up
2077 * using the same duplicated collection as the scene collection.
2078 * If light linking used its own collection (outside any scene collection), the collection
2079 * will be duplicated, and the objects inside this collection will be remapped to the objects
2080 * from the duplicated scene. */
2081 FOREACH_SCENE_OBJECT_BEGIN (sce_copy, object) {
2082 if (!object->light_linking) {
2083 continue;
2084 }
2085 if (object->light_linking->receiver_collection) {
2087 nullptr,
2088 nullptr,
2089 object->light_linking->receiver_collection,
2090 duplicate_flags,
2092 }
2093 if (object->light_linking->blocker_collection) {
2095 nullptr,
2096 nullptr,
2097 object->light_linking->blocker_collection,
2098 duplicate_flags,
2100 }
2101 }
2103 }
2104 else {
2105 /* Remove sequencer if not full copy */
2106 /* XXX Why in Hell? :/ */
2107 remove_sequencer_fcurves(sce_copy);
2108 seq::editing_free(sce_copy, true);
2109 }
2110
2111 /* The final step is to ensure that all of the newly duplicated IDs are used by other newly
2112 * duplicated IDs, and some standard cleanup & updates. */
2113 if (!is_subprocess) {
2114 /* This code will follow into all ID links using an ID tagged with ID_TAG_NEW. */
2115 /* Unfortunate, but with some types (e.g. meshes), an object is considered in Edit mode if
2116 * its obdata contains edit mode runtime data. This can be the case of all newly duplicated
2117 * objects, as even though duplicate code move the object back in Object mode, they are still
2118 * using the original obdata ID, leading to them being falsely detected as being in Edit
2119 * mode, and therefore not remapping their obdata to the newly duplicated one. See #139715.
2120 */
2123
2124#ifndef NDEBUG
2125 /* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those
2126 * flags. */
2127 ID *id_iter;
2128 FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2129 BLI_assert((id_iter->tag & ID_TAG_NEW) == 0);
2130 }
2132#endif
2133
2134 /* Cleanup. */
2136
2138 }
2139
2140 return sce_copy;
2141}
2142
2144{
2145 if (sce->rigidbody_world) {
2147 }
2148}
2149
2150bool BKE_scene_can_be_removed(const Main *bmain, const Scene *scene)
2151{
2152 /* Linked scenes can always be removed. */
2153 if (ID_IS_LINKED(scene)) {
2154 return true;
2155 }
2156 /* Local scenes can only be removed, when there is at least one local scene left. */
2157 for (Scene &other_scene : bmain->scenes) {
2158 if (ID_IS_LINKED(&other_scene)) {
2159 /* Once the first linked scene is reached, there is no more local ones to check, so at this
2160 * point there is no other local scene and the given one cannot be deleted. */
2161 break;
2162 }
2163 if (&other_scene != scene) {
2164 return true;
2165 }
2166 }
2167 return false;
2168}
2169
2171 const Scene &scene,
2172 FunctionRef<bool(const Scene &scene)> scene_validate_cb)
2173{
2174 UNUSED_VARS_NDEBUG(bmain);
2175 BLI_assert(BLI_findindex(&bmain.scenes, &scene) >= 0);
2176
2177 /* Simply return a closest neighbor scene, unless a validate callback is provided and it rejects
2178 * the iterated scene. */
2179 for (Scene *scene_iter = static_cast<Scene *>(scene.id.prev); scene_iter != nullptr;
2180 scene_iter = static_cast<Scene *>(scene_iter->id.prev))
2181 {
2182 if (scene_validate_cb && !scene_validate_cb(*scene_iter)) {
2183 continue;
2184 }
2185 return scene_iter;
2186 }
2187
2188 for (Scene *scene_iter = static_cast<Scene *>(scene.id.next); scene_iter != nullptr;
2189 scene_iter = static_cast<Scene *>(scene_iter->id.next))
2190 {
2191 if (scene_validate_cb && !scene_validate_cb(*scene_iter)) {
2192 continue;
2193 }
2194 return scene_iter;
2195 }
2196
2197 return nullptr;
2198}
2199
2200Scene *BKE_scene_add(Main *bmain, const char *name)
2201{
2202 Scene *sce = BKE_id_new<Scene>(bmain, name);
2203 id_us_min(&sce->id);
2204 id_us_ensure_real(&sce->id);
2205
2206 return sce;
2207}
2208
2209bool BKE_scene_object_find(const Main &bmain, Scene *scene, Object *ob)
2210{
2211 for (ViewLayer &view_layer : scene->view_layers) {
2212 BKE_view_layer_synced_ensure(bmain, scene, &view_layer);
2213 if (BLI_findptr(BKE_view_layer_object_bases_get(&view_layer), ob, offsetof(Base, object))) {
2214 return true;
2215 }
2216 }
2217 return false;
2218}
2219
2220Object *BKE_scene_object_find_by_name(const Main &bmain, const Scene *scene, const char *name)
2221{
2222 for (ViewLayer &view_layer : scene->view_layers) {
2223 BKE_view_layer_synced_ensure(bmain, scene, &view_layer);
2224 for (Base &base : *BKE_view_layer_object_bases_get(&view_layer)) {
2225 if (STREQ(base.object->id.name + 2, name)) {
2226 return base.object;
2227 }
2228 }
2229 }
2230 return nullptr;
2231}
2232
2234{
2235 /* check for cyclic sets, for reading old files but also for definite security (py?) */
2236 BKE_scene_validate_setscene(bmain, scene);
2237
2238 /* Deselect objects (for data select). */
2239 for (Object &ob : bmain->objects) {
2240 ob.flag &= ~OB_SELECT;
2241 }
2242
2243 /* copy layers and flags from bases to objects */
2244 for (ViewLayer &view_layer : scene->view_layers) {
2245 BKE_view_layer_synced_ensure(*bmain, scene, &view_layer);
2246 for (Base &base : *BKE_view_layer_object_bases_get(&view_layer)) {
2247 /* collection patch... */
2249 }
2250 }
2251 /* No full animation update, this to enable render code to work
2252 * (render code calls own animation updates). */
2253}
2254
2255Scene *BKE_scene_set_name(Main *bmain, const char *name)
2256{
2257 Scene *sce = id_cast<Scene *>(BKE_libblock_find_name(bmain, ID_SCE, name));
2258 if (sce) {
2259 BKE_scene_set_background(bmain, sce);
2260 printf("Scene switch for render: '%s' in file: '%s'\n", name, BKE_main_blendfile_path(bmain));
2261 return sce;
2262 }
2263
2264 printf("Can't find scene: '%s' in file: '%s'\n", name, BKE_main_blendfile_path(bmain));
2265 return nullptr;
2266}
2267
2269 Depsgraph *depsgraph, SceneBaseIter *iter, Scene **scene, int val, Base **base, Object **ob)
2270{
2271 bool run_again = true;
2272
2273 const Main *bmain = depsgraph ? DEG_get_bmain(depsgraph) : nullptr;
2274
2275 /* init */
2276 if (val == 0) {
2277 iter->phase = F_START;
2278 iter->dupob = nullptr;
2279 iter->dupob_index = -1;
2280 iter->duplilist.clear();
2281 iter->dupli_refob = nullptr;
2282 }
2283 else {
2284 /* run_again is set when a duplilist has been ended */
2285 while (run_again) {
2286 run_again = false;
2287
2288 /* the first base */
2289 if (iter->phase == F_START) {
2290 ViewLayer *view_layer = (depsgraph) ? DEG_get_evaluated_view_layer(depsgraph) :
2292 if (bmain) {
2293 BKE_view_layer_synced_ensure(*bmain, *scene, view_layer);
2294 }
2295 else {
2297 }
2298 *base = BKE_view_layer_object_bases_get(view_layer)->first();
2299 if (*base) {
2300 *ob = (*base)->object;
2301 iter->phase = F_SCENE;
2302 }
2303 else {
2304 /* exception: empty scene layer */
2305 while ((*scene)->set) {
2306 (*scene) = (*scene)->set;
2307 ViewLayer *view_layer_set = BKE_view_layer_default_render(*scene);
2308 if (bmain) {
2309 BKE_view_layer_synced_ensure(*bmain, *scene, view_layer_set);
2310 }
2311 else {
2312 BLI_assert(BKE_view_layer_is_synced(*view_layer_set));
2313 }
2314 ListBaseT<Base> *object_bases = BKE_view_layer_object_bases_get(view_layer_set);
2315 if (object_bases->first()) {
2316 *base = object_bases->first();
2317 *ob = (*base)->object;
2318 iter->phase = F_SCENE;
2319 break;
2320 }
2321 }
2322 }
2323 }
2324 else {
2325 if (*base && iter->phase != F_DUPLI) {
2326 *base = (*base)->next;
2327 if (*base) {
2328 *ob = (*base)->object;
2329 }
2330 else {
2331 if (iter->phase == F_SCENE) {
2332 /* (*scene) is finished, now do the set */
2333 while ((*scene)->set) {
2334 (*scene) = (*scene)->set;
2335 ViewLayer *view_layer_set = BKE_view_layer_default_render(*scene);
2336 if (bmain) {
2337 BKE_view_layer_synced_ensure(*bmain, *scene, view_layer_set);
2338 }
2339 else {
2340 BLI_assert(BKE_view_layer_is_synced(*view_layer_set));
2341 }
2342 ListBaseT<Base> *object_bases = BKE_view_layer_object_bases_get(view_layer_set);
2343 if (object_bases->first()) {
2344 *base = object_bases->first();
2345 *ob = (*base)->object;
2346 break;
2347 }
2348 }
2349 }
2350 }
2351 }
2352 }
2353
2354 if (*base == nullptr) {
2355 iter->phase = F_START;
2356 }
2357 else {
2358 if (iter->phase != F_DUPLI) {
2359 if (depsgraph && (*base)->object->transflag & OB_DUPLI) {
2360 /* Collections cannot be duplicated for meta-balls yet,
2361 * this enters eternal loop because of
2362 * makeDispListMBall getting called inside of collection_duplilist */
2363 if ((*base)->object->instance_collection == nullptr) {
2364 object_duplilist(depsgraph, (*base)->object, nullptr, iter->duplilist);
2365
2366 iter->dupob = iter->duplilist.is_empty() ? nullptr : &iter->duplilist.first();
2367 iter->dupob_index = 0;
2368
2369 if (!iter->dupob) {
2370 iter->duplilist.clear();
2371 iter->dupob_index = -1;
2372 }
2373 iter->dupli_refob = nullptr;
2374 }
2375 }
2376 }
2377 /* handle dupli's */
2378 if (iter->dupob) {
2379 (*base)->flag_legacy |= OB_FROMDUPLI;
2380 *ob = iter->dupob->ob;
2381 iter->phase = F_DUPLI;
2382
2383 if (iter->dupli_refob != *ob) {
2384 if (iter->dupli_refob) {
2385 /* Restore previous object's real matrix. */
2387 }
2388 /* Backup new object's real matrix. */
2389 iter->dupli_refob = *ob;
2390 copy_m4_m4(iter->omat, iter->dupli_refob->object_to_world().ptr());
2391 }
2392 copy_m4_m4((*ob)->runtime->object_to_world.ptr(), iter->dupob->mat);
2393
2394 if (++iter->dupob_index < iter->duplilist.size()) {
2395 iter->dupob = &iter->duplilist[iter->dupob_index];
2396 }
2397 else {
2398 iter->dupob = nullptr;
2399 iter->dupob_index = -1;
2400 }
2401 }
2402 else if (iter->phase == F_DUPLI) {
2403 iter->phase = F_SCENE;
2404 (*base)->flag_legacy &= ~OB_FROMDUPLI;
2405
2406 if (iter->dupli_refob) {
2407 /* Restore last object's real matrix. */
2409 iter->dupli_refob = nullptr;
2410 }
2411
2412 iter->duplilist.clear();
2413 run_again = true;
2414 }
2415 }
2416 }
2417 }
2418
2419 return iter->phase;
2420}
2421
2423{
2424 return BLI_findindex(&scene->view_layers, layer) != -1;
2425}
2426
2427Scene *BKE_scene_find_from_collection(const Main *bmain, const Collection *collection)
2428{
2429 for (Scene &scene : bmain->scenes) {
2430 for (ViewLayer &layer : scene.view_layers) {
2431 if (BKE_view_layer_has_collection(&layer, collection)) {
2432 return &scene;
2433 }
2434 }
2435 }
2436
2437 return nullptr;
2438}
2439
2440Object *BKE_scene_camera_switch_find(const Scene *scene, const int time)
2441{
2442 if (scene->r.mode & R_NO_CAMERA_SWITCH) {
2443 return nullptr;
2444 }
2445
2446 int frame = -(MAXFRAME + 1);
2447 int min_frame = MAXFRAME + 1;
2448 Object *camera = nullptr;
2449 Object *first_camera = nullptr;
2450
2451 for (TimeMarker &m : scene->markers) {
2452 if (m.camera && (m.camera->visibility_flag & OB_HIDE_RENDER) == 0) {
2453 if ((m.frame <= time) && (m.frame > frame)) {
2454 camera = m.camera;
2455 frame = m.frame;
2456
2457 if (frame == time) {
2458 break;
2459 }
2460 }
2461
2462 if (m.frame < min_frame) {
2463 first_camera = m.camera;
2464 min_frame = m.frame;
2465 }
2466 }
2467 }
2468
2469 if (camera == nullptr) {
2470 /* If there's no marker to the left of current frame,
2471 * use camera from left-most marker to solve all sort
2472 * of Schrodinger uncertainties.
2473 */
2474 return first_camera;
2475 }
2476
2477 return camera;
2478}
2479
2481{
2483 if (camera && (camera != scene->camera)) {
2484 scene->camera = camera;
2486 return true;
2487 }
2488 return false;
2489}
2490
2491const char *BKE_scene_find_marker_name(const Scene *scene, int frame)
2492{
2493 const ListBaseT<TimeMarker> *markers = &scene->markers;
2494 const TimeMarker *m1, *m2;
2495
2496 /* search through markers for match */
2497 for (m1 = markers->first(), m2 = markers->last(); m1 && m2; m1 = m1->next, m2 = m2->prev) {
2498 if (m1->frame == frame) {
2499 return m1->name;
2500 }
2501
2502 if (m1 == m2) {
2503 break;
2504 }
2505
2506 if (m2->frame == frame) {
2507 return m2->name;
2508 }
2509 }
2510
2511 return nullptr;
2512}
2513
2514const char *BKE_scene_find_last_marker_name(const Scene *scene, int frame)
2515{
2516 const TimeMarker *best_marker = nullptr;
2517 int best_frame = -MAXFRAME * 2;
2518 for (const TimeMarker &marker : scene->markers) {
2519 if (marker.frame == frame) {
2520 return marker.name;
2521 }
2522
2523 if (marker.frame > best_frame && marker.frame < frame) {
2524 best_marker = &marker;
2525 best_frame = marker.frame;
2526 }
2527 }
2528
2529 return best_marker ? best_marker->name : nullptr;
2530}
2531
2533 const double interval_in_seconds,
2534 const float frame)
2535{
2536 BLI_assert(interval_in_seconds > 0);
2537 BLI_assert(scene->frames_per_second() > 0);
2538
2539 const double interval_in_frames = scene->frames_per_second() * interval_in_seconds;
2540 const double second_prev = interval_in_frames * floor(frame / interval_in_frames);
2541 const double second_next = second_prev + ceil(interval_in_frames);
2542 const double delta_prev = frame - second_prev;
2543 const double delta_next = second_next - frame;
2544 return float((delta_prev < delta_next) ? second_prev : second_next);
2545}
2546
2547void BKE_scene_remove_rigidbody_object(Main *bmain, Scene *scene, Object *ob, const bool free_us)
2548{
2549 /* remove rigid body constraint from world before removing object */
2550 if (ob->rigidbody_constraint) {
2551 BKE_rigidbody_remove_constraint(bmain, scene, ob, free_us);
2552 }
2553 /* remove rigid body object from world before removing object */
2554 if (ob->rigidbody_object) {
2555 BKE_rigidbody_remove_object(bmain, scene, ob, free_us);
2556 }
2557}
2558
2560{
2561 Scene *sce_iter;
2562 int a, totscene;
2563
2564 if (sce->set == nullptr) {
2565 return true;
2566 }
2567 totscene = bmain->scenes.count();
2568
2569 for (a = 0, sce_iter = sce; sce_iter->set; sce_iter = sce_iter->set, a++) {
2570 /* more iterations than scenes means we have a cycle */
2571 if (a > totscene) {
2572 /* The tested scene gets zeroed, that's typically current scene. */
2573 sce->set = nullptr;
2574 return false;
2575 }
2576 }
2577
2578 return true;
2579}
2580
2581float BKE_scene_ctime_get(const Scene *scene)
2582{
2583 return BKE_scene_frame_to_ctime(scene, scene->r.cfra);
2584}
2585
2586float BKE_scene_frame_to_ctime(const Scene *scene, const int frame)
2587{
2588 float ctime = frame;
2589 ctime += scene->r.subframe;
2590 ctime *= scene->r.framelen;
2591
2592 return ctime;
2593}
2594
2595float BKE_scene_frame_get(const Scene *scene)
2596{
2597 return scene->r.cfra + scene->r.subframe;
2598}
2599
2600void BKE_scene_frame_set(Scene *scene, float frame)
2601{
2602 double intpart;
2603 scene->r.subframe = modf(double(frame), &intpart);
2604 scene->r.cfra = int(intpart);
2605}
2606
2608{
2609 if (scene->r.flag & SCER_PRV_RANGE) {
2610 return {scene->r.psfra, scene->r.pefra};
2611 }
2612 return {scene->r.sfra, scene->r.efra};
2613}
2614
2615void BKE_scene_frame_clamp_for_playback(Scene *scene, const bool is_playing_forward)
2616{
2618 /* To avoid a flicker to the last frame, reset the current frame to the start of the playback
2619 * range relative to the playback direction. */
2620 if (is_playing_forward) {
2621 if (scene->r.cfra > range.end_frame) {
2622 scene->r.cfra = range.start_frame;
2623 }
2624 }
2625 else {
2626 if (scene->r.cfra < range.start_frame) {
2627 scene->r.cfra = range.end_frame;
2628 }
2629 }
2630 if (!(scene->r.flag & SCER_ALLOW_PREROLL)) {
2631 scene->r.cfra = clamp_i(scene->r.cfra, range.start_frame, range.end_frame);
2632 }
2633}
2634
2635/* -------------------------------------------------------------------- */
2638
2640{
2641 if ((scene->orientation_slots[slot_index].flag & SELECT) == 0) {
2642 slot_index = SCE_ORIENT_DEFAULT;
2643 }
2644 return &scene->orientation_slots[slot_index];
2645}
2646
2648{
2651 int slot_index = SCE_ORIENT_DEFAULT;
2653 slot_index = SCE_ORIENT_TRANSLATE;
2654 }
2655 else if (flag & V3D_GIZMO_SHOW_OBJECT_ROTATE) {
2656 slot_index = SCE_ORIENT_ROTATE;
2657 }
2658 else if (flag & V3D_GIZMO_SHOW_OBJECT_SCALE) {
2659 slot_index = SCE_ORIENT_SCALE;
2660 }
2661 return BKE_scene_orientation_slot_get(scene, slot_index);
2662}
2663
2665{
2666 const bool is_custom = orientation >= V3D_ORIENT_CUSTOM;
2667 orient_slot->type = is_custom ? V3D_ORIENT_CUSTOM : orientation;
2668 orient_slot->index_custom = is_custom ? (orientation - V3D_ORIENT_CUSTOM) : -1;
2669}
2670
2672{
2673 return (orient_slot->type == V3D_ORIENT_CUSTOM) ?
2674 (orient_slot->type + orient_slot->index_custom) :
2675 orient_slot->type;
2676}
2677
2678int BKE_scene_orientation_get_index(Scene *scene, int slot_index)
2679{
2680 TransformOrientationSlot *orient_slot = BKE_scene_orientation_slot_get(scene, slot_index);
2681 return BKE_scene_orientation_slot_get_index(orient_slot);
2682}
2683
2689
2691
2693{
2694 wmWindowManager *wm = bmain->wm.first();
2695 for (const wmWindow &window : wm->windows) {
2697 Scene *scene = window.scene;
2698 RenderEngineType *type = RE_engines_find(scene->r.engine);
2699
2700 if ((type->flag & RE_INTERNAL) || !type->render) {
2701 continue;
2702 }
2703
2704 for (ScrArea &area : screen->areabase) {
2705 View3D *v3d = area.spacedata.first_as<View3D>();
2706 if (area.spacetype != SPACE_VIEW3D) {
2707 continue;
2708 }
2709 if (v3d->shading.type == OB_RENDER) {
2710 return true;
2711 }
2712 }
2713 }
2714 return false;
2715}
2716
2717/* TODO(@ideasman42): shouldn't we be able to use 'DEG_get_view_layer' here?
2718 * Currently this is nullptr on load, so don't. */
2720 const Scene *scene,
2721 ViewLayer *view_layer)
2722{
2723 /* This is needed to prepare mesh to be used by the render
2724 * engine from the viewport rendering. We do loading here
2725 * so all the objects which shares the same mesh datablock
2726 * are nicely tagged for update and updated.
2727 *
2728 * This makes it so viewport render engine doesn't need to
2729 * call loading of the edit data for the mesh objects.
2730 */
2731 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2732 Object *obedit = BKE_view_layer_edit_object_get(view_layer);
2733 if (obedit) {
2734 if ((obedit->type == OB_MESH) &&
2735 ((obedit->id.recalc & ID_RECALC_ALL) || (obedit->data->recalc & ID_RECALC_ALL)))
2736 {
2738 Mesh *mesh = id_cast<Mesh *>(obedit->data);
2740 BMeshToMeshParams params{};
2741 params.calc_object_remap = true;
2742 params.update_shapekey_indices = true;
2743 BM_mesh_bm_to_me(bmain, bm, mesh, &params);
2744 DEG_id_tag_update(&mesh->id, 0);
2745 }
2746 }
2747 }
2748}
2749
2750void BKE_scene_update_sound(Depsgraph *depsgraph, Main *bmain)
2751{
2752 Scene *scene = DEG_get_evaluated_scene(depsgraph);
2753 const int recalc = scene->id.recalc;
2755 if (recalc & ID_RECALC_FRAME_CHANGE) {
2756 BKE_sound_seek_scene(bmain, scene);
2757 }
2758 if (recalc & ID_RECALC_AUDIO_FPS) {
2759 BKE_sound_update_fps(bmain, scene);
2760 }
2761 if (recalc & ID_RECALC_AUDIO_VOLUME) {
2763 }
2764 if (recalc & ID_RECALC_AUDIO_MUTE) {
2765 const bool is_mute = (DEG_get_mode(depsgraph) == DAG_EVAL_VIEWPORT) &&
2766 (scene->audio.flag & AUDIO_MUTE);
2767 BKE_sound_mute_scene(scene, is_mute);
2768 }
2769 if (recalc & ID_RECALC_AUDIO_LISTENER) {
2771 }
2772 BKE_sound_update_scene(depsgraph, scene);
2773}
2774
2775void BKE_scene_update_tag_audio_volume(Depsgraph * /*depsgraph*/, Scene *scene)
2776{
2778 /* The volume is actually updated in BKE_scene_update_sound(), from either
2779 * scene_graph_update_tagged() or from BKE_scene_graph_update_for_newframe(). */
2781}
2782
2783/* TODO(sergey): This actually should become view_layer_graph or so.
2784 * Same applies to update_for_newframe.
2785 *
2786 * If only_if_tagged is truth then the function will do nothing if the dependency graph is up
2787 * to date already.
2788 */
2789static void scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain, bool only_if_tagged)
2790{
2791 if (only_if_tagged && DEG_is_fully_evaluated(depsgraph)) {
2792 return;
2793 }
2794
2795 Scene *scene = DEG_get_input_scene(depsgraph);
2796 ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
2797 bool used_multiple_passes = false;
2798
2799 bool run_callbacks = DEG_id_type_any_updated(depsgraph);
2800 if (run_callbacks) {
2802 }
2803
2804 /* Cannot limit this to the currently evaluated scene/view layer, as the depsgraph may have
2805 * dependencies on others, see e.g. #158225, which pulls in another scene. */
2806 /* TODO: If this becomes a performance issue, we'll likely have to find a way in the depsgraph
2807 * itself to gather all 'known' scenes, and ensure that their viewlayers / collections
2808 * hierarchies are in sync. */
2810
2811 for (int pass = 0; pass < 2; pass++) {
2812 /* (Re-)build dependency graph if needed. */
2813 DEG_graph_relations_update(depsgraph);
2814 /* Uncomment this to check if graph was properly tagged for update. */
2815 // DEG_debug_graph_relations_validate(depsgraph, bmain, scene, view_layer);
2816 /* Flush editing data if needed. */
2817 prepare_mesh_for_viewport_render(bmain, scene, view_layer);
2818 /* Update all objects: drivers, matrices, etc. flags set
2819 * by depsgraph or manual, no layer check here, gets correct flushed. */
2821 /* Update sound system. */
2822 BKE_scene_update_sound(depsgraph, bmain);
2823 /* Notify python about depsgraph update. */
2824 if (run_callbacks) {
2826 bmain, &scene->id, depsgraph, BKE_CB_EVT_DEPSGRAPH_UPDATE_POST);
2827
2828 /* It is possible that the custom callback modified scene and removed some IDs from the main
2829 * database. In this case DEG_editors_update() will crash because it iterates over all IDs
2830 * which depsgraph was built for.
2831 *
2832 * The solution is to update relations prior to this call, avoiding access to freed IDs.
2833 * Should be safe because relations update is supposed to preserve flags of all IDs which are
2834 * still a part of the dependency graph. If an ID is kicked out of the dependency graph it
2835 * should also be fine because when/if it's added to another dependency graph it will need to
2836 * be tagged for an update anyway.
2837 *
2838 * If there are no relations changed by the callback this call will do nothing. */
2839 DEG_graph_relations_update(depsgraph);
2840 }
2841
2842 /* If user callback did not tag anything for update we can skip second iteration.
2843 * Otherwise we update scene once again, but without running callbacks to bring
2844 * scene to a fully evaluated state with user modifications taken into account. */
2845 if (DEG_is_fully_evaluated(depsgraph)) {
2846 break;
2847 }
2848
2849 /* Clear recalc flags for second pass, but back them up for editors update. */
2850 const bool backup = true;
2851 DEG_ids_clear_recalc(depsgraph, backup);
2852 used_multiple_passes = true;
2853 run_callbacks = false;
2854 }
2855
2856 /* Inform editors about changes, using recalc flags from both passes. */
2857 if (used_multiple_passes) {
2858 DEG_ids_restore_recalc(depsgraph);
2859 }
2860 const bool is_time_update = false;
2861 DEG_editors_update(depsgraph, is_time_update);
2862
2863 const bool backup = false;
2864 DEG_ids_clear_recalc(depsgraph, backup);
2865}
2866
2867void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
2868{
2869 scene_graph_update_tagged(depsgraph, bmain, false);
2870}
2871
2872void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
2873{
2874 scene_graph_update_tagged(depsgraph, bmain, true);
2875}
2876
2877void BKE_scene_graph_update_for_newframe_ex(Depsgraph *depsgraph, const bool clear_recalc)
2878{
2879 Scene *scene = DEG_get_input_scene(depsgraph);
2880 Main *bmain = DEG_get_bmain(depsgraph);
2881 bool used_multiple_passes = false;
2882
2883 /* Keep this first. */
2885
2886 /* Cannot limit this to the currently evaluated scene/view layer, as the depsgraph may have
2887 * dependencies on others, see e.g. #158225, which pulls in another scene. */
2888 /* TODO: If this becomes a performance issue, we'll likely have to find a way in the depsgraph
2889 * itself to gather all 'known' scenes, and ensure that their viewlayers / collections
2890 * hierarchies are in sync. */
2892
2893 for (int pass = 0; pass < 2; pass++) {
2894 /* Update animated image textures for particles, modifiers, gpu, etc,
2895 * call this at the start so modifiers with textures don't lag 1 frame.
2896 */
2897 BKE_image_editors_update_frame(bmain, scene->r.cfra);
2898 DEG_graph_relations_update(depsgraph);
2899 /* Update all objects: drivers, matrices, etc. flags set
2900 * by depsgraph or manual, no layer check here, gets correct flushed.
2901 *
2902 * NOTE: Only update for new frame on first iteration. Second iteration is for ensuring user
2903 * edits from callback are properly taken into account. Doing a time update on those would
2904 * lose any possible unkeyed changes made by the handler. */
2905 if (pass == 0) {
2906 const float frame = BKE_scene_frame_get(scene);
2908 }
2909 else {
2911 }
2912 /* Update sound system animation. */
2913 BKE_scene_update_sound(depsgraph, bmain);
2914
2915 /* Notify editors and python about recalc. */
2916 if (pass == 0) {
2918
2919 /* NOTE: Similar to this case in scene_graph_update_tagged(). Need to ensure that
2920 * DEG_editors_update() doesn't access freed memory of possibly removed ID. */
2921 DEG_graph_relations_update(depsgraph);
2922 }
2923
2924 /* If user callback did not tag anything for update we can skip second iteration.
2925 * Otherwise we update scene once again, but without running callbacks to bring
2926 * scene to a fully evaluated state with user modifications taken into account. */
2927 if (DEG_is_fully_evaluated(depsgraph)) {
2928 break;
2929 }
2930
2931 /* Clear recalc flags for second pass, but back them up for editors update. */
2932 const bool backup = true;
2933 DEG_ids_clear_recalc(depsgraph, backup);
2934 used_multiple_passes = true;
2935 }
2936
2937 /* Inform editors about changes, using recalc flags from both passes. */
2938 if (used_multiple_passes) {
2939 DEG_ids_restore_recalc(depsgraph);
2940 }
2941
2942 const bool is_time_update = true;
2943 DEG_editors_update(depsgraph, is_time_update);
2944
2945 /* Clear recalc flags, can be skipped for example renderers that will read these
2946 * and clear the flags later. */
2947 if (clear_recalc) {
2948 const bool backup = false;
2949 DEG_ids_clear_recalc(depsgraph, backup);
2950 }
2951}
2952
2953void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
2954{
2956}
2957
2959{
2960 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
2961 DEG_make_active(depsgraph);
2962 BKE_scene_graph_update_tagged(depsgraph, bmain);
2963}
2964
2966{
2967 if (!name) {
2968 name = DATA_("RenderView");
2969 }
2970
2971 SceneRenderView *srv = MEM_new<SceneRenderView>(__func__);
2972 STRNCPY_UTF8(srv->name, name);
2973 BLI_uniquename(&sce->r.views,
2974 srv,
2975 DATA_("RenderView"),
2976 '.',
2978 sizeof(srv->name));
2979 BLI_addtail(&sce->r.views, srv);
2980
2981 return srv;
2982}
2983
2985{
2986 const int act = BLI_findindex(&scene->r.views, srv);
2987
2988 if (act == -1) {
2989 return false;
2990 }
2991 if (scene->r.views.first() == scene->r.views.last()) {
2992 /* ensure 1 view is kept */
2993 return false;
2994 }
2995
2996 BLI_remlink(&scene->r.views, srv);
2997 MEM_delete(srv);
2998
2999 scene->r.actview = 0;
3000
3001 return true;
3002}
3003
3004/* render simplification */
3005
3006int get_render_subsurf_level(const RenderData *r, int lvl, bool for_render)
3007{
3008 if (r->mode & R_SIMPLIFY) {
3009 if (for_render) {
3010 return min_ii(r->simplify_subsurf_render, lvl);
3011 }
3012
3013 return min_ii(r->simplify_subsurf, lvl);
3014 }
3015
3016 return lvl;
3017}
3018
3019int get_render_child_particle_number(const RenderData *r, int child_num, bool for_render)
3020{
3021 if (r->mode & R_SIMPLIFY) {
3022 if (for_render) {
3023 return int(r->simplify_particles_render * child_num);
3024 }
3025
3026 return int(r->simplify_particles * child_num);
3027 }
3028
3029 return child_num;
3030}
3031
3032Base *_setlooper_base_step(const Main &bmain, Scene **sce_iter, ViewLayer *view_layer, Base *base)
3033{
3034 if (base && base->next) {
3035 /* Common case, step to the next. */
3036 return base->next;
3037 }
3038 if ((base == nullptr) && (view_layer != nullptr)) {
3039 /* First time looping, return the scenes first base. */
3040 /* For the first loop we should get the layer from workspace when available. */
3041 BKE_view_layer_synced_ensure(bmain, *sce_iter, view_layer);
3042 ListBaseT<Base> *object_bases = BKE_view_layer_object_bases_get(view_layer);
3043 if (object_bases->first()) {
3044 return object_bases->first();
3045 }
3046 /* No base on this scene layer. */
3047 goto next_set;
3048 }
3049 else {
3050 next_set:
3051 /* Reached the end, get the next base in the set. */
3052 while ((*sce_iter = (*sce_iter)->set)) {
3053 ViewLayer *view_layer_set = BKE_view_layer_default_render(*sce_iter);
3054 base = BKE_view_layer_object_bases_get(view_layer_set)->first();
3055
3056 if (base) {
3057 return base;
3058 }
3059 }
3060 }
3061
3062 return nullptr;
3063}
3064
3066{
3067 RenderEngineType *type = RE_engines_find(scene->r.engine);
3068 return (type && type->flag & RE_USE_SHADING_NODES_CUSTOM);
3069}
3070
3072{
3073 RenderEngineType *type = RE_engines_find(scene->r.engine);
3074 return (type && type->flag & RE_USE_SPHERICAL_STEREO);
3075}
3076
3078{
3079 return STREQ(scene->r.engine, RE_engine_id_BLENDER_EEVEE);
3080}
3081
3083{
3085}
3086
3088{
3089 return STREQ(scene->r.engine, RE_engine_id_CYCLES);
3090}
3091
3093{
3095}
3096
3097/* This enumeration has to match the one defined in the Cycles addon. */
3102
3103void BKE_scene_base_flag_to_objects(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
3104{
3105 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
3106 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
3108 }
3109}
3110
3112{
3113 Object *ob = base->object;
3114 ob->base_flag = base->flag;
3115}
3116
3118{
3119 ColorManagedDisplaySettings *display_settings = &scene->display_settings;
3120 ColorManagedViewSettings *view_settings = &scene->view_settings;
3121 const char *view;
3122 const char *none_display_name;
3123
3124 none_display_name = IMB_colormanagement_display_get_none_name();
3125
3126 STRNCPY_UTF8(display_settings->display_device, none_display_name);
3127
3129
3130 if (view) {
3131 STRNCPY_UTF8(view_settings->view_transform, view);
3132 }
3133}
3134
3136{
3137 return scene && scene->rigidbody_world && scene->rigidbody_world->group &&
3138 !(scene->rigidbody_world->flag & RBW_FLAG_MUTED);
3139}
3140
3142{
3143 int threads;
3144
3145 /* override set from command line? */
3147
3148 if (threads > 0) {
3149 return threads;
3150 }
3151
3152 /* fixed number of threads specified in scene? */
3153 if (rd->mode & R_FIXED_THREADS) {
3154 threads = rd->threads;
3155 }
3156 else {
3157 threads = BLI_system_thread_count();
3158 }
3159
3160 return max_ii(threads, 1);
3161}
3162
3164{
3165 return BKE_render_num_threads(&scene->r);
3166}
3167
3168void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
3169{
3170 *r_width = (r->xsch * r->size) / 100;
3171 *r_height = (r->ysch * r->size) / 100;
3172
3173 if (use_crop && (r->mode & R_BORDER) && (r->mode & R_CROP)) {
3174 /* Compute the difference between the integer bounds instead of multiplying by the float
3175 * border size directly to be consistent with how the render pipeline computes render size, see
3176 * for instance render_init_from_main. That's because difference in rounding and imprecisions
3177 * can cause off by one errors. */
3178 *r_width = int(r->border.xmax * *r_width) - int(r->border.xmin * *r_width);
3179 *r_height = int(r->border.ymax * *r_height) - int(r->border.ymin * *r_height);
3180 }
3181}
3182
3184{
3185 if (r->preview_pixel_size == 0) {
3186 return (U.pixelsize > 1.5f) ? 2 : 1;
3187 }
3188 return r->preview_pixel_size;
3189}
3190
3191/******************** multiview *************************/
3192
3194{
3195 int totviews = 0;
3196
3197 if ((rd->scemode & R_MULTIVIEW) == 0) {
3198 return 1;
3199 }
3200
3202 SceneRenderView *srv = static_cast<SceneRenderView *>(
3204 if ((srv && srv->viewflag & SCE_VIEW_DISABLE) == 0) {
3205 totviews++;
3206 }
3207
3208 srv = static_cast<SceneRenderView *>(
3210 if ((srv && srv->viewflag & SCE_VIEW_DISABLE) == 0) {
3211 totviews++;
3212 }
3213 }
3214 else {
3215 for (SceneRenderView &srv : rd->views) {
3216 if ((srv.viewflag & SCE_VIEW_DISABLE) == 0) {
3217 totviews++;
3218 }
3219 }
3220 }
3221 return totviews;
3222}
3223
3225{
3226 SceneRenderView *srv[2];
3227
3228 if ((rd->scemode & R_MULTIVIEW) == 0) {
3229 return false;
3230 }
3231
3232 srv[0] = static_cast<SceneRenderView *>(
3234 srv[1] = static_cast<SceneRenderView *>(
3236
3237 return (srv[0] && ((srv[0]->viewflag & SCE_VIEW_DISABLE) == 0) && srv[1] &&
3238 ((srv[1]->viewflag & SCE_VIEW_DISABLE) == 0));
3239}
3240
3242{
3243 if (srv == nullptr) {
3244 return false;
3245 }
3246
3247 if ((rd->scemode & R_MULTIVIEW) == 0) {
3248 return false;
3249 }
3250
3251 if (srv->viewflag & SCE_VIEW_DISABLE) {
3252 return false;
3253 }
3254
3256 return true;
3257 }
3258
3259 /* SCE_VIEWS_SETUP_BASIC */
3261 return true;
3262 }
3263
3264 return false;
3265}
3266
3267bool BKE_scene_multiview_is_render_view_first(const RenderData *rd, const char *viewname)
3268{
3269 if ((rd->scemode & R_MULTIVIEW) == 0) {
3270 return true;
3271 }
3272
3273 if ((!viewname) || (!viewname[0])) {
3274 return true;
3275 }
3276
3277 for (const SceneRenderView &srv : rd->views) {
3279 return STREQ(viewname, srv.name);
3280 }
3281 }
3282
3283 return true;
3284}
3285
3286bool BKE_scene_multiview_is_render_view_last(const RenderData *rd, const char *viewname)
3287{
3288 if ((rd->scemode & R_MULTIVIEW) == 0) {
3289 return true;
3290 }
3291
3292 if ((!viewname) || (!viewname[0])) {
3293 return true;
3294 }
3295
3296 for (const SceneRenderView &srv : rd->views.items_reversed()) {
3298 return STREQ(viewname, srv.name);
3299 }
3300 }
3301
3302 return true;
3303}
3304
3306{
3307 SceneRenderView *srv;
3308 size_t nr;
3309
3310 if ((rd->scemode & R_MULTIVIEW) == 0) {
3311 return nullptr;
3312 }
3313
3314 for (srv = rd->views.first(), nr = 0; srv; srv = srv->next) {
3316 if (nr++ == view_id) {
3317 return srv;
3318 }
3319 }
3320 }
3321 return srv;
3322}
3323
3324const char *BKE_scene_multiview_render_view_name_get(const RenderData *rd, const int view_id)
3325{
3327
3328 if (srv) {
3329 return srv->name;
3330 }
3331
3332 return "";
3333}
3334
3335int BKE_scene_multiview_view_id_get(const RenderData *rd, const char *viewname)
3336{
3337 SceneRenderView *srv;
3338 size_t nr;
3339
3340 if ((!rd) || ((rd->scemode & R_MULTIVIEW) == 0)) {
3341 return 0;
3342 }
3343
3344 if ((!viewname) || (!viewname[0])) {
3345 return 0;
3346 }
3347
3348 for (srv = rd->views.first(), nr = 0; srv; srv = srv->next) {
3350 if (STREQ(viewname, srv->name)) {
3351 return nr;
3352 }
3353
3354 nr += 1;
3355 }
3356 }
3357
3358 return 0;
3359}
3360
3362 const char *filepath,
3363 char *r_filepath)
3364{
3365 BLI_strncpy(r_filepath, filepath, FILE_MAX);
3366 BLI_path_suffix(r_filepath, FILE_MAX, srv->suffix, "");
3367}
3368
3370 const char *filepath,
3371 const char *viewname,
3372 char *r_filepath)
3373{
3374 SceneRenderView *srv;
3375 char suffix[FILE_MAX];
3376
3377 srv = static_cast<SceneRenderView *>(
3378 BLI_findstring(&rd->views, viewname, offsetof(SceneRenderView, name)));
3379 if (srv) {
3380 STRNCPY(suffix, srv->suffix);
3381 }
3382 else {
3383 STRNCPY(suffix, viewname);
3384 }
3385
3386 BLI_strncpy(r_filepath, filepath, FILE_MAX);
3387 BLI_path_suffix(r_filepath, FILE_MAX, suffix, "");
3388}
3389
3390const char *BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char *viewname)
3391{
3392 SceneRenderView *srv;
3393
3394 if ((viewname == nullptr) || (viewname[0] == '\0')) {
3395 return viewname;
3396 }
3397
3398 srv = static_cast<SceneRenderView *>(
3399 BLI_findstring(&rd->views, viewname, offsetof(SceneRenderView, name)));
3400 if (srv) {
3401 return srv->suffix;
3402 }
3403
3404 return viewname;
3405}
3406
3407const char *BKE_scene_multiview_view_id_suffix_get(const RenderData *rd, const int view_id)
3408{
3409 if ((rd->scemode & R_MULTIVIEW) == 0) {
3410 return "";
3411 }
3412
3413 const char *viewname = BKE_scene_multiview_render_view_name_get(rd, view_id);
3414 return BKE_scene_multiview_view_suffix_get(rd, viewname);
3415}
3416
3418 const char *filepath,
3419 char *r_prefix,
3420 const char **r_ext)
3421{
3422 const char *unused;
3423 const char delims[] = {'.', '\0'};
3424
3425 r_prefix[0] = '\0';
3426
3427 /* Split `filepath` into base name and extension. */
3428 const size_t basename_len = BLI_str_rpartition(filepath, delims, r_ext, &unused);
3429 if (*r_ext == nullptr) {
3430 return;
3431 }
3432 BLI_assert(basename_len > 0);
3433
3434 /* Split base name into prefix and known suffix. */
3435 for (SceneRenderView &srv : scene->r.views) {
3436 if (BKE_scene_multiview_is_render_view_active(&scene->r, &srv)) {
3437 const size_t suffix_len = strlen(srv.suffix);
3438 if (basename_len >= suffix_len &&
3439 STREQLEN(filepath + basename_len - suffix_len, srv.suffix, suffix_len))
3440 {
3441 BLI_strncpy(r_prefix, filepath, basename_len - suffix_len + 1);
3442 break;
3443 }
3444 }
3445 }
3446}
3447
3449 const ImageFormatData *imf,
3450 const size_t width,
3451 const size_t height,
3452 size_t *r_width,
3453 size_t *r_height)
3454{
3455 if ((rd->scemode & R_MULTIVIEW) && imf->views_format == R_IMF_VIEWS_STEREO_3D) {
3458 width,
3459 height,
3460 r_width,
3461 r_height);
3462 }
3463 else {
3464 *r_width = width;
3465 *r_height = height;
3466 }
3467}
3468
3470{
3471 if (BKE_imtype_is_movie(imf->imtype) == false) {
3472 return 0;
3473 }
3474
3475 if ((rd->scemode & R_MULTIVIEW) == 0) {
3476 return 1;
3477 }
3478
3479 if (imf->views_format == R_IMF_VIEWS_STEREO_3D) {
3480 return 1;
3481 }
3482
3483 /* R_IMF_VIEWS_INDIVIDUAL */
3485}
3486
3487void BKE_scene_ppm_get(const RenderData *rd, double r_ppm[2])
3488{
3489 /* Should not be zero, prevent divide by zero if it is. */
3490 if (rd->ppm_base == 0.0f) [[unlikely]] {
3491 /* Zero PPM should be ignored. */
3492 r_ppm[0] = 0.0;
3493 r_ppm[1] = 0.0;
3494 }
3495 /* Non-square aspects result in a lower density on one dimension to indicate
3496 * the image should be stretched to match the original size causing the pixel
3497 * density to be lower on that dimension. */
3498 double xasp = 1.0, yasp = 1.0;
3499 if (rd->xasp < rd->yasp) {
3500 yasp = double(rd->xasp) / double(rd->yasp);
3501 }
3502 else if (rd->xasp > rd->yasp) {
3503 xasp = double(rd->yasp) / double(rd->xasp);
3504 }
3505
3506 const double ppm_base = rd->ppm_base;
3507 const double ppm_factor = rd->ppm_factor;
3508
3509 r_ppm[0] = (ppm_factor / ppm_base) * xasp;
3510 r_ppm[1] = (ppm_factor / ppm_base) * yasp;
3511}
3512
3513/* Manipulation of depsgraph storage. */
3514
3515/* This is a key which identifies depsgraph. */
3518 /* TODO(sergey): Need to include window somehow (same layer might be in a
3519 * different states in different windows).
3520 */
3521
3523 {
3524 return get_default_hash(this->view_layer);
3525 }
3526
3527 friend bool operator==(const DepsgraphKey &a, const DepsgraphKey &b) = default;
3528};
3529
3530static void depsgraph_key_value_free(void *value)
3531{
3532 Depsgraph *depsgraph = static_cast<Depsgraph *>(value);
3533 DEG_graph_free(depsgraph);
3534}
3535
3537{
3538 scene->depsgraph_hash = MEM_new<SceneDepsgraphsMap>("Scene Depsgraph Hash");
3539}
3540
3542{
3543 if (scene->depsgraph_hash == nullptr) {
3545 }
3546}
3547
3549{
3550 if (scene->depsgraph_hash == nullptr) {
3551 return;
3552 }
3553 for (Depsgraph *depsgraph : scene->depsgraph_hash->values()) {
3554 DEG_graph_free(depsgraph);
3555 }
3556 MEM_delete(scene->depsgraph_hash);
3557 scene->depsgraph_hash = nullptr;
3558}
3559
3561{
3562 if (scene->depsgraph_hash != nullptr) {
3563 DepsgraphKey key = {view_layer};
3564 if (Depsgraph *depsgraph = scene->depsgraph_hash->pop_default(key, nullptr)) {
3565 DEG_graph_free(depsgraph);
3566 }
3567 }
3568}
3569
3570/* Query depsgraph for a specific contexts. */
3571
3572static Depsgraph **scene_get_depsgraph_p(Scene *scene,
3573 ViewLayer *view_layer,
3574 const bool allocate_ghash_entry)
3575{
3576 /* bmain may be nullptr here! */
3577 BLI_assert(scene != nullptr);
3578 BLI_assert(view_layer != nullptr);
3579 BLI_assert(BKE_scene_has_view_layer(scene, view_layer));
3580
3581 /* Make sure hash itself exists. */
3582 if (allocate_ghash_entry) {
3584 }
3585 if (scene->depsgraph_hash == nullptr) {
3586 return nullptr;
3587 }
3588
3589 DepsgraphKey key;
3590 key.view_layer = view_layer;
3591
3592 if (!allocate_ghash_entry) {
3593 return scene->depsgraph_hash->lookup_ptr(key);
3594 }
3595
3596 return &scene->depsgraph_hash->lookup_or_add(key, nullptr);
3597}
3598
3599static Depsgraph **scene_ensure_depsgraph_p(Main *bmain, Scene *scene, ViewLayer *view_layer)
3600{
3601 BLI_assert(bmain != nullptr);
3602
3603 Depsgraph **depsgraph_ptr = scene_get_depsgraph_p(scene, view_layer, true);
3604 if (depsgraph_ptr == nullptr) {
3605 /* The scene has no depsgraph hash. */
3606 return nullptr;
3607 }
3608 if (*depsgraph_ptr != nullptr) {
3609 /* The depsgraph was found, no need to allocate. */
3610 return depsgraph_ptr;
3611 }
3612
3613 /* Allocate a new depsgraph. scene_get_depsgraph_p() already ensured that the pointer is stored
3614 * in the scene's depsgraph hash. */
3615 *depsgraph_ptr = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT);
3616
3617 /* TODO(sergey): Would be cool to avoid string format print,
3618 * but is a bit tricky because we can't know in advance whether
3619 * we will ever enable debug messages for this depsgraph.
3620 */
3621 char name[1024];
3622 SNPRINTF_UTF8(name, "%s :: %s", scene->id.name, view_layer->name);
3623 DEG_debug_name_set(*depsgraph_ptr, name);
3624
3625 /* These viewport depsgraphs communicate changes to the editors. */
3626 DEG_enable_editors_update(*depsgraph_ptr);
3627
3628 return depsgraph_ptr;
3629}
3630
3631Depsgraph *BKE_scene_get_depsgraph(const Scene *scene, const ViewLayer *view_layer)
3632{
3633 BLI_assert(BKE_scene_has_view_layer(scene, view_layer));
3634
3635 if (scene->depsgraph_hash == nullptr) {
3636 return nullptr;
3637 }
3638
3639 DepsgraphKey key;
3640 key.view_layer = view_layer;
3641 return scene->depsgraph_hash->lookup_default(key, nullptr);
3642}
3643
3644Depsgraph *BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
3645{
3646 Depsgraph **depsgraph_ptr = scene_ensure_depsgraph_p(bmain, scene, view_layer);
3647 return (depsgraph_ptr != nullptr) ? *depsgraph_ptr : nullptr;
3648}
3649
3650static char *scene_undo_depsgraph_gen_key(Scene *scene, ViewLayer *view_layer, char *key_full)
3651{
3652 if (key_full == nullptr) {
3653 key_full = MEM_new_array_zeroed<char>(MAX_ID_NAME + FILE_MAX + MAX_NAME, __func__);
3654 }
3655
3656 size_t key_full_offset = BLI_strncpy_rlen(key_full, scene->id.name, MAX_ID_NAME);
3657 if (ID_IS_LINKED(scene)) {
3658 key_full_offset += BLI_strncpy_rlen(
3659 key_full + key_full_offset, scene->id.lib->filepath, FILE_MAX);
3660 }
3661 key_full_offset += BLI_strncpy_rlen(key_full + key_full_offset, view_layer->name, MAX_NAME);
3662 BLI_assert(key_full_offset < MAX_ID_NAME + FILE_MAX + MAX_NAME);
3663
3664 return key_full;
3665}
3666
3668{
3669 GHash *depsgraph_extract = BLI_ghash_new(
3671
3672 for (Scene &scene : bmain->scenes) {
3673 if (scene.depsgraph_hash == nullptr) {
3674 /* In some cases, e.g. when undo has to perform multiple steps at once, no depsgraph will
3675 * be built so this pointer may be nullptr. */
3676 continue;
3677 }
3678 for (ViewLayer &view_layer : scene.view_layers) {
3679 DepsgraphKey key;
3680 key.view_layer = &view_layer;
3681 Depsgraph **depsgraph = scene.depsgraph_hash->lookup_ptr(key);
3682
3683 if (depsgraph != nullptr && *depsgraph != nullptr) {
3684 char *key_full = scene_undo_depsgraph_gen_key(&scene, &view_layer, nullptr);
3685
3686 /* We steal the depsgraph from the scene. */
3687 BLI_ghash_insert(depsgraph_extract, key_full, *depsgraph);
3688 *depsgraph = nullptr;
3689 }
3690 }
3691 }
3692
3693 return depsgraph_extract;
3694}
3695
3696void BKE_scene_undo_depsgraphs_restore(Main *bmain, GHash *depsgraph_extract)
3697{
3698 for (Scene &scene : bmain->scenes) {
3699 for (ViewLayer &view_layer : scene.view_layers) {
3700 char key_full[MAX_ID_NAME + FILE_MAX + MAX_NAME] = {0};
3701 scene_undo_depsgraph_gen_key(&scene, &view_layer, key_full);
3702
3703 Depsgraph **depsgraph_extract_ptr = reinterpret_cast<Depsgraph **>(
3704 BLI_ghash_lookup_p(depsgraph_extract, key_full));
3705 if (depsgraph_extract_ptr == nullptr) {
3706 continue;
3707 }
3708 BLI_assert(*depsgraph_extract_ptr != nullptr);
3709
3710 Depsgraph **depsgraph_scene_ptr = scene_get_depsgraph_p(&scene, &view_layer, true);
3711 BLI_assert(depsgraph_scene_ptr != nullptr);
3712 BLI_assert(*depsgraph_scene_ptr == nullptr);
3713
3714 /* We steal the depsgraph back from our 'extract' storage to the scene. */
3715 Depsgraph *depsgraph = *depsgraph_extract_ptr;
3716
3717 DEG_graph_replace_owners(depsgraph, bmain, &scene, &view_layer);
3718
3720
3721 *depsgraph_scene_ptr = depsgraph;
3722 *depsgraph_extract_ptr = nullptr;
3723 }
3724 }
3725
3727}
3728
3729/* -------------------------------------------------------------------- */
3732
3734{
3735 const int orientation_index = BKE_scene_transform_orientation_get_index(scene, orientation);
3736
3737 for (int i = 0; i < ARRAY_SIZE(scene->orientation_slots); i++) {
3738 TransformOrientationSlot *orient_slot = &scene->orientation_slots[i];
3739 if (orient_slot->index_custom == orientation_index) {
3740 /* could also use orientation_index-- */
3741 orient_slot->type = V3D_ORIENT_GLOBAL;
3742 orient_slot->index_custom = -1;
3743 }
3744 else if (orient_slot->index_custom > orientation_index) {
3745 BLI_assert(orient_slot->type == V3D_ORIENT_CUSTOM);
3746 orient_slot->index_custom--;
3747 }
3748 }
3749
3750 BLI_freelinkN(&scene->transform_spaces, orientation);
3751}
3752
3754{
3755 return static_cast<TransformOrientation *>(BLI_findlink(&scene->transform_spaces, index));
3756}
3757
3759 const TransformOrientation *orientation)
3760{
3761 return BLI_findindex(&scene->transform_spaces, orientation);
3762}
3763
3765
3766/* -------------------------------------------------------------------- */
3771
3772template<> float3x3 View3DCursor::matrix<float3x3>() const
3773{
3774 float3x3 mat;
3775 if (this->rotation_mode > 0) {
3776 eulO_to_mat3(mat.ptr(), this->rotation_euler, this->rotation_mode);
3777 }
3778 else if (this->rotation_mode == ROT_MODE_AXISANGLE) {
3779 axis_angle_to_mat3(mat.ptr(), this->rotation_axis, this->rotation_angle);
3780 }
3781 else {
3782 float tquat[4];
3783 normalize_qt_qt(tquat, this->rotation_quaternion);
3784 quat_to_mat3(mat.ptr(), tquat);
3785 }
3786 return mat;
3787}
3788
3789math::Quaternion View3DCursor::rotation() const
3790{
3791 math::Quaternion quat;
3792 if (this->rotation_mode > 0) {
3793 eulO_to_quat(&quat.w, this->rotation_euler, this->rotation_mode);
3794 }
3795 else if (this->rotation_mode == ROT_MODE_AXISANGLE) {
3796 axis_angle_to_quat(&quat.w, this->rotation_axis, this->rotation_angle);
3797 }
3798 else {
3799 normalize_qt_qt(&quat.w, this->rotation_quaternion);
3800 }
3801 return quat;
3802}
3803
3804void View3DCursor::set_matrix(const float3x3 &mat, const bool use_compat)
3805{
3806 BLI_ASSERT_UNIT_M3(mat.ptr());
3807
3808 switch (this->rotation_mode) {
3809 case ROT_MODE_QUAT: {
3810 float quat[4];
3811 mat3_normalized_to_quat(quat, mat.ptr());
3812 if (use_compat) {
3813 float quat_orig[4];
3814 copy_v4_v4(quat_orig, this->rotation_quaternion);
3815 quat_to_compatible_quat(this->rotation_quaternion, quat, quat_orig);
3816 }
3817 else {
3818 copy_v4_v4(this->rotation_quaternion, quat);
3819 }
3820 break;
3821 }
3822 case ROT_MODE_AXISANGLE: {
3823 mat3_to_axis_angle(this->rotation_axis, &this->rotation_angle, mat.ptr());
3824 break;
3825 }
3826 default: {
3827 if (use_compat) {
3829 this->rotation_euler, this->rotation_euler, this->rotation_mode, mat.ptr());
3830 }
3831 else {
3832 mat3_to_eulO(this->rotation_euler, this->rotation_mode, mat.ptr());
3833 }
3834 break;
3835 }
3836 }
3837}
3838
3839void View3DCursor::set_rotation(const math::Quaternion &quat, bool use_compat)
3840{
3841 BLI_ASSERT_UNIT_QUAT(&quat.w);
3842
3843 switch (this->rotation_mode) {
3844 case ROT_MODE_QUAT: {
3845 if (use_compat) {
3846 float quat_orig[4];
3847 copy_v4_v4(quat_orig, this->rotation_quaternion);
3848 quat_to_compatible_quat(this->rotation_quaternion, &quat.w, quat_orig);
3849 }
3850 else {
3851 copy_qt_qt(this->rotation_quaternion, &quat.w);
3852 }
3853 break;
3854 }
3855 case ROT_MODE_AXISANGLE: {
3856 quat_to_axis_angle(this->rotation_axis, &this->rotation_angle, &quat.w);
3857 break;
3858 }
3859 default: {
3860 if (use_compat) {
3862 this->rotation_euler, this->rotation_euler, this->rotation_mode, &quat.w);
3863 }
3864 else {
3865 quat_to_eulO(this->rotation_euler, this->rotation_mode, &quat.w);
3866 }
3867 break;
3868 }
3869 }
3870}
3871
3872template<> float4x4 View3DCursor::matrix<float4x4>() const
3873{
3874 float4x4 mat(this->matrix<float3x3>());
3875 mat.location() = float3(this->location);
3876 return mat;
3877}
3878
3879void View3DCursor::set_matrix(const float4x4 &mat, const bool use_compat)
3880{
3881 this->set_matrix(float3x3(mat), use_compat);
3882 copy_v3_v3(this->location, mat.location());
3883}
3884
3886
3887} // namespace blender
Functions and classes to work with Actions.
Blender kernel action and pose functionality.
#define FOREACH_SCENE_OBJECT_END
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
#define IDP_BlendDataRead(reader, prop)
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data_, func_call_)
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
#define FOREACH_MAIN_ID_END
Definition BKE_main.hh:735
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition BKE_main.hh:729
#define SELECT
Definition BKE_mask.hh:19
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:479
#define CMP_NODE_COMPOSITE_DEPRECATED
API for Blender-side Rigid Body stuff.
#define BLI_ASSERT_UNIT_M3(m)
#define BLI_ASSERT_UNIT_QUAT(q)
#define FILE_MAX
#define STR_ELEM(...)
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define BLO_read_raw_address(reader, ptr_p)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define BLO_read_struct_no_us(reader, struct_name, ptr_p)
external readfile function prototypes.
#define RPT_(msgid)
#define BLT_I18NCONTEXT_ID_SCENE
#define DATA_(msgid)
#define FILTER_ID_GD_LEGACY
Definition DNA_ID.h:1204
#define FILTER_ID_OB
Definition DNA_ID.h:1216
#define FILTER_ID_MC
Definition DNA_ID.h:1212
#define FILTER_ID_MA
Definition DNA_ID.h:1210
#define FILTER_ID_SO
Definition DNA_ID.h:1221
#define FILTER_ID_BR
Definition DNA_ID.h:1201
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define FILTER_ID_GR
Definition DNA_ID.h:1205
#define FILTER_ID_LS
Definition DNA_ID.h:1208
#define FILTER_ID_MSK
Definition DNA_ID.h:1214
#define FILTER_ID_PAL
Definition DNA_ID.h:1217
#define ID_NEW_SET(_id, _idn)
Definition DNA_ID.h:757
#define FILTER_ID_IM
Definition DNA_ID.h:1206
#define FILTER_ID_SCE
Definition DNA_ID.h:1219
#define FILTER_ID_WO
Definition DNA_ID.h:1225
#define FILTER_ID_NT
Definition DNA_ID.h:1215
#define FILTER_ID_TXT
Definition DNA_ID.h:1223
Object groups, one object can be in many groups at once.
#define MAX_NAME
Definition DNA_defs.h:63
Object is a sort of wrapper for general info.
Types and defines for representing Rigid Body entities.
#define STEREO_LEFT_NAME
#define STEREO_LEFT_SUFFIX
#define STEREO_RIGHT_NAME
#define STEREO_RIGHT_SUFFIX
#define MAXFRAME
#define STRIP_HAS_PATH(_strip)
Read Blender memory allocation and freeing.
#define STREQLEN(a, b, n)
#define UNUSED_VARS_NDEBUG(...)
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:508
ValueIterator values() const &
Definition BLI_map.hh:884
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
Value pop_default(const Key &key, const Value &default_value)
Definition BLI_map.hh:439
Value & lookup_or_add(const Key &key, const Value &value)
Definition BLI_map.hh:588
bool fcurve_remove(FCurve &fcurve_to_remove)
Span< const FCurve * > fcurves() const
const T & data(const Action &owning_action) const
#define offsetof(t, d)
#define layer
#define modf
#define floor
#define ceil
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline int4 srl(const int4 a, const int i)
Definition math_int4.h:205
const animrig::Channelbag * channelbag_for_action_slot(const Action &action, slot_handle_t slot_handle)
std::optional< std::pair< Action *, Slot * > > get_action_slot_pair(ID &animated_id)
void copy_effects(Scene &target_scene, const Scene &source_scene, const int flags)
void write_effects(const Scene &scene, BlendWriter &writer)
void for_each_id_in_effects(const Scene &scene, LibraryForeachIDData &data)
void read_effects(Scene &scene, BlendDataReader &reader)
bool is_effect_enabled(const SceneCompositorEffect &effect, ExecutionMode mode)
void node_tree_blend_write(BlendWriter *writer, bNodeTree *ntree)
Definition node.cc:1361
bNodeTree * node_tree_copy_tree_ex(const bNodeTree &ntree, Main *bmain, bool do_id_user)
Definition node.cc:5013
void node_tree_free_embedded_tree(bNodeTree *ntree)
Definition node.cc:5231
void shallow_swap(T &a, T &b)
Definition DNA_defs.h:164
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
uint32_t struct_size(Span< shader::ShaderCreateInfo::PushConst > push_constants)
QuaternionBase< float > Quaternion
SequencerToolSettings * tool_settings_init()
Definition sequencer.cc:375
void seqbase_duplicate_recursive(Main *bmain, const Scene *scene_src, Scene *scene_dst, ListBaseT< Strip > *seqbase_dst, const ListBaseT< Strip > *seqbase_src, const StripDuplicate dupe_flag, const int copy_flag)
Definition sequencer.cc:861
void foreach_strip(ListBaseT< Strip > *seqbase, ForEachFunc callback, void *user_data)
Definition iterator.cc:60
SequencerToolSettings * tool_settings_copy(SequencerToolSettings *tool_settings)
Definition sequencer.cc:882
void tool_settings_free(SequencerToolSettings *tool_settings)
Definition sequencer.cc:404
void editing_free(Scene *scene, const bool do_id_user)
Definition sequencer.cc:321
void blend_read(BlendDataReader *reader, ListBaseT< Strip > *seqbase)
bool is_valid_strip_channel(const Strip *strip)
Definition sequencer.cc:877
void blend_write(BlendWriter *writer, ListBaseT< Strip > *seqbase)
Definition sequencer.cc:987
BMesh Iterators.
bool BKE_scene_multiview_is_render_view_active(const RenderData *rd, const SceneRenderView *srv)
Definition scene.cc:3241
void BKE_sound_update_scene(Depsgraph *depsgraph, Scene *scene)
void DEG_graph_tag_relations_update(Depsgraph *graph)
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:99
void * BLI_findptr(const ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:710
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
const char * IMB_colormanagement_display_get_none_name()
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_keyingsets_blend_read_data(BlendDataReader *reader, ListBaseT< KeyingSet > *list)
Definition anim_sys.cc:326
@ SCE_READFILE_LIBLINK_NEED_SETSCENE_CHECK
static void scene_foreach_id(ID *id, LibraryForeachIDData *data)
Definition scene.cc:869
void BKE_callback_exec_id_depsgraph(Main *bmain, ID *id, Depsgraph *depsgraph, eCbEvent evt)
Definition callbacks.cc:54
int BKE_render_preview_pixel_size(const RenderData *r)
Definition scene.cc:3183
static void scene_init_data(ID *id)
Definition scene.cc:175
void BKE_copy_time_markers(ListBaseT< TimeMarker > &markers_dst, const ListBaseT< TimeMarker > &markers_src, int flag)
Definition anim_sys.cc:3962
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
Definition scene.cc:2953
unsigned __int64 uint64_t
Definition BKE_text.h:91
Main * BKE_lib_query_foreachid_process_main_get(const LibraryForeachIDData *data)
Definition lib_query.cc:138
void BLO_read_glob_list(BlendDataReader *reader, ListBase *list)
Definition readfile.cc:6829
CurveMapping * BKE_curvemapping_copy(const CurveMapping *cumap)
void BKE_previewimg_id_free(ID *id)
void BKE_scene_view_layer_graph_evaluated_ensure(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:2958
char * STRNCPY(char(&dst)[N], const char *src)
bool BKE_scene_use_spherical_stereo(Scene *scene)
Definition scene.cc:3071
void DEG_enable_editors_update(Depsgraph *depsgraph)
void BKE_time_markers_blend_read(BlendDataReader *reader, ListBaseT< TimeMarker > &markers)
Definition anim_sys.cc:3944
static void scene_foreach_asset_weak_reference(ID *id, FunctionRef< void(AssetWeakReference &)> fn)
Definition scene.cc:1053
bool BKE_bpath_foreach_path_dirfile_fixed_process(BPathForeachPathData *bpath_data, char *path_dir, size_t path_dir_maxncpy, char *path_file, size_t path_file_maxncpy)
Definition bpath.cc:235
const char * BKE_scene_multiview_render_view_name_get(const RenderData *rd, int view_id)
Definition scene.cc:3324
ID * BKE_libblock_find_name(Main *bmain, short type, const char *name, const std::optional< Library * > lib=std::nullopt) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition lib_id.cc:1808
Scene * BKE_scene_find_replacement(const Main &bmain, const Scene &scene, FunctionRef< bool(const Scene &scene)> scene_validate_cb=nullptr)
Definition scene.cc:2170
IDTypeInfo IDType_ID_SCE
Definition scene.cc:1651
@ RPT_WARNING
Definition BKE_report.hh:40
void BKE_scene_ensure_depsgraph_hash(Scene *scene)
Definition scene.cc:3541
Collection * BKE_collection_duplicate(Main *bmain, Collection *parent, CollectionChild *child_old, Collection *collection, eDupli_ID_Flags duplicate_flags, uint duplicate_options)
void BKE_scene_frame_clamp_for_playback(Scene *scene, bool is_playing_forward)
Definition scene.cc:2615
static void scene_foreach_rigidbodyworldSceneLooper(RigidBodyWorld *, ID **id_pointer, void *user_data, const LibraryForeachIDCallbackFlag cb_flag)
Definition scene.cc:461
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
int BKE_scene_num_threads(const Scene *scene)
Definition scene.cc:3163
void BKE_sound_ensure_scene(Scene *scene)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void BKE_previewimg_blend_read(BlendDataReader *reader, PreviewImage *prv)
BlendFileReadReport * BLO_read_data_reports(BlendDataReader *reader)
Definition readfile.cc:6834
Scene * BKE_scene_set_name(Main *bmain, const char *name)
Definition scene.cc:2255
@ BKE_CB_EVT_DEPSGRAPH_UPDATE_POST
@ BKE_CB_EVT_FRAME_CHANGE_POST
@ BKE_CB_EVT_DEPSGRAPH_UPDATE_PRE
@ BKE_CB_EVT_FRAME_CHANGE_PRE
bool DEG_is_fully_evaluated(const Depsgraph *depsgraph)
void BKE_libblock_relink_to_newid(Main *bmain, ID *id, int remap_flag) ATTR_NONNULL()
Definition lib_remap.cc:932
Depsgraph * BKE_scene_get_depsgraph(const Scene *scene, const ViewLayer *view_layer)
Definition scene.cc:3631
int BKE_scene_multiview_view_id_get(const RenderData *rd, const char *viewname)
Definition scene.cc:3335
const char * IMB_colormanagement_view_get_raw_or_default_name(const char *display_name)
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:307
void BKE_keyingsets_copy(ListBaseT< KeyingSet > *newlist, const ListBaseT< KeyingSet > *list)
Definition anim_sys.cc:249
@ V3D_GIZMO_SHOW_OBJECT_TRANSLATE
@ V3D_GIZMO_SHOW_OBJECT_SCALE
@ V3D_GIZMO_SHOW_OBJECT_ROTATE
void BKE_view_layer_blend_write(BlendWriter *writer, const Scene *scene, ViewLayer *view_layer)
bool BKE_scene_can_be_removed(const Main *bmain, const Scene *scene)
Definition scene.cc:2150
void BKE_paint_settings_foreach_mode(ToolSettings *ts, FunctionRef< void(Paint &paint)> fn)
static void scene_blend_write_compositor_forward_compat(Scene &scene, const bNodeTree &compositing_node_group, BlendWriter *writer)
Definition scene.cc:1077
void BKE_collection_blend_write_prepare_nolib(BlendWriter *writer, Collection *collection)
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:834
void BKE_scene_multiview_filepath_get(const SceneRenderView *srv, const char *filepath, char *r_filepath)
Definition scene.cc:3361
void BKE_scene_allocate_depsgraph_hash(Scene *scene)
Definition scene.cc:3536
@ VIEWLAYER_ADD_NEW
Definition BKE_layer.hh:40
void mat3_normalized_to_quat(float q[4], const float mat[3][3])
bool BKE_scene_has_view_layer(const Scene *scene, const ViewLayer *layer)
Definition scene.cc:2422
void BKE_image_format_blend_write(BlendWriter *writer, ImageFormatData *imf)
@ IDWALK_NO_ORIG_POINTERS_ACCESS
@ IDWALK_DO_DEPRECATED_POINTERS
void BKE_rigidbody_world_init_runtime(struct RigidBodyWorld *rbw)
Definition rigidbody.cc:98
void BKE_previewimg_blend_write(BlendWriter *writer, const PreviewImage *prv)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
void BKE_scene_remove_rigidbody_object(Main *bmain, Scene *scene, Object *ob, bool free_us)
Definition scene.cc:2547
int get_render_subsurf_level(const RenderData *r, int lvl, bool for_render)
Definition scene.cc:3006
static void prepare_mesh_for_viewport_render(Main *bmain, const Scene *scene, ViewLayer *view_layer)
Definition scene.cc:2719
static void scene_lib_override_apply_post(ID *id_dst, ID *)
Definition scene.cc:1638
eSceneForeachUndoPreserveProcess
Definition scene.cc:475
@ SCENE_FOREACH_UNDO_RESTORE
Definition scene.cc:478
@ SCENE_FOREACH_UNDO_NO_RESTORE
Definition scene.cc:481
static void scene_blend_read_data(BlendDataReader *reader, ID *id)
Definition scene.cc:1371
static void depsgraph_key_value_free(void *value)
Definition scene.cc:3530
float BKE_scene_frame_to_ctime(const Scene *scene, int frame)
Definition scene.cc:2586
bool bool BLI_path_suffix(char *path, size_t path_maxncpy, const char *suffix, const char *sep) ATTR_NONNULL(1
void BKE_scene_disable_color_management(Scene *scene)
Definition scene.cc:3117
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, FunctionRef< void(IDProperty *id_property)> callback)
void(*)(ID *id, const IDCacheKey *cache_key, void **cache_p, uint flags, void *user_data) IDTypeForeachCacheFunctionCallback
void BKE_curvemapping_copy_data(CurveMapping *target, const CurveMapping *cumap)
@ RE_USE_SPHERICAL_STEREO
Definition RE_engine.h:50
@ RE_INTERNAL
Definition RE_engine.h:45
@ RE_USE_SHADING_NODES_CUSTOM
Definition RE_engine.h:49
void BKE_color_managed_view_settings_init(ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const char *view_transform)
void BKE_scene_free_view_layer_depsgraph(Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3560
void BKE_color_managed_colorspace_settings_copy(ColorManagedColorspaceSettings *colorspace_settings, const ColorManagedColorspaceSettings *settings)
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:279
static Depsgraph ** scene_get_depsgraph_p(Scene *scene, ViewLayer *view_layer, const bool allocate_ghash_entry)
Definition scene.cc:3572
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
eSceneCopyMethod
Definition BKE_scene.hh:35
@ SCE_COPY_FULL
Definition BKE_scene.hh:39
@ SCE_COPY_EMPTY
Definition BKE_scene.hh:37
void BKE_curvemapping_blend_write(BlendWriter *writer, const CurveMapping *cumap)
void mat3_to_compatible_eulO(float eul[3], const float oldrot[3], short order, const float mat[3][3])
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void BKE_curvemapping_curves_blend_write(BlendWriter *writer, const CurveMapping *cumap)
int BKE_scene_orientation_get_index(Scene *scene, int slot_index)
Definition scene.cc:2678
ID * BKE_id_copy_for_duplicate(Main *bmain, ID *id, eDupli_ID_Flags duplicate_flags, int copy_flags)
Definition lib_id.cc:861
static char * scene_undo_depsgraph_gen_key(Scene *scene, ViewLayer *view_layer, char *key_full)
Definition scene.cc:3650
const char * BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char *viewname)
Definition scene.cc:3390
void BKE_color_managed_display_settings_init(ColorManagedDisplaySettings *settings)
static void remove_sequencer_fcurves(Scene *sce)
Definition scene.cc:1722
void BKE_callback_exec_id(Main *bmain, ID *id, eCbEvent evt)
Definition callbacks.cc:45
@ ID_REMAP_SKIP_USER_CLEAR
@ ID_REMAP_FORCE_OBDATA_IN_EDITMODE
const char * RE_engine_id_CYCLES
Definition scene.cc:1720
MINLINE int max_ii(int a, int b)
static void scene_foreach_working_space_color(ID *id, const IDTypeForeachColorFunctionCallback &fn)
Definition scene.cc:1043
void BKE_screen_view3d_shading_blend_read_data(BlendDataReader *reader, View3DShading *shading)
Definition screen.cc:1352
void BKE_color_managed_view_settings_blend_read_data(BlendDataReader *reader, ColorManagedViewSettings *settings)
void BKE_paint_copy(const Paint *src, Paint *dst, int flag)
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:684
void DEG_make_active(Depsgraph *depsgraph)
Definition depsgraph.cc:337
int BKE_scene_multiview_num_views_get(const RenderData *rd)
Definition scene.cc:3193
MatBase< float, 4, 4 > float4x4
int BKE_unit_base_of_type_get(int system, int type)
Definition unit.cc:2594
static void scene_foreach_path(ID *id, BPathForeachPathData *bpath_data)
Definition scene.cc:1035
ListBaseT< Base > * BKE_view_layer_object_bases_unsynced_get(ViewLayer *view_layer)
void BKE_curvemapping_free(CurveMapping *cumap)
void BKE_animdata_duplicate_id_action(Main *bmain, ID *id, uint duplicate_flags)
Definition anim_data.cc:434
bool BKE_scene_validate_setscene(Main *bmain, Scene *sce)
Definition scene.cc:2559
LibraryForeachIDFlag BKE_lib_query_foreachid_process_flags_get(const LibraryForeachIDData *data)
Definition lib_query.cc:133
bool BKE_scene_use_shading_nodes_custom(Scene *scene)
Definition scene.cc:3065
void DEG_ids_clear_recalc(Depsgraph *depsgraph, bool backup)
void DEG_evaluate_on_refresh(Depsgraph *graph, DepsgraphEvaluateSyncWriteback sync_writeback=DEG_EVALUATE_SYNC_WRITEBACK_NO)
void BKE_view_layer_free_ex(ViewLayer *view_layer, bool do_id_user)
void BKE_toolsettings_free(ToolSettings *toolsettings)
Definition scene.cc:1828
void BKE_id_blend_write(BlendWriter *writer, ID *id)
Definition lib_id.cc:2890
static void scene_foreach_toolsettings(LibraryForeachIDData *data, ToolSettings *toolsett, const bool do_undo_restore, BlendLibReader *reader, ToolSettings *toolsett_old)
Definition scene.cc:607
void BKE_color_managed_view_settings_copy(ColorManagedViewSettings *new_settings, const ColorManagedViewSettings *settings)
void BKE_scene_update_tag_audio_volume(Depsgraph *, Scene *scene)
Definition scene.cc:2775
void MEM_delete_void(void *vmemh)
const char * RE_engine_id_BLENDER_WORKBENCH
Definition scene.cc:1719
@ LIB_ID_CREATE_NO_USER_REFCOUNT
@ LIB_ID_COPY_NO_PREVIEW
@ LIB_ID_COPY_DEFAULT
@ LIB_ID_CREATE_NO_ALLOCATE
void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw)
void BKE_scene_frame_set(Scene *scene, float frame)
Definition scene.cc:2600
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:3168
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2872
void quat_to_compatible_eulO(float eul[3], const float oldrot[3], short order, const float quat[4])
void BKE_sound_update_scene_listener(Scene *scene)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.cc:711
static bool strip_foreach_path_callback(Strip *strip, void *user_data)
Definition scene.cc:995
static void scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain, bool only_if_tagged)
Definition scene.cc:2789
const char * RE_engine_id_BLENDER_EEVEE
Definition scene.cc:1717
ScenePlaybackRange BKE_scene_get_playback_range(const Scene *scene)
Definition scene.cc:2607
void quat_to_compatible_quat(float q[4], const float a[4], const float old[4])
int BKE_scene_base_iter_next(Depsgraph *depsgraph, SceneBaseIter *iter, Scene **scene, int val, Base **base, Object **ob)
Definition scene.cc:2268
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
void BKE_ptcache_blend_read_data(struct BlendDataReader *reader, ListBaseT< PointCache > *ptcaches, struct PointCache **ocache, int force_disk)
void ** BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:749
void BKE_scene_ppm_get(const RenderData *rd, double r_ppm[2])
Definition scene.cc:3487
void BKE_lib_query_foreachid_process(LibraryForeachIDData *data, ID **id_pp, LibraryForeachIDCallbackFlag cb_flag)
Definition lib_query.cc:82
@ LIB_ID_DUPLICATE_IS_SUBPROCESS
@ LIB_ID_DUPLICATE_IS_ROOT_ID
void eulO_to_mat3(float M[3][3], const float e[3], short order)
void BKE_keyingsets_foreach_id(LibraryForeachIDData *data, const ListBaseT< KeyingSet > *keyingsets)
Definition anim_sys.cc:262
void quat_to_mat3(float m[3][3], const float q[4])
int BLI_system_thread_count()
Definition threads.cc:258
void BKE_collection_free_data(Collection *collection)
void BKE_curvemapping_init(CurveMapping *cumap)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void BLI_uniquename(const ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
int BKE_render_num_threads(const RenderData *r)
Definition scene.cc:3141
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void BKE_curvemapping_blend_read(BlendDataReader *reader, CurveMapping *cumap)
bool BKE_scene_multiview_is_render_view_first(const RenderData *rd, const char *viewname)
Definition scene.cc:3267
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void BKE_image_editors_update_frame(const Main *bmain, int cfra)
eCyclesFeatureSet
Definition scene.cc:3098
@ CYCLES_FEATURES_EXPERIMENTAL
Definition scene.cc:3100
@ CYCLES_FEATURES_SUPPORTED
Definition scene.cc:3099
ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
const char * BKE_scene_find_last_marker_name(const Scene *scene, int frame)
Definition scene.cc:2514
bool BKE_scene_uses_blender_eevee(const Scene *scene)
Definition scene.cc:3077
unsigned char uchar
Definition BKE_text.h:58
void BKE_color_managed_display_settings_copy(ColorManagedDisplaySettings *new_settings, const ColorManagedDisplaySettings *settings)
static bool check_rendered_viewport_visible(Main *bmain)
Definition scene.cc:2692
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:866
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void copy_qt_qt(float q[4], const float a[4])
bool DEG_id_type_any_updated(const Depsgraph *depsgraph)
Object * BKE_view_layer_edit_object_get(const ViewLayer *view_layer)
Main * DEG_get_bmain(const Depsgraph *graph)
void DEG_id_tag_update(ID *id, unsigned int flags)
float BKE_scene_frame_get(const Scene *scene)
Definition scene.cc:2595
const char * IMB_colormanagement_role_colorspace_name_get(int role)
void BKE_keyingsets_blend_write(BlendWriter *writer, ListBaseT< KeyingSet > *list)
Definition anim_sys.cc:308
void BKE_view_layer_copy_data(Scene *scene_dst, const Scene *scene_src, ViewLayer *view_layer_dst, const ViewLayer *view_layer_src, int flag)
int BKE_scene_orientation_get_index_from_flag(Scene *scene, int flag)
Definition scene.cc:2684
BMesh const char void * data
void object_duplilist(Depsgraph *depsgraph, Object *ob, Set< const Object * > *include_objects, DupliList &r_duplilist)
bool BKE_view_layer_is_synced(const ViewLayer &view_layer)
void BKE_time_markers_blend_write(BlendWriter *writer, ListBaseT< TimeMarker > &markers)
Definition anim_sys.cc:3933
TransformOrientationSlot * BKE_scene_orientation_slot_get(Scene *scene, int slot_index)
Definition scene.cc:2639
void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, CurveMapSlopeType slope)
static Depsgraph ** scene_ensure_depsgraph_p(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3599
void BKE_library_foreach_ID_embedded(LibraryForeachIDData *data, ID **id_pp)
Definition lib_query.cc:176
void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *paint)
ToolSettings * BKE_toolsettings_copy(ToolSettings *toolsettings, int flag)
Definition scene.cc:1746
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, bool ensure_brushes=true)
void IMB_colormanagement_colorspace_settings_set(ColorManagedColorspaceSettings *settings, const char *name)
void quat_to_eulO(float e[3], short order, const float q[4])
void DEG_graph_replace_owners(Depsgraph *depsgraph, Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition depsgraph.cc:286
void BKE_scene_object_base_flag_sync_from_base(Base *base)
Definition scene.cc:3111
BlendFileReadReport * BLO_read_lib_reports(BlendLibReader *reader)
Definition readfile.cc:6858
void BKE_sound_set_scene_volume(Scene *scene, float volume)
bool BKE_main_view_layers_synced_ensure(const Main *bmain)
char char size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BKE_scene_free_depsgraph_hash(Scene *scene)
Definition scene.cc:3548
void IMB_stereo3d_write_dimensions(char mode, bool is_squeezed, size_t width, size_t height, size_t *r_width, size_t *r_height)
const char * BKE_scene_multiview_view_id_suffix_get(const RenderData *rd, int view_id)
Definition scene.cc:3407
static void scene_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition scene.cc:1150
void BKE_curvemapping_changed(CurveMapping *cumap, bool rem_doubles)
CurveMapping * BKE_paint_default_curve_inverted()
Definition scene.cc:166
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
static void scene_foreach_paint(LibraryForeachIDData *data, Paint *paint, const bool do_undo_restore, BlendLibReader *reader, Paint *paint_old)
Definition scene.cc:573
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2867
Scene * BKE_scene_add(Main *bmain, const char *name)
Definition scene.cc:2200
CurveMapping * BKE_sculpt_default_cavity_curve()
Definition scene.cc:142
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void DEG_debug_name_set(Depsgraph *depsgraph, const char *name)
@ DAG_EVAL_VIEWPORT
void DEG_ids_restore_recalc(Depsgraph *depsgraph)
void BKE_image_format_blend_read_data(BlendDataReader *reader, ImageFormatData *imf)
void DEG_editors_update(Depsgraph *depsgraph, bool time)
bool BKE_scene_multiview_is_render_view_last(const RenderData *rd, const char *viewname)
Definition scene.cc:3286
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
SceneRenderView * BKE_scene_multiview_render_view_findindex(const RenderData *rd, int view_id)
Definition scene.cc:3305
void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition readfile.cc:237
void BKE_image_format_init(ImageFormatData *imf)
void mat3_to_axis_angle(float axis[3], float *angle, const float mat[3][3])
struct RigidBodyWorld * BKE_rigidbody_world_copy(struct RigidBodyWorld *rbw, int flag)
Scene * BKE_scene_find_from_collection(const Main *bmain, const Collection *collection)
Definition scene.cc:2427
MatBase< float, 3, 3 > float3x3
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
void BKE_view_layer_blend_read_data(BlendDataReader *reader, ViewLayer *view_layer)
void BKE_sound_mute_scene(Scene *scene, bool muted)
void BKE_curveprofile_blend_write(struct BlendWriter *writer, const struct CurveProfile *profile)
bool BKE_scene_multiview_is_stereo3d(const RenderData *rd)
Definition scene.cc:3224
RenderEngineType * RE_engines_find(const char *idname)
static void scene_undo_preserve(BlendLibReader *reader, ID *id_new, ID *id_old)
Definition scene.cc:1622
TransformOrientation * BKE_scene_transform_orientation_find(const Scene *scene, int index)
Definition scene.cc:3753
void BKE_image_format_free(ImageFormatData *imf)
void BKE_scene_multiview_videos_dimensions_get(const RenderData *rd, const ImageFormatData *imf, size_t width, size_t height, size_t *r_width, size_t *r_height)
Definition scene.cc:3448
void BKE_curvemapping_set_defaults(CurveMapping *cumap, int tot, float minx, float miny, float maxx, float maxy, eBezTriple_Handle default_handle_type)
Definition colortools.cc:47
bool BKE_scene_uses_shader_previews(const Scene *scene)
Definition scene.cc:3092
int BKE_scene_transform_orientation_get_index(const Scene *scene, const TransformOrientation *orientation)
Definition scene.cc:3758
static void scene_foreach_cache(ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data)
Definition scene.cc:1062
void BKE_sound_update_fps(Main *bmain, Scene *scene)
void BKE_scene_transform_orientation_remove(Scene *scene, TransformOrientation *orientation)
Definition scene.cc:3733
bool BKE_imtype_is_movie(char imtype)
static void scene_foreach_toolsettings_id_pointer_process(ID **id_p, const eSceneForeachUndoPreserveProcess action, BlendLibReader *reader, ID **id_old_p, const uint cb_flag)
Definition scene.cc:484
void BKE_main_id_newptr_and_tag_clear(Main *bmain)
Definition lib_id.cc:2097
SceneRenderView * BKE_scene_add_render_view(Scene *sce, const char *name)
Definition scene.cc:2965
int BKE_scene_multiview_num_videos_get(const RenderData *rd, const ImageFormatData *imf)
Definition scene.cc:3469
void id_us_ensure_real(ID *id)
Definition lib_id.cc:388
@ BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE
Definition BKE_bpath.hh:76
void BKE_scene_set_background(Main *bmain, Scene *sce)
Definition scene.cc:2233
void BKE_previewimg_id_copy(ID *new_id, const ID *old_id)
void BKE_curveprofile_free(struct CurveProfile *profile)
void BKE_rigidbody_remove_object(struct Main *bmain, struct Scene *scene, struct Object *ob, bool free_us)
static void scene_copy_data(Main *bmain, std::optional< Library * > owner_library, ID *id_dst, const ID *id_src, const int flag)
Definition scene.cc:285
Object * BKE_scene_camera_switch_find(const Scene *scene, const int time)
Definition scene.cc:2440
void BKE_curvemapping_free_data(CurveMapping *cumap)
void BKE_rigidbody_free_world(struct Scene *scene)
Definition rigidbody.cc:110
void BKE_sound_destroy_scene(Scene *scene)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
bool BKE_scene_uses_blender_workbench(const Scene *scene)
Definition scene.cc:3082
bool BKE_bpath_foreach_path_fixed_process(BPathForeachPathData *bpath_data, char *path, size_t path_maxncpy)
Definition bpath.cc:130
static void scene_blend_read_after_liblink(BlendLibReader *reader, ID *id)
Definition scene.cc:1587
float BKE_scene_ctime_get(const Scene *scene)
Definition scene.cc:2581
void BKE_paint_free(Paint *paint)
@ INDEX_ID_SCE
Definition DNA_ID.h:1351
void BKE_scene_orientation_slot_set_index(TransformOrientationSlot *orient_slot, int orientation)
Definition scene.cc:2664
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
void BKE_scene_undo_depsgraphs_restore(Main *bmain, GHash *depsgraph_extract)
Definition scene.cc:3696
bool BKE_scene_camera_switch_update(Scene *scene)
Definition scene.cc:2480
bool BKE_scene_uses_cycles(const Scene *scene)
Definition scene.cc:3087
int BLI_system_num_threads_override_get()
Definition threads.cc:299
Collection * BKE_collection_master_add(Scene *scene)
void eulO_to_quat(float q[4], const float e[3], short order)
void BKE_free_time_markers(ListBaseT< TimeMarker > &markers, bool do_id_user)
Definition anim_sys.cc:3982
void BKE_scene_base_flag_to_objects(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3103
struct CurveProfile * BKE_curveprofile_add(eCurveProfilePresets preset)
@ ID_RECALC_PARAMETERS
Definition DNA_ID.h:1138
@ ID_RECALC_ALL
Definition DNA_ID.h:1190
@ ID_RECALC_AUDIO_LISTENER
Definition DNA_ID.h:1130
@ ID_RECALC_AUDIO_FPS
Definition DNA_ID.h:1127
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1125
@ ID_RECALC_AUDIO_MUTE
Definition DNA_ID.h:1129
@ ID_RECALC_AUDIO_VOLUME
Definition DNA_ID.h:1128
bool BKE_scene_object_find(const Main &bmain, Scene *scene, Object *ob)
Definition scene.cc:2209
float BKE_scene_frame_snap_by_seconds(const Scene *scene, double interval_in_seconds, float frame)
Definition scene.cc:2532
Scene * DEG_get_input_scene(const Depsgraph *graph)
void BKE_rigidbody_remove_constraint(struct Main *bmain, struct Scene *scene, struct Object *ob, bool free_us)
@ R_IMF_VIEWS_STEREO_3D
bool BKE_scene_remove_render_view(Scene *scene, SceneRenderView *srv)
Definition scene.cc:2984
@ ID_TAG_NEW
Definition DNA_ID.h:922
static void link_recurs_seq(BlendDataReader *reader, ListBaseT< Strip > *lb)
Definition scene.cc:1355
void DEG_graph_relations_update(Depsgraph *graph)
TransformOrientationSlot * BKE_scene_orientation_slot_get_from_flag(Scene *scene, int flag)
Definition scene.cc:2647
GHash * BKE_scene_undo_depsgraphs_extract(Main *bmain)
Definition scene.cc:3667
void DEG_evaluate_on_framechange(Depsgraph *graph, float frame, DepsgraphEvaluateSyncWriteback sync_writeback=DEG_EVALUATE_SYNC_WRITEBACK_NO)
CurveMapping * BKE_paint_default_curve()
Definition scene.cc:157
int bool bool bool size_t size_t BLI_str_rpartition(const char *str, const char delim[], const char **sep, const char **suf) ATTR_NONNULL(1
unsigned int BLI_ghashutil_strhash_p(const void *ptr)
ViewLayer * BKE_view_layer_add(const Main *bmain, Scene *scene, const char *name, ViewLayer *view_layer_source, int type)
void BKE_ptcache_blend_write(struct BlendWriter *writer, ListBaseT< PointCache > *ptcaches)
int BKE_scene_orientation_slot_get_index(const TransformOrientationSlot *orient_slot)
Definition scene.cc:2671
void BKE_scene_copy_data_eevee(Scene *sce_dst, const Scene *sce_src)
Definition scene.cc:1911
void BKE_color_managed_view_settings_free(ColorManagedViewSettings *settings)
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:775
void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw)
@ SCE_VIEWS_FORMAT_MULTIVIEW
@ SCE_VIEWS_FORMAT_STEREO_3D
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
void BKE_keyingsets_free(ListBaseT< KeyingSet > *list)
Definition anim_sys.cc:289
MINLINE void copy_v4_v4(float r[4], const float a[4])
Base * _setlooper_base_step(const Main &bmain, Scene **sce_iter, ViewLayer *view_layer, Base *base)
Definition scene.cc:3032
void BKE_scene_update_sound(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2750
ViewLayer * BKE_view_layer_context_active_PLACEHOLDER(const Scene *scene)
void BKE_screen_view3d_shading_blend_write(BlendWriter *writer, View3DShading *shading)
Definition screen.cc:1345
void BKE_scene_groups_relink(Scene *sce)
Definition scene.cc:2143
void BKE_sound_seek_scene(Main *bmain, Scene *scene)
struct CurveProfile * BKE_curveprofile_copy(const struct CurveProfile *profile)
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParams *params)
Object * BKE_scene_object_find_by_name(const Main &bmain, const Scene *scene, const char *name)
Definition scene.cc:2220
void BKE_color_managed_view_settings_blend_write(BlendWriter *writer, const ColorManagedViewSettings *settings)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:690
const char * RE_engine_id_BLENDER_EEVEE_NEXT
Definition scene.cc:1718
LibraryForeachIDCallbackFlag
@ IDWALK_CB_DIRECT_WEAK_LINK
@ IDWALK_CB_EMBEDDED_NOT_OWNING
@ IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE
@ IDWALK_CB_NEVER_SELF
VecBase< float, 3 > float3
@ DEG_EVALUATE_SYNC_WRITEBACK_YES
bool DEG_is_evaluated(const T *id)
bool BKE_main_collection_sync(const Main *bmain)
void BKE_curveprofile_blend_read(struct BlendDataReader *reader, struct CurveProfile *profile)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
void mat3_to_eulO(float eul[3], short order, const float m[3][3])
ViewLayer * BKE_view_layer_default_render(const Scene *scene)
@ B_UNIT_MASS
Definition BKE_unit.hh:169
@ B_UNIT_LENGTH
Definition BKE_unit.hh:166
@ B_UNIT_TIME
Definition BKE_unit.hh:171
@ B_UNIT_TEMPERATURE
Definition BKE_unit.hh:177
void BKE_scene_multiview_view_filepath_get(const RenderData *rd, const char *filepath, const char *view, char *r_filepath)
Definition scene.cc:3369
static bool strip_foreach_member_id_cb(Strip *strip, void *user_data)
Definition scene.cc:806
@ eSeqModifierType_Compositor
MINLINE int min_ii(int a, int b)
MINLINE int clamp_i(int value, int min, int max)
ID * BKE_id_copy(Main *bmain, const ID *id)
Definition lib_id.cc:856
void BKE_scene_graph_update_for_newframe_ex(Depsgraph *depsgraph, bool clear_recalc)
Definition scene.cc:2877
void BKE_view_layer_blend_read_after_liblink(BlendLibReader *reader, ID *self_id, ViewLayer *view_layer)
void id_us_plus_no_lib(ID *id)
Definition lib_id.cc:417
struct EffectorWeights * BKE_effector_add_weights(struct Collection *collection)
Definition effect.cc:63
void BKE_scene_multiview_view_prefix_get(const Scene *scene, const char *filepath, char *r_prefix, const char **r_ext)
Definition scene.cc:3417
void id_us_min(ID *id)
Definition lib_id.cc:441
void BKE_image_format_copy(ImageFormatData *imf_dst, const ImageFormatData *imf_src)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
bool BKE_scene_check_rigidbody_active(const Scene *scene)
Definition scene.cc:3135
ID * BLO_read_get_new_id_address_from_session_uid(BlendLibReader *reader, uint session_uid) ATTR_NONNULL(1)
Definition readfile.cc:6541
bNodeLink & version_node_add_link(bNodeTree &ntree, bNode &node_a, bNodeSocket &socket_a, bNode &node_b, bNodeSocket &socket_b)
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
static void scene_free_data(ID *id)
Definition scene.cc:390
struct ID * BKE_id_copy_in_lib(Main *bmain, std::optional< Library * > owner_library, const ID *id, std::optional< const ID * > new_owner_id, ID **new_id_p, int flag)
Definition lib_id.cc:749
@ IDP_TYPE_FILTER_ID
const char * BKE_scene_find_marker_name(const Scene *scene, int frame)
Definition scene.cc:2491
void BKE_rigidbody_world_id_loop(struct RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata)
bool BKE_view_layer_has_collection(const ViewLayer *view_layer, const Collection *collection)
Scene * BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type, eDupli_ID_Flags duplicate_flags, uint duplicate_options)
Definition scene.cc:1917
bNode & version_node_add_unknown(bNodeTree &ntree, bke::bNodeType &ntype, const char *idname, const int16_t legacy_type, const std::string &ui_name, const std::string &ui_description, const std::string &enum_name_legacy, const short nclass, const float width, const float height, const bool no_muting)
static void scene_foreach_layer_collection(LibraryForeachIDData *data, ListBaseT< LayerCollection > *lb, const bool is_master)
Definition scene.cc:789
void BKE_paint_blend_write(BlendWriter *writer, Paint *paint)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
int get_render_child_particle_number(const RenderData *r, int child_num, bool for_render)
Definition scene.cc:3019
bool BLI_ghashutil_strcmp(const void *a, const void *b)
@ CUMA_EXTEND_EXTRAPOLATE
void BKE_libblock_free_data_py(ID *id)
bNodeSocket & version_node_add_socket(bNodeTree &ntree, bNode &node, const eNodeSocketInOut in_out, const char *idname, const char *identifier)
static void direct_link_paint_helper(BlendDataReader *reader, const Scene *scene, Paint **paint)
Definition scene.cc:1345
float normalize_qt_qt(float r[4], const float q[4])
@ IDTYPE_FLAGS_NEVER_UNUSED
Definition BKE_idtype.hh:73
#define BKE_LIB_FOREACHID_UNDO_PRESERVE_PROCESS_FUNCTION_CALL(_data, _do_undo_restore, _func_call)
Definition scene.cc:560
#define FOREACHID_PROCESS_IDSUPER(_data, _id_super, _cb_flag)
#define BKE_LIB_FOREACHID_UNDO_PRESERVE_PROCESS_IDSUPER_P(_data, _id_p, _do_undo_restore, _action, _reader, _id_old_p, _cb_flag)
Definition scene.cc:546
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ImageFormatData im_format
struct Object * cage_object
struct Object * object
struct Base * next
struct blender::BlendFileReadReport::@140003175311343306107257242277261221002217304000 count
void write_embedded_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
void write_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
bool is_undo() const
struct IDProperty * system_properties
eCurveMappingFlags flag
eCurveMappingPreset preset
const ViewLayer * view_layer
Definition scene.cc:3517
uint64_t hash() const
Definition scene.cc:3522
friend bool operator==(const DepsgraphKey &a, const DepsgraphKey &b)=default
eEditingProxyStorageMode proxy_storage
eEditingShowMissingMediaFlag show_missing_media_flag
seq::EditingRuntime * runtime
ListBaseT< SeqTimelineChannel > channels
eEditingCacheFlag cache_flag
ListBaseT< Strip > seqbase
ListBaseT< FreestyleModuleConfig > modules
ListBaseT< FreestyleLineSet > linesets
struct FreestyleLineStyle * linestyle
struct Object * reference_object
struct GP_Sculpt_Guide guide
struct CurveMapping * cur_falloff
struct CurveMapping * cur_primitive
unsigned int id_session_uid
Definition BKE_idtype.hh:78
char name[258]
Definition DNA_ID.h:433
unsigned int session_uid
Definition DNA_ID.h:463
struct ID * newid
Definition DNA_ID.h:419
struct Library * lib
Definition DNA_ID.h:421
IDProperty * system_properties
Definition DNA_ID.h:490
void * prev
Definition DNA_ID.h:418
short flag
Definition DNA_ID.h:439
void * next
Definition DNA_ID.h:418
IDProperty * properties
Definition DNA_ID.h:481
unsigned int recalc
Definition DNA_ID.h:446
struct ID * orig_id
Definition DNA_ID.h:502
eImageFormat_ViewsFormat views_format
char filepath[1024]
Definition DNA_ID.h:562
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
const c_style_mat & ptr() const
bke::ObjectRuntime * runtime
eObject_VisibilityFlag visibility_flag
struct RigidBodyOb * rigidbody_object
struct RigidBodyCon * rigidbody_constraint
ListBaseT< PointCache > * ptcaches
struct Brush * brush
struct Palette * palette
ListBaseT< SceneRenderLayer > layers
ListBaseT< SceneRenderView > views
struct CurveMapping mblur_shutter_curve
ImageFormatData im_format
eSceneViews_Format views_format
void(*) render(struct RenderEngine *engine, struct Depsgraph *depsgraph)
Definition RE_engine.h:90
struct Collection * constraints
eRigidBodyWorld_Flag flag
struct EffectorWeights * effector_weights
DNA_DEPRECATED struct PointCache * pointcache
struct RigidBodyWorld_Shared * shared
ListBaseT< PointCache > ptcaches
DupliObject * dupob
Definition BKE_scene.hh:83
struct SceneRenderView * next
ListBaseT< ViewLayer > view_layers
struct World * world
struct Editing * ed
struct PreviewImage * preview
TransformOrientationSlot orientation_slots[4]
struct SceneDisplay display
struct Collection * master_collection
DNA_DEPRECATED struct Base * basact
ColorManagedViewSettings view_settings
struct PhysicsSettings physics_settings
struct Scene * set
struct Object * camera
ListBaseT< TimeMarker > markers
struct UnitSettings unit
SceneDepsgraphsMap * depsgraph_hash
struct CustomData_MeshMasks customdata_mask
ListBaseT< TransformOrientation > transform_spaces
ListBaseT< struct KeyingSet > keyingsets
DNA_DEPRECATED char use_nodes
ColorManagedDisplaySettings display_settings
struct bGPdata * gpd
struct CustomData_MeshMasks customdata_mask_modal
ListBaseT< Base > base
DNA_DEPRECATED struct bNodeTree * compositing_node_group
View3DCursor cursor
ListBaseT< SceneCompositorEffect > compositor_effects
IDProperty * layer_properties
bke::SceneRuntime * runtime
DNA_DEPRECATED struct bNodeTree * nodetree
ColorManagedColorspaceSettings sequencer_colorspace_settings
struct MovieClip * clip
struct RenderData r
struct AudioData audio
struct SceneEEVEE eevee
struct ToolSettings * toolsettings
struct RigidBodyWorld * rigidbody_world
ListBaseT< SpaceLink > spacedata
DNA_DEPRECATED struct CurveMapping * automasking_cavity_curve_op
DNA_DEPRECATED struct CurveMapping * automasking_cavity_curve
struct Object * gravity_object
eStereoDisplayMode display_mode
struct IDProperty * system_properties
struct VFont * text_font
struct Object * camera
struct IDProperty * prop
struct TimeMarker * prev
struct TimeMarker * next
CurvesSculpt * curves_sculpt
DNA_DEPRECATED struct UnifiedPaintSettings unified_paint_settings
struct ParticleEditSettings particle
struct CurveProfile * custom_bevel_profile_preset
struct ImagePaintSettings imapaint
struct GP_Interpolate_Settings gp_interpolate
struct PaintModeSettings paint_mode
GpSculptPaint * gp_sculptpaint
struct SequencerToolSettings * sequencer_tool_settings
GpVertexPaint * gp_vertexpaint
struct Object * anim_mirror_object
struct Object * anim_relative_object
struct GP_Sculpt_Settings gp_sculpt
GpWeightPaint * gp_weightpaint
struct CurveMapping * curve_rand_saturation
struct CurveMapping * curve_rand_value
struct CurveMapping * curve_rand_hue
struct CurveMapping * curve_distance_falloff
struct IDProperty * prop
View3DShading shading
struct FreestyleConfig freestyle_config
ListBaseT< LayerCollection > layer_collections
struct IDProperty * id_properties
struct World * world_override
struct Material * mat_override
struct IDProperty * system_properties
ListBaseT< bNodeLink > links
DNA_DEPRECATED int chunksize
ListBaseT< bNode > nodes
ListBaseT< struct ScrArea > areabase
Defines a node type.
Definition BKE_node.hh:265
struct WorkSpaceInstanceHook * workspace_hook
#define N_(msgid)