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