- moved unit settings from user prefs into the scene.
[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);
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
284         sce->unit.scale_length = 1.0f;
285
286         pset= &sce->toolsettings->particle;
287         pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
288         pset->emitterdist= 0.25f;
289         pset->totrekey= 5;
290         pset->totaddkey= 5;
291         pset->brushtype= PE_BRUSH_NONE;
292         for(a=0; a<PE_TOT_BRUSH; a++) {
293                 pset->brush[a].strength= 50;
294                 pset->brush[a].size= 50;
295                 pset->brush[a].step= 10;
296         }
297         pset->brush[PE_BRUSH_CUT].strength= 100;
298         
299         sce->jumpframe = 10;
300         sce->audio.mixrate = 44100;
301
302         strcpy(sce->r.backbuf, "//backbuf");
303         strcpy(sce->r.pic, U.renderdir);
304
305         BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
306         sce->r.osa= 8;
307
308         /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
309         scene_add_render_layer(sce);
310         
311         /* game data */
312         sce->gm.stereoflag = STEREO_NOSTEREO;
313         sce->gm.stereomode = STEREO_ANAGLYPH;
314         sce->gm.dome.angle = 180;
315         sce->gm.dome.mode = DOME_FISHEYE;
316         sce->gm.dome.res = 4;
317         sce->gm.dome.resbuf = 1.0f;
318         sce->gm.dome.tilt = 0;
319
320         sce->gm.xplay= 800;
321         sce->gm.yplay= 600;
322         sce->gm.freqplay= 60;
323         sce->gm.depth= 32;
324
325         sce->gm.gravity= 9.8f;
326         sce->gm.physicsEngine= WOPHY_BULLET;
327         sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling 
328         sce->gm.occlusionRes = 128;
329         sce->gm.ticrate = 60;
330         sce->gm.maxlogicstep = 5;
331         sce->gm.physubstep = 1;
332         sce->gm.maxphystep = 5;
333
334         return sce;
335 }
336
337 Base *object_in_scene(Object *ob, Scene *sce)
338 {
339         Base *base;
340         
341         base= sce->base.first;
342         while(base) {
343                 if(base->object == ob) return base;
344                 base= base->next;
345         }
346         return NULL;
347 }
348
349 void set_scene_bg(Scene *scene)
350 {
351         Scene *sce;
352         Base *base;
353         Object *ob;
354         Group *group;
355         GroupObject *go;
356         int flag;
357         
358         /* check for cyclic sets, for reading old files but also for definite security (py?) */
359         scene_check_setscene(scene);
360         
361         /* deselect objects (for dataselect) */
362         for(ob= G.main->object.first; ob; ob= ob->id.next)
363                 ob->flag &= ~(SELECT|OB_FROMGROUP);
364
365         /* group flags again */
366         for(group= G.main->group.first; group; group= group->id.next) {
367                 go= group->gobject.first;
368                 while(go) {
369                         if(go->ob) go->ob->flag |= OB_FROMGROUP;
370                         go= go->next;
371                 }
372         }
373
374         /* sort baselist */
375         DAG_scene_sort(scene);
376         
377         /* ensure dags are built for sets */
378         for(sce= scene->set; sce; sce= sce->set)
379                 if(sce->theDag==NULL)
380                         DAG_scene_sort(sce);
381
382         /* copy layers and flags from bases to objects */
383         for(base= scene->base.first; base; base= base->next) {
384                 ob= base->object;
385                 ob->lay= base->lay;
386                 
387                 /* group patch... */
388                 base->flag &= ~(OB_FROMGROUP);
389                 flag= ob->flag & (OB_FROMGROUP);
390                 base->flag |= flag;
391                 
392                 /* not too nice... for recovering objects with lost data */
393                 if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
394                 ob->flag= base->flag;
395                 
396                 ob->ctime= -1234567.0;  /* force ipo to be calculated later */
397         }
398         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
399 }
400
401 /* called from creator.c */
402 void set_scene_name(char *name)
403 {
404         Scene *sce;
405
406         for (sce= G.main->scene.first; sce; sce= sce->id.next) {
407                 if (BLI_streq(name, sce->id.name+2)) {
408                         set_scene_bg(sce);
409                         return;
410                 }
411         }
412         
413         //XXX error("Can't find scene: %s", name);
414 }
415
416 /* used by metaballs
417  * doesnt return the original duplicated object, only dupli's
418  */
419 int next_object(Scene *scene, int val, Base **base, Object **ob)
420 {
421         static ListBase *duplilist= NULL;
422         static DupliObject *dupob;
423         static int fase= F_START, in_next_object= 0;
424         int run_again=1;
425         
426         /* init */
427         if(val==0) {
428                 fase= F_START;
429                 dupob= NULL;
430                 
431                 /* XXX particle systems with metas+dupligroups call this recursively */
432                 /* see bug #18725 */
433                 if(in_next_object) {
434                         printf("ERROR: MetaBall generation called recursively, not supported\n");
435                         
436                         return F_ERROR;
437                 }
438         }
439         else {
440                 in_next_object= 1;
441                 
442                 /* run_again is set when a duplilist has been ended */
443                 while(run_again) {
444                         run_again= 0;
445
446                         /* the first base */
447                         if(fase==F_START) {
448                                 *base= scene->base.first;
449                                 if(*base) {
450                                         *ob= (*base)->object;
451                                         fase= F_SCENE;
452                                 }
453                                 else {
454                                     /* exception: empty scene */
455                                         if(scene->set && scene->set->base.first) {
456                                                 *base= scene->set->base.first;
457                                                 *ob= (*base)->object;
458                                                 fase= F_SET;
459                                         }
460                                 }
461                         }
462                         else {
463                                 if(*base && fase!=F_DUPLI) {
464                                         *base= (*base)->next;
465                                         if(*base) *ob= (*base)->object;
466                                         else {
467                                                 if(fase==F_SCENE) {
468                                                         /* scene is finished, now do the set */
469                                                         if(scene->set && scene->set->base.first) {
470                                                                 *base= scene->set->base.first;
471                                                                 *ob= (*base)->object;
472                                                                 fase= F_SET;
473                                                         }
474                                                 }
475                                         }
476                                 }
477                         }
478                         
479                         if(*base == NULL) fase= F_START;
480                         else {
481                                 if(fase!=F_DUPLI) {
482                                         if( (*base)->object->transflag & OB_DUPLI) {
483                                                 /* groups cannot be duplicated for mballs yet, 
484                                                 this enters eternal loop because of 
485                                                 makeDispListMBall getting called inside of group_duplilist */
486                                                 if((*base)->object->dup_group == NULL) {
487                                                         duplilist= object_duplilist(scene, (*base)->object);
488                                                         
489                                                         dupob= duplilist->first;
490
491                                                         if(!dupob)
492                                                                 free_object_duplilist(duplilist);
493                                                 }
494                                         }
495                                 }
496                                 /* handle dupli's */
497                                 if(dupob) {
498                                         
499                                         Mat4CpyMat4(dupob->ob->obmat, dupob->mat);
500                                         
501                                         (*base)->flag |= OB_FROMDUPLI;
502                                         *ob= dupob->ob;
503                                         fase= F_DUPLI;
504                                         
505                                         dupob= dupob->next;
506                                 }
507                                 else if(fase==F_DUPLI) {
508                                         fase= F_SCENE;
509                                         (*base)->flag &= ~OB_FROMDUPLI;
510                                         
511                                         for(dupob= duplilist->first; dupob; dupob= dupob->next) {
512                                                 Mat4CpyMat4(dupob->ob->obmat, dupob->omat);
513                                         }
514                                         
515                                         free_object_duplilist(duplilist);
516                                         duplilist= NULL;
517                                         run_again= 1;
518                                 }
519                         }
520                 }
521         }
522         
523         /* reset recursion test */
524         in_next_object= 0;
525         
526         return fase;
527 }
528
529 Object *scene_find_camera(Scene *sc)
530 {
531         Base *base;
532         
533         for (base= sc->base.first; base; base= base->next)
534                 if (base->object->type==OB_CAMERA)
535                         return base->object;
536
537         return NULL;
538 }
539
540
541 Base *scene_add_base(Scene *sce, Object *ob)
542 {
543         Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
544         BLI_addhead(&sce->base, b);
545
546         b->object= ob;
547         b->flag= ob->flag;
548         b->lay= ob->lay;
549
550         return b;
551 }
552
553 void scene_deselect_all(Scene *sce)
554 {
555         Base *b;
556
557         for (b= sce->base.first; b; b= b->next) {
558                 b->flag&= ~SELECT;
559                 b->object->flag= b->flag;
560         }
561 }
562
563 void scene_select_base(Scene *sce, Base *selbase)
564 {
565         scene_deselect_all(sce);
566
567         selbase->flag |= SELECT;
568         selbase->object->flag= selbase->flag;
569
570         sce->basact= selbase;
571 }
572
573 /* checks for cycle, returns 1 if it's all OK */
574 int scene_check_setscene(Scene *sce)
575 {
576         Scene *scene;
577         int a, totscene;
578         
579         if(sce->set==NULL) return 1;
580         
581         totscene= 0;
582         for(scene= G.main->scene.first; scene; scene= scene->id.next)
583                 totscene++;
584         
585         for(a=0, scene=sce; scene->set; scene=scene->set, a++) {
586                 /* more iterations than scenes means we have a cycle */
587                 if(a > totscene) {
588                         /* the tested scene gets zero'ed, that's typically current scene */
589                         sce->set= NULL;
590                         return 0;
591                 }
592         }
593
594         return 1;
595 }
596
597 /* This (evil) function is needed to cope with two legacy Blender rendering features
598 * mblur (motion blur that renders 'subframes' and blurs them together), and fields 
599 * rendering. Thus, the use of ugly globals from object.c
600 */
601 // BAD... EVIL... JUJU...!!!!
602 // XXX moved here temporarily
603 float frame_to_float (Scene *scene, int cfra)           /* see also bsystem_time in object.c */
604 {
605         extern float bluroffs;  /* bad stuff borrowed from object.c */
606         extern float fieldoffs;
607         float ctime;
608         
609         ctime= (float)cfra;
610         ctime+= bluroffs+fieldoffs;
611         ctime*= scene->r.framelen;
612         
613         return ctime;
614 }
615
616 static void scene_update(Scene *sce, unsigned int lay)
617 {
618         Base *base;
619         Object *ob;
620         float ctime = frame_to_float(sce, sce->r.cfra); 
621         
622         if(sce->theDag==NULL)
623                 DAG_scene_sort(sce);
624         
625         DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
626         
627         /* All 'standard' (i.e. without any dependencies) animation is handled here,
628                 * with an 'local' to 'macro' order of evaluation. This should ensure that
629                 * settings stored nestled within a hierarchy (i.e. settings in a Texture block
630             * can be overridden by settings from Scene, which owns the Texture through a hierarchy 
631             * such as Scene->World->MTex/Texture) can still get correctly overridden.
632                 */
633         BKE_animsys_evaluate_all_animation(G.main, ctime);
634         
635         for(base= sce->base.first; base; base= base->next) {
636                 ob= base->object;
637                 
638                 object_handle_update(sce, ob);   // bke_object.h
639                 
640                 /* only update layer when an ipo */
641                         // XXX old animation system
642                 //if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
643                 //      base->lay= ob->lay;
644                 //}
645         }
646 }
647
648
649 /* applies changes right away, does all sets too */
650 void scene_update_for_newframe(Scene *sce, unsigned int lay)
651 {
652         Scene *scene= sce;
653         
654         /* clear animation overrides */
655         // XXX TODO...
656         
657         /* sets first, we allow per definition current scene to have dependencies on sets */
658         for(sce= sce->set; sce; sce= sce->set)
659                 scene_update(sce, lay);
660
661         scene_update(scene, lay);
662 }
663
664 /* return default layer, also used to patch old files */
665 void scene_add_render_layer(Scene *sce)
666 {
667         SceneRenderLayer *srl;
668         int tot= 1 + BLI_countlist(&sce->r.layers);
669         
670         srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
671         sprintf(srl->name, "%d RenderLayer", tot);
672         BLI_addtail(&sce->r.layers, srl);
673
674         /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
675         srl->lay= (1<<20) -1;
676         srl->layflag= 0x7FFF;   /* solid ztra halo edge strand */
677         srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
678 }
679
680 void sculptsession_free(Sculpt *sculpt)
681 {
682         SculptSession *ss= sculpt->session;
683         if(ss) {
684                 if(ss->projverts)
685                         MEM_freeN(ss->projverts);
686
687                 if(ss->fmap)
688                         MEM_freeN(ss->fmap);
689
690                 if(ss->fmap_mem)
691                         MEM_freeN(ss->fmap_mem);
692
693                 if(ss->texcache)
694                         MEM_freeN(ss->texcache);
695
696                 if(ss->layer_disps)
697                         MEM_freeN(ss->layer_disps);
698
699                 if(ss->mesh_co_orig)
700                         MEM_freeN(ss->mesh_co_orig);
701
702                 MEM_freeN(ss);
703                 sculpt->session= NULL;
704         }
705 }
706
707 /* render simplification */
708
709 int get_render_subsurf_level(RenderData *r, int lvl)
710 {
711         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
712                 return MIN2(r->simplify_subsurf, lvl);
713         else
714                 return lvl;
715 }
716
717 int get_render_child_particle_number(RenderData *r, int num)
718 {
719         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
720                 return (int)(r->simplify_particles*num);
721         else
722                 return num;
723 }
724
725 int get_render_shadow_samples(RenderData *r, int samples)
726 {
727         if(G.rt == 1 && (r->mode & R_SIMPLIFY) && samples > 0)
728                 return MIN2(r->simplify_shadowsamples, samples);
729         else
730                 return samples;
731 }
732
733 float get_render_aosss_error(RenderData *r, float error)
734 {
735         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
736                 return ((1.0f-r->simplify_aosss)*10.0f + 1.0f)*error;
737         else
738                 return error;
739 }
740
741 void free_dome_warp_text(struct Text *txt)
742 {
743         Scene *scene;
744
745         scene = G.main->scene.first;
746         while(scene) {
747                 if (scene->r.dometext == txt)
748                         scene->r.dometext = NULL;
749                 scene = scene->id.next;
750         }
751 }