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