svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22205:22290
[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_texture_types.h"
58 #include "DNA_userdef_types.h"
59
60 #include "BKE_action.h"                 
61 #include "BKE_anim.h"
62 #include "BKE_animsys.h"
63 #include "BKE_armature.h"               
64 #include "BKE_colortools.h"
65 #include "BKE_colortools.h"
66 #include "BKE_constraint.h"
67 #include "BKE_depsgraph.h"
68 #include "BKE_global.h"
69 #include "BKE_group.h"
70 #include "BKE_ipo.h"
71 #include "BKE_idprop.h"
72 #include "BKE_image.h"
73 #include "BKE_key.h"
74 #include "BKE_library.h"
75 #include "BKE_main.h"
76 #include "BKE_node.h"
77 #include "BKE_object.h"
78 #include "BKE_scene.h"
79 #include "BKE_sculpt.h"
80 #include "BKE_sequence.h"
81 #include "BKE_world.h"
82 #include "BKE_utildefines.h"
83
84 //XXX #include "BIF_previewrender.h"
85 //XXX #include "BIF_editseq.h"
86
87 #ifndef DISABLE_PYTHON
88 #include "BPY_extern.h"
89 #endif
90
91 #include "BLI_arithb.h"
92 #include "BLI_blenlib.h"
93
94 //XXX #include "nla.h"
95
96 #ifdef WIN32
97 #else
98 #include <sys/time.h>
99 #endif
100
101 void free_avicodecdata(AviCodecData *acd)
102 {
103         if (acd) {
104                 if (acd->lpFormat){
105                         MEM_freeN(acd->lpFormat);
106                         acd->lpFormat = NULL;
107                         acd->cbFormat = 0;
108                 }
109                 if (acd->lpParms){
110                         MEM_freeN(acd->lpParms);
111                         acd->lpParms = NULL;
112                         acd->cbParms = 0;
113                 }
114         }
115 }
116
117 void free_qtcodecdata(QuicktimeCodecData *qcd)
118 {
119         if (qcd) {
120                 if (qcd->cdParms){
121                         MEM_freeN(qcd->cdParms);
122                         qcd->cdParms = NULL;
123                         qcd->cdSize = 0;
124                 }
125         }
126 }
127
128 /* copy_scene moved to src/header_info.c... should be back */
129
130 /* do not free scene itself */
131 void free_scene(Scene *sce)
132 {
133         Base *base;
134
135         base= sce->base.first;
136         while(base) {
137                 base->object->id.us--;
138                 base= base->next;
139         }
140         /* do not free objects! */
141
142         BLI_freelistN(&sce->base);
143         seq_free_editing(sce->ed);
144
145         BKE_free_animdata((ID *)sce);
146         BKE_keyingsets_free(&sce->keyingsets);
147         
148         if (sce->r.avicodecdata) {
149                 free_avicodecdata(sce->r.avicodecdata);
150                 MEM_freeN(sce->r.avicodecdata);
151                 sce->r.avicodecdata = NULL;
152         }
153         if (sce->r.qtcodecdata) {
154                 free_qtcodecdata(sce->r.qtcodecdata);
155                 MEM_freeN(sce->r.qtcodecdata);
156                 sce->r.qtcodecdata = NULL;
157         }
158         if (sce->r.ffcodecdata.properties) {
159                 IDP_FreeProperty(sce->r.ffcodecdata.properties);
160                 MEM_freeN(sce->r.ffcodecdata.properties);
161                 sce->r.ffcodecdata.properties = NULL;
162         }
163         
164         BLI_freelistN(&sce->markers);
165         BLI_freelistN(&sce->transform_spaces);
166         BLI_freelistN(&sce->r.layers);
167         
168         if(sce->toolsettings) {
169                 if(sce->toolsettings->vpaint)
170                         MEM_freeN(sce->toolsettings->vpaint);
171                 if(sce->toolsettings->wpaint)
172                         MEM_freeN(sce->toolsettings->wpaint);
173                 if(sce->toolsettings->sculpt) {
174                         sculptsession_free(sce->toolsettings->sculpt);
175                         MEM_freeN(sce->toolsettings->sculpt);
176                 }
177                 
178                 MEM_freeN(sce->toolsettings);
179                 sce->toolsettings = NULL;       
180         }
181         
182         if (sce->theDag) {
183                 free_forest(sce->theDag);
184                 MEM_freeN(sce->theDag);
185         }
186         
187         if(sce->nodetree) {
188                 ntreeFreeTree(sce->nodetree);
189                 MEM_freeN(sce->nodetree);
190         }
191 }
192
193 Scene *add_scene(char *name)
194 {
195         Scene *sce;
196         ParticleEditSettings *pset;
197         int a;
198
199         sce= alloc_libblock(&G.main->scene, ID_SCE, name);
200         sce->lay= 1;
201         
202         sce->r.mode= R_GAMMA|R_OSA|R_SHADOW|R_SSS|R_ENVMAP|R_RAYTRACE;
203         sce->r.cfra= 1;
204         sce->r.sfra= 1;
205         sce->r.efra= 250;
206         sce->r.xsch= 1920;
207         sce->r.ysch= 1080;
208         sce->r.xasp= 1;
209         sce->r.yasp= 1;
210         sce->r.xparts= 8;
211         sce->r.yparts= 8;
212         sce->r.size= 25;
213         sce->r.planes= 24;
214         sce->r.quality= 90;
215         sce->r.framapto= 100;
216         sce->r.images= 100;
217         sce->r.framelen= 1.0;
218         sce->r.frs_sec= 25;
219         sce->r.frs_sec_base= 1;
220         sce->r.ocres = 128;
221         sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
222         
223         sce->r.bake_mode= 1;    /* prevent to include render stuff here */
224         sce->r.bake_filter= 8;
225         sce->r.bake_osa= 5;
226         sce->r.bake_flag= R_BAKE_CLEAR;
227         sce->r.bake_normal_space= R_BAKE_SPACE_TANGENT;
228
229         sce->r.scemode= R_DOCOMP|R_DOSEQ|R_EXTENSION;
230         sce->r.stamp= R_STAMP_TIME|R_STAMP_FRAME|R_STAMP_DATE|R_STAMP_SCENE|R_STAMP_CAMERA;
231         
232         sce->r.threads= 1;
233
234         sce->r.simplify_subsurf= 6;
235         sce->r.simplify_particles= 1.0f;
236         sce->r.simplify_shadowsamples= 16;
237         sce->r.simplify_aosss= 1.0f;
238
239         sce->r.cineonblack= 95;
240         sce->r.cineonwhite= 685;
241         sce->r.cineongamma= 1.7f;
242         
243         sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings),"Tool Settings Struct");
244         sce->toolsettings->cornertype=1;
245         sce->toolsettings->degr = 90; 
246         sce->toolsettings->step = 9;
247         sce->toolsettings->turn = 1;                            
248         sce->toolsettings->extr_offs = 1; 
249         sce->toolsettings->doublimit = 0.001;
250         sce->toolsettings->segments = 32;
251         sce->toolsettings->rings = 32;
252         sce->toolsettings->vertices = 32;
253         sce->toolsettings->editbutflag = 1;
254         sce->toolsettings->uvcalc_radius = 1.0f;
255         sce->toolsettings->uvcalc_cubesize = 1.0f;
256         sce->toolsettings->uvcalc_mapdir = 1;
257         sce->toolsettings->uvcalc_mapalign = 1;
258         sce->toolsettings->unwrapper = 1;
259         sce->toolsettings->select_thresh= 0.01f;
260         sce->toolsettings->jointrilimit = 0.8f;
261
262         sce->toolsettings->selectmode= SCE_SELECT_VERTEX;
263         sce->toolsettings->normalsize= 0.1;
264         sce->toolsettings->autokey_mode= U.autokey_mode;
265
266         sce->toolsettings->skgen_resolution = 100;
267         sce->toolsettings->skgen_threshold_internal     = 0.01f;
268         sce->toolsettings->skgen_threshold_external     = 0.01f;
269         sce->toolsettings->skgen_angle_limit                    = 45.0f;
270         sce->toolsettings->skgen_length_ratio                   = 1.3f;
271         sce->toolsettings->skgen_length_limit                   = 1.5f;
272         sce->toolsettings->skgen_correlation_limit              = 0.98f;
273         sce->toolsettings->skgen_symmetry_limit                 = 0.1f;
274         sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
275         sce->toolsettings->skgen_postpro_passes = 1;
276         sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_HARMONIC|SKGEN_SUB_CORRELATION|SKGEN_STICK_TO_EMBEDDING;
277         sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
278         sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
279         sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
280
281         sce->toolsettings->proportional_size = 1.0f;
282
283         pset= &sce->toolsettings->particle;
284         pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
285         pset->emitterdist= 0.25f;
286         pset->totrekey= 5;
287         pset->totaddkey= 5;
288         pset->brushtype= PE_BRUSH_NONE;
289         for(a=0; a<PE_TOT_BRUSH; a++) {
290                 pset->brush[a].strength= 50;
291                 pset->brush[a].size= 50;
292                 pset->brush[a].step= 10;
293         }
294         pset->brush[PE_BRUSH_CUT].strength= 100;
295         
296         sce->jumpframe = 10;
297         sce->audio.mixrate = 44100;
298
299         strcpy(sce->r.backbuf, "//backbuf");
300         strcpy(sce->r.pic, U.renderdir);
301
302         BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
303         sce->r.osa= 8;
304
305         /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
306         scene_add_render_layer(sce);
307         
308         /* game data */
309         sce->gm.stereoflag = STEREO_NOSTEREO;
310         sce->gm.stereomode = STEREO_ANAGLYPH;
311         sce->gm.dome.angle = 180;
312         sce->gm.dome.mode = DOME_FISHEYE;
313         sce->gm.dome.res = 4;
314         sce->gm.dome.resbuf = 1.0f;
315         sce->gm.dome.tilt = 0;
316
317         sce->gm.xplay= 800;
318         sce->gm.yplay= 600;
319         sce->gm.freqplay= 60;
320         sce->gm.depth= 32;
321
322         sce->gm.gravity= 9.8f;
323         sce->gm.physicsEngine= WOPHY_BULLET;
324         sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling 
325         sce->gm.occlusionRes = 128;
326         sce->gm.ticrate = 60;
327         sce->gm.maxlogicstep = 5;
328         sce->gm.physubstep = 1;
329         sce->gm.maxphystep = 5;
330
331         return sce;
332 }
333
334 Base *object_in_scene(Object *ob, Scene *sce)
335 {
336         Base *base;
337         
338         base= sce->base.first;
339         while(base) {
340                 if(base->object == ob) return base;
341                 base= base->next;
342         }
343         return NULL;
344 }
345
346 void set_scene_bg(Scene *scene)
347 {
348         Scene *sce;
349         Base *base;
350         Object *ob;
351         Group *group;
352         GroupObject *go;
353         int flag;
354         
355         /* check for cyclic sets, for reading old files but also for definite security (py?) */
356         scene_check_setscene(scene);
357         
358         /* deselect objects (for dataselect) */
359         for(ob= G.main->object.first; ob; ob= ob->id.next)
360                 ob->flag &= ~(SELECT|OB_FROMGROUP);
361
362         /* group flags again */
363         for(group= G.main->group.first; group; group= group->id.next) {
364                 go= group->gobject.first;
365                 while(go) {
366                         if(go->ob) go->ob->flag |= OB_FROMGROUP;
367                         go= go->next;
368                 }
369         }
370
371         /* sort baselist */
372         DAG_scene_sort(scene);
373         
374         /* ensure dags are built for sets */
375         for(sce= scene->set; sce; sce= sce->set)
376                 if(sce->theDag==NULL)
377                         DAG_scene_sort(sce);
378
379         /* copy layers and flags from bases to objects */
380         for(base= scene->base.first; base; base= base->next) {
381                 ob= base->object;
382                 ob->lay= base->lay;
383                 
384                 /* group patch... */
385                 base->flag &= ~(OB_FROMGROUP);
386                 flag= ob->flag & (OB_FROMGROUP);
387                 base->flag |= flag;
388                 
389                 /* not too nice... for recovering objects with lost data */
390                 if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
391                 ob->flag= base->flag;
392                 
393                 ob->ctime= -1234567.0;  /* force ipo to be calculated later */
394         }
395         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
396 }
397
398 /* called from creator.c */
399 void set_scene_name(char *name)
400 {
401         Scene *sce;
402
403         for (sce= G.main->scene.first; sce; sce= sce->id.next) {
404                 if (BLI_streq(name, sce->id.name+2)) {
405                         set_scene_bg(sce);
406                         return;
407                 }
408         }
409         
410         //XXX error("Can't find scene: %s", name);
411 }
412
413 /* used by metaballs
414  * doesnt return the original duplicated object, only dupli's
415  */
416 int next_object(Scene *scene, int val, Base **base, Object **ob)
417 {
418         static ListBase *duplilist= NULL;
419         static DupliObject *dupob;
420         static int fase= F_START, in_next_object= 0;
421         int run_again=1;
422         
423         /* init */
424         if(val==0) {
425                 fase= F_START;
426                 dupob= NULL;
427                 
428                 /* XXX particle systems with metas+dupligroups call this recursively */
429                 /* see bug #18725 */
430                 if(in_next_object) {
431                         printf("ERROR: MetaBall generation called recursively, not supported\n");
432                         
433                         return F_ERROR;
434                 }
435         }
436         else {
437                 in_next_object= 1;
438                 
439                 /* run_again is set when a duplilist has been ended */
440                 while(run_again) {
441                         run_again= 0;
442
443                         /* the first base */
444                         if(fase==F_START) {
445                                 *base= scene->base.first;
446                                 if(*base) {
447                                         *ob= (*base)->object;
448                                         fase= F_SCENE;
449                                 }
450                                 else {
451                                     /* exception: empty scene */
452                                         if(scene->set && scene->set->base.first) {
453                                                 *base= scene->set->base.first;
454                                                 *ob= (*base)->object;
455                                                 fase= F_SET;
456                                         }
457                                 }
458                         }
459                         else {
460                                 if(*base && fase!=F_DUPLI) {
461                                         *base= (*base)->next;
462                                         if(*base) *ob= (*base)->object;
463                                         else {
464                                                 if(fase==F_SCENE) {
465                                                         /* scene is finished, now do the set */
466                                                         if(scene->set && scene->set->base.first) {
467                                                                 *base= scene->set->base.first;
468                                                                 *ob= (*base)->object;
469                                                                 fase= F_SET;
470                                                         }
471                                                 }
472                                         }
473                                 }
474                         }
475                         
476                         if(*base == NULL) fase= F_START;
477                         else {
478                                 if(fase!=F_DUPLI) {
479                                         if( (*base)->object->transflag & OB_DUPLI) {
480                                                 /* groups cannot be duplicated for mballs yet, 
481                                                 this enters eternal loop because of 
482                                                 makeDispListMBall getting called inside of group_duplilist */
483                                                 if((*base)->object->dup_group == NULL) {
484                                                         duplilist= object_duplilist(scene, (*base)->object);
485                                                         
486                                                         dupob= duplilist->first;
487
488                                                         if(!dupob)
489                                                                 free_object_duplilist(duplilist);
490                                                 }
491                                         }
492                                 }
493                                 /* handle dupli's */
494                                 if(dupob) {
495                                         
496                                         Mat4CpyMat4(dupob->ob->obmat, dupob->mat);
497                                         
498                                         (*base)->flag |= OB_FROMDUPLI;
499                                         *ob= dupob->ob;
500                                         fase= F_DUPLI;
501                                         
502                                         dupob= dupob->next;
503                                 }
504                                 else if(fase==F_DUPLI) {
505                                         fase= F_SCENE;
506                                         (*base)->flag &= ~OB_FROMDUPLI;
507                                         
508                                         for(dupob= duplilist->first; dupob; dupob= dupob->next) {
509                                                 Mat4CpyMat4(dupob->ob->obmat, dupob->omat);
510                                         }
511                                         
512                                         free_object_duplilist(duplilist);
513                                         duplilist= NULL;
514                                         run_again= 1;
515                                 }
516                         }
517                 }
518         }
519         
520         /* reset recursion test */
521         in_next_object= 0;
522         
523         return fase;
524 }
525
526 Object *scene_find_camera(Scene *sc)
527 {
528         Base *base;
529         
530         for (base= sc->base.first; base; base= base->next)
531                 if (base->object->type==OB_CAMERA)
532                         return base->object;
533
534         return NULL;
535 }
536
537
538 Base *scene_add_base(Scene *sce, Object *ob)
539 {
540         Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
541         BLI_addhead(&sce->base, b);
542
543         b->object= ob;
544         b->flag= ob->flag;
545         b->lay= ob->lay;
546
547         return b;
548 }
549
550 void scene_deselect_all(Scene *sce)
551 {
552         Base *b;
553
554         for (b= sce->base.first; b; b= b->next) {
555                 b->flag&= ~SELECT;
556                 b->object->flag= b->flag;
557         }
558 }
559
560 void scene_select_base(Scene *sce, Base *selbase)
561 {
562         scene_deselect_all(sce);
563
564         selbase->flag |= SELECT;
565         selbase->object->flag= selbase->flag;
566
567         sce->basact= selbase;
568 }
569
570 /* checks for cycle, returns 1 if it's all OK */
571 int scene_check_setscene(Scene *sce)
572 {
573         Scene *scene;
574         int a, totscene;
575         
576         if(sce->set==NULL) return 1;
577         
578         totscene= 0;
579         for(scene= G.main->scene.first; scene; scene= scene->id.next)
580                 totscene++;
581         
582         for(a=0, scene=sce; scene->set; scene=scene->set, a++) {
583                 /* more iterations than scenes means we have a cycle */
584                 if(a > totscene) {
585                         /* the tested scene gets zero'ed, that's typically current scene */
586                         sce->set= NULL;
587                         return 0;
588                 }
589         }
590
591         return 1;
592 }
593
594 /* This (evil) function is needed to cope with two legacy Blender rendering features
595 * mblur (motion blur that renders 'subframes' and blurs them together), and fields 
596 * rendering. Thus, the use of ugly globals from object.c
597 */
598 // BAD... EVIL... JUJU...!!!!
599 // XXX moved here temporarily
600 float frame_to_float (Scene *scene, int cfra)           /* see also bsystem_time in object.c */
601 {
602         extern float bluroffs;  /* bad stuff borrowed from object.c */
603         extern float fieldoffs;
604         float ctime;
605         
606         ctime= (float)cfra;
607         ctime+= bluroffs+fieldoffs;
608         ctime*= scene->r.framelen;
609         
610         return ctime;
611 }
612
613 static void scene_update(Scene *sce, unsigned int lay)
614 {
615         Base *base;
616         Object *ob;
617         float ctime = frame_to_float(sce, sce->r.cfra); 
618         
619         if(sce->theDag==NULL)
620                 DAG_scene_sort(sce);
621         
622         DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
623         
624         /* All 'standard' (i.e. without any dependencies) animation is handled here,
625                 * with an 'local' to 'macro' order of evaluation. This should ensure that
626                 * settings stored nestled within a hierarchy (i.e. settings in a Texture block
627             * can be overridden by settings from Scene, which owns the Texture through a hierarchy 
628             * such as Scene->World->MTex/Texture) can still get correctly overridden.
629                 */
630         BKE_animsys_evaluate_all_animation(G.main, ctime);
631         
632         for(base= sce->base.first; base; base= base->next) {
633                 ob= base->object;
634                 
635                 object_handle_update(sce, ob);   // bke_object.h
636                 
637                 /* only update layer when an ipo */
638                         // XXX old animation system
639                 //if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
640                 //      base->lay= ob->lay;
641                 //}
642         }
643 }
644
645
646 /* applies changes right away, does all sets too */
647 void scene_update_for_newframe(Scene *sce, unsigned int lay)
648 {
649         Scene *scene= sce;
650         
651         /* clear animation overrides */
652         // XXX TODO...
653         
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 }