2.50: added sequence.c in blenkernel for sequencer functionality
[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 *sce)
321 {
322         Base *base;
323         Object *ob;
324         Group *group;
325         GroupObject *go;
326         int flag;
327         
328         // Note: this here is defined in editseq.c (BIF_editseq.h), NOT in blenkernel! 
329         //XXX clear_last_seq();
330         
331         G.scene= sce;
332         
333         /* check for cyclic sets, for reading old files but also for definite security (py?) */
334         scene_check_setscene(G.scene);
335         
336         /* deselect objects (for dataselect) */
337         for(ob= G.main->object.first; ob; ob= ob->id.next)
338                 ob->flag &= ~(SELECT|OB_FROMGROUP);
339
340         /* group flags again */
341         for(group= G.main->group.first; group; group= group->id.next) {
342                 go= group->gobject.first;
343                 while(go) {
344                         if(go->ob) go->ob->flag |= OB_FROMGROUP;
345                         go= go->next;
346                 }
347         }
348
349         /* sort baselist */
350         DAG_scene_sort(sce);
351         
352         /* ensure dags are built for sets */
353         for(sce= sce->set; sce; sce= sce->set)
354                 if(sce->theDag==NULL)
355                         DAG_scene_sort(sce);
356
357         /* copy layers and flags from bases to objects */
358         for(base= G.scene->base.first; base; base= base->next) {
359                 ob= base->object;
360                 ob->lay= base->lay;
361                 
362                 /* group patch... */
363                 base->flag &= ~(OB_FROMGROUP);
364                 flag= ob->flag & (OB_FROMGROUP);
365                 base->flag |= flag;
366                 
367                 /* not too nice... for recovering objects with lost data */
368                 if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
369                 ob->flag= base->flag;
370                 
371                 ob->ctime= -1234567.0;  /* force ipo to be calculated later */
372         }
373         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
374         
375         /* do we need FRAMECHANGED in set_scene? */
376 //      if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
377 }
378
379 /* called from creator.c */
380 void set_scene_name(char *name)
381 {
382         Scene *sce;
383
384         for (sce= G.main->scene.first; sce; sce= sce->id.next) {
385                 if (BLI_streq(name, sce->id.name+2)) {
386                         set_scene_bg(sce);
387                         return;
388                 }
389         }
390         
391         //XXX error("Can't find scene: %s", name);
392 }
393
394 /* used by metaballs
395  * doesnt return the original duplicated object, only dupli's
396  */
397 int next_object(int val, Base **base, Object **ob)
398 {
399         static ListBase *duplilist= NULL;
400         static DupliObject *dupob;
401         static int fase;
402         int run_again=1;
403         
404         /* init */
405         if(val==0) {
406                 fase= F_START;
407                 dupob= NULL;
408         }
409         else {
410
411                 /* run_again is set when a duplilist has been ended */
412                 while(run_again) {
413                         run_again= 0;
414
415                         /* the first base */
416                         if(fase==F_START) {
417                                 *base= G.scene->base.first;
418                                 if(*base) {
419                                         *ob= (*base)->object;
420                                         fase= F_SCENE;
421                                 }
422                                 else {
423                                     /* exception: empty scene */
424                                         if(G.scene->set && G.scene->set->base.first) {
425                                                 *base= G.scene->set->base.first;
426                                                 *ob= (*base)->object;
427                                                 fase= F_SET;
428                                         }
429                                 }
430                         }
431                         else {
432                                 if(*base && fase!=F_DUPLI) {
433                                         *base= (*base)->next;
434                                         if(*base) *ob= (*base)->object;
435                                         else {
436                                                 if(fase==F_SCENE) {
437                                                         /* scene is finished, now do the set */
438                                                         if(G.scene->set && G.scene->set->base.first) {
439                                                                 *base= G.scene->set->base.first;
440                                                                 *ob= (*base)->object;
441                                                                 fase= F_SET;
442                                                         }
443                                                 }
444                                         }
445                                 }
446                         }
447                         
448                         if(*base == NULL) fase= F_START;
449                         else {
450                                 if(fase!=F_DUPLI) {
451                                         if( (*base)->object->transflag & OB_DUPLI) {
452                                                 /* groups cannot be duplicated for mballs yet, 
453                                                 this enters eternal loop because of 
454                                                 makeDispListMBall getting called inside of group_duplilist */
455                                                 if((*base)->object->dup_group == NULL) {
456                                                         duplilist= object_duplilist(G.scene, (*base)->object);
457                                                         
458                                                         dupob= duplilist->first;
459
460                                                         if(!dupob)
461                                                                 free_object_duplilist(duplilist);
462                                                 }
463                                         }
464                                 }
465                                 /* handle dupli's */
466                                 if(dupob) {
467                                         
468                                         Mat4CpyMat4(dupob->ob->obmat, dupob->mat);
469                                         
470                                         (*base)->flag |= OB_FROMDUPLI;
471                                         *ob= dupob->ob;
472                                         fase= F_DUPLI;
473                                         
474                                         dupob= dupob->next;
475                                 }
476                                 else if(fase==F_DUPLI) {
477                                         fase= F_SCENE;
478                                         (*base)->flag &= ~OB_FROMDUPLI;
479                                         
480                                         for(dupob= duplilist->first; dupob; dupob= dupob->next) {
481                                                 Mat4CpyMat4(dupob->ob->obmat, dupob->omat);
482                                         }
483                                         
484                                         free_object_duplilist(duplilist);
485                                         duplilist= NULL;
486                                         run_again= 1;
487                                 }
488                         }
489                 }
490         }
491         
492         return fase;
493 }
494
495 Object *scene_find_camera(Scene *sc)
496 {
497         Base *base;
498         
499         for (base= sc->base.first; base; base= base->next)
500                 if (base->object->type==OB_CAMERA)
501                         return base->object;
502
503         return NULL;
504 }
505
506
507 Base *scene_add_base(Scene *sce, Object *ob)
508 {
509         Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
510         BLI_addhead(&sce->base, b);
511
512         b->object= ob;
513         b->flag= ob->flag;
514         b->lay= ob->lay;
515
516         return b;
517 }
518
519 void scene_deselect_all(Scene *sce)
520 {
521         Base *b;
522
523         for (b= sce->base.first; b; b= b->next) {
524                 b->flag&= ~SELECT;
525                 b->object->flag= b->flag;
526         }
527 }
528
529 void scene_select_base(Scene *sce, Base *selbase)
530 {
531         scene_deselect_all(sce);
532
533         selbase->flag |= SELECT;
534         selbase->object->flag= selbase->flag;
535
536         sce->basact= selbase;
537 }
538
539 /* checks for cycle, returns 1 if it's all OK */
540 int scene_check_setscene(Scene *sce)
541 {
542         Scene *scene;
543         int a, totscene;
544         
545         if(sce->set==NULL) return 1;
546         
547         totscene= 0;
548         for(scene= G.main->scene.first; scene; scene= scene->id.next)
549                 totscene++;
550         
551         for(a=0, scene=sce; scene->set; scene=scene->set, a++) {
552                 /* more iterations than scenes means we have a cycle */
553                 if(a > totscene) {
554                         /* the tested scene gets zero'ed, that's typically current scene */
555                         sce->set= NULL;
556                         return 0;
557                 }
558         }
559
560         return 1;
561 }
562
563 static void scene_update(Scene *sce, unsigned int lay)
564 {
565         Base *base;
566         Object *ob;
567         
568         if(sce->theDag==NULL)
569                 DAG_scene_sort(sce);
570         
571         DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
572         
573         for(base= sce->base.first; base; base= base->next) {
574                 ob= base->object;
575                 
576                 object_handle_update(ob);   // bke_object.h
577                 
578                 /* only update layer when an ipo */
579                 if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
580                         base->lay= ob->lay;
581                 }
582         }
583 }
584
585 /* applies changes right away, does all sets too */
586 void scene_update_for_newframe(Scene *sce, unsigned int lay)
587 {
588         Scene *scene= sce;
589         
590         /* clears all BONE_UNKEYED flags for every pose's pchans */
591         framechange_poses_clear_unkeyed();
592         
593         /* object ipos are calculated in where_is_object */
594         do_all_data_ipos();
595 #ifndef DISABLE_PYTHON
596         if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
597 #endif
598         /* sets first, we allow per definition current scene to have dependencies on sets */
599         for(sce= sce->set; sce; sce= sce->set)
600                 scene_update(sce, lay);
601
602         scene_update(scene, lay);
603 }
604
605 /* return default layer, also used to patch old files */
606 void scene_add_render_layer(Scene *sce)
607 {
608         SceneRenderLayer *srl;
609         int tot= 1 + BLI_countlist(&sce->r.layers);
610         
611         srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
612         sprintf(srl->name, "%d RenderLayer", tot);
613         BLI_addtail(&sce->r.layers, srl);
614
615         /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
616         srl->lay= (1<<20) -1;
617         srl->layflag= 0x7FFF;   /* solid ztra halo edge strand */
618         srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
619 }
620
621 /* Initialize 'permanent' sculpt data that is saved with file kept after
622    switching out of sculptmode. */
623 void sculptdata_init(Scene *sce)
624 {
625         SculptData *sd;
626
627         if(!sce)
628                 return;
629
630         sd= &sce->sculptdata;
631
632         if(sd->cumap) {
633                 curvemapping_free(sd->cumap);
634                 sd->cumap = NULL;
635         }
636
637         memset(sd, 0, sizeof(SculptData));
638
639         sd->drawbrush.size = sd->smoothbrush.size = sd->pinchbrush.size =
640                 sd->inflatebrush.size = sd->grabbrush.size =
641                 sd->layerbrush.size = sd->flattenbrush.size = 50;
642         sd->drawbrush.strength = sd->smoothbrush.strength =
643                 sd->pinchbrush.strength = sd->inflatebrush.strength =
644                 sd->grabbrush.strength = sd->layerbrush.strength =
645                 sd->flattenbrush.strength = 25;
646         sd->drawbrush.dir = sd->pinchbrush.dir = sd->inflatebrush.dir = sd->layerbrush.dir= 1;
647         sd->drawbrush.flag = sd->smoothbrush.flag =
648                 sd->pinchbrush.flag = sd->inflatebrush.flag =
649                 sd->layerbrush.flag = sd->flattenbrush.flag = 0;
650         sd->drawbrush.view= 0;
651         sd->brush_type= DRAW_BRUSH;
652         sd->texact= -1;
653         sd->texfade= 1;
654         sd->averaging= 1;
655         sd->texsep= 0;
656         sd->texrept= SCULPTREPT_DRAG;
657         sd->flags= SCULPT_DRAW_BRUSH;
658         sd->tablet_size=3;
659         sd->tablet_strength=10;
660         sd->rake=0;
661         sculpt_reset_curve(sd);
662 }
663
664 void sculptdata_free(Scene *sce)
665 {
666         SculptData *sd= &sce->sculptdata;
667         int a;
668
669         sculptsession_free(sce);
670
671         for(a=0; a<MAX_MTEX; a++) {
672                 MTex *mtex= sd->mtex[a];
673                 if(mtex) {
674                         if(mtex->tex) mtex->tex->id.us--;
675                         MEM_freeN(mtex);
676                 }
677         }
678
679         curvemapping_free(sd->cumap);
680         sd->cumap = NULL;
681 }
682
683 void sculpt_vertexusers_free(SculptSession *ss)
684 {
685         if(ss && ss->vertex_users){
686                 MEM_freeN(ss->vertex_users);
687                 MEM_freeN(ss->vertex_users_mem);
688                 ss->vertex_users= NULL;
689                 ss->vertex_users_mem= NULL;
690                 ss->vertex_users_size= 0;
691         }
692 }
693
694 void sculptsession_free(Scene *sce)
695 {
696         SculptSession *ss= sce->sculptdata.session;
697         if(ss) {
698                 if(ss->projverts)
699                         MEM_freeN(ss->projverts);
700                 if(ss->mats)
701                         MEM_freeN(ss->mats);
702
703                 if(ss->radialcontrol)
704                         MEM_freeN(ss->radialcontrol);
705
706                 sculpt_vertexusers_free(ss);
707                 if(ss->texcache)
708                         MEM_freeN(ss->texcache);
709                 MEM_freeN(ss);
710                 sce->sculptdata.session= NULL;
711         }
712 }
713
714 /*  Default curve approximates 0.5 * (cos(pi * x) + 1), with 0 <= x <= 1 */
715 void sculpt_reset_curve(SculptData *sd)
716 {
717         CurveMap *cm = NULL;
718
719         if(!sd->cumap)
720                 sd->cumap = curvemapping_add(1, 0, 0, 1, 1);
721
722         cm = sd->cumap->cm;
723
724         if(cm->curve)
725                 MEM_freeN(cm->curve);
726         cm->curve= MEM_callocN(6*sizeof(CurveMapPoint), "curve points");
727         cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
728         cm->totpoint= 6;
729         cm->curve[0].x= 0;
730         cm->curve[0].y= 1;
731         cm->curve[1].x= 0.1;
732         cm->curve[1].y= 0.97553;
733         cm->curve[2].x= 0.3;
734         cm->curve[2].y= 0.79389;
735         cm->curve[3].x= 0.9;
736         cm->curve[3].y= 0.02447;
737         cm->curve[4].x= 0.7;
738         cm->curve[4].y= 0.20611;
739         cm->curve[5].x= 1;
740         cm->curve[5].y= 0;
741
742         curvemapping_changed(sd->cumap, 0);
743 }
744
745 /* render simplification */
746
747 int get_render_subsurf_level(RenderData *r, int lvl)
748 {
749         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
750                 return MIN2(r->simplify_subsurf, lvl);
751         else
752                 return lvl;
753 }
754
755 int get_render_child_particle_number(RenderData *r, int num)
756 {
757         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
758                 return (int)(r->simplify_particles*num);
759         else
760                 return num;
761 }
762
763 int get_render_shadow_samples(RenderData *r, int samples)
764 {
765         if(G.rt == 1 && (r->mode & R_SIMPLIFY) && samples > 0)
766                 return MIN2(r->simplify_shadowsamples, samples);
767         else
768                 return samples;
769 }
770
771 float get_render_aosss_error(RenderData *r, float error)
772 {
773         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
774                 return ((1.0f-r->simplify_aosss)*10.0f + 1.0f)*error;
775         else
776                 return error;
777 }
778