2.5
[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_armature_types.h" 
47 #include "DNA_color_types.h"
48 #include "DNA_constraint_types.h"
49 #include "DNA_curve_types.h"
50 #include "DNA_group_types.h"
51 #include "DNA_lamp_types.h"
52 #include "DNA_material_types.h"
53 #include "DNA_meta_types.h"
54 #include "DNA_object_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_scriptlink_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_armature.h"               
63 #include "BKE_colortools.h"
64 #include "BKE_colortools.h"
65 #include "BKE_constraint.h"
66 #include "BKE_depsgraph.h"
67 #include "BKE_global.h"
68 #include "BKE_group.h"
69 #include "BKE_ipo.h"
70 #include "BKE_idprop.h"
71 #include "BKE_image.h"
72 #include "BKE_key.h"
73 #include "BKE_library.h"
74 #include "BKE_main.h"
75 #include "BKE_node.h"
76 #include "BKE_object.h"
77 #include "BKE_scene.h"
78 #include "BKE_sculpt.h"
79 #include "BKE_sequence.h"
80 #include "BKE_world.h"
81 #include "BKE_utildefines.h"
82
83 //XXX #include "BIF_previewrender.h"
84 //XXX #include "BIF_editseq.h"
85
86 #ifndef DISABLE_PYTHON
87 #include "BPY_extern.h"
88 #endif
89
90 #include "BLI_arithb.h"
91 #include "BLI_blenlib.h"
92
93 //XXX #include "nla.h"
94
95 #ifdef WIN32
96 #else
97 #include <sys/time.h>
98 #endif
99
100 void free_avicodecdata(AviCodecData *acd)
101 {
102         if (acd) {
103                 if (acd->lpFormat){
104                         MEM_freeN(acd->lpFormat);
105                         acd->lpFormat = NULL;
106                         acd->cbFormat = 0;
107                 }
108                 if (acd->lpParms){
109                         MEM_freeN(acd->lpParms);
110                         acd->lpParms = NULL;
111                         acd->cbParms = 0;
112                 }
113         }
114 }
115
116 void free_qtcodecdata(QuicktimeCodecData *qcd)
117 {
118         if (qcd) {
119                 if (qcd->cdParms){
120                         MEM_freeN(qcd->cdParms);
121                         qcd->cdParms = NULL;
122                         qcd->cdSize = 0;
123                 }
124         }
125 }
126
127 /* copy_scene moved to src/header_info.c... should be back */
128
129 /* do not free scene itself */
130 void free_scene(Scene *sce)
131 {
132         Base *base;
133
134         base= sce->base.first;
135         while(base) {
136                 base->object->id.us--;
137                 base= base->next;
138         }
139         /* do not free objects! */
140
141         BLI_freelistN(&sce->base);
142         seq_free_editing(sce->ed);
143         if(sce->radio) MEM_freeN(sce->radio);
144         sce->radio= 0;
145         
146 #ifndef DISABLE_PYTHON
147         BPY_free_scriptlink(&sce->scriptlink);
148 #endif
149         
150         if (sce->r.avicodecdata) {
151                 free_avicodecdata(sce->r.avicodecdata);
152                 MEM_freeN(sce->r.avicodecdata);
153                 sce->r.avicodecdata = NULL;
154         }
155         if (sce->r.qtcodecdata) {
156                 free_qtcodecdata(sce->r.qtcodecdata);
157                 MEM_freeN(sce->r.qtcodecdata);
158                 sce->r.qtcodecdata = NULL;
159         }
160         if (sce->r.ffcodecdata.properties) {
161                 IDP_FreeProperty(sce->r.ffcodecdata.properties);
162                 MEM_freeN(sce->r.ffcodecdata.properties);
163                 sce->r.ffcodecdata.properties = NULL;
164         }
165         
166         BLI_freelistN(&sce->markers);
167         BLI_freelistN(&sce->transform_spaces);
168         BLI_freelistN(&sce->r.layers);
169         
170         if(sce->toolsettings){
171                 MEM_freeN(sce->toolsettings);
172                 sce->toolsettings = NULL;       
173         }
174         
175         if (sce->theDag) {
176                 free_forest(sce->theDag);
177                 MEM_freeN(sce->theDag);
178         }
179         
180         if(sce->nodetree) {
181                 ntreeFreeTree(sce->nodetree);
182                 MEM_freeN(sce->nodetree);
183         }
184
185         sculptdata_free(sce);
186 }
187
188 Scene *add_scene(char *name)
189 {
190         Scene *sce;
191         ParticleEditSettings *pset;
192         int a;
193
194         sce= alloc_libblock(&G.main->scene, ID_SCE, name);
195         sce->lay= 1;
196         sce->selectmode= SCE_SELECT_VERTEX;
197         sce->editbutsize= 0.1;
198         sce->autokey_mode= U.autokey_mode;
199         
200         sce->r.mode= R_GAMMA;
201         sce->r.cfra= 1;
202         sce->r.sfra= 1;
203         sce->r.efra= 250;
204         sce->r.xsch= 320;
205         sce->r.ysch= 256;
206         sce->r.xasp= 1;
207         sce->r.yasp= 1;
208         sce->r.xparts= 4;
209         sce->r.yparts= 4;
210         sce->r.size= 100;
211         sce->r.planes= 24;
212         sce->r.quality= 90;
213         sce->r.framapto= 100;
214         sce->r.images= 100;
215         sce->r.framelen= 1.0;
216         sce->r.frs_sec= 25;
217         sce->r.frs_sec_base= 1;
218         sce->r.ocres = 128;
219         
220         sce->r.bake_mode= 1;    /* prevent to include render stuff here */
221         sce->r.bake_filter= 2;
222         sce->r.bake_osa= 5;
223         sce->r.bake_flag= R_BAKE_CLEAR;
224         sce->r.bake_normal_space= R_BAKE_SPACE_TANGENT;
225         
226         sce->r.xplay= 640;
227         sce->r.yplay= 480;
228         sce->r.freqplay= 60;
229         sce->r.depth= 32;
230         
231         sce->r.threads= 1;
232         
233         sce->r.stereomode = 1;  // no stereo
234
235         sce->r.simplify_subsurf= 6;
236         sce->r.simplify_particles= 1.0f;
237         sce->r.simplify_shadowsamples= 16;
238         sce->r.simplify_aosss= 1.0f;
239
240         sce->r.cineonblack= 95;
241         sce->r.cineonwhite= 685;
242         sce->r.cineongamma= 1.7f;
243         
244         sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings),"Tool Settings Struct");
245         sce->toolsettings->cornertype=1;
246         sce->toolsettings->degr = 90; 
247         sce->toolsettings->step = 9;
248         sce->toolsettings->turn = 1;                            
249         sce->toolsettings->extr_offs = 1; 
250         sce->toolsettings->doublimit = 0.001;
251         sce->toolsettings->segments = 32;
252         sce->toolsettings->rings = 32;
253         sce->toolsettings->vertices = 32;
254         sce->toolsettings->editbutflag = 1;
255         sce->toolsettings->uvcalc_radius = 1.0f;
256         sce->toolsettings->uvcalc_cubesize = 1.0f;
257         sce->toolsettings->uvcalc_mapdir = 1;
258         sce->toolsettings->uvcalc_mapalign = 1;
259         sce->toolsettings->unwrapper = 1;
260         sce->toolsettings->select_thresh= 0.01f;
261         sce->toolsettings->jointrilimit = 0.8f;
262
263         sce->toolsettings->skgen_resolution = 100;
264         sce->toolsettings->skgen_threshold_internal     = 0.01f;
265         sce->toolsettings->skgen_threshold_external     = 0.01f;
266         sce->toolsettings->skgen_angle_limit                    = 45.0f;
267         sce->toolsettings->skgen_length_ratio                   = 1.3f;
268         sce->toolsettings->skgen_length_limit                   = 1.5f;
269         sce->toolsettings->skgen_correlation_limit              = 0.98f;
270         sce->toolsettings->skgen_symmetry_limit                 = 0.1f;
271         sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
272         sce->toolsettings->skgen_postpro_passes = 1;
273         sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_HARMONIC|SKGEN_SUB_CORRELATION|SKGEN_STICK_TO_EMBEDDING;
274         sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
275         sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
276         sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
277
278         pset= &sce->toolsettings->particle;
279         pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
280         pset->emitterdist= 0.25f;
281         pset->totrekey= 5;
282         pset->totaddkey= 5;
283         pset->brushtype= PE_BRUSH_NONE;
284         for(a=0; a<PE_TOT_BRUSH; a++) {
285                 pset->brush[a].strength= 50;
286                 pset->brush[a].size= 50;
287                 pset->brush[a].step= 10;
288         }
289         pset->brush[PE_BRUSH_CUT].strength= 100;
290         
291         sce->jumpframe = 10;
292         sce->audio.mixrate = 44100;
293
294         strcpy(sce->r.backbuf, "//backbuf");
295         strcpy(sce->r.pic, U.renderdir);
296
297         BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
298         sce->r.osa= 8;
299
300         sculptdata_init(sce);
301
302         /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
303         scene_add_render_layer(sce);
304         
305         return sce;
306 }
307
308 Base *object_in_scene(Object *ob, Scene *sce)
309 {
310         Base *base;
311         
312         base= sce->base.first;
313         while(base) {
314                 if(base->object == ob) return base;
315                 base= base->next;
316         }
317         return NULL;
318 }
319
320 void set_scene_bg(Scene *scene)
321 {
322         Scene *sce;
323         Base *base;
324         Object *ob;
325         Group *group;
326         GroupObject *go;
327         int flag;
328         
329         /* check for cyclic sets, for reading old files but also for definite security (py?) */
330         scene_check_setscene(scene);
331         
332         /* deselect objects (for dataselect) */
333         for(ob= G.main->object.first; ob; ob= ob->id.next)
334                 ob->flag &= ~(SELECT|OB_FROMGROUP);
335
336         /* group flags again */
337         for(group= G.main->group.first; group; group= group->id.next) {
338                 go= group->gobject.first;
339                 while(go) {
340                         if(go->ob) go->ob->flag |= OB_FROMGROUP;
341                         go= go->next;
342                 }
343         }
344
345         /* sort baselist */
346         DAG_scene_sort(scene);
347         
348         /* ensure dags are built for sets */
349         for(sce= scene->set; sce; sce= sce->set)
350                 if(sce->theDag==NULL)
351                         DAG_scene_sort(sce);
352
353         /* copy layers and flags from bases to objects */
354         for(base= scene->base.first; base; base= base->next) {
355                 ob= base->object;
356                 ob->lay= base->lay;
357                 
358                 /* group patch... */
359                 base->flag &= ~(OB_FROMGROUP);
360                 flag= ob->flag & (OB_FROMGROUP);
361                 base->flag |= flag;
362                 
363                 /* not too nice... for recovering objects with lost data */
364                 if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
365                 ob->flag= base->flag;
366                 
367                 ob->ctime= -1234567.0;  /* force ipo to be calculated later */
368         }
369         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
370         
371         /* do we need FRAMECHANGED in set_scene? */
372 //      if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
373 }
374
375 /* called from creator.c */
376 void set_scene_name(char *name)
377 {
378         Scene *sce;
379
380         for (sce= G.main->scene.first; sce; sce= sce->id.next) {
381                 if (BLI_streq(name, sce->id.name+2)) {
382                         set_scene_bg(sce);
383                         return;
384                 }
385         }
386         
387         //XXX error("Can't find scene: %s", name);
388 }
389
390 /* used by metaballs
391  * doesnt return the original duplicated object, only dupli's
392  */
393 int next_object(Scene *scene, int val, Base **base, Object **ob)
394 {
395         static ListBase *duplilist= NULL;
396         static DupliObject *dupob;
397         static int fase;
398         int run_again=1;
399         
400         /* init */
401         if(val==0) {
402                 fase= F_START;
403                 dupob= NULL;
404         }
405         else {
406
407                 /* run_again is set when a duplilist has been ended */
408                 while(run_again) {
409                         run_again= 0;
410
411                         /* the first base */
412                         if(fase==F_START) {
413                                 *base= scene->base.first;
414                                 if(*base) {
415                                         *ob= (*base)->object;
416                                         fase= F_SCENE;
417                                 }
418                                 else {
419                                     /* exception: empty scene */
420                                         if(scene->set && scene->set->base.first) {
421                                                 *base= scene->set->base.first;
422                                                 *ob= (*base)->object;
423                                                 fase= F_SET;
424                                         }
425                                 }
426                         }
427                         else {
428                                 if(*base && fase!=F_DUPLI) {
429                                         *base= (*base)->next;
430                                         if(*base) *ob= (*base)->object;
431                                         else {
432                                                 if(fase==F_SCENE) {
433                                                         /* scene is finished, now do the set */
434                                                         if(scene->set && scene->set->base.first) {
435                                                                 *base= scene->set->base.first;
436                                                                 *ob= (*base)->object;
437                                                                 fase= F_SET;
438                                                         }
439                                                 }
440                                         }
441                                 }
442                         }
443                         
444                         if(*base == NULL) fase= F_START;
445                         else {
446                                 if(fase!=F_DUPLI) {
447                                         if( (*base)->object->transflag & OB_DUPLI) {
448                                                 /* groups cannot be duplicated for mballs yet, 
449                                                 this enters eternal loop because of 
450                                                 makeDispListMBall getting called inside of group_duplilist */
451                                                 if((*base)->object->dup_group == NULL) {
452                                                         duplilist= object_duplilist(scene, (*base)->object);
453                                                         
454                                                         dupob= duplilist->first;
455
456                                                         if(!dupob)
457                                                                 free_object_duplilist(duplilist);
458                                                 }
459                                         }
460                                 }
461                                 /* handle dupli's */
462                                 if(dupob) {
463                                         
464                                         Mat4CpyMat4(dupob->ob->obmat, dupob->mat);
465                                         
466                                         (*base)->flag |= OB_FROMDUPLI;
467                                         *ob= dupob->ob;
468                                         fase= F_DUPLI;
469                                         
470                                         dupob= dupob->next;
471                                 }
472                                 else if(fase==F_DUPLI) {
473                                         fase= F_SCENE;
474                                         (*base)->flag &= ~OB_FROMDUPLI;
475                                         
476                                         for(dupob= duplilist->first; dupob; dupob= dupob->next) {
477                                                 Mat4CpyMat4(dupob->ob->obmat, dupob->omat);
478                                         }
479                                         
480                                         free_object_duplilist(duplilist);
481                                         duplilist= NULL;
482                                         run_again= 1;
483                                 }
484                         }
485                 }
486         }
487         
488         return fase;
489 }
490
491 Object *scene_find_camera(Scene *sc)
492 {
493         Base *base;
494         
495         for (base= sc->base.first; base; base= base->next)
496                 if (base->object->type==OB_CAMERA)
497                         return base->object;
498
499         return NULL;
500 }
501
502
503 Base *scene_add_base(Scene *sce, Object *ob)
504 {
505         Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
506         BLI_addhead(&sce->base, b);
507
508         b->object= ob;
509         b->flag= ob->flag;
510         b->lay= ob->lay;
511
512         return b;
513 }
514
515 void scene_deselect_all(Scene *sce)
516 {
517         Base *b;
518
519         for (b= sce->base.first; b; b= b->next) {
520                 b->flag&= ~SELECT;
521                 b->object->flag= b->flag;
522         }
523 }
524
525 void scene_select_base(Scene *sce, Base *selbase)
526 {
527         scene_deselect_all(sce);
528
529         selbase->flag |= SELECT;
530         selbase->object->flag= selbase->flag;
531
532         sce->basact= selbase;
533 }
534
535 /* checks for cycle, returns 1 if it's all OK */
536 int scene_check_setscene(Scene *sce)
537 {
538         Scene *scene;
539         int a, totscene;
540         
541         if(sce->set==NULL) return 1;
542         
543         totscene= 0;
544         for(scene= G.main->scene.first; scene; scene= scene->id.next)
545                 totscene++;
546         
547         for(a=0, scene=sce; scene->set; scene=scene->set, a++) {
548                 /* more iterations than scenes means we have a cycle */
549                 if(a > totscene) {
550                         /* the tested scene gets zero'ed, that's typically current scene */
551                         sce->set= NULL;
552                         return 0;
553                 }
554         }
555
556         return 1;
557 }
558
559 static void scene_update(Scene *sce, unsigned int lay)
560 {
561         Base *base;
562         Object *ob;
563         
564         if(sce->theDag==NULL)
565                 DAG_scene_sort(sce);
566         
567         DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
568         
569         for(base= sce->base.first; base; base= base->next) {
570                 ob= base->object;
571                 
572                 object_handle_update(sce, ob);   // bke_object.h
573                 
574                 /* only update layer when an ipo */
575                 if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
576                         base->lay= ob->lay;
577                 }
578         }
579 }
580
581 /* applies changes right away, does all sets too */
582 void scene_update_for_newframe(Scene *sce, unsigned int lay)
583 {
584         Scene *scene= sce;
585         
586         /* clears all BONE_UNKEYED flags for every pose's pchans */
587         framechange_poses_clear_unkeyed();
588         
589         /* object ipos are calculated in where_is_object */
590         do_all_data_ipos(sce);
591 #ifndef DISABLE_PYTHON
592         if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
593 #endif
594         /* sets first, we allow per definition current scene to have dependencies on sets */
595         for(sce= sce->set; sce; sce= sce->set)
596                 scene_update(sce, lay);
597
598         scene_update(scene, lay);
599 }
600
601 /* return default layer, also used to patch old files */
602 void scene_add_render_layer(Scene *sce)
603 {
604         SceneRenderLayer *srl;
605         int tot= 1 + BLI_countlist(&sce->r.layers);
606         
607         srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
608         sprintf(srl->name, "%d RenderLayer", tot);
609         BLI_addtail(&sce->r.layers, srl);
610
611         /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
612         srl->lay= (1<<20) -1;
613         srl->layflag= 0x7FFF;   /* solid ztra halo edge strand */
614         srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
615 }
616
617 /* Initialize 'permanent' sculpt data that is saved with file kept after
618    switching out of sculptmode. */
619 void sculptdata_init(Scene *sce)
620 {
621         SculptData *sd;
622
623         if(!sce)
624                 return;
625
626         sd= &sce->sculptdata;
627
628         if(sd->cumap) {
629                 curvemapping_free(sd->cumap);
630                 sd->cumap = NULL;
631         }
632
633         memset(sd, 0, sizeof(SculptData));
634
635         sd->drawbrush.size = sd->smoothbrush.size = sd->pinchbrush.size =
636                 sd->inflatebrush.size = sd->grabbrush.size =
637                 sd->layerbrush.size = sd->flattenbrush.size = 50;
638         sd->drawbrush.strength = sd->smoothbrush.strength =
639                 sd->pinchbrush.strength = sd->inflatebrush.strength =
640                 sd->grabbrush.strength = sd->layerbrush.strength =
641                 sd->flattenbrush.strength = 25;
642         sd->drawbrush.dir = sd->pinchbrush.dir = sd->inflatebrush.dir = sd->layerbrush.dir= 1;
643         sd->drawbrush.flag = sd->smoothbrush.flag =
644                 sd->pinchbrush.flag = sd->inflatebrush.flag =
645                 sd->layerbrush.flag = sd->flattenbrush.flag = 0;
646         sd->drawbrush.view= 0;
647         sd->brush_type= DRAW_BRUSH;
648         sd->texact= -1;
649         sd->texfade= 1;
650         sd->averaging= 1;
651         sd->texsep= 0;
652         sd->texrept= SCULPTREPT_DRAG;
653         sd->flags= SCULPT_DRAW_BRUSH;
654         sd->tablet_size=3;
655         sd->tablet_strength=10;
656         sd->rake=0;
657         sculpt_reset_curve(sd);
658 }
659
660 void sculptdata_free(Scene *sce)
661 {
662         SculptData *sd= &sce->sculptdata;
663         int a;
664
665         sculptsession_free(sce);
666
667         for(a=0; a<MAX_MTEX; a++) {
668                 MTex *mtex= sd->mtex[a];
669                 if(mtex) {
670                         if(mtex->tex) mtex->tex->id.us--;
671                         MEM_freeN(mtex);
672                 }
673         }
674
675         curvemapping_free(sd->cumap);
676         sd->cumap = NULL;
677 }
678
679 void sculpt_vertexusers_free(SculptSession *ss)
680 {
681         if(ss && ss->vertex_users){
682                 MEM_freeN(ss->vertex_users);
683                 MEM_freeN(ss->vertex_users_mem);
684                 ss->vertex_users= NULL;
685                 ss->vertex_users_mem= NULL;
686                 ss->vertex_users_size= 0;
687         }
688 }
689
690 void sculptsession_free(Scene *sce)
691 {
692         SculptSession *ss= sce->sculptdata.session;
693         if(ss) {
694                 if(ss->projverts)
695                         MEM_freeN(ss->projverts);
696                 if(ss->mats)
697                         MEM_freeN(ss->mats);
698
699                 if(ss->radialcontrol)
700                         MEM_freeN(ss->radialcontrol);
701
702                 sculpt_vertexusers_free(ss);
703                 if(ss->texcache)
704                         MEM_freeN(ss->texcache);
705                 MEM_freeN(ss);
706                 sce->sculptdata.session= NULL;
707         }
708 }
709
710 /*  Default curve approximates 0.5 * (cos(pi * x) + 1), with 0 <= x <= 1 */
711 void sculpt_reset_curve(SculptData *sd)
712 {
713         CurveMap *cm = NULL;
714
715         if(!sd->cumap)
716                 sd->cumap = curvemapping_add(1, 0, 0, 1, 1);
717
718         cm = sd->cumap->cm;
719
720         if(cm->curve)
721                 MEM_freeN(cm->curve);
722         cm->curve= MEM_callocN(6*sizeof(CurveMapPoint), "curve points");
723         cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
724         cm->totpoint= 6;
725         cm->curve[0].x= 0;
726         cm->curve[0].y= 1;
727         cm->curve[1].x= 0.1;
728         cm->curve[1].y= 0.97553;
729         cm->curve[2].x= 0.3;
730         cm->curve[2].y= 0.79389;
731         cm->curve[3].x= 0.9;
732         cm->curve[3].y= 0.02447;
733         cm->curve[4].x= 0.7;
734         cm->curve[4].y= 0.20611;
735         cm->curve[5].x= 1;
736         cm->curve[5].y= 0;
737
738         curvemapping_changed(sd->cumap, 0);
739 }
740
741 /* render simplification */
742
743 int get_render_subsurf_level(RenderData *r, int lvl)
744 {
745         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
746                 return MIN2(r->simplify_subsurf, lvl);
747         else
748                 return lvl;
749 }
750
751 int get_render_child_particle_number(RenderData *r, int num)
752 {
753         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
754                 return (int)(r->simplify_particles*num);
755         else
756                 return num;
757 }
758
759 int get_render_shadow_samples(RenderData *r, int samples)
760 {
761         if(G.rt == 1 && (r->mode & R_SIMPLIFY) && samples > 0)
762                 return MIN2(r->simplify_shadowsamples, samples);
763         else
764                 return samples;
765 }
766
767 float get_render_aosss_error(RenderData *r, float error)
768 {
769         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
770                 return ((1.0f-r->simplify_aosss)*10.0f + 1.0f)*error;
771         else
772                 return error;
773 }
774