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

World.c « api2_2x « python « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c57488a2664cb629e551cde0f5cd69cece7c59a (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
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
/* 
 * $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): Jacques Guignot, Johnny Matthews
 *
 * ***** END GPL LICENSE BLOCK *****
*/

/**
 * \file World.c
 * \ingroup scripts
 * \brief Blender.World Module and World Data PyObject implementation.
 *
 * Note: Parameters between "<" and ">" are optional.  But if one of them is
 * given, all preceding ones must be given, too.  Of course, this only relates
 * to the Python functions and methods described here and only inside Python
 * code. [ This will go to another file later, probably the main exppython
 * doc file].  XXX Better: put optional args with their default value:
 * (self, name = "MyName")
 */

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

#include "DNA_scene_types.h"  /* for G.scene */
#include "BKE_global.h"
#include "BKE_world.h"
#include "BKE_main.h"
#include "BKE_library.h"
#include "BKE_texture.h"
#include "BLI_blenlib.h"
#include "BSE_editipo.h"
#include "BIF_keyframing.h"
#include "BIF_space.h"
#include "mydevice.h"
#include "Ipo.h"
#include "MTex.h"
#include "gen_utils.h"
#include "gen_library.h"
#include "MEM_guardedalloc.h"

#define IPOKEY_ZENITH   0
#define IPOKEY_HORIZON  1
#define IPOKEY_MIST     2
#define IPOKEY_STARS    3
#define IPOKEY_OFFSET   4
#define IPOKEY_SIZE     5
/*****************************************************************************/
/* Python BPy_World methods declarations:                                   */
/*****************************************************************************/
static PyObject *World_getRange( BPy_World * self );
static PyObject *World_setRange( BPy_World * self, PyObject * args );
static PyObject *World_getIpo( BPy_World * self );
static PyObject *World_oldsetIpo( BPy_World * self, PyObject * args );
static int       World_setIpo( BPy_World * self, PyObject * args );
static PyObject *World_clearIpo( BPy_World * self );
static PyObject *World_insertIpoKey( BPy_World * self, PyObject * args );
static PyObject *World_getMode( BPy_World * self );
static PyObject *World_oldsetMode( BPy_World * self, PyObject * args );
static int       World_setMode( BPy_World * self, PyObject * args );
static PyObject *World_getSkytype( BPy_World * self );
static PyObject *World_oldsetSkytype( BPy_World * self, PyObject * args );
static int       World_setSkytype( BPy_World * self, PyObject * args );
static PyObject *World_getMistype( BPy_World * self );
static PyObject *World_oldsetMistype( BPy_World * self, PyObject * args );
static int       World_setMistype( BPy_World * self, PyObject * args );
static PyObject *World_getHor( BPy_World * self );
static PyObject *World_oldsetHor( BPy_World * self, PyObject * args );
static int       World_setHor( BPy_World * self, PyObject * args );
static PyObject *World_getZen( BPy_World * self );
static PyObject *World_oldsetZen( BPy_World * self, PyObject * args );
static int       World_setZen( BPy_World * self, PyObject * args );
static PyObject *World_getAmb( BPy_World * self );
static PyObject *World_oldsetAmb( BPy_World * self, PyObject * args );
static int       World_setAmb( BPy_World * self, PyObject * args );
static PyObject *World_getStar( BPy_World * self );
static PyObject *World_oldsetStar( BPy_World * self, PyObject * args );
static int       World_setStar( BPy_World * self, PyObject * args );
static PyObject *World_getMist( BPy_World * self );
static PyObject *World_oldsetMist( BPy_World * self, PyObject * args );
static int       World_setMist( BPy_World * self, PyObject * args );
static PyObject *World_getScriptLinks( BPy_World * self, PyObject * value );
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args );
static PyObject *World_clearScriptLinks( BPy_World * self, PyObject * args );
static PyObject *World_setCurrent( BPy_World * self );
static PyObject *World_getTextures( BPy_World * self );
static int 		 World_setTextures( BPy_World * self, PyObject * value );
static PyObject *World_copy( BPy_World * self );


/*****************************************************************************/
/* Python API function prototypes for the World module.                     */
/*****************************************************************************/
static PyObject *M_World_New( PyObject * self, PyObject * args,
			      PyObject * keywords );
static PyObject *M_World_Get( PyObject * self, PyObject * args );
static PyObject *M_World_GetCurrent( PyObject * self );


/*****************************************************************************/
/* Python World_Type callback function prototypes:			*/
/*****************************************************************************/
//static int World_Print (BPy_World *self, FILE *fp, int flags);
static int World_Compare( BPy_World * a, BPy_World * b );
static PyObject *World_Repr( BPy_World * self );



/*****************************************************************************/
/* The following string definitions are used for documentation strings.      */
/* In Python these will be written to the console when doing a               */
/* Blender.World.__doc__                                                     */
/*****************************************************************************/
static char M_World_doc[] = "The Blender World module\n\n\
This module provides access to **World Data** objects in Blender\n\n";

static char M_World_New_doc[] = "() - return a new World object";

static char M_World_Get_doc[] =
	"(name) - return the world with the name 'name', \
returns None if not found.\n If 'name' is not specified, \
it returns a list of all worlds in the\ncurrent scene.";
static char M_World_GetCurrent_doc[] = "() - returns the current world, or \
None if the Scene has no world";



/*****************************************************************************/
/* Python method structure definition for Blender.World module:              */
/*****************************************************************************/
struct PyMethodDef M_World_methods[] = {
	{"New", ( PyCFunction ) M_World_New, METH_VARARGS | METH_KEYWORDS,
	 M_World_New_doc},
	{"Get", M_World_Get, METH_VARARGS, M_World_Get_doc},
	{"GetActive", ( PyCFunction ) M_World_GetCurrent, METH_NOARGS,
	 M_World_GetCurrent_doc},
	{"GetCurrent", ( PyCFunction ) M_World_GetCurrent, METH_NOARGS,
	 M_World_GetCurrent_doc},
	{"get", M_World_Get, METH_VARARGS, M_World_Get_doc},
	{NULL, NULL, 0, NULL}
};



/*****************************************************************************/
/* Python BPy_World methods table:                                          */
/*****************************************************************************/
static PyMethodDef BPy_World_methods[] = {
	{"getRange", ( PyCFunction ) World_getRange, METH_NOARGS,
	 "() - Return World Range"},
	{"setRange", ( PyCFunction ) World_setRange, METH_VARARGS,
	 "() - Change this World's range"},
	{"getIpo", ( PyCFunction ) World_getIpo, METH_NOARGS,
	 "() - Return World Ipo"},
	{"setIpo", ( PyCFunction ) World_oldsetIpo, METH_VARARGS,
	 "() - Change this World's ipo"},
	{"clearIpo", ( PyCFunction ) World_clearIpo, METH_VARARGS,
	 "() - Unlink Ipo from this World"},
	{"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
	 "() - Return World Data name"},
	{"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
	 "() - Set World Data name"},
	{"getMode", ( PyCFunction ) World_getMode, METH_NOARGS,
	 "() - Return World Data mode"},
	{"setMode", ( PyCFunction ) World_oldsetMode, METH_VARARGS,
	 "(i) - Set World Data mode"},
	{"getSkytype", ( PyCFunction ) World_getSkytype, METH_NOARGS,
	 "() - Return World Data skytype"},
	{"setSkytype", ( PyCFunction ) World_oldsetSkytype, METH_VARARGS,
	 "() - Return World Data skytype"},
	{"getMistype", ( PyCFunction ) World_getMistype, METH_NOARGS,
	 "() - Return World Data mistype"},
	{"setMistype", ( PyCFunction ) World_oldsetMistype, METH_VARARGS,
	 "() - Return World Data mistype"},
	{"getHor", ( PyCFunction ) World_getHor, METH_NOARGS,
	 "() - Return World Data hor"},
	{"setHor", ( PyCFunction ) World_oldsetHor, METH_VARARGS,
	 "() - Return World Data hor"},
	{"getZen", ( PyCFunction ) World_getZen, METH_NOARGS,
	 "() - Return World Data zen"},
	{"setZen", ( PyCFunction ) World_oldsetZen, METH_VARARGS,
	 "() - Return World Data zen"},
	{"getAmb", ( PyCFunction ) World_getAmb, METH_NOARGS,
	 "() - Return World Data amb"},
	{"setAmb", ( PyCFunction ) World_oldsetAmb, METH_VARARGS,
	 "() - Return World Data amb"},
	{"getStar", ( PyCFunction ) World_getStar, METH_NOARGS,
	 "() - Return World Data star"},
	{"setStar", ( PyCFunction ) World_oldsetStar, METH_VARARGS,
	 "() - Return World Data star"},
	{"getMist", ( PyCFunction ) World_getMist, METH_NOARGS,
	 "() - Return World Data mist"},
	{"setMist", ( PyCFunction ) World_oldsetMist, METH_VARARGS,
	 "() - Return World Data mist"},
	{"getScriptLinks", ( PyCFunction ) World_getScriptLinks, METH_O,
	 "(eventname) - Get a list of this world's scriptlinks (Text names) "
	 "of the given type\n"
	 "(eventname) - string: FrameChanged, Redraw or Render."},
	{"addScriptLink", ( PyCFunction ) World_addScriptLink, METH_VARARGS,
	 "(text, evt) - Add a new world scriptlink.\n"
	 "(text) - string: an existing Blender Text name;\n"
	 "(evt) string: FrameChanged, Redraw or Render."},
	{"clearScriptLinks", ( PyCFunction ) World_clearScriptLinks,
	 METH_VARARGS,
	 "() - Delete all scriptlinks from this world.\n"
	 "([s1<,s2,s3...>]) - Delete specified scriptlinks from this world."},
	{"setCurrent", ( PyCFunction ) World_setCurrent, METH_NOARGS,
	 "() - Makes this world the active world for the current scene."},
	{"makeActive", ( PyCFunction ) World_setCurrent, METH_NOARGS,
	 "please use setCurrent instead, this alias will be removed."},
	{"insertIpoKey", ( PyCFunction ) World_insertIpoKey, METH_VARARGS,
	 "( World IPO type ) - Inserts a key into the IPO"},
	{"__copy__", ( PyCFunction ) World_copy, METH_NOARGS,
	 "() - Makes a copy of this world."},
	{"copy", ( PyCFunction ) World_copy, METH_NOARGS,
	 "() - Makes a copy of this world."},
	{NULL, NULL, 0, NULL}
};

/*****************************************************************************/
/* Python attributes get/set structure:                                      */
/*****************************************************************************/
static PyGetSetDef BPy_World_getseters[] = {
	GENERIC_LIB_GETSETATTR,
	{"skytype", (getter)World_getSkytype, (setter)World_setSkytype,
	 "sky settings as a list", NULL},
	{"mode", (getter)World_getMode, (setter)World_setMode,
	 "world mode", NULL},
	{"mistype", (getter)World_getMistype, (setter)World_setMistype,
	 "world mist type", NULL},
	{"hor", (getter)World_getHor, (setter)World_setHor,
	 "world horizon color", NULL},
	{"amb", (getter)World_getAmb, (setter)World_setAmb,
	 "world ambient color", NULL},
	{"mist", (getter)World_getMist, (setter)World_setMist,
	 "world mist settings", NULL},
	{"ipo", (getter)World_getIpo, (setter)World_setIpo,
	 "world ipo", NULL},
    {"textures", (getter)World_getTextures, (setter)World_setTextures,
     "The World's texture list as a tuple",
     NULL},
	{NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
};

/*****************************************************************************/
/* Python World_Type structure definition:			          */
/*****************************************************************************/
PyTypeObject World_Type = {
	PyObject_HEAD_INIT( NULL ) 
	0,	/* ob_size */
	"World",		/* tp_name */
	sizeof( BPy_World ),	/* tp_basicsize */
	0,			/* tp_itemsize */
	/* methods */
	NULL,	/* tp_dealloc */
	0,		/* tp_print */
	NULL,	/* tp_getattr */
	NULL,	/* tp_setattr */
	( cmpfunc ) World_Compare,	/* tp_compare */
	( reprfunc ) World_Repr,	/* tp_repr */

	/* Method suites for standard classes */

	NULL,                       /* PyNumberMethods *tp_as_number; */
	NULL,                       /* PySequenceMethods *tp_as_sequence; */
	NULL,                       /* PyMappingMethods *tp_as_mapping; */

	/* More standard operations (here for binary compatibility) */

	( hashfunc ) GenericLib_hash,	/* hashfunc tp_hash; */
	NULL,                       /* ternaryfunc tp_call; */
	NULL,                       /* reprfunc tp_str; */
	NULL,                       /* getattrofunc tp_getattro; */
	NULL,                       /* setattrofunc tp_setattro; */

	/* Functions to access object as input/output buffer */
	NULL,                       /* PyBufferProcs *tp_as_buffer; */

  /*** Flags to define presence of optional/expanded features ***/
	Py_TPFLAGS_DEFAULT,         /* long tp_flags; */

	NULL,                       /*  char *tp_doc;  Documentation string */
  /*** Assigned meaning in release 2.0 ***/
	/* call function for all accessible objects */
	NULL,                       /* traverseproc tp_traverse; */

	/* delete references to contained objects */
	NULL,                       /* inquiry tp_clear; */

  /***  Assigned meaning in release 2.1 ***/
  /*** rich comparisons ***/
	NULL,                       /* richcmpfunc tp_richcompare; */

  /***  weak reference enabler ***/
	0,                          /* long tp_weaklistoffset; */

  /*** Added in release 2.2 ***/
	/*   Iterators */
	NULL,                       /* getiterfunc tp_iter; */
	NULL,                       /* iternextfunc tp_iternext; */

  /*** Attribute descriptor and subclassing stuff ***/
	BPy_World_methods,           /* struct PyMethodDef *tp_methods; */
	NULL,                       /* struct PyMemberDef *tp_members; */
	BPy_World_getseters,         /* struct PyGetSetDef *tp_getset; */
	NULL,                       /* struct _typeobject *tp_base; */
	NULL,                       /* PyObject *tp_dict; */
	NULL,                       /* descrgetfunc tp_descr_get; */
	NULL,                       /* descrsetfunc tp_descr_set; */
	0,                          /* long tp_dictoffset; */
	NULL,                       /* initproc tp_init; */
	NULL,                       /* allocfunc tp_alloc; */
	NULL,                       /* newfunc tp_new; */
	/*  Low-level free-memory routine */
	NULL,                       /* freefunc tp_free;  */
	/* For PyObject_IS_GC */
	NULL,                       /* inquiry tp_is_gc;  */
	NULL,                       /* PyObject *tp_bases; */
	/* method resolution order */
	NULL,                       /* PyObject *tp_mro;  */
	NULL,                       /* PyObject *tp_cache; */
	NULL,                       /* PyObject *tp_subclasses; */
	NULL,                       /* PyObject *tp_weaklist; */
	NULL
};

/**
 * \defgroup World_Module Blender.World module functions
 *
 */

/*@{*/

/**
 * \brief Python module function: Blender.World.New()
 *
 * This is the .New() function of the Blender.World submodule. It creates
 * new World Data in Blender and returns its Python wrapper object.  The
 * name parameter is mandatory.
 * \param <name> - string: The World Data name.
 * \return A new World PyObject.
 */

static PyObject *M_World_New( PyObject * self, PyObject * args,
			      PyObject * kwords )
{
	char *name = NULL;
	BPy_World *pyworld;
	World *blworld;

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


	blworld = add_world( name );

	if( blworld ) {
		/* return user count to zero because add_world() inc'd it */
		blworld->id.us = 0;
		/* create python wrapper obj */
		pyworld =
			( BPy_World * ) PyObject_NEW( BPy_World, &World_Type );
	} else
		return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
						"couldn't create World Data in Blender" ) );

	if( pyworld == NULL )
		return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
						"couldn't create World Data object" ) );

	pyworld->world = blworld;

	return ( PyObject * ) pyworld;
}

/**
 * \brief Python module function: Blender.World.Get()
 *
 * This is the .Get() function of the Blender.World submodule.	It searches
 * the list of current World Data objects and returns a Python wrapper for
 * the one with the name provided by the user.	If called with no arguments,
 * it returns a list of all current World Data object names in Blender.
 * \param <name> - string: The name of an existing Blender World Data object.
 * \return () - A list with the names of all current World Data objects;\n
 * \return (name) - A Python wrapper for the World Data called 'name'
 * in Blender.
 */

static PyObject *M_World_Get( PyObject * self, PyObject * args )
{

	char *name = NULL;
	World *world_iter;
	PyObject *worldlist;
	char error_msg[64];

	if( !PyArg_ParseTuple( args, "|s", &name ) )
		return ( EXPP_ReturnPyObjError( PyExc_TypeError,
						"expected string argument (or nothing)" ) );

	if( name ) {		/* (name) - Search world by name */
		world_iter = ( World * ) GetIdFromList( &( G.main->world ), name );
		
		if( world_iter == NULL ) {	/* Requested world doesn't exist */
			PyOS_snprintf( error_msg, sizeof( error_msg ),
				       "World \"%s\" not found", name );
			return ( EXPP_ReturnPyObjError
				 ( PyExc_NameError, error_msg ) );
		}

		return ( PyObject * ) World_CreatePyObject(world_iter);
	}

	else {			/* return a list of all worlds in the scene */
		world_iter = G.main->world.first;
		worldlist = PyList_New( 0 );
		if( worldlist == NULL )
			return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
							"couldn't create PyList" ) );

		while( world_iter ) {
			BPy_World *found_world =
				( BPy_World * ) PyObject_NEW( BPy_World,
							      &World_Type );
			found_world->world = world_iter;
			PyList_Append( worldlist, ( PyObject * ) found_world );
			Py_DECREF(found_world);
			
			world_iter = world_iter->id.next;
		}
		return ( worldlist );
	}

}

static PyObject *M_World_GetCurrent( PyObject * self )
{
	BPy_World *w = NULL;
#if 0	/* add back in when bpy becomes "official" */
	static char warning = 1;
	if( warning ) {
		printf("Blender.World.GetCurrent() deprecated!\n\tuse bpy.scenes.world instead\n");
		--warning;
	}
#endif

	if( !G.scene->world )
		Py_RETURN_NONE;
	
	w = ( BPy_World * ) PyObject_NEW( BPy_World, &World_Type );
	w->world = G.scene->world;
	return ( PyObject * ) w;
}

/*@}*/

/**
 * \brief Initializes the Blender.World submodule
 *
 * This function is used by Blender_Init() in Blender.c to register the
 * Blender.World submodule in the main Blender module.
 * \return PyObject*: The initialized submodule.
 */

PyObject *World_Init( void )
{
	PyObject *submodule;

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

	submodule = Py_InitModule3( "Blender.World",
				    M_World_methods, M_World_doc );

	PyModule_AddIntConstant( submodule, "ZENITH",      IPOKEY_ZENITH );
	PyModule_AddIntConstant( submodule, "HORIZON",     IPOKEY_HORIZON );
	PyModule_AddIntConstant( submodule, "MIST",        IPOKEY_MIST );
	PyModule_AddIntConstant( submodule, "STARS",       IPOKEY_STARS );
	PyModule_AddIntConstant( submodule, "OFFSET",      IPOKEY_OFFSET );
	PyModule_AddIntConstant( submodule, "SIZE",        IPOKEY_SIZE );

	return ( submodule );
}

/*****************************************************************************/
/* Python BPy_World methods:						*/
/*****************************************************************************/
static PyObject *World_getRange( BPy_World * self )
{
	return PyFloat_FromDouble( self->world->range );
}

static PyObject *World_setRange( BPy_World * self, PyObject * args )
{
	float range = 0.f;
	if( !PyArg_ParseTuple( args, "f", &range ) )
		return ( EXPP_ReturnPyObjError
			 ( PyExc_TypeError, "expected a float argument" ) );
	self->world->range = range;
	Py_RETURN_NONE;
}


static PyObject *World_getIpo( BPy_World * self )
{
	struct Ipo *ipo = self->world->ipo;

	if( !ipo )
		Py_RETURN_NONE;

	return Ipo_CreatePyObject( ipo );
}

static int World_setIpo( BPy_World * self, PyObject * value )
{
	return GenericLib_assignData(value, (void **) &self->world->ipo, 0, 1, ID_IP, ID_WO);
}

static PyObject *World_oldsetIpo( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setIpo );
}

static PyObject *World_clearIpo( BPy_World * self )
{
	World *world = self->world;
	Ipo *ipo = ( Ipo * ) world->ipo;

	if( ipo ) {
		ID *id = &ipo->id;
		if( id->us > 0 )
			id->us--;
		world->ipo = NULL;

		return EXPP_incr_ret_True();
	}

	return EXPP_incr_ret_False(); /* no ipo found */
}

/**
 * \brief World PyMethod getSkytype
 *
 * \return int : The World Data skytype.
 */

static PyObject *World_getSkytype( BPy_World * self )
{
	return PyInt_FromLong( ( long ) self->world->skytype );
}


/**
 * \brief World PyMethod setSkytype
 *
 * \return int : The World Data skytype.
 */

static int World_setSkytype( BPy_World * self, PyObject * value )
{
	if( !PyInt_Check(value) )
		return ( EXPP_ReturnIntError( PyExc_TypeError,
						"expected int argument" ) );
	self->world->skytype = (short)PyInt_AsLong(value);
	return 0;
}

static PyObject *World_oldsetSkytype( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setSkytype );
}


/**
 * \brief World PyMethod getMode
 *
 * \return int : The World Data mode.
 */

static PyObject *World_getMode( BPy_World * self )
{
	return PyInt_FromLong( ( long ) self->world->mode );
}


/**
 * \brief World PyMethod setMode
 *
 * \return int : The World Data mode.
 */

static int World_setMode( BPy_World * self, PyObject * value )
{
	if( !PyInt_Check(value) )
		return ( EXPP_ReturnIntError( PyExc_TypeError,
						"expected int argument" ) );
	self->world->mode = (short)PyInt_AsLong(value);
	return 0;
}

static PyObject *World_oldsetMode( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setMode );
}



/**
 * \brief World PyMethod getMistype
 *
 * \return int : The World Data mistype.
 */

static PyObject *World_getMistype( BPy_World * self )
{
	return PyInt_FromLong( ( long ) self->world->mistype );
}


/**
 * \brief World PyMethod setMistype
 *
 * \return int : The World Data mistype.
 */

static int World_setMistype( BPy_World * self, PyObject * value )
{
	if( !PyInt_Check(value) )
		return ( EXPP_ReturnIntError( PyExc_TypeError,
						"expected int argument" ) );
	self->world->mistype = (short)PyInt_AsLong(value);
	return 0;
}

static PyObject *World_oldsetMistype( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setMistype );
}



static PyObject *World_getHor( BPy_World * self )
{
	PyObject *attr = PyList_New( 3 );
	if( !attr )
		return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
						"couldn't create list" ) );
	PyList_SET_ITEM( attr, 0, PyFloat_FromDouble( self->world->horr ) );
	PyList_SET_ITEM( attr, 1, PyFloat_FromDouble( self->world->horg ) );
	PyList_SET_ITEM( attr, 2, PyFloat_FromDouble( self->world->horb ) );
	return attr;
}


static int World_setHor( BPy_World * self, PyObject * value )
{
	if( !PyList_Check( value ) )
		return ( EXPP_ReturnIntError( PyExc_TypeError,
						"expected list argument" ) );
	if( PyList_Size( value ) != 3 )
		return ( EXPP_ReturnIntError
			 ( PyExc_TypeError, "list size must be 3" ) );
	self->world->horr = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
	self->world->horg = (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
	self->world->horb = (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
	return 0;
}

static PyObject *World_oldsetHor( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setHor );
}

static PyObject *World_getZen( BPy_World * self )
{
	PyObject *attr = PyList_New( 3 );
	if( !attr )
		return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
						"couldn't create list" ) );
	PyList_SET_ITEM( attr, 0, PyFloat_FromDouble( self->world->zenr ) );
	PyList_SET_ITEM( attr, 1, PyFloat_FromDouble( self->world->zeng ) );
	PyList_SET_ITEM( attr, 2, PyFloat_FromDouble( self->world->zenb ) );
	return attr;
}


static int World_setZen( BPy_World * self, PyObject * value )
{
	if( !PyList_Check( value ) )
		return ( EXPP_ReturnIntError( PyExc_TypeError,
						"expected list argument" ) );
	if( PyList_Size( value ) != 3 )
		return ( EXPP_ReturnIntError
			 ( PyExc_TypeError, "list size must be 3" ) );
	self->world->zenr = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
	self->world->zeng = (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
	self->world->zenb = (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
	return 0;
}

static PyObject *World_oldsetZen( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setZen );
}


static PyObject *World_getAmb( BPy_World * self )
{
	PyObject *attr = PyList_New( 3 );
	if( !attr )
		return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
						"couldn't create list" ) );
	PyList_SET_ITEM( attr, 0, PyFloat_FromDouble( self->world->ambr ) );
	PyList_SET_ITEM( attr, 1, PyFloat_FromDouble( self->world->ambg ) );
	PyList_SET_ITEM( attr, 2, PyFloat_FromDouble( self->world->ambb ) );
	return attr;
}


static int World_setAmb( BPy_World * self, PyObject * value )
{
	if( !PyList_Check( value ) )
		return ( EXPP_ReturnIntError( PyExc_TypeError,
						"expected list argument" ) );
	if( PyList_Size( value ) != 3 )
		return ( EXPP_ReturnIntError
			 ( PyExc_TypeError, "wrong list size" ) );
	self->world->ambr = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
	self->world->ambg = (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
	self->world->ambb = (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
	return 0;
}

static PyObject *World_oldsetAmb( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setAmb );
}

static PyObject *World_getStar( BPy_World * self )
{
	PyObject *attr = PyList_New( 7 );
	if( !attr )
		return ( EXPP_ReturnPyObjError
			 ( PyExc_RuntimeError, "couldn't create list" ) );
	PyList_SET_ITEM( attr, 0, PyFloat_FromDouble( self->world->starr ) );
	PyList_SET_ITEM( attr, 1, PyFloat_FromDouble( self->world->starg ) );
	PyList_SET_ITEM( attr, 2, PyFloat_FromDouble( self->world->starb ) );
	PyList_SET_ITEM( attr, 3, PyFloat_FromDouble( self->world->starsize ) );
	PyList_SET_ITEM( attr, 4, PyFloat_FromDouble( self->world->starmindist ) );
	PyList_SET_ITEM( attr, 5, PyFloat_FromDouble( self->world->stardist ) );
	PyList_SET_ITEM( attr, 6, PyFloat_FromDouble( self->world->starcolnoise ) );
	return attr;
}


static int World_setStar( BPy_World * self, PyObject * value )
{
	if( !PyList_Check( value ) )
		return ( EXPP_ReturnIntError
			 ( PyExc_TypeError, "expected list argument" ) );
	if( PyList_Size( value ) != 7 )
		return ( EXPP_ReturnIntError
			 ( PyExc_TypeError, "wrong list size" ) );
	self->world->starr = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
	self->world->starg = (float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
	self->world->starb = (float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
	self->world->starsize =
		(float)PyFloat_AsDouble( PyList_GetItem( value, 3 ) );
	self->world->starmindist =
		(float)PyFloat_AsDouble( PyList_GetItem( value, 4 ) );
	self->world->stardist =
		(float)PyFloat_AsDouble( PyList_GetItem( value, 5 ) );
	self->world->starcolnoise =
		(float)PyFloat_AsDouble( PyList_GetItem( value, 6 ) );
	return 0;
}

static PyObject *World_oldsetStar( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setStar );
}


static PyObject *World_getMist( BPy_World * self )
{
	PyObject *attr = PyList_New( 4 );
	if( !attr )
		return ( EXPP_ReturnPyObjError
			 ( PyExc_RuntimeError, "couldn't create list" ) );
	PyList_SET_ITEM( attr, 0, PyFloat_FromDouble( self->world->misi ) );
	PyList_SET_ITEM( attr, 1, PyFloat_FromDouble( self->world->miststa ) );
	PyList_SET_ITEM( attr, 2, PyFloat_FromDouble( self->world->mistdist ) );
	PyList_SET_ITEM( attr, 3, PyFloat_FromDouble( self->world->misthi ) );
	return attr;
}

static int World_setMist( BPy_World * self, PyObject * value )
{
	if( !PyList_Check( value ) )
		return ( EXPP_ReturnIntError
			 ( PyExc_TypeError, "expected list argument" ) );
	if( PyList_Size( value ) != 4 )
		return ( EXPP_ReturnIntError
			 ( PyExc_TypeError, "wrong list size" ) );
	self->world->misi = (float)PyFloat_AsDouble( PyList_GetItem( value, 0 ) );
	self->world->miststa =
		(float)PyFloat_AsDouble( PyList_GetItem( value, 1 ) );
	self->world->mistdist =
		(float)PyFloat_AsDouble( PyList_GetItem( value, 2 ) );
	self->world->misthi =
		(float)PyFloat_AsDouble( PyList_GetItem( value, 3 ) );
	return 0;
}

static PyObject *World_oldsetMist( BPy_World * self, PyObject * args )
{
	return EXPP_setterWrapper( (void *)self, args, (setter)World_setMist );
}


/* world.addScriptLink */
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args )
{
	World *world = self->world;
	ScriptLink *slink = NULL;

	slink = &( world )->scriptlink;

	return EXPP_addScriptLink( slink, args, 0 );
}

/* world.clearScriptLinks */
static PyObject *World_clearScriptLinks( BPy_World * self, PyObject * args )
{
	World *world = self->world;
	ScriptLink *slink = NULL;

	slink = &( world )->scriptlink;

	return EXPP_clearScriptLinks( slink, args );
}

/* world.getScriptLinks */
static PyObject *World_getScriptLinks( BPy_World * self, PyObject * value )
{
	World *world = self->world;
	ScriptLink *slink = NULL;
	PyObject *ret = NULL;

	slink = &( world )->scriptlink;

	ret = EXPP_getScriptLinks( slink, value, 0 );

	if( ret )
		return ret;
	else
		return NULL;
}


/* world.setCurrent */
static PyObject *World_setCurrent( BPy_World * self )
{
	World *world = self->world;
#if 0	/* add back in when bpy becomes "official" */
	static char warning = 1;
	if( warning ) {
		printf("world.setCurrent() deprecated!\n\tuse bpy.scenes.world=world instead\n");
		--warning;
	}
#endif

	/* If there is a world then it now has one less user */
	if( G.scene->world )
		G.scene->world->id.us--;
	world->id.us++;
	G.scene->world = world;
	Py_RETURN_NONE;
}

/* world.__copy__ */
static PyObject *World_copy( BPy_World * self )
{
	World *world = copy_world(self->world );
	world->id.us = 0;
	return World_CreatePyObject(world);
}

/**
 * \brief The World PyType compare function
 *
 * This function compares two given World PyObjects, returning 0 for equality
 * and -1 otherwise.	In Python it becomes 1 if they are equal and 0 case not.
 * The comparison is done with their pointers to Blender World Data objects,
 * so any two wrappers pointing to the same Blender World Data will be
 * considered the same World PyObject.	Currently, only the "==" and "!="
 * comparisons are meaninful -- the "<", "<=", ">" or ">=" are not.
 */

static int World_Compare( BPy_World * a, BPy_World * b )
{
	return ( a->world == b->world ) ? 0 : -1;
}

/**
 * \brief The World PyType print callback
 *
 * This function is called when the user tries to print a PyObject of type
 * World.  It builds a string with the name of the wrapped Blender World.
 */

/*
static int World_Print(BPy_World *self, FILE *fp, int flags)
{ 
	fprintf(fp, "[World \"%s\"]", self->world->id.name+2);
	return 0;
}
*/

/**
 * \brief The World PyType repr callback
 *
 * This function is called when the statement "repr(myworld)" is executed in
 * Python.	Repr gives a string representation of a PyObject.
 */

static PyObject *World_Repr( BPy_World * self )
{
	return PyString_FromFormat( "[World \"%s\"]",
				    self->world->id.name + 2 );
}

/*@}*/
/*
static int World_compare (BPy_World *a, BPy_World *b)
{
	World *pa = a->world, *pb = b->world;
	return (pa == pb) ? 0:-1;
}
*/
PyObject *World_CreatePyObject( struct World * world )
{
	BPy_World *blen_object;

	blen_object = ( BPy_World * ) PyObject_NEW( BPy_World, &World_Type );

	if( blen_object == NULL ) {
		return ( NULL );
	}
	blen_object->world = world;
	return ( ( PyObject * ) blen_object );
}

World *World_FromPyObject( PyObject * py_obj )
{
	BPy_World *blen_obj;

	blen_obj = ( BPy_World * ) py_obj;
	return ( blen_obj->world );

}

/*
 * World_insertIpoKey()
 *  inserts World IPO key for ZENITH,HORIZON,MIST,STARS,OFFSET,SIZE
 */

static PyObject *World_insertIpoKey( BPy_World * self, PyObject * args )
{
	int key = 0, map;

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

	map = texchannel_to_adrcode(self->world->texact);

	if(key == IPOKEY_ZENITH) {
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_ZEN_R, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_ZEN_G, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_ZEN_B, 0);
	}
	if(key == IPOKEY_HORIZON) {
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_HOR_R, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_HOR_G, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_HOR_B, 0);
	}
	if(key == IPOKEY_MIST) {
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_MISI, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_MISTDI, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_MISTSTA, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_MISTHI, 0);
	}
	if(key == IPOKEY_STARS) {
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_STAR_R, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_STAR_G, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_STAR_B, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_STARDIST, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, WO_STARSIZE, 0);
	}
	if(key == IPOKEY_OFFSET) {
		insertkey((ID *)self->world, ID_WO, NULL, NULL, map+MAP_OFS_X, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, map+MAP_OFS_Y, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, map+MAP_OFS_Z, 0);
	}
	if(key == IPOKEY_SIZE) {
		insertkey((ID *)self->world, ID_WO, NULL, NULL, map+MAP_SIZE_X, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, map+MAP_SIZE_Y, 0);
		insertkey((ID *)self->world, ID_WO, NULL, NULL, map+MAP_SIZE_Z, 0);
	}

	allspace(REMAKEIPO, 0);
	EXPP_allqueue(REDRAWIPO, 0);
	EXPP_allqueue(REDRAWVIEW3D, 0);
	EXPP_allqueue(REDRAWACTION, 0);
	EXPP_allqueue(REDRAWNLA, 0);

	Py_RETURN_NONE;
}

static PyObject *World_getTextures( BPy_World * self )
{
	int i;
	PyObject *tuple;

	/* build a texture list */
	tuple = PyTuple_New( MAX_MTEX );
	if( !tuple )
		return EXPP_ReturnPyObjError( PyExc_MemoryError,
					      "couldn't create PyTuple" );

	for( i = 0; i < MAX_MTEX; ++i ) {
		struct MTex *mtex = self->world->mtex[i];
		if( mtex ) {
			PyTuple_SET_ITEM( tuple, i, MTex_CreatePyObject( mtex, ID_WO ) );
		} else {
			Py_INCREF( Py_None );
			PyTuple_SET_ITEM( tuple, i, Py_None );
		}
	}

	return tuple;
}

static int World_setTextures( BPy_World * self, PyObject * value )
{
	int i;

	if( !PyList_Check( value ) && !PyTuple_Check( value ) )
		return EXPP_ReturnIntError( PyExc_TypeError,
						"expected tuple or list of integers" );

	/* don't allow more than MAX_MTEX items */
	if( PySequence_Size(value) > MAX_MTEX )
		return EXPP_ReturnIntError( PyExc_AttributeError,
						"size of sequence greater than number of allowed textures" );

	/* get a fast sequence; in Python 2.5, this just return the original
	 * list or tuple and INCREFs it, so we must DECREF */
	value = PySequence_Fast( value, "" );

	/* check the list for valid entries */
	for( i= 0; i < PySequence_Size(value) ; ++i ) {
		PyObject *item = PySequence_Fast_GET_ITEM( value, i );
		if( item == Py_None || ( BPy_MTex_Check( item ) &&
						((BPy_MTex *)item)->type == ID_WO ) ) {
			continue;
		} else {
			Py_DECREF(value);
			return EXPP_ReturnIntError( PyExc_TypeError,
					"expected tuple or list containing world MTex objects and NONE" );
		}
	}

	/* for each MTex object, copy to this structure */
	for( i= 0; i < PySequence_Size(value) ; ++i ) {
		PyObject *item = PySequence_Fast_GET_ITEM( value, i );
		struct MTex *mtex = self->world->mtex[i];
		if( item != Py_None ) {
			BPy_MTex *obj = (BPy_MTex *)item;

			/* if MTex is already at this location, just skip it */
			if( obj->mtex == mtex )	continue;

			/* create a new entry if needed, otherwise update reference count
			 * for texture that is being replaced */
			if( !mtex )
				mtex = self->world->mtex[i] = add_mtex(  );
			else
				mtex->tex->id.us--;

			/* copy the data */
			mtex->tex = obj->mtex->tex;
			id_us_plus( &mtex->tex->id );
			mtex->texco = obj->mtex->texco;
			mtex->mapto = obj->mtex->mapto;
		}
	}

	/* now go back and free any entries now marked as None */
	for( i= 0; i < PySequence_Size(value) ; ++i ) {
		PyObject *item = PySequence_Fast_GET_ITEM( value, i );
		struct MTex *mtex = self->world->mtex[i];
		if( item == Py_None && mtex ) {
			mtex->tex->id.us--;
			MEM_freeN( mtex );
			self->world->mtex[i] = NULL;
		} 
	}

	Py_DECREF(value);
	return 0;
}