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