2ab67ed6151bd6722d95ce29d5536837abd8e755
[blender-staging.git] / source / blender / blenkernel / intern / scene.c
1 /*  scene.c
2  *  
3  * 
4  * $Id$
5  *
6  * ***** BEGIN GPL LICENSE BLOCK *****
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL LICENSE BLOCK *****
30  */
31
32 #include <stdio.h>
33 #include <string.h>
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #ifndef WIN32 
40 #include <unistd.h>
41 #else
42 #include <io.h>
43 #endif
44 #include "MEM_guardedalloc.h"
45
46 #include "DNA_anim_types.h"
47 #include "DNA_armature_types.h" 
48 #include "DNA_color_types.h"
49 #include "DNA_constraint_types.h"
50 #include "DNA_curve_types.h"
51 #include "DNA_group_types.h"
52 #include "DNA_lamp_types.h"
53 #include "DNA_material_types.h"
54 #include "DNA_meta_types.h"
55 #include "DNA_object_types.h"
56 #include "DNA_scene_types.h"
57 #include "DNA_scriptlink_types.h"
58 #include "DNA_texture_types.h"
59 #include "DNA_userdef_types.h"
60
61 #include "BKE_action.h"                 
62 #include "BKE_anim.h"
63 #include "BKE_animsys.h"
64 #include "BKE_armature.h"               
65 #include "BKE_colortools.h"
66 #include "BKE_colortools.h"
67 #include "BKE_constraint.h"
68 #include "BKE_depsgraph.h"
69 #include "BKE_global.h"
70 #include "BKE_group.h"
71 #include "BKE_ipo.h"
72 #include "BKE_idprop.h"
73 #include "BKE_image.h"
74 #include "BKE_key.h"
75 #include "BKE_library.h"
76 #include "BKE_main.h"
77 #include "BKE_node.h"
78 #include "BKE_object.h"
79 #include "BKE_scene.h"
80 #include "BKE_sculpt.h"
81 #include "BKE_sequence.h"
82 #include "BKE_world.h"
83 #include "BKE_utildefines.h"
84
85 //XXX #include "BIF_previewrender.h"
86 //XXX #include "BIF_editseq.h"
87
88 #ifndef DISABLE_PYTHON
89 #include "BPY_extern.h"
90 #endif
91
92 #include "BLI_arithb.h"
93 #include "BLI_blenlib.h"
94
95 //XXX #include "nla.h"
96
97 #ifdef WIN32
98 #else
99 #include <sys/time.h>
100 #endif
101
102 void free_avicodecdata(AviCodecData *acd)
103 {
104         if (acd) {
105                 if (acd->lpFormat){
106                         MEM_freeN(acd->lpFormat);
107                         acd->lpFormat = NULL;
108                         acd->cbFormat = 0;
109                 }
110                 if (acd->lpParms){
111                         MEM_freeN(acd->lpParms);
112                         acd->lpParms = NULL;
113                         acd->cbParms = 0;
114                 }
115         }
116 }
117
118 void free_qtcodecdata(QuicktimeCodecData *qcd)
119 {
120         if (qcd) {
121                 if (qcd->cdParms){
122                         MEM_freeN(qcd->cdParms);
123                         qcd->cdParms = NULL;
124                         qcd->cdSize = 0;
125                 }
126         }
127 }
128
129 /* copy_scene moved to src/header_info.c... should be back */
130
131 /* do not free scene itself */
132 void free_scene(Scene *sce)
133 {
134         Base *base;
135
136         base= sce->base.first;
137         while(base) {
138                 base->object->id.us--;
139                 base= base->next;
140         }
141         /* do not free objects! */
142
143         BLI_freelistN(&sce->base);
144         seq_free_editing(sce->ed);
145         
146 #ifndef DISABLE_PYTHON
147         BPY_free_scriptlink(&sce->scriptlink);
148 #endif
149
150         BKE_free_animdata((ID *)sce);
151         BKE_keyingsets_free(&sce->keyingsets);
152         
153         if (sce->r.avicodecdata) {
154                 free_avicodecdata(sce->r.avicodecdata);
155                 MEM_freeN(sce->r.avicodecdata);
156                 sce->r.avicodecdata = NULL;
157         }
158         if (sce->r.qtcodecdata) {
159                 free_qtcodecdata(sce->r.qtcodecdata);
160                 MEM_freeN(sce->r.qtcodecdata);
161                 sce->r.qtcodecdata = NULL;
162         }
163         if (sce->r.ffcodecdata.properties) {
164                 IDP_FreeProperty(sce->r.ffcodecdata.properties);
165                 MEM_freeN(sce->r.ffcodecdata.properties);
166                 sce->r.ffcodecdata.properties = NULL;
167         }
168         
169         BLI_freelistN(&sce->markers);
170         BLI_freelistN(&sce->transform_spaces);
171         BLI_freelistN(&sce->r.layers);
172         
173         if(sce->toolsettings) {
174                 if(sce->toolsettings->vpaint)
175                         MEM_freeN(sce->toolsettings->vpaint);
176                 if(sce->toolsettings->wpaint)
177                         MEM_freeN(sce->toolsettings->wpaint);
178                 if(sce->toolsettings->sculpt) {
179                         sculptsession_free(sce->toolsettings->sculpt);
180                         MEM_freeN(sce->toolsettings->sculpt);
181                 }
182                 
183                 MEM_freeN(sce->toolsettings);
184                 sce->toolsettings = NULL;       
185         }
186         
187         if (sce->theDag) {
188                 free_forest(sce->theDag);
189                 MEM_freeN(sce->theDag);
190         }
191         
192         if(sce->nodetree) {
193                 ntreeFreeTree(sce->nodetree);
194                 MEM_freeN(sce->nodetree);
195         }
196 }
197
198 Scene *add_scene(char *name)
199 {
200         Scene *sce;
201         ParticleEditSettings *pset;
202         int a;
203
204         sce= alloc_libblock(&G.main->scene, ID_SCE, name);
205         sce->lay= 1;
206         
207         sce->r.mode= R_GAMMA|R_OSA|R_SHADOW|R_SSS|R_ENVMAP|R_RAYTRACE;
208         sce->r.cfra= 1;
209         sce->r.sfra= 1;
210         sce->r.efra= 250;
211         sce->r.xsch= 1920;
212         sce->r.ysch= 1080;
213         sce->r.xasp= 1;
214         sce->r.yasp= 1;
215         sce->r.xparts= 8;
216         sce->r.yparts= 8;
217         sce->r.size= 25;
218         sce->r.planes= 24;
219         sce->r.quality= 90;
220         sce->r.framapto= 100;
221         sce->r.images= 100;
222         sce->r.framelen= 1.0;
223         sce->r.frs_sec= 25;
224         sce->r.frs_sec_base= 1;
225         sce->r.ocres = 128;
226         sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
227         
228         sce->r.bake_mode= 1;    /* prevent to include render stuff here */
229         sce->r.bake_filter= 8;
230         sce->r.bake_osa= 5;
231         sce->r.bake_flag= R_BAKE_CLEAR;
232         sce->r.bake_normal_space= R_BAKE_SPACE_TANGENT;
233         
234         sce->r.xplay= 640;
235         sce->r.yplay= 480;
236         sce->r.freqplay= 60;
237         sce->r.depth= 32;
238
239         sce->r.scemode= R_DOCOMP|R_DOSEQ|R_EXTENSION;
240         sce->r.stamp= R_STAMP_TIME|R_STAMP_FRAME|R_STAMP_DATE|R_STAMP_SCENE|R_STAMP_CAMERA;
241         
242         sce->r.threads= 1;
243         
244         sce->r.stereomode = 1;  // no stereo
245         sce->r.domeangle = 180;
246         sce->r.domemode = 1;
247         sce->r.domeres = 4;
248         sce->r.domeresbuf = 1.0f;
249         sce->r.dometilt = 0;
250
251         sce->r.simplify_subsurf= 6;
252         sce->r.simplify_particles= 1.0f;
253         sce->r.simplify_shadowsamples= 16;
254         sce->r.simplify_aosss= 1.0f;
255
256         sce->r.cineonblack= 95;
257         sce->r.cineonwhite= 685;
258         sce->r.cineongamma= 1.7f;
259         
260         sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings),"Tool Settings Struct");
261         sce->toolsettings->cornertype=1;
262         sce->toolsettings->degr = 90; 
263         sce->toolsettings->step = 9;
264         sce->toolsettings->turn = 1;                            
265         sce->toolsettings->extr_offs = 1; 
266         sce->toolsettings->doublimit = 0.001;
267         sce->toolsettings->segments = 32;
268         sce->toolsettings->rings = 32;
269         sce->toolsettings->vertices = 32;
270         sce->toolsettings->editbutflag = 1;
271         sce->toolsettings->uvcalc_radius = 1.0f;
272         sce->toolsettings->uvcalc_cubesize = 1.0f;
273         sce->toolsettings->uvcalc_mapdir = 1;
274         sce->toolsettings->uvcalc_mapalign = 1;
275         sce->toolsettings->unwrapper = 1;
276         sce->toolsettings->select_thresh= 0.01f;
277         sce->toolsettings->jointrilimit = 0.8f;
278
279         sce->toolsettings->selectmode= SCE_SELECT_VERTEX;
280         sce->toolsettings->normalsize= 0.1;
281         sce->toolsettings->autokey_mode= U.autokey_mode;
282
283         sce->toolsettings->skgen_resolution = 100;
284         sce->toolsettings->skgen_threshold_internal     = 0.01f;
285         sce->toolsettings->skgen_threshold_external     = 0.01f;
286         sce->toolsettings->skgen_angle_limit                    = 45.0f;
287         sce->toolsettings->skgen_length_ratio                   = 1.3f;
288         sce->toolsettings->skgen_length_limit                   = 1.5f;
289         sce->toolsettings->skgen_correlation_limit              = 0.98f;
290         sce->toolsettings->skgen_symmetry_limit                 = 0.1f;
291         sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
292         sce->toolsettings->skgen_postpro_passes = 1;
293         sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_HARMONIC|SKGEN_SUB_CORRELATION|SKGEN_STICK_TO_EMBEDDING;
294         sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
295         sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
296         sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
297
298         sce->toolsettings->proportional_size = 1.0f;
299
300         pset= &sce->toolsettings->particle;
301         pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
302         pset->emitterdist= 0.25f;
303         pset->totrekey= 5;
304         pset->totaddkey= 5;
305         pset->brushtype= PE_BRUSH_NONE;
306         for(a=0; a<PE_TOT_BRUSH; a++) {
307                 pset->brush[a].strength= 50;
308                 pset->brush[a].size= 50;
309                 pset->brush[a].step= 10;
310         }
311         pset->brush[PE_BRUSH_CUT].strength= 100;
312         
313         sce->jumpframe = 10;
314         sce->audio.mixrate = 44100;
315
316         strcpy(sce->r.backbuf, "//backbuf");
317         strcpy(sce->r.pic, U.renderdir);
318
319         BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
320         sce->r.osa= 8;
321
322         /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
323         scene_add_render_layer(sce);
324         
325         return sce;
326 }
327
328 Base *object_in_scene(Object *ob, Scene *sce)
329 {
330         Base *base;
331         
332         base= sce->base.first;
333         while(base) {
334                 if(base->object == ob) return base;
335                 base= base->next;
336         }
337         return NULL;
338 }
339
340 void set_scene_bg(Scene *scene)
341 {
342         Scene *sce;
343         Base *base;
344         Object *ob;
345         Group *group;
346         GroupObject *go;
347         int flag;
348         
349         /* check for cyclic sets, for reading old files but also for definite security (py?) */
350         scene_check_setscene(scene);
351         
352         /* deselect objects (for dataselect) */
353         for(ob= G.main->object.first; ob; ob= ob->id.next)
354                 ob->flag &= ~(SELECT|OB_FROMGROUP);
355
356         /* group flags again */
357         for(group= G.main->group.first; group; group= group->id.next) {
358                 go= group->gobject.first;
359                 while(go) {
360                         if(go->ob) go->ob->flag |= OB_FROMGROUP;
361                         go= go->next;
362                 }
363         }
364
365         /* sort baselist */
366         DAG_scene_sort(scene);
367         
368         /* ensure dags are built for sets */
369         for(sce= scene->set; sce; sce= sce->set)
370                 if(sce->theDag==NULL)
371                         DAG_scene_sort(sce);
372
373         /* copy layers and flags from bases to objects */
374         for(base= scene->base.first; base; base= base->next) {
375                 ob= base->object;
376                 ob->lay= base->lay;
377                 
378                 /* group patch... */
379                 base->flag &= ~(OB_FROMGROUP);
380                 flag= ob->flag & (OB_FROMGROUP);
381                 base->flag |= flag;
382                 
383                 /* not too nice... for recovering objects with lost data */
384                 if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
385                 ob->flag= base->flag;
386                 
387                 ob->ctime= -1234567.0;  /* force ipo to be calculated later */
388         }
389         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
390         
391         /* do we need FRAMECHANGED in set_scene? */
392 //      if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
393 }
394
395 /* called from creator.c */
396 void set_scene_name(char *name)
397 {
398         Scene *sce;
399
400         for (sce= G.main->scene.first; sce; sce= sce->id.next) {
401                 if (BLI_streq(name, sce->id.name+2)) {
402                         set_scene_bg(sce);
403                         return;
404                 }
405         }
406         
407         //XXX error("Can't find scene: %s", name);
408 }
409
410 /* used by metaballs
411  * doesnt return the original duplicated object, only dupli's
412  */
413 int next_object(Scene *scene, int val, Base **base, Object **ob)
414 {
415         static ListBase *duplilist= NULL;
416         static DupliObject *dupob;
417         static int fase= F_START, in_next_object= 0;
418         int run_again=1;
419         
420         /* init */
421         if(val==0) {
422                 fase= F_START;
423                 dupob= NULL;
424                 
425                 /* XXX particle systems with metas+dupligroups call this recursively */
426                 /* see bug #18725 */
427                 if(in_next_object) {
428                         printf("ERROR: MetaBall generation called recursively, not supported\n");
429                         
430                         return F_ERROR;
431                 }
432         }
433         else {
434                 in_next_object= 1;
435                 
436                 /* run_again is set when a duplilist has been ended */
437                 while(run_again) {
438                         run_again= 0;
439
440                         /* the first base */
441                         if(fase==F_START) {
442                                 *base= scene->base.first;
443                                 if(*base) {
444                                         *ob= (*base)->object;
445                                         fase= F_SCENE;
446                                 }
447                                 else {
448                                     /* exception: empty scene */
449                                         if(scene->set && scene->set->base.first) {
450                                                 *base= scene->set->base.first;
451                                                 *ob= (*base)->object;
452                                                 fase= F_SET;
453                                         }
454                                 }
455                         }
456                         else {
457                                 if(*base && fase!=F_DUPLI) {
458                                         *base= (*base)->next;
459                                         if(*base) *ob= (*base)->object;
460                                         else {
461                                                 if(fase==F_SCENE) {
462                                                         /* scene is finished, now do the set */
463                                                         if(scene->set && scene->set->base.first) {
464                                                                 *base= scene->set->base.first;
465                                                                 *ob= (*base)->object;
466                                                                 fase= F_SET;
467                                                         }
468                                                 }
469                                         }
470                                 }
471                         }
472                         
473                         if(*base == NULL) fase= F_START;
474                         else {
475                                 if(fase!=F_DUPLI) {
476                                         if( (*base)->object->transflag & OB_DUPLI) {
477                                                 /* groups cannot be duplicated for mballs yet, 
478                                                 this enters eternal loop because of 
479                                                 makeDispListMBall getting called inside of group_duplilist */
480                                                 if((*base)->object->dup_group == NULL) {
481                                                         duplilist= object_duplilist(scene, (*base)->object);
482                                                         
483                                                         dupob= duplilist->first;
484
485                                                         if(!dupob)
486                                                                 free_object_duplilist(duplilist);
487                                                 }
488                                         }
489                                 }
490                                 /* handle dupli's */
491                                 if(dupob) {
492                                         
493                                         Mat4CpyMat4(dupob->ob->obmat, dupob->mat);
494                                         
495                                         (*base)->flag |= OB_FROMDUPLI;
496                                         *ob= dupob->ob;
497                                         fase= F_DUPLI;
498                                         
499                                         dupob= dupob->next;
500                                 }
501                                 else if(fase==F_DUPLI) {
502                                         fase= F_SCENE;
503                                         (*base)->flag &= ~OB_FROMDUPLI;
504                                         
505                                         for(dupob= duplilist->first; dupob; dupob= dupob->next) {
506                                                 Mat4CpyMat4(dupob->ob->obmat, dupob->omat);
507                                         }
508                                         
509                                         free_object_duplilist(duplilist);
510                                         duplilist= NULL;
511                                         run_again= 1;
512                                 }
513                         }
514                 }
515         }
516         
517         /* reset recursion test */
518         in_next_object= 0;
519         
520         return fase;
521 }
522
523 Object *scene_find_camera(Scene *sc)
524 {
525         Base *base;
526         
527         for (base= sc->base.first; base; base= base->next)
528                 if (base->object->type==OB_CAMERA)
529                         return base->object;
530
531         return NULL;
532 }
533
534
535 Base *scene_add_base(Scene *sce, Object *ob)
536 {
537         Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
538         BLI_addhead(&sce->base, b);
539
540         b->object= ob;
541         b->flag= ob->flag;
542         b->lay= ob->lay;
543
544         return b;
545 }
546
547 void scene_deselect_all(Scene *sce)
548 {
549         Base *b;
550
551         for (b= sce->base.first; b; b= b->next) {
552                 b->flag&= ~SELECT;
553                 b->object->flag= b->flag;
554         }
555 }
556
557 void scene_select_base(Scene *sce, Base *selbase)
558 {
559         scene_deselect_all(sce);
560
561         selbase->flag |= SELECT;
562         selbase->object->flag= selbase->flag;
563
564         sce->basact= selbase;
565 }
566
567 /* checks for cycle, returns 1 if it's all OK */
568 int scene_check_setscene(Scene *sce)
569 {
570         Scene *scene;
571         int a, totscene;
572         
573         if(sce->set==NULL) return 1;
574         
575         totscene= 0;
576         for(scene= G.main->scene.first; scene; scene= scene->id.next)
577                 totscene++;
578         
579         for(a=0, scene=sce; scene->set; scene=scene->set, a++) {
580                 /* more iterations than scenes means we have a cycle */
581                 if(a > totscene) {
582                         /* the tested scene gets zero'ed, that's typically current scene */
583                         sce->set= NULL;
584                         return 0;
585                 }
586         }
587
588         return 1;
589 }
590
591 /* This (evil) function is needed to cope with two legacy Blender rendering features
592 * mblur (motion blur that renders 'subframes' and blurs them together), and fields 
593 * rendering. Thus, the use of ugly globals from object.c
594 */
595 // BAD... EVIL... JUJU...!!!!
596 // XXX moved here temporarily
597 float frame_to_float (Scene *scene, int cfra)           /* see also bsystem_time in object.c */
598 {
599         extern float bluroffs;  /* bad stuff borrowed from object.c */
600         extern float fieldoffs;
601         float ctime;
602         
603         ctime= (float)cfra;
604         ctime+= bluroffs+fieldoffs;
605         ctime*= scene->r.framelen;
606         
607         return ctime;
608 }
609
610 static void scene_update(Scene *sce, unsigned int lay)
611 {
612         Base *base;
613         Object *ob;
614         float ctime = frame_to_float(sce, sce->r.cfra); 
615         
616         if(sce->theDag==NULL)
617                 DAG_scene_sort(sce);
618         
619         DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
620         
621         /* All 'standard' (i.e. without any dependencies) animation is handled here,
622                 * with an 'local' to 'macro' order of evaluation. This should ensure that
623                 * settings stored nestled within a hierarchy (i.e. settings in a Texture block
624             * can be overridden by settings from Scene, which owns the Texture through a hierarchy 
625             * such as Scene->World->MTex/Texture) can still get correctly overridden.
626                 */
627         BKE_animsys_evaluate_all_animation(G.main, ctime);
628         
629         for(base= sce->base.first; base; base= base->next) {
630                 ob= base->object;
631                 
632                 object_handle_update(sce, ob);   // bke_object.h
633                 
634                 /* only update layer when an ipo */
635                         // XXX old animation system
636                 //if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
637                 //      base->lay= ob->lay;
638                 //}
639         }
640 }
641
642
643 /* applies changes right away, does all sets too */
644 void scene_update_for_newframe(Scene *sce, unsigned int lay)
645 {
646         Scene *scene= sce;
647         
648         /* clear animation overrides */
649         // XXX TODO...
650         
651 #ifndef DISABLE_PYTHON
652         if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
653 #endif
654         /* sets first, we allow per definition current scene to have dependencies on sets */
655         for(sce= sce->set; sce; sce= sce->set)
656                 scene_update(sce, lay);
657
658         scene_update(scene, lay);
659 }
660
661 /* return default layer, also used to patch old files */
662 void scene_add_render_layer(Scene *sce)
663 {
664         SceneRenderLayer *srl;
665         int tot= 1 + BLI_countlist(&sce->r.layers);
666         
667         srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
668         sprintf(srl->name, "%d RenderLayer", tot);
669         BLI_addtail(&sce->r.layers, srl);
670
671         /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
672         srl->lay= (1<<20) -1;
673         srl->layflag= 0x7FFF;   /* solid ztra halo edge strand */
674         srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
675 }
676
677 void sculptsession_free(Sculpt *sculpt)
678 {
679         SculptSession *ss= sculpt->session;
680         if(ss) {
681                 if(ss->projverts)
682                         MEM_freeN(ss->projverts);
683
684                 if(ss->fmap)
685                         MEM_freeN(ss->fmap);
686
687                 if(ss->fmap_mem)
688                         MEM_freeN(ss->fmap_mem);
689
690                 if(ss->texcache)
691                         MEM_freeN(ss->texcache);
692                 MEM_freeN(ss);
693                 sculpt->session= NULL;
694         }
695 }
696
697 /* render simplification */
698
699 int get_render_subsurf_level(RenderData *r, int lvl)
700 {
701         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
702                 return MIN2(r->simplify_subsurf, lvl);
703         else
704                 return lvl;
705 }
706
707 int get_render_child_particle_number(RenderData *r, int num)
708 {
709         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
710                 return (int)(r->simplify_particles*num);
711         else
712                 return num;
713 }
714
715 int get_render_shadow_samples(RenderData *r, int samples)
716 {
717         if(G.rt == 1 && (r->mode & R_SIMPLIFY) && samples > 0)
718                 return MIN2(r->simplify_shadowsamples, samples);
719         else
720                 return samples;
721 }
722
723 float get_render_aosss_error(RenderData *r, float error)
724 {
725         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
726                 return ((1.0f-r->simplify_aosss)*10.0f + 1.0f)*error;
727         else
728                 return error;
729 }
730
731 void free_dome_warp_text(struct Text *txt)
732 {
733         Scene *scene;
734
735         scene = G.main->scene.first;
736         while(scene) {
737                 if (scene->r.dometext == txt)
738                         scene->r.dometext = NULL;
739                 scene = scene->id.next;
740         }
741 }