Fix #33123: lamp nodes drivers not working, now uses same hacks as material
[blender.git] / source / blender / blenkernel / intern / scene.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/blenkernel/intern/scene.c
29  *  \ingroup bke
30  */
31
32
33 #include <stddef.h>
34 #include <stdio.h>
35 #include <string.h>
36
37 #ifndef WIN32 
38 #include <unistd.h>
39 #else
40 #include <io.h>
41 #endif
42
43 #include "MEM_guardedalloc.h"
44
45 #include "DNA_anim_types.h"
46 #include "DNA_group_types.h"
47 #include "DNA_node_types.h"
48 #include "DNA_object_types.h"
49 #include "DNA_scene_types.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_sequence_types.h"
52
53 #include "BLI_math.h"
54 #include "BLI_blenlib.h"
55 #include "BLI_utildefines.h"
56 #include "BLI_callbacks.h"
57 #include "BLI_string.h"
58
59 #include "BKE_anim.h"
60 #include "BKE_animsys.h"
61 #include "BKE_action.h"
62 #include "BKE_colortools.h"
63 #include "BKE_depsgraph.h"
64 #include "BKE_fcurve.h"
65 #include "BKE_global.h"
66 #include "BKE_group.h"
67 #include "BKE_idprop.h"
68 #include "BKE_library.h"
69 #include "BKE_main.h"
70 #include "BKE_mask.h"
71 #include "BKE_node.h"
72 #include "BKE_object.h"
73 #include "BKE_paint.h"
74 #include "BKE_pointcache.h"
75 #include "BKE_scene.h"
76 #include "BKE_sequencer.h"
77 #include "BKE_world.h"
78
79 #include "BKE_sound.h"
80
81 #include "RE_engine.h"
82
83 #include "IMB_colormanagement.h"
84
85 //XXX #include "BIF_previewrender.h"
86 //XXX #include "BIF_editseq.h"
87
88 #ifdef WIN32
89 #else
90 #include <sys/time.h>
91 #endif
92
93 void free_avicodecdata(AviCodecData *acd)
94 {
95         if (acd) {
96                 if (acd->lpFormat) {
97                         MEM_freeN(acd->lpFormat);
98                         acd->lpFormat = NULL;
99                         acd->cbFormat = 0;
100                 }
101                 if (acd->lpParms) {
102                         MEM_freeN(acd->lpParms);
103                         acd->lpParms = NULL;
104                         acd->cbParms = 0;
105                 }
106         }
107 }
108
109 void free_qtcodecdata(QuicktimeCodecData *qcd)
110 {
111         if (qcd) {
112                 if (qcd->cdParms) {
113                         MEM_freeN(qcd->cdParms);
114                         qcd->cdParms = NULL;
115                         qcd->cdSize = 0;
116                 }
117         }
118 }
119
120 static void remove_sequencer_fcurves(Scene *sce)
121 {
122         AnimData *adt = BKE_animdata_from_id(&sce->id);
123
124         if (adt && adt->action) {
125                 FCurve *fcu, *nextfcu;
126                 
127                 for (fcu = adt->action->curves.first; fcu; fcu = nextfcu) {
128                         nextfcu = fcu->next;
129                         
130                         if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
131                                 action_groups_remove_channel(adt->action, fcu);
132                                 free_fcurve(fcu);
133                         }
134                 }
135         }
136 }
137
138 Scene *BKE_scene_copy(Scene *sce, int type)
139 {
140         Scene *scen;
141         ToolSettings *ts;
142         Base *base, *obase;
143         
144         if (type == SCE_COPY_EMPTY) {
145                 ListBase lb;
146                 scen = BKE_scene_add(sce->id.name + 2);
147                 
148                 lb = scen->r.layers;
149                 scen->r = sce->r;
150                 scen->r.layers = lb;
151                 scen->unit = sce->unit;
152                 scen->physics_settings = sce->physics_settings;
153                 scen->gm = sce->gm;
154                 scen->audio = sce->audio;
155
156                 MEM_freeN(scen->toolsettings);
157         }
158         else {
159                 scen = BKE_libblock_copy(&sce->id);
160                 BLI_duplicatelist(&(scen->base), &(sce->base));
161                 
162                 clear_id_newpoins();
163                 
164                 id_us_plus((ID *)scen->world);
165                 id_us_plus((ID *)scen->set);
166                 id_us_plus((ID *)scen->gm.dome.warptext);
167
168                 scen->ed = NULL;
169                 scen->theDag = NULL;
170                 scen->obedit = NULL;
171                 scen->stats = NULL;
172                 scen->fps_info = NULL;
173
174                 BLI_duplicatelist(&(scen->markers), &(sce->markers));
175                 BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces));
176                 BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers));
177                 BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets));
178
179                 if (sce->nodetree) {
180                         /* ID's are managed on both copy and switch */
181                         scen->nodetree = ntreeCopyTree(sce->nodetree);
182                         ntreeSwitchID(scen->nodetree, &sce->id, &scen->id);
183                 }
184
185                 obase = sce->base.first;
186                 base = scen->base.first;
187                 while (base) {
188                         id_us_plus(&base->object->id);
189                         if (obase == sce->basact) scen->basact = base;
190         
191                         obase = obase->next;
192                         base = base->next;
193                 }
194
195                 /* copy color management settings */
196                 BKE_color_managed_display_settings_copy(&scen->display_settings, &sce->display_settings);
197                 BKE_color_managed_view_settings_copy(&scen->view_settings, &sce->view_settings);
198                 BKE_color_managed_view_settings_copy(&scen->r.im_format.view_settings, &sce->r.im_format.view_settings);
199
200                 BLI_strncpy(scen->sequencer_colorspace_settings.name, sce->sequencer_colorspace_settings.name,
201                             sizeof(scen->sequencer_colorspace_settings.name));
202
203                 /* remove animation used by sequencer */
204                 if (type != SCE_COPY_FULL)
205                         remove_sequencer_fcurves(scen);
206         }
207
208         /* tool settings */
209         scen->toolsettings = MEM_dupallocN(sce->toolsettings);
210
211         ts = scen->toolsettings;
212         if (ts) {
213                 if (ts->vpaint) {
214                         ts->vpaint = MEM_dupallocN(ts->vpaint);
215                         ts->vpaint->paintcursor = NULL;
216                         ts->vpaint->vpaint_prev = NULL;
217                         ts->vpaint->wpaint_prev = NULL;
218                         BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint);
219                 }
220                 if (ts->wpaint) {
221                         ts->wpaint = MEM_dupallocN(ts->wpaint);
222                         ts->wpaint->paintcursor = NULL;
223                         ts->wpaint->vpaint_prev = NULL;
224                         ts->wpaint->wpaint_prev = NULL;
225                         BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint);
226                 }
227                 if (ts->sculpt) {
228                         ts->sculpt = MEM_dupallocN(ts->sculpt);
229                         BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint);
230                 }
231
232                 BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint);
233                 ts->imapaint.paintcursor = NULL;
234                 ts->particle.paintcursor = NULL;
235         }
236         
237         /* make a private copy of the avicodecdata */
238         if (sce->r.avicodecdata) {
239                 scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
240                 scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
241                 scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
242         }
243         
244         /* make a private copy of the qtcodecdata */
245         if (sce->r.qtcodecdata) {
246                 scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata);
247                 scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
248         }
249         
250         if (sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */
251                 scen->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties);
252         }
253
254         /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations
255          * are done outside of blenkernel with ED_objects_single_users! */
256
257         /*  camera */
258         if (type == SCE_COPY_LINK_DATA || type == SCE_COPY_FULL) {
259                 ID_NEW(scen->camera);
260         }
261         
262         /* before scene copy */
263         sound_create_scene(scen);
264
265         /* world */
266         if (type == SCE_COPY_FULL) {
267                 BKE_copy_animdata_id_action((ID *)scen);
268                 if (scen->world) {
269                         id_us_plus((ID *)scen->world);
270                         scen->world = BKE_world_copy(scen->world);
271                         BKE_copy_animdata_id_action((ID *)scen->world);
272                 }
273
274                 if (sce->ed) {
275                         scen->ed = MEM_callocN(sizeof(Editing), "addseq");
276                         scen->ed->seqbasep = &scen->ed->seqbase;
277                         BKE_sequence_base_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL);
278                 }
279         }
280
281         return scen;
282 }
283
284 /* do not free scene itself */
285 void BKE_scene_free(Scene *sce)
286 {
287         Base *base;
288
289         base = sce->base.first;
290         while (base) {
291                 base->object->id.us--;
292                 base = base->next;
293         }
294         /* do not free objects! */
295         
296         if (sce->gpd) {
297 #if 0   /* removed since this can be invalid memory when freeing everything */
298                 /* since the grease pencil data is freed before the scene.
299                  * since grease pencil data is not (yet?), shared between objects
300                  * its probably safe not to do this, some save and reload will free this. */
301                 sce->gpd->id.us--;
302 #endif
303                 sce->gpd = NULL;
304         }
305
306         BLI_freelistN(&sce->base);
307         BKE_sequencer_editing_free(sce);
308
309         BKE_free_animdata((ID *)sce);
310         BKE_keyingsets_free(&sce->keyingsets);
311         
312         if (sce->r.avicodecdata) {
313                 free_avicodecdata(sce->r.avicodecdata);
314                 MEM_freeN(sce->r.avicodecdata);
315                 sce->r.avicodecdata = NULL;
316         }
317         if (sce->r.qtcodecdata) {
318                 free_qtcodecdata(sce->r.qtcodecdata);
319                 MEM_freeN(sce->r.qtcodecdata);
320                 sce->r.qtcodecdata = NULL;
321         }
322         if (sce->r.ffcodecdata.properties) {
323                 IDP_FreeProperty(sce->r.ffcodecdata.properties);
324                 MEM_freeN(sce->r.ffcodecdata.properties);
325                 sce->r.ffcodecdata.properties = NULL;
326         }
327         
328         BLI_freelistN(&sce->markers);
329         BLI_freelistN(&sce->transform_spaces);
330         BLI_freelistN(&sce->r.layers);
331         
332         if (sce->toolsettings) {
333                 if (sce->toolsettings->vpaint) {
334                         BKE_paint_free(&sce->toolsettings->vpaint->paint);
335                         MEM_freeN(sce->toolsettings->vpaint);
336                 }
337                 if (sce->toolsettings->wpaint) {
338                         BKE_paint_free(&sce->toolsettings->wpaint->paint);
339                         MEM_freeN(sce->toolsettings->wpaint);
340                 }
341                 if (sce->toolsettings->sculpt) {
342                         BKE_paint_free(&sce->toolsettings->sculpt->paint);
343                         MEM_freeN(sce->toolsettings->sculpt);
344                 }
345                 if (sce->toolsettings->uvsculpt) {
346                         BKE_paint_free(&sce->toolsettings->uvsculpt->paint);
347                         MEM_freeN(sce->toolsettings->uvsculpt);
348                 }
349                 BKE_paint_free(&sce->toolsettings->imapaint.paint);
350
351                 MEM_freeN(sce->toolsettings);
352                 sce->toolsettings = NULL;
353         }
354         
355         if (sce->theDag) {
356                 free_forest(sce->theDag);
357                 MEM_freeN(sce->theDag);
358         }
359         
360         if (sce->nodetree) {
361                 ntreeFreeTree(sce->nodetree);
362                 MEM_freeN(sce->nodetree);
363         }
364
365         if (sce->stats)
366                 MEM_freeN(sce->stats);
367         if (sce->fps_info)
368                 MEM_freeN(sce->fps_info);
369
370         sound_destroy_scene(sce);
371
372         BKE_color_managed_view_settings_free(&sce->view_settings);
373 }
374
375 Scene *BKE_scene_add(const char *name)
376 {
377         Main *bmain = G.main;
378         Scene *sce;
379         ParticleEditSettings *pset;
380         int a;
381         const char *colorspace_name;
382
383         sce = BKE_libblock_alloc(&bmain->scene, ID_SCE, name);
384         sce->lay = sce->layact = 1;
385         
386         sce->r.mode = R_GAMMA | R_OSA | R_SHADOW | R_SSS | R_ENVMAP | R_RAYTRACE;
387         sce->r.cfra = 1;
388         sce->r.sfra = 1;
389         sce->r.efra = 250;
390         sce->r.frame_step = 1;
391         sce->r.xsch = 1920;
392         sce->r.ysch = 1080;
393         sce->r.xasp = 1;
394         sce->r.yasp = 1;
395         sce->r.tilex = 256;
396         sce->r.tiley = 256;
397         sce->r.mblur_samples = 1;
398         sce->r.filtertype = R_FILTER_MITCH;
399         sce->r.size = 50;
400
401         sce->r.im_format.planes = R_IMF_PLANES_RGB;
402         sce->r.im_format.imtype = R_IMF_IMTYPE_PNG;
403         sce->r.im_format.quality = 90;
404
405         sce->r.displaymode = R_OUTPUT_AREA;
406         sce->r.framapto = 100;
407         sce->r.images = 100;
408         sce->r.framelen = 1.0;
409         sce->r.blurfac = 0.5;
410         sce->r.frs_sec = 24;
411         sce->r.frs_sec_base = 1;
412         sce->r.edgeint = 10;
413         sce->r.ocres = 128;
414
415         /* OCIO_TODO: for forwards compatibility only, so if no tonecurve are used,
416          *            images would look in the same way as in current blender
417          *
418          *            perhaps at some point should be completely deprecated?
419          */
420         sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
421
422         sce->r.gauss = 1.0;
423         
424         /* deprecated but keep for upwards compat */
425         sce->r.postgamma = 1.0;
426         sce->r.posthue = 0.0;
427         sce->r.postsat = 1.0;
428
429         sce->r.bake_mode = 1;    /* prevent to include render stuff here */
430         sce->r.bake_filter = 2;
431         sce->r.bake_osa = 5;
432         sce->r.bake_flag = R_BAKE_CLEAR;
433         sce->r.bake_normal_space = R_BAKE_SPACE_TANGENT;
434         sce->r.scemode = R_DOCOMP | R_DOSEQ | R_EXTENSION;
435         sce->r.stamp = R_STAMP_TIME | R_STAMP_FRAME | R_STAMP_DATE | R_STAMP_CAMERA | R_STAMP_SCENE | R_STAMP_FILENAME | R_STAMP_RENDERTIME;
436         sce->r.stamp_font_id = 12;
437         sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f;
438         sce->r.fg_stamp[3] = 1.0f;
439         sce->r.bg_stamp[0] = sce->r.bg_stamp[1] = sce->r.bg_stamp[2] = 0.0f;
440         sce->r.bg_stamp[3] = 0.25f;
441         sce->r.raytrace_options = R_RAYTRACE_USE_INSTANCES;
442
443         sce->r.seq_prev_type = OB_SOLID;
444         sce->r.seq_rend_type = OB_SOLID;
445         sce->r.seq_flag = R_SEQ_GL_PREV;
446
447         sce->r.threads = 1;
448
449         sce->r.simplify_subsurf = 6;
450         sce->r.simplify_particles = 1.0f;
451         sce->r.simplify_shadowsamples = 16;
452         sce->r.simplify_aosss = 1.0f;
453
454         sce->r.border.xmin = 0.0f;
455         sce->r.border.ymin = 0.0f;
456         sce->r.border.xmax = 1.0f;
457         sce->r.border.ymax = 1.0f;
458         
459         sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
460         sce->toolsettings->cornertype = 1;
461         sce->toolsettings->degr = 90; 
462         sce->toolsettings->step = 9;
463         sce->toolsettings->turn = 1;
464         sce->toolsettings->extr_offs = 1; 
465         sce->toolsettings->doublimit = 0.001;
466         sce->toolsettings->segments = 32;
467         sce->toolsettings->rings = 32;
468         sce->toolsettings->vertices = 32;
469         sce->toolsettings->uvcalc_radius = 1.0f;
470         sce->toolsettings->uvcalc_cubesize = 1.0f;
471         sce->toolsettings->uvcalc_mapdir = 1;
472         sce->toolsettings->uvcalc_mapalign = 1;
473         sce->toolsettings->uvcalc_margin = 0.001f;
474         sce->toolsettings->unwrapper = 1;
475         sce->toolsettings->select_thresh = 0.01f;
476         sce->toolsettings->jointrilimit = 0.8f;
477
478         sce->toolsettings->selectmode = SCE_SELECT_VERTEX;
479         sce->toolsettings->uv_selectmode = UV_SELECT_VERTEX;
480         sce->toolsettings->normalsize = 0.1;
481         sce->toolsettings->autokey_mode = U.autokey_mode;
482
483         sce->toolsettings->skgen_resolution = 100;
484         sce->toolsettings->skgen_threshold_internal     = 0.01f;
485         sce->toolsettings->skgen_threshold_external     = 0.01f;
486         sce->toolsettings->skgen_angle_limit            = 45.0f;
487         sce->toolsettings->skgen_length_ratio           = 1.3f;
488         sce->toolsettings->skgen_length_limit           = 1.5f;
489         sce->toolsettings->skgen_correlation_limit      = 0.98f;
490         sce->toolsettings->skgen_symmetry_limit         = 0.1f;
491         sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
492         sce->toolsettings->skgen_postpro_passes = 1;
493         sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL | SKGEN_FILTER_EXTERNAL | SKGEN_FILTER_SMART | SKGEN_HARMONIC | SKGEN_SUB_CORRELATION | SKGEN_STICK_TO_EMBEDDING;
494         sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
495         sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
496         sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
497
498         sce->toolsettings->proportional_size = 1.0f;
499
500         sce->physics_settings.gravity[0] = 0.0f;
501         sce->physics_settings.gravity[1] = 0.0f;
502         sce->physics_settings.gravity[2] = -9.81f;
503         sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
504
505         sce->unit.scale_length = 1.0f;
506
507         pset = &sce->toolsettings->particle;
508         pset->flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY;
509         pset->emitterdist = 0.25f;
510         pset->totrekey = 5;
511         pset->totaddkey = 5;
512         pset->brushtype = PE_BRUSH_NONE;
513         pset->draw_step = 2;
514         pset->fade_frames = 2;
515         pset->selectmode = SCE_SELECT_PATH;
516         for (a = 0; a < PE_TOT_BRUSH; a++) {
517                 pset->brush[a].strength = 0.5;
518                 pset->brush[a].size = 50;
519                 pset->brush[a].step = 10;
520                 pset->brush[a].count = 10;
521         }
522         pset->brush[PE_BRUSH_CUT].strength = 100;
523
524         sce->r.ffcodecdata.audio_mixrate = 44100;
525         sce->r.ffcodecdata.audio_volume = 1.0f;
526         sce->r.ffcodecdata.audio_bitrate = 192;
527         sce->r.ffcodecdata.audio_channels = 2;
528
529         BLI_strncpy(sce->r.engine, "BLENDER_RENDER", sizeof(sce->r.engine));
530
531         sce->audio.distance_model = 2.0f;
532         sce->audio.doppler_factor = 1.0f;
533         sce->audio.speed_of_sound = 343.3f;
534         sce->audio.volume = 1.0f;
535
536         BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic));
537
538         BLI_rctf_init(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
539         sce->r.osa = 8;
540
541         /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
542         BKE_scene_add_render_layer(sce, NULL);
543         
544         /* game data */
545         sce->gm.stereoflag = STEREO_NOSTEREO;
546         sce->gm.stereomode = STEREO_ANAGLYPH;
547         sce->gm.eyeseparation = 0.10;
548
549         sce->gm.dome.angle = 180;
550         sce->gm.dome.mode = DOME_FISHEYE;
551         sce->gm.dome.res = 4;
552         sce->gm.dome.resbuf = 1.0f;
553         sce->gm.dome.tilt = 0;
554
555         sce->gm.xplay = 640;
556         sce->gm.yplay = 480;
557         sce->gm.freqplay = 60;
558         sce->gm.depth = 32;
559
560         sce->gm.gravity = 9.8f;
561         sce->gm.physicsEngine = WOPHY_BULLET;
562         sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling 
563         sce->gm.occlusionRes = 128;
564         sce->gm.ticrate = 60;
565         sce->gm.maxlogicstep = 5;
566         sce->gm.physubstep = 1;
567         sce->gm.maxphystep = 5;
568         sce->gm.lineardeactthreshold = 0.8f;
569         sce->gm.angulardeactthreshold = 1.0f;
570         sce->gm.deactivationtime = 0.0f;
571
572         sce->gm.flag = GAME_DISPLAY_LISTS;
573         sce->gm.matmode = GAME_MAT_MULTITEX;
574
575         sce->gm.obstacleSimulation = OBSTSIMULATION_NONE;
576         sce->gm.levelHeight = 2.f;
577
578         sce->gm.recastData.cellsize = 0.3f;
579         sce->gm.recastData.cellheight = 0.2f;
580         sce->gm.recastData.agentmaxslope = M_PI / 2;
581         sce->gm.recastData.agentmaxclimb = 0.9f;
582         sce->gm.recastData.agentheight = 2.0f;
583         sce->gm.recastData.agentradius = 0.6f;
584         sce->gm.recastData.edgemaxlen = 12.0f;
585         sce->gm.recastData.edgemaxerror = 1.3f;
586         sce->gm.recastData.regionminsize = 8.f;
587         sce->gm.recastData.regionmergesize = 20.f;
588         sce->gm.recastData.vertsperpoly = 6;
589         sce->gm.recastData.detailsampledist = 6.0f;
590         sce->gm.recastData.detailsamplemaxerror = 1.0f;
591
592         sce->gm.exitkey = 218; // Blender key code for ESC
593
594         sound_create_scene(sce);
595
596         /* color management */
597         colorspace_name = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_SEQUENCER);
598
599         BKE_color_managed_display_settings_init(&sce->display_settings);
600         BKE_color_managed_view_settings_init(&sce->view_settings);
601         BLI_strncpy(sce->sequencer_colorspace_settings.name, colorspace_name,
602                     sizeof(sce->sequencer_colorspace_settings.name));
603
604         return sce;
605 }
606
607 Base *BKE_scene_base_find(Scene *scene, Object *ob)
608 {
609         return BLI_findptr(&scene->base, ob, offsetof(Base, object));
610 }
611
612 void BKE_scene_set_background(Main *bmain, Scene *scene)
613 {
614         Scene *sce;
615         Base *base;
616         Object *ob;
617         Group *group;
618         GroupObject *go;
619         int flag;
620         
621         /* check for cyclic sets, for reading old files but also for definite security (py?) */
622         BKE_scene_validate_setscene(bmain, scene);
623         
624         /* can happen when switching modes in other scenes */
625         if (scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT))
626                 scene->obedit = NULL;
627
628         /* deselect objects (for dataselect) */
629         for (ob = bmain->object.first; ob; ob = ob->id.next)
630                 ob->flag &= ~(SELECT | OB_FROMGROUP);
631
632         /* group flags again */
633         for (group = bmain->group.first; group; group = group->id.next) {
634                 for (go = group->gobject.first; go; go = go->next) {
635                         if (go->ob) {
636                                 go->ob->flag |= OB_FROMGROUP;
637                         }
638                 }
639         }
640
641         /* sort baselist */
642         DAG_scene_sort(bmain, scene);
643         
644         /* ensure dags are built for sets */
645         for (sce = scene->set; sce; sce = sce->set)
646                 if (sce->theDag == NULL)
647                         DAG_scene_sort(bmain, sce);
648
649         /* copy layers and flags from bases to objects */
650         for (base = scene->base.first; base; base = base->next) {
651                 ob = base->object;
652                 ob->lay = base->lay;
653                 
654                 /* group patch... */
655                 base->flag &= ~(OB_FROMGROUP);
656                 flag = ob->flag & (OB_FROMGROUP);
657                 base->flag |= flag;
658                 
659                 /* not too nice... for recovering objects with lost data */
660                 //if (ob->pose == NULL) base->flag &= ~OB_POSEMODE;
661                 ob->flag = base->flag;
662         }
663         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
664 }
665
666 /* called from creator.c */
667 Scene *BKE_scene_set_name(Main *bmain, const char *name)
668 {
669         Scene *sce = (Scene *)BKE_libblock_find_name(ID_SCE, name);
670         if (sce) {
671                 BKE_scene_set_background(bmain, sce);
672                 printf("Scene switch: '%s' in file: '%s'\n", name, G.main->name);
673                 return sce;
674         }
675
676         printf("Can't find scene: '%s' in file: '%s'\n", name, G.main->name);
677         return NULL;
678 }
679
680 void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce)
681 {
682         Scene *sce1;
683         bScreen *sc;
684
685         /* check all sets */
686         for (sce1 = bmain->scene.first; sce1; sce1 = sce1->id.next)
687                 if (sce1->set == sce)
688                         sce1->set = NULL;
689         
690         /* check all sequences */
691         BKE_sequencer_clear_scene_in_allseqs(bmain, sce);
692
693         /* check render layer nodes in other scenes */
694         clear_scene_in_nodes(bmain, sce);
695         
696         /* al screens */
697         for (sc = bmain->screen.first; sc; sc = sc->id.next)
698                 if (sc->scene == sce)
699                         sc->scene = newsce;
700
701         BKE_libblock_free(&bmain->scene, sce);
702 }
703
704 /* used by metaballs
705  * doesnt return the original duplicated object, only dupli's
706  */
707 int BKE_scene_base_iter_next(Scene **scene, int val, Base **base, Object **ob)
708 {
709         static ListBase *duplilist = NULL;
710         static DupliObject *dupob;
711         static int fase = F_START, in_next_object = 0;
712         int run_again = 1;
713         
714         /* init */
715         if (val == 0) {
716                 fase = F_START;
717                 dupob = NULL;
718                 
719                 /* XXX particle systems with metas+dupligroups call this recursively */
720                 /* see bug #18725 */
721                 if (in_next_object) {
722                         printf("ERROR: Metaball generation called recursively, not supported\n");
723                         
724                         return F_ERROR;
725                 }
726         }
727         else {
728                 in_next_object = 1;
729                 
730                 /* run_again is set when a duplilist has been ended */
731                 while (run_again) {
732                         run_again = 0;
733
734                         /* the first base */
735                         if (fase == F_START) {
736                                 *base = (*scene)->base.first;
737                                 if (*base) {
738                                         *ob = (*base)->object;
739                                         fase = F_SCENE;
740                                 }
741                                 else {
742                                         /* exception: empty scene */
743                                         while ((*scene)->set) {
744                                                 (*scene) = (*scene)->set;
745                                                 if ((*scene)->base.first) {
746                                                         *base = (*scene)->base.first;
747                                                         *ob = (*base)->object;
748                                                         fase = F_SCENE;
749                                                         break;
750                                                 }
751                                         }
752                                 }
753                         }
754                         else {
755                                 if (*base && fase != F_DUPLI) {
756                                         *base = (*base)->next;
757                                         if (*base) *ob = (*base)->object;
758                                         else {
759                                                 if (fase == F_SCENE) {
760                                                         /* (*scene) is finished, now do the set */
761                                                         while ((*scene)->set) {
762                                                                 (*scene) = (*scene)->set;
763                                                                 if ((*scene)->base.first) {
764                                                                         *base = (*scene)->base.first;
765                                                                         *ob = (*base)->object;
766                                                                         break;
767                                                                 }
768                                                         }
769                                                 }
770                                         }
771                                 }
772                         }
773                         
774                         if (*base == NULL) fase = F_START;
775                         else {
776                                 if (fase != F_DUPLI) {
777                                         if ( (*base)->object->transflag & OB_DUPLI) {
778                                                 /* groups cannot be duplicated for mballs yet, 
779                                                  * this enters eternal loop because of 
780                                                  * makeDispListMBall getting called inside of group_duplilist */
781                                                 if ((*base)->object->dup_group == NULL) {
782                                                         duplilist = object_duplilist((*scene), (*base)->object, FALSE);
783                                                         
784                                                         dupob = duplilist->first;
785
786                                                         if (!dupob)
787                                                                 free_object_duplilist(duplilist);
788                                                 }
789                                         }
790                                 }
791                                 /* handle dupli's */
792                                 if (dupob) {
793                                         
794                                         copy_m4_m4(dupob->ob->obmat, dupob->mat);
795                                         
796                                         (*base)->flag |= OB_FROMDUPLI;
797                                         *ob = dupob->ob;
798                                         fase = F_DUPLI;
799                                         
800                                         dupob = dupob->next;
801                                 }
802                                 else if (fase == F_DUPLI) {
803                                         fase = F_SCENE;
804                                         (*base)->flag &= ~OB_FROMDUPLI;
805                                         
806                                         for (dupob = duplilist->first; dupob; dupob = dupob->next) {
807                                                 copy_m4_m4(dupob->ob->obmat, dupob->omat);
808                                         }
809                                         
810                                         free_object_duplilist(duplilist);
811                                         duplilist = NULL;
812                                         run_again = 1;
813                                 }
814                         }
815                 }
816         }
817
818 #if 0
819         if (ob && *ob) {
820                 printf("Scene: '%s', '%s'\n", (*scene)->id.name + 2, (*ob)->id.name + 2);
821         }
822 #endif
823
824         /* reset recursion test */
825         in_next_object = 0;
826         
827         return fase;
828 }
829
830 Object *BKE_scene_camera_find(Scene *sc)
831 {
832         Base *base;
833         
834         for (base = sc->base.first; base; base = base->next)
835                 if (base->object->type == OB_CAMERA)
836                         return base->object;
837
838         return NULL;
839 }
840
841 #ifdef DURIAN_CAMERA_SWITCH
842 Object *BKE_scene_camera_switch_find(Scene *scene)
843 {
844         TimeMarker *m;
845         int cfra = scene->r.cfra;
846         int frame = -(MAXFRAME + 1);
847         Object *camera = NULL;
848
849         for (m = scene->markers.first; m; m = m->next) {
850                 if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0 && (m->frame <= cfra) && (m->frame > frame)) {
851                         camera = m->camera;
852                         frame = m->frame;
853
854                         if (frame == cfra)
855                                 break;
856
857                 }
858         }
859         return camera;
860 }
861 #endif
862
863 int BKE_scene_camera_switch_update(Scene *scene)
864 {
865 #ifdef DURIAN_CAMERA_SWITCH
866         Object *camera = BKE_scene_camera_switch_find(scene);
867         if (camera) {
868                 scene->camera = camera;
869                 return 1;
870         }
871 #else
872         (void)scene;
873 #endif
874         return 0;
875 }
876
877 char *BKE_scene_find_marker_name(Scene *scene, int frame)
878 {
879         ListBase *markers = &scene->markers;
880         TimeMarker *m1, *m2;
881
882         /* search through markers for match */
883         for (m1 = markers->first, m2 = markers->last; m1 && m2; m1 = m1->next, m2 = m2->prev) {
884                 if (m1->frame == frame)
885                         return m1->name;
886
887                 if (m1 == m2)
888                         break;
889
890                 if (m2->frame == frame)
891                         return m2->name;
892         }
893
894         return NULL;
895 }
896
897 /* return the current marker for this frame,
898  * we can have more then 1 marker per frame, this just returns the first :/ */
899 char *BKE_scene_find_last_marker_name(Scene *scene, int frame)
900 {
901         TimeMarker *marker, *best_marker = NULL;
902         int best_frame = -MAXFRAME * 2;
903         for (marker = scene->markers.first; marker; marker = marker->next) {
904                 if (marker->frame == frame) {
905                         return marker->name;
906                 }
907
908                 if (marker->frame > best_frame && marker->frame < frame) {
909                         best_marker = marker;
910                         best_frame = marker->frame;
911                 }
912         }
913
914         return best_marker ? best_marker->name : NULL;
915 }
916
917
918 Base *BKE_scene_base_add(Scene *sce, Object *ob)
919 {
920         Base *b = MEM_callocN(sizeof(*b), "BKE_scene_base_add");
921         BLI_addhead(&sce->base, b);
922
923         b->object = ob;
924         b->flag = ob->flag;
925         b->lay = ob->lay;
926
927         return b;
928 }
929
930 void BKE_scene_base_deselect_all(Scene *sce)
931 {
932         Base *b;
933
934         for (b = sce->base.first; b; b = b->next) {
935                 b->flag &= ~SELECT;
936                 b->object->flag = b->flag;
937         }
938 }
939
940 void BKE_scene_base_select(Scene *sce, Base *selbase)
941 {
942         selbase->flag |= SELECT;
943         selbase->object->flag = selbase->flag;
944
945         sce->basact = selbase;
946 }
947
948 /* checks for cycle, returns 1 if it's all OK */
949 int BKE_scene_validate_setscene(Main *bmain, Scene *sce)
950 {
951         Scene *scene;
952         int a, totscene;
953         
954         if (sce->set == NULL) return 1;
955         
956         totscene = 0;
957         for (scene = bmain->scene.first; scene; scene = scene->id.next)
958                 totscene++;
959         
960         for (a = 0, scene = sce; scene->set; scene = scene->set, a++) {
961                 /* more iterations than scenes means we have a cycle */
962                 if (a > totscene) {
963                         /* the tested scene gets zero'ed, that's typically current scene */
964                         sce->set = NULL;
965                         return 0;
966                 }
967         }
968
969         return 1;
970 }
971
972 /* This function is needed to cope with fractional frames - including two Blender rendering features
973  * mblur (motion blur that renders 'subframes' and blurs them together), and fields rendering. 
974  */
975 float BKE_scene_frame_get(Scene *scene)
976 {
977         return BKE_scene_frame_get_from_ctime(scene, scene->r.cfra);
978 }
979
980 /* This function is used to obtain arbitrary fractional frames */
981 float BKE_scene_frame_get_from_ctime(Scene *scene, const float frame)
982 {
983         float ctime = frame;
984         ctime += scene->r.subframe;
985         ctime *= scene->r.framelen;
986         
987         return ctime;
988 }
989
990 /* drivers support/hacks 
991  *  - this method is called from scene_update_tagged_recursive(), so gets included in viewport + render
992  *      - these are always run since the depsgraph can't handle non-object data
993  *      - these happen after objects are all done so that we can read in their final transform values,
994  *        though this means that objects can't refer to scene info for guidance...
995  */
996 static void scene_update_drivers(Main *UNUSED(bmain), Scene *scene)
997 {
998         float ctime = BKE_scene_frame_get(scene);
999         
1000         /* scene itself */
1001         if (scene->adt && scene->adt->drivers.first) {
1002                 BKE_animsys_evaluate_animdata(scene, &scene->id, scene->adt, ctime, ADT_RECALC_DRIVERS);
1003         }
1004
1005         /* world */
1006         /* TODO: what about world textures? but then those have nodes too... */
1007         if (scene->world) {
1008                 ID *wid = (ID *)scene->world;
1009                 AnimData *adt = BKE_animdata_from_id(wid);
1010                 
1011                 if (adt && adt->drivers.first)
1012                         BKE_animsys_evaluate_animdata(scene, wid, adt, ctime, ADT_RECALC_DRIVERS);
1013         }
1014         
1015         /* nodes */
1016         if (scene->nodetree) {
1017                 ID *nid = (ID *)scene->nodetree;
1018                 AnimData *adt = BKE_animdata_from_id(nid);
1019                 
1020                 if (adt && adt->drivers.first)
1021                         BKE_animsys_evaluate_animdata(scene, nid, adt, ctime, ADT_RECALC_DRIVERS);
1022         }
1023 }
1024
1025 static void scene_update_tagged_recursive(Main *bmain, Scene *scene, Scene *scene_parent)
1026 {
1027         Base *base;
1028         
1029         
1030         scene->customdata_mask = scene_parent->customdata_mask;
1031
1032         /* sets first, we allow per definition current scene to have
1033          * dependencies on sets, but not the other way around. */
1034         if (scene->set)
1035                 scene_update_tagged_recursive(bmain, scene->set, scene_parent);
1036         
1037         /* scene objects */
1038         for (base = scene->base.first; base; base = base->next) {
1039                 Object *ob = base->object;
1040                 
1041                 BKE_object_handle_update(scene_parent, ob);
1042                 
1043                 if (ob->dup_group && (ob->transflag & OB_DUPLIGROUP))
1044                         group_handle_recalc_and_update(scene_parent, ob, ob->dup_group);
1045                         
1046                 /* always update layer, so that animating layers works (joshua july 2010) */
1047                 /* XXX commented out, this has depsgraph issues anyway - and this breaks setting scenes
1048                    (on scene-set, the base-lay is copied to ob-lay (ton nov 2012) */
1049                 // base->lay = ob->lay;
1050         }
1051         
1052         /* scene drivers... */
1053         scene_update_drivers(bmain, scene);
1054
1055         /* update sound system animation */
1056         sound_update_scene(scene);
1057
1058         /* update masking curves */
1059         BKE_mask_update_scene(bmain, scene, FALSE);
1060 }
1061
1062 /* this is called in main loop, doing tagged updates before redraw */
1063 void BKE_scene_update_tagged(Main *bmain, Scene *scene)
1064 {
1065         /* keep this first */
1066         BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_PRE);
1067
1068         /* flush recalc flags to dependencies */
1069         DAG_ids_flush_tagged(bmain);
1070
1071         /* removed calls to quick_cache, see pointcache.c */
1072         
1073         /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later 
1074          * when trying to find materials with drivers that need evaluating [#32017] 
1075          */
1076         tag_main_idcode(bmain, ID_MA, FALSE);
1077         tag_main_idcode(bmain, ID_LA, FALSE);
1078
1079         /* update all objects: drivers, matrices, displists, etc. flags set
1080          * by depgraph or manual, no layer check here, gets correct flushed
1081          *
1082          * in the future this should handle updates for all datablocks, not
1083          * only objects and scenes. - brecht */
1084         scene_update_tagged_recursive(bmain, scene, scene);
1085
1086         /* extra call here to recalc scene animation (for sequencer) */
1087         {
1088                 AnimData *adt = BKE_animdata_from_id(&scene->id);
1089                 float ctime = BKE_scene_frame_get(scene);
1090                 
1091                 if (adt && (adt->recalc & ADT_RECALC_ANIM))
1092                         BKE_animsys_evaluate_animdata(scene, &scene->id, adt, ctime, 0);
1093         }
1094         
1095         /* notify editors and python about recalc */
1096         BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_POST);
1097         DAG_ids_check_recalc(bmain, scene, FALSE);
1098
1099         /* clear recalc flags */
1100         DAG_ids_clear_recalc(bmain);
1101 }
1102
1103 /* applies changes right away, does all sets too */
1104 void BKE_scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay)
1105 {
1106         float ctime = BKE_scene_frame_get(sce);
1107         Scene *sce_iter;
1108
1109         /* keep this first */
1110         BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_PRE);
1111         BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_SCENE_UPDATE_PRE);
1112
1113         sound_set_cfra(sce->r.cfra);
1114         
1115         /* clear animation overrides */
1116         /* XXX TODO... */
1117
1118         for (sce_iter = sce; sce_iter; sce_iter = sce_iter->set) {
1119                 if (sce_iter->theDag == NULL)
1120                         DAG_scene_sort(bmain, sce_iter);
1121         }
1122
1123         /* flush recalc flags to dependencies, if we were only changing a frame
1124          * this would not be necessary, but if a user or a script has modified
1125          * some datablock before BKE_scene_update_tagged was called, we need the flush */
1126         DAG_ids_flush_tagged(bmain);
1127
1128         /* Following 2 functions are recursive
1129          * so don't call within 'scene_update_tagged_recursive' */
1130         DAG_scene_update_flags(bmain, sce, lay, TRUE);   // only stuff that moves or needs display still
1131
1132         BKE_mask_evaluate_all_masks(bmain, ctime, TRUE);
1133
1134         /* All 'standard' (i.e. without any dependencies) animation is handled here,
1135          * with an 'local' to 'macro' order of evaluation. This should ensure that
1136          * settings stored nestled within a hierarchy (i.e. settings in a Texture block
1137          * can be overridden by settings from Scene, which owns the Texture through a hierarchy
1138          * such as Scene->World->MTex/Texture) can still get correctly overridden.
1139          */
1140         BKE_animsys_evaluate_all_animation(bmain, sce, ctime);
1141         /*...done with recusrive funcs */
1142
1143         /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later 
1144          * when trying to find materials with drivers that need evaluating [#32017] 
1145          */
1146         tag_main_idcode(bmain, ID_MA, FALSE);
1147         tag_main_idcode(bmain, ID_LA, FALSE);
1148
1149         /* BKE_object_handle_update() on all objects, groups and sets */
1150         scene_update_tagged_recursive(bmain, sce, sce);
1151
1152         /* notify editors and python about recalc */
1153         BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_SCENE_UPDATE_POST);
1154         BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_POST);
1155
1156         DAG_ids_check_recalc(bmain, sce, TRUE);
1157
1158         /* clear recalc flags */
1159         DAG_ids_clear_recalc(bmain);
1160 }
1161
1162 /* return default layer, also used to patch old files */
1163 SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name)
1164 {
1165         SceneRenderLayer *srl;
1166
1167         if (!name)
1168                 name = "RenderLayer";
1169
1170         srl = MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
1171         BLI_strncpy(srl->name, name, sizeof(srl->name));
1172         BLI_uniquename(&sce->r.layers, srl, "RenderLayer", '.', offsetof(SceneRenderLayer, name), sizeof(srl->name));
1173         BLI_addtail(&sce->r.layers, srl);
1174
1175         /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
1176         srl->lay = (1 << 20) - 1;
1177         srl->layflag = 0x7FFF;   /* solid ztra halo edge strand */
1178         srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
1179
1180         return srl;
1181 }
1182
1183 int BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl)
1184 {
1185         const int act = BLI_findindex(&scene->r.layers, srl);
1186         Scene *sce;
1187
1188         if (act == -1) {
1189                 return 0;
1190         }
1191         else if ( (scene->r.layers.first == scene->r.layers.last) &&
1192                   (scene->r.layers.first == srl))
1193         {
1194                 /* ensure 1 layer is kept */
1195                 return 0;
1196         }
1197
1198         BLI_remlink(&scene->r.layers, srl);
1199         MEM_freeN(srl);
1200
1201         scene->r.actlay = 0;
1202
1203         for (sce = bmain->scene.first; sce; sce = sce->id.next) {
1204                 if (sce->nodetree) {
1205                         bNode *node;
1206                         for (node = sce->nodetree->nodes.first; node; node = node->next) {
1207                                 if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) {
1208                                         if (node->custom1 == act)
1209                                                 node->custom1 = 0;
1210                                         else if (node->custom1 > act)
1211                                                 node->custom1--;
1212                                 }
1213                         }
1214                 }
1215         }
1216
1217         return 1;
1218 }
1219
1220 /* render simplification */
1221
1222 int get_render_subsurf_level(RenderData *r, int lvl)
1223 {
1224         if (r->mode & R_SIMPLIFY)
1225                 return min_ii(r->simplify_subsurf, lvl);
1226         else
1227                 return lvl;
1228 }
1229
1230 int get_render_child_particle_number(RenderData *r, int num)
1231 {
1232         if (r->mode & R_SIMPLIFY)
1233                 return (int)(r->simplify_particles * num);
1234         else
1235                 return num;
1236 }
1237
1238 int get_render_shadow_samples(RenderData *r, int samples)
1239 {
1240         if ((r->mode & R_SIMPLIFY) && samples > 0)
1241                 return min_ii(r->simplify_shadowsamples, samples);
1242         else
1243                 return samples;
1244 }
1245
1246 float get_render_aosss_error(RenderData *r, float error)
1247 {
1248         if (r->mode & R_SIMPLIFY)
1249                 return ((1.0f - r->simplify_aosss) * 10.0f + 1.0f) * error;
1250         else
1251                 return error;
1252 }
1253
1254 /* helper function for the SETLOOPER macro */
1255 Base *_setlooper_base_step(Scene **sce_iter, Base *base)
1256 {
1257         if (base && base->next) {
1258                 /* common case, step to the next */
1259                 return base->next;
1260         }
1261         else if (base == NULL && (*sce_iter)->base.first) {
1262                 /* first time looping, return the scenes first base */
1263                 return (Base *)(*sce_iter)->base.first;
1264         }
1265         else {
1266                 /* reached the end, get the next base in the set */
1267                 while ((*sce_iter = (*sce_iter)->set)) {
1268                         base = (Base *)(*sce_iter)->base.first;
1269                         if (base) {
1270                                 return base;
1271                         }
1272                 }
1273         }
1274
1275         return NULL;
1276 }
1277
1278 int BKE_scene_use_new_shading_nodes(Scene *scene)
1279 {
1280         RenderEngineType *type = RE_engines_find(scene->r.engine);
1281         return (type && type->flag & RE_USE_SHADING_NODES);
1282 }
1283
1284 void BKE_scene_base_flag_to_objects(struct Scene *scene)
1285 {
1286         Base *base = scene->base.first;
1287
1288         while (base) {
1289                 base->object->flag = base->flag;
1290                 base = base->next;
1291         }
1292 }
1293
1294 void BKE_scene_base_flag_from_objects(struct Scene *scene)
1295 {
1296         Base *base = scene->base.first;
1297
1298         while (base) {
1299                 base->flag = base->object->flag;
1300                 base = base->next;
1301         }
1302 }
1303
1304 void BKE_scene_disable_color_management(Scene *scene)
1305 {
1306         ColorManagedDisplaySettings *display_settings = &scene->display_settings;
1307         ColorManagedViewSettings *view_settings = &scene->view_settings;
1308         const char *view;
1309         const char *none_display_name;
1310
1311         none_display_name = IMB_colormanagement_display_get_none_name();
1312
1313         BLI_strncpy(display_settings->display_device, none_display_name, sizeof(display_settings->display_device));
1314
1315         view = IMB_colormanagement_view_get_default_name(display_settings->display_device);
1316
1317         if (view) {
1318                 BLI_strncpy(view_settings->view_transform, view, sizeof(view_settings->view_transform));
1319         }
1320 }
1321
1322 int BKE_scene_check_color_management_enabled(const Scene *scene)
1323 {
1324         return strcmp(scene->display_settings.display_device, "None") != 0;
1325 }