Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sceneRadio.c « api2_2x « python « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6bdc45d582cf413c770825b57b1810e6b74becf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
/* 
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can Redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA	02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * This is a new part of Blender.
 *
 * Contributor(s): Willian P. Germano
 *
 * ***** END GPL LICENSE BLOCK *****
*/

#include "sceneRadio.h"		/*This must come first*/

#include "BKE_global.h"
#include "BKE_object.h"		/* disable_where_script() */
#include "gen_utils.h"
#include "constant.h"
#include "radio.h"


/* bitflags */
#define EXPP_RADIO_flag_SHOWLIM 1
#define EXPP_RADIO_flag_Z 2
/* shorts */
#define EXPP_RADIO_hemires_MIN 100
#define EXPP_RADIO_hemires_MAX 1000
#define EXPP_RADIO_maxiter_MIN 0
#define EXPP_RADIO_maxiter_MAX 10000
#define EXPP_RADIO_subshootp_MIN 0
#define EXPP_RADIO_subshootp_MAX 10
#define EXPP_RADIO_subshoote_MIN 0
#define EXPP_RADIO_subshoote_MAX 10
#define EXPP_RADIO_nodelim_MIN 0
#define EXPP_RADIO_nodelim_MAX 50
#define EXPP_RADIO_maxsublamp_MIN 1
#define EXPP_RADIO_maxsublamp_MAX 250
#define EXPP_RADIO_pama_MIN 10
#define EXPP_RADIO_pama_MAX 1000
#define EXPP_RADIO_pami_MIN 10
#define EXPP_RADIO_pami_MAX 1000
#define EXPP_RADIO_elma_MIN 1
#define EXPP_RADIO_elma_MAX 500
#define EXPP_RADIO_elmi_MIN 1
#define EXPP_RADIO_elmi_MAX 100
/* ints */
#define EXPP_RADIO_maxnode_MIN 1
#define EXPP_RADIO_maxnode_MAX 250000
/* floats */
#define EXPP_RADIO_convergence_MIN 0.0
#define EXPP_RADIO_convergence_MAX 0.1f
#define EXPP_RADIO_radfac_MIN 0.001f
#define EXPP_RADIO_radfac_MAX 250.0
#define EXPP_RADIO_gamma_MIN 0.2f
#define EXPP_RADIO_gamma_MAX 10.0
/* drawtypes */
#define EXPP_RADIO_drawtype_WIRE 0
#define EXPP_RADIO_drawtype_SOLID 1
#define EXPP_RADIO_drawtype_GOURAUD 2

static int EXPP_check_scene( Scene * scene )
{
	if( scene != G.scene ) {
		PyErr_SetString( PyExc_EnvironmentError,
				 "\nradiosity only works on the current scene, check scene.makeCurrent()." );
		return 0;
	} else if( !scene->radio ) {
		PyErr_SetString( PyExc_EnvironmentError,
				 "\nradiosity data was deleted from scene!" );
		return 0;
	}

	return 1;
}

static PyObject *Radio_collectMeshes( BPy_Radio * self );
static PyObject *Radio_go( BPy_Radio * self );
static PyObject *Radio_freeData( BPy_Radio * self );
static PyObject *Radio_replaceMeshes( BPy_Radio * self );
static PyObject *Radio_addMesh( BPy_Radio * self );
static PyObject *Radio_filterFaces( BPy_Radio * self );
static PyObject *Radio_filterElems( BPy_Radio * self );
static PyObject *Radio_limitSubdivide( BPy_Radio * self );
static PyObject *Radio_subdividePatches( BPy_Radio * self );
static PyObject *Radio_subdivideElems( BPy_Radio * self );
static PyObject *Radio_removeDoubles( BPy_Radio * self );

static PyObject *Radio_repr( BPy_Radio * self );

static PyObject *EXPP_create_ret_PyInt( int value )
{
	PyObject *pyval = PyInt_FromLong( value );

	if( !pyval )
		PyErr_SetString( PyExc_MemoryError,
				 "couldn't create py int!" );

	return pyval;
}

static PyObject *EXPP_create_ret_PyFloat( float value )
{
	PyObject *pyval = PyFloat_FromDouble( ( double ) value );

	if( !pyval )
		PyErr_SetString( PyExc_MemoryError,
				 "couldn't create py int!" );

	return pyval;
}

static PyObject *Radio_get_hemires( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->hemires );
}

static PyObject *Radio_get_maxiter( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->maxiter );
}

static PyObject *Radio_get_subshootp( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->subshootp );
}

static PyObject *Radio_get_subshoote( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->subshoote );
}

static PyObject *Radio_get_nodelim( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->nodelim );
}

static PyObject *Radio_get_maxsublamp( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->maxsublamp );
}

static PyObject *Radio_get_pama( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->pama );
}

static PyObject *Radio_get_pami( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->pami );
}

static PyObject *Radio_get_elma( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->elma );
}

static PyObject *Radio_get_elmi( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->elmi );
}

static PyObject *Radio_get_drawtype( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->drawtype );
}

static PyObject *Radio_get_flag( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->flag );
}

static PyObject *Radio_get_maxnode( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyInt( ( int ) self->scene->radio->maxnode );
}

static PyObject *Radio_get_convergence( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyFloat( self->scene->radio->convergence );
}

static PyObject *Radio_get_radfac( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyFloat( self->scene->radio->radfac );
}

static PyObject *Radio_get_gamma( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_create_ret_PyFloat( self->scene->radio->gamma );
}

static PyObject *EXPP_unpack_set_int( PyObject * args, int *ptr,
				      int min, int max )
{
	int value;

	if( !PyArg_ParseTuple( args, "i", &value ) )
		return EXPP_ReturnPyObjError( PyExc_TypeError,
					      "expected int argument" );

	*ptr = EXPP_ClampInt( value, min, max );

	return EXPP_incr_ret( Py_None );
}

/* could merge with set_int, but is cleaner this way */
static PyObject *EXPP_unpack_set_short( PyObject * args, short *ptr,
					short min, short max )
{
	int value;

	if( !PyArg_ParseTuple( args, "i", &value ) )
		return EXPP_ReturnPyObjError( PyExc_TypeError,
					      "expected int argument" );

	*ptr = ( short ) EXPP_ClampInt( value, min, max );

	return EXPP_incr_ret( Py_None );
}

static PyObject *EXPP_unpack_set_float( PyObject * args, float *ptr,
					float min, float max )
{
	float value;

	if( !PyArg_ParseTuple( args, "f", &value ) )
		return EXPP_ReturnPyObjError( PyExc_TypeError,
					      "expected float argument" );

	*ptr = EXPP_ClampFloat( value, min, max );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_set_hemires( BPy_Radio * self, PyObject * args )
{
	PyObject *ret;

	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	ret = EXPP_unpack_set_short( args, &self->scene->radio->hemires,
				     EXPP_RADIO_hemires_MIN,
				     EXPP_RADIO_hemires_MAX );

	if( ret )
		rad_setlimits(  );

	return ret;
}

static PyObject *Radio_set_maxiter( BPy_Radio * self, PyObject * args )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_unpack_set_short( args, &self->scene->radio->maxiter,
				      EXPP_RADIO_maxiter_MIN,
				      EXPP_RADIO_maxiter_MAX );
}

static PyObject *Radio_set_subshootp( BPy_Radio * self, PyObject * args )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_unpack_set_short( args, &self->scene->radio->subshootp,
				      EXPP_RADIO_subshootp_MIN,
				      EXPP_RADIO_subshootp_MAX );
}

static PyObject *Radio_set_subshoote( BPy_Radio * self, PyObject * args )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_unpack_set_short( args, &self->scene->radio->subshoote,
				      EXPP_RADIO_subshoote_MIN,
				      EXPP_RADIO_subshoote_MAX );
}

static PyObject *Radio_set_nodelim( BPy_Radio * self, PyObject * args )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_unpack_set_short( args, &self->scene->radio->nodelim,
				      EXPP_RADIO_nodelim_MIN,
				      EXPP_RADIO_nodelim_MAX );
}

static PyObject *Radio_set_maxsublamp( BPy_Radio * self, PyObject * args )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_unpack_set_short( args, &self->scene->radio->maxsublamp,
				      EXPP_RADIO_maxsublamp_MIN,
				      EXPP_RADIO_maxsublamp_MAX );
}

static PyObject *Radio_set_pama( BPy_Radio * self, PyObject * args )
{
	PyObject *ret;

	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	ret = EXPP_unpack_set_short( args, &self->scene->radio->pama,
				     EXPP_RADIO_pama_MIN,
				     EXPP_RADIO_pama_MAX );

	if( ret )
		rad_setlimits(  );

	return ret;
}

static PyObject *Radio_set_pami( BPy_Radio * self, PyObject * args )
{
	PyObject *ret;

	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	ret = EXPP_unpack_set_short( args, &self->scene->radio->pami,
				     EXPP_RADIO_pami_MIN,
				     EXPP_RADIO_pami_MAX );

	if( ret )
		rad_setlimits(  );

	return ret;
}

static PyObject *Radio_set_elma( BPy_Radio * self, PyObject * args )
{
	PyObject *ret;

	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	ret = EXPP_unpack_set_short( args, &self->scene->radio->elma,
				     EXPP_RADIO_elma_MIN,
				     EXPP_RADIO_elma_MAX );

	if( ret )
		rad_setlimits(  );

	return ret;
}

static PyObject *Radio_set_elmi( BPy_Radio * self, PyObject * args )
{
	PyObject *ret;

	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	ret = EXPP_unpack_set_short( args, &self->scene->radio->elmi,
				     EXPP_RADIO_elmi_MIN,
				     EXPP_RADIO_elmi_MAX );

	if( ret )
		rad_setlimits(  );

	return ret;
}

static PyObject *Radio_set_drawtype( BPy_Radio * self, PyObject * args )
{
	PyObject *pyob = NULL;
	char *str = NULL;
	short dt = EXPP_RADIO_drawtype_WIRE;

	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( !PyArg_ParseTuple( args, "O", &pyob ) )
		return EXPP_ReturnPyObjError( PyExc_TypeError,
					      "expected int or string and another optional int as arguments" );

	if( PyString_Check( pyob ) ) {
		str = PyString_AsString( pyob );
		if( !str )
			return EXPP_ReturnPyObjError( PyExc_MemoryError,
						      "couldn't create py string!" );
		else if( !strcmp( str, "Wire" ) )
			dt = EXPP_RADIO_drawtype_WIRE;
		else if( !strcmp( str, "Solid" ) )
			dt = EXPP_RADIO_drawtype_SOLID;
		else if( !strcmp( str, "Gouraud" ) )
			dt = EXPP_RADIO_drawtype_GOURAUD;
		else
			return EXPP_ReturnPyObjError( PyExc_AttributeError,
						      "unknown drawtype string" );
	} else if( PyInt_Check( pyob ) ) {
		dt = ( short ) EXPP_ClampInt( PyInt_AsLong( pyob ),
					      EXPP_RADIO_drawtype_WIRE,
					      EXPP_RADIO_drawtype_GOURAUD );
	} else
		return EXPP_ReturnPyObjError( PyExc_TypeError,
					      "expected int or string as argument" );

	self->scene->radio->drawtype = dt;

	set_radglobal(  );	/* needed to update 3d view(s) */

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_set_flag( BPy_Radio * self, PyObject * args )
{
	int i, imode = 0;
	char *mode[2] = { NULL, NULL };

	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( !PyArg_ParseTuple( args, "|ss", &mode[0], &mode[1] ) )
		return EXPP_ReturnPyObjError( PyExc_TypeError,
					      "expected string arguments (or nothing)" );

	for( i = 0; i < 2; i++ ) {
		if( !mode[i] )
			break;
		else if( !strcmp( mode[i], "ShowLimits" ) )
			imode |= EXPP_RADIO_flag_SHOWLIM;
		else if( !strcmp( mode[i], "Z" ) )
			imode |= EXPP_RADIO_flag_Z;
		else
			return EXPP_ReturnPyObjError( PyExc_AttributeError,
						      "unknown mode string" );
	}

	self->scene->radio->flag = ( short ) EXPP_ClampInt( imode, 0, 3 );

	set_radglobal(  );	/* needed to update 3d view(s) */

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_set_maxnode( BPy_Radio * self, PyObject * args )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_unpack_set_int( args, &self->scene->radio->maxnode,
				    EXPP_RADIO_maxnode_MIN,
				    EXPP_RADIO_maxnode_MAX );
}

static PyObject *Radio_set_convergence( BPy_Radio * self, PyObject * args )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_unpack_set_float( args, &self->scene->radio->convergence,
				      EXPP_RADIO_convergence_MIN,
				      EXPP_RADIO_convergence_MAX );
}

static PyObject *Radio_set_radfac( BPy_Radio * self, PyObject * args )
{
	PyObject *ret;

	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	ret = EXPP_unpack_set_float( args, &self->scene->radio->radfac,
				     EXPP_RADIO_radfac_MIN,
				     EXPP_RADIO_radfac_MAX );

	if( ret ) {
		set_radglobal(  );
		if( rad_phase(  ) & RAD_PHASE_FACES )
			make_face_tab(  );
		else
			make_node_display(  );
	}

	return ret;
}

static PyObject *Radio_set_gamma( BPy_Radio * self, PyObject * args )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;
	return EXPP_unpack_set_float( args, &self->scene->radio->gamma,
				      EXPP_RADIO_gamma_MIN,
				      EXPP_RADIO_gamma_MAX );
}

static PyMethodDef BPy_Radio_methods[] = {
	{"collectMeshes", ( PyCFunction ) Radio_collectMeshes, METH_NOARGS,
	 "() - Convert selected meshes to patches."},
	{"go", ( PyCFunction ) Radio_go, METH_NOARGS,
	 "() - Start radiosity calculations."},
	{"freeData", ( PyCFunction ) Radio_freeData, METH_NOARGS,
	 "() - Free all memory used by radiosity."},
	{"addMesh", ( PyCFunction ) Radio_addMesh, METH_NOARGS,
	 "() - Add a new mesh with the radio values as vertex colors to Blender."},
	{"replaceMeshes", ( PyCFunction ) Radio_replaceMeshes, METH_NOARGS,
	 "() - Replace input meshes with the one created by radiosity simulation."},
	{"limitSubdivide", ( PyCFunction ) Radio_limitSubdivide, METH_NOARGS,
	 "() - Subdivide patches."},
	{"filterFaces", ( PyCFunction ) Radio_filterFaces, METH_NOARGS,
	 "() - Force an extra smoothing."},
	{"filterElems", ( PyCFunction ) Radio_filterElems, METH_NOARGS,
	 "() - Filter elements to remove aliasing artifacts."},
	{"subdividePatches", ( PyCFunction ) Radio_subdividePatches,
	 METH_NOARGS,
	 "() - Pre-subdivision: detect high-energy patches and subdivide them."},
	{"subdivideElems", ( PyCFunction ) Radio_subdivideElems, METH_NOARGS,
	 "() - Pre-subdivision: detect high-energy elements and subdivide them."},
	{"removeDoubles", ( PyCFunction ) Radio_removeDoubles, METH_NOARGS,
	 "() - Join elements which differ less than the defined node limit."},
	{"getHemiRes", ( PyCFunction ) Radio_get_hemires, METH_NOARGS,
	 "() - Get hemicube size."},
	{"setHemiRes", ( PyCFunction ) Radio_set_hemires, METH_VARARGS,
	 "(int) - Set hemicube size, the range is [100, 1000]."},
	{"getMaxIter", ( PyCFunction ) Radio_get_maxiter, METH_NOARGS,
	 "() - Get maximum number of radiosity rounds."},
	{"setMaxIter", ( PyCFunction ) Radio_set_maxiter, METH_VARARGS,
	 "(i) - Set maximum number of radiosity rounds in [0, 10000]."},
	{"getSubShPatch", ( PyCFunction ) Radio_get_subshootp, METH_NOARGS,
	 "() - Get max number of times environment is tested to detect patches."},
	{"setSubShPatch", ( PyCFunction ) Radio_set_subshootp, METH_VARARGS,
	 "(i) - Set max number of times environment is tested to detect patches.\n\
	Range is [0, 10]."},
	{"getSubShElem", ( PyCFunction ) Radio_get_subshoote, METH_NOARGS,
	 "() - Get number of times environment is tested to detect elements."},
	{"setSubShElem", ( PyCFunction ) Radio_set_subshoote, METH_VARARGS,
	 "(i) - Set number of times environment is tested to detect elements.\n\
	Range is [0, 10]."},
	{"getElemLimit", ( PyCFunction ) Radio_get_nodelim, METH_NOARGS,
	 "() - Get the range for removing doubles."},
	{"setElemLimit", ( PyCFunction ) Radio_set_nodelim, METH_VARARGS,
	 "(i) - Set the range for removing doubles in [0, 50]."},
	{"getMaxSubdivSh", ( PyCFunction ) Radio_get_maxsublamp, METH_NOARGS,
	 "() - Get max number of initial shoot patches evaluated."},
	{"setMaxSubdivSh", ( PyCFunction ) Radio_set_maxsublamp, METH_VARARGS,
	 "(i) - Set max number of initial shoot patches evaluated in [1, 250]."},
	{"getPatchMax", ( PyCFunction ) Radio_get_pama, METH_NOARGS,
	 "() - Get max size of a patch."},
	{"setPatchMax", ( PyCFunction ) Radio_set_pama, METH_VARARGS,
	 "(i) - Set max size of a patch in [10, 1000]."},
	{"getPatchMin", ( PyCFunction ) Radio_get_pami, METH_NOARGS,
	 "() - Get minimum size of a patch."},
	{"setPatchMin", ( PyCFunction ) Radio_set_pami, METH_VARARGS,
	 "(i) - Set minimum size of a patch in [10, 1000]."},
	{"getElemMax", ( PyCFunction ) Radio_get_elma, METH_NOARGS,
	 "() - Get max size of an element."},
	{"setElemMax", ( PyCFunction ) Radio_set_elma, METH_VARARGS,
	 "(i) - Set max size of an element in [1, 100]."},
	{"getElemMin", ( PyCFunction ) Radio_get_elmi, METH_NOARGS,
	 "() - Get minimum size of an element."},
	{"setElemMin", ( PyCFunction ) Radio_set_elmi, METH_VARARGS,
	 "(i) - Set minimum size of an element in [1, 100]."},
	{"getMaxElems", ( PyCFunction ) Radio_get_maxnode, METH_NOARGS,
	 "() - Get maximum number of elements."},
	{"setMaxElems", ( PyCFunction ) Radio_set_maxnode, METH_VARARGS,
	 "(i) - Set maximum nunber of elements in [1, 250000]."},
	{"getConvergence", ( PyCFunction ) Radio_get_convergence, METH_NOARGS,
	 "() - Get lower threshold of unshot energy."},
	{"setConvergence", ( PyCFunction ) Radio_set_convergence, METH_VARARGS,
	 "(f) - Set lower threshold of unshot energy in [0.0, 1.0]."},
	{"getMult", ( PyCFunction ) Radio_get_radfac, METH_NOARGS,
	 "() - Get energy value multiplier."},
	{"setMult", ( PyCFunction ) Radio_set_radfac, METH_VARARGS,
	 "(f) - Set energy value multiplier in [0.001, 250.0]."},
	{"getGamma", ( PyCFunction ) Radio_get_gamma, METH_NOARGS,
	 "() - Get change in the contrast of energy values."},
	{"setGamma", ( PyCFunction ) Radio_set_gamma, METH_VARARGS,
	 "(f) - Set change in the contrast of energy values in [0.2, 10.0]."},
	{"getDrawType", ( PyCFunction ) Radio_get_drawtype, METH_NOARGS,
	 "() - Get the draw type: Wire, Solid or Gouraud as an int value."},
	{"setDrawType", ( PyCFunction ) Radio_set_drawtype, METH_VARARGS,
	 "(i or s) - Set the draw type: wire, solid (default) or gouraud."},
	{"getMode", ( PyCFunction ) Radio_get_flag, METH_NOARGS,
	 "() - Get mode as int (or'ed bitflags), see Radio.Modes dict."},
	{"setMode", ( PyCFunction ) Radio_set_flag, METH_VARARGS,
	 "(|ss) - Set mode flags as strings: 'ShowLimits', 'Z'."},
	{NULL, NULL, 0, NULL}
};

static PyTypeObject Radio_Type = {
	PyObject_HEAD_INIT( NULL ) 
	0,	/*ob_size */
	"Blender Radiosity",	/*tp_name */
	sizeof( BPy_Radio ),	/*tp_basicsize */
	0,			/*tp_itemsize */
	NULL,		/*tp_dealloc */
	0,			/*tp_print */
	0,			/*tp_getattr */
	0,			/*tp_setattr */
	0,			/*tp_compare */
	( reprfunc ) Radio_repr,	/*tp_repr */
	0,			/*tp_as_number */
	0,			/*tp_as_sequence */
	0,			/*tp_as_mapping */
	0,			/*tp_hash */
	0,			/*tp_call */
	0,			/*tp_str */
	0,			/*tp_getattro */
	0,			/*tp_setattro */
	0,			/*tp_as_buffer */
	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,	/*tp_flags */
	"Blender radiosity",	/* tp_doc */
	0,			/* tp_traverse */
	0,			/* tp_clear */
	0,			/* tp_richcompare */
	0,			/* tp_weaklistoffset */
	0,			/* tp_iter */
	0,			/* tp_iternext */
	BPy_Radio_methods,	/* tp_methods */
	0,			/* tp_members */
	0,			/* tp_getset */
	0,			/* tp_base */
	0,			/* tp_dict */
	0,			/* tp_descr_get */
	0,			/* tp_descr_set */
	0,			/* tp_dictoffset */
	0,			/* tp_init */
	0,			/* tp_alloc */
	0,			/* tp_new */
	0, 0, 0, 0, 0, 0, 0, 0,	/* up to tp_del, so we don't get a warning */
};

static PyObject *Radio_repr( BPy_Radio * self )
{
	if( self->radio )
		return PyString_FromFormat( "[Radiosity \"%s\"]",
					    self->scene->id.name + 2 );
	else
		return PyString_FromString( "NULL" );
}

PyObject *Radio_CreatePyObject( struct Scene * scene )
{
	BPy_Radio *py_radio;

	if( scene != G.scene ) {
		return EXPP_ReturnPyObjError( PyExc_EnvironmentError,
					      "\nradiosity only works on the current scene, check scene.makeCurrent()." );
	}

	py_radio = ( BPy_Radio * ) PyObject_NEW( BPy_Radio, &Radio_Type );

	if( !py_radio )
		return NULL;

	if( !scene->radio )
		add_radio(  );	/* adds to G.scene */

	py_radio->radio = scene->radio;
	py_radio->scene = scene;

	return ( ( PyObject * ) py_radio );
}

static PyObject *Radio_collectMeshes( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	disable_where_script( 1 );	/* used to avoid error popups */
	rad_collect_meshes(  );
	disable_where_script( 0 );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_freeData( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	delete_radio(  );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_go( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) == RAD_PHASE_PATCHES )
		rad_go(  );
	else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call radio.collectMeshes() first." );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_replaceMeshes( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) & RAD_PHASE_FACES )
		rad_replacemesh(  );
	else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call radio.collectMeshes() and radio.go() first." );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_addMesh( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) & RAD_PHASE_FACES )
		rad_addmesh(  );
	else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call radio.collectMeshes() and radio.go() first." );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_filterFaces( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) & RAD_PHASE_FACES )
		filterFaces(  );
	else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call radio.collectMeshes() and radio.go() first." );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_filterElems( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) & RAD_PHASE_FACES ) {
		set_radglobal(  );
		filterNodes(  );
		make_face_tab(  );
	} else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call radio.collectMeshes() and radio.go() first." );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_limitSubdivide( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) == RAD_PHASE_PATCHES )
		rad_limit_subdivide(  );
	else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call this before calculating the radiosity simulation." );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_subdividePatches( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) == RAD_PHASE_PATCHES )
		rad_subdivshootpatch(  );
	else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call this before calculating the radiosity simulation." );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_subdivideElems( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) == RAD_PHASE_PATCHES )
		rad_subdivshootelem(  );
	else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call radio.collectMeshes() and radio.go() first." );

	return EXPP_incr_ret( Py_None );
}

static PyObject *Radio_removeDoubles( BPy_Radio * self )
{
	if( !EXPP_check_scene( self->scene ) )
		return NULL;

	if( rad_phase(  ) == RAD_PHASE_FACES ) {
		set_radglobal(  );
		removeEqualNodes( self->scene->radio->nodelim );
		make_face_tab(  );
	} else
		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
					      "you need to call radio.collectMeshes() and radio.go() first." );

	return EXPP_incr_ret( Py_None );
}

static PyMethodDef M_Radio_methods[] = { {NULL, NULL, 0, NULL} };

PyObject *Radio_Init( void )
{
	PyObject *submodule, *Modes, *DrawTypes;

	if( PyType_Ready( &Radio_Type ) < 0 )
		return NULL;

	submodule = Py_InitModule3( "Blender.Scene.Radio", M_Radio_methods,
				    "The Blender Radiosity submodule" );

	Modes = PyConstant_New(  );
	DrawTypes = PyConstant_New(  );

	if( Modes ) {
		BPy_constant *d = ( BPy_constant * ) Modes;

		PyConstant_Insert( d, "ShowLimits",
				 PyInt_FromLong( EXPP_RADIO_flag_SHOWLIM ) );
		PyConstant_Insert( d, "Z", PyInt_FromLong( EXPP_RADIO_flag_Z ) );

		PyModule_AddObject( submodule, "Modes", Modes );
	}

	if( DrawTypes ) {
		BPy_constant *d = ( BPy_constant * ) DrawTypes;

		PyConstant_Insert( d, "Wire",
				 PyInt_FromLong( EXPP_RADIO_drawtype_WIRE ) );
		PyConstant_Insert( d, "Solid",
				 PyInt_FromLong( EXPP_RADIO_drawtype_SOLID ) );
		PyConstant_Insert( d, "Gouraud",
				 PyInt_FromLong
				 ( EXPP_RADIO_drawtype_GOURAUD ) );

		PyModule_AddObject( submodule, "DrawTypes", DrawTypes );
	}

	return submodule;
}