Added extra ranlib on libary files after being copied to the lib tree for OSX only.
[blender-staging.git] / intern / python / py_main.c
1 /**
2  * $Id$
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
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/BL DUAL LICENSE BLOCK *****
30  */
31
32 /* CVS */
33
34 /* $Author$ */
35 /* $Date$ */
36 /* $RCSfile$ */
37 /* $Revision$ */
38
39 /*  Jan Walter's stuff */
40 #include "Python.h"
41 #include "blender.h"
42
43 static PyObject* ErrorObject;
44
45 uint* mcol_to_vcol(Mesh *me);
46 void mcol_to_rgb(uint col, float *r, float *g, float *b);
47 void initBlender();
48 static PyObject* blend_connect(PyObject* self, PyObject* args);
49 static PyObject* blend_getObject(PyObject* self, PyObject* args);
50 /*  Jan Walter's stuff */
51
52 /*  Daniel Dunbar's stuff */
53 void start_python (void);
54 void end_python(void);
55 void txt_do_python (Text* text);
56 void do_all_scripts(short event);
57 void do_all_scriptlist(ListBase* list, short event);
58 void do_pyscript(ID *id, short event);
59 void clear_bad_scriptlink(ID* id, Text* byebye);
60 void clear_bad_scriptlinks(Text *byebye);
61 void free_scriptlink(ScriptLink *slink);
62 void copy_scriptlink(ScriptLink *scriptlink);
63
64 void start_python (void)
65 {
66   Py_SetProgramName("blender");
67   Py_Initialize();
68   initBlender();
69 }
70
71 void end_python(void)
72 {
73   Py_Finalize();
74 }
75
76 void txt_do_python (Text* text)
77 {
78   char filename[] = "test.py";
79   FILE* fp = NULL;
80
81   if (text->name)
82     {
83       fp = fopen(text->name, "r");
84     }
85   else
86     {
87       fp = fopen(filename, "r");
88     }
89   if (fp)
90     {
91       if (text->name)
92         {
93           PyRun_AnyFile(fp, text->name);
94         }
95       else
96         {
97           PyRun_AnyFile(fp, filename);
98         }
99     }
100   else
101     {
102       if (text->name)
103         {
104           printf("Couldn't run %s ...\n", text->name);
105         }
106       else
107         {
108           printf("Couldn't run test.py ...\n");
109         }
110     }
111 }
112
113 void do_all_scripts(short event)
114 {
115 }
116
117 void do_all_scriptlist(ListBase* list, short event)
118 {
119 }
120
121 void do_pyscript(ID *id, short event)
122 {
123 }
124
125 void clear_bad_scriptlink(ID* id, Text* byebye)
126 {
127 }
128
129 void clear_bad_scriptlinks(Text *byebye)
130 {
131 }
132
133 void free_scriptlink(ScriptLink *slink)
134 {
135 }
136
137 void copy_scriptlink(ScriptLink *scriptlink)
138 {
139 }
140 /*  Daniel Dunbar's stuff */
141
142 ID* find_name_in_list(ID* list, const char* name)
143 {
144   while (list)
145     {
146       if (STREQ(name, list->name+2))
147         {
148           break;
149         }
150       else
151         {
152           list = list->next;
153         }
154     }
155
156   return list;
157 }
158
159 /*  Jan Walter's stuff */
160 /**************/
161 /* structures */
162 /**************/
163
164 typedef struct {
165   PyObject_HEAD
166   char name[24];
167   PyObject* Lens;
168   PyObject* ClSta;
169   PyObject* ClEnd;
170 } camobject;
171
172 staticforward PyTypeObject Camtype;
173
174 typedef struct {
175   PyObject_HEAD
176   PyObject* startFrame;
177   PyObject* endFrame;
178   PyObject* currentFrame;
179   PyObject* xResolution;
180   PyObject* yResolution;
181   PyObject* pixelAspectRatio;
182 } dspobject;
183
184 staticforward PyTypeObject Dsptype;
185
186 typedef struct {
187   PyObject_HEAD
188   char name[24];
189   PyObject* R;
190   PyObject* G;
191   PyObject* B;
192 } lmpobject;
193
194 staticforward PyTypeObject Lmptype;
195
196 typedef struct {
197   PyObject_HEAD
198   char name[24];
199   PyObject* R;
200   PyObject* G;
201   PyObject* B;
202 } matobject;
203
204 staticforward PyTypeObject Mattype;
205
206 typedef struct {
207   PyObject_HEAD
208   char name[24];
209   PyObject* vertices;
210   PyObject* normals;
211   PyObject* colors;
212   PyObject* faces;
213   PyObject* texture;
214   PyObject* texcoords;
215 } mshobject;
216
217 staticforward PyTypeObject Mshtype;
218
219 typedef struct {
220   PyObject_HEAD
221   char name[24];
222   PyObject* matrix;
223   PyObject* inverseMatrix;
224   PyObject* materials;
225   PyObject* data;
226   PyObject* type;
227 } objobject;
228
229 staticforward PyTypeObject Objtype;
230
231 typedef struct {
232   PyObject_HEAD
233   char name[24];
234   PyObject* objects;
235 } sceobject;
236
237 staticforward PyTypeObject Scetype;
238
239 /**********/
240 /* camera */
241 /**********/
242
243 static struct PyMethodDef cam_methods[] = {
244   { NULL, NULL }
245 };
246
247 static camobject*
248 newcamobject(char* name)
249 {
250   camobject* self;
251   ID*        list = NULL;
252
253   self = PyObject_NEW(camobject, &Camtype);
254   if (self == NULL)
255     {
256       return NULL;
257     }
258   strcpy(self->name, name);
259   self->Lens  = PyFloat_FromDouble(35.0);
260   self->ClSta = PyFloat_FromDouble(0.1);
261   self->ClEnd = PyFloat_FromDouble(100.0);
262
263   return self;
264 }
265
266 static void
267 cam_dealloc(camobject* self)
268 {
269   camobject* cam = (camobject*) self;
270
271   Py_DECREF(cam->Lens);
272   Py_DECREF(cam->ClSta);
273   Py_DECREF(cam->ClEnd);
274
275   PyMem_DEL(self);
276 }
277
278 static int
279 cam_print(camobject* self, FILE* fp, int flags)
280 {
281   fprintf(fp, "Camera(name = \"%s\")\n", self->name);
282
283   return 0;
284 }
285
286 static PyObject*
287 cam_repr(camobject* self)
288 {
289   PyObject* s;
290
291   s = PyString_FromString("Camera()\n");
292
293   return s;
294 }
295
296 static PyObject*
297 cam_str(camobject* self)
298 {
299   PyObject* s;
300
301   s = PyString_FromString("Camera()\n");
302
303   return s;
304 }
305
306 #include "structmember.h"
307
308 static struct memberlist cam_memberlist[] = {
309   /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
310   {"Lens",  T_OBJECT, offsetof(camobject, Lens),  RO},
311   {"ClSta", T_OBJECT, offsetof(camobject, ClSta), RO},
312   {"ClEnd", T_OBJECT, offsetof(camobject, ClEnd), RO},
313   {NULL}
314 };
315
316 static PyObject*
317 cam_getattr(camobject* self, char* name)
318 {
319   PyObject* rv;
320
321   /* XXXX Add your own getattr code here */
322   rv = PyMember_Get((char*) self, cam_memberlist, name);
323   if (rv)
324     {
325       return rv;
326     }
327   PyErr_Clear();
328
329   return Py_FindMethod(cam_methods, (PyObject*)self, name);
330 }
331
332
333 static int
334 cam_setattr(camobject* self, char* name, PyObject* v)
335 {
336   /* XXXX Add your own setattr code here */
337   if ( v == NULL )
338     {
339       PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
340       return -1;
341     }
342
343   return PyMember_Set((char*)/*XXXX*/0, cam_memberlist, name, v);
344 }
345
346 static char Camtype__doc__[] =
347 ""
348 ;
349
350 static PyTypeObject Camtype = {
351   PyObject_HEAD_INIT(&PyType_Type)
352   0,                            /*ob_size*/
353   "Camera",                     /*tp_name*/
354   sizeof(camobject),    /*tp_basicsize*/
355   0,                            /*tp_itemsize*/
356   /* methods */
357   (destructor) cam_dealloc,     /*tp_dealloc*/
358   (printfunc) cam_print,        /*tp_print*/
359   (getattrfunc) cam_getattr,    /*tp_getattr*/
360   (setattrfunc) cam_setattr,    /*tp_setattr*/
361   (cmpfunc) 0,  /*tp_compare*/
362   (reprfunc) cam_repr,          /*tp_repr*/
363   0,            /*tp_as_number*/
364   0,            /*tp_as_sequence*/
365   0,            /*tp_as_mapping*/
366   (hashfunc) 0,         /*tp_hash*/
367   (ternaryfunc) 0,      /*tp_call*/
368   (reprfunc) cam_str,           /*tp_str*/
369
370   /* Space for future expansion */
371   0L,0L,0L,0L,
372   Camtype__doc__ /* Documentation string */
373 };
374
375 /********************/
376 /* display settings */
377 /********************/
378
379 static struct PyMethodDef dsp_methods[] = {
380   { NULL, NULL }
381 };
382
383 static dspobject*
384 newdspobject(void)
385 {
386   dspobject* self;
387   ID*        list = NULL;
388
389   self = PyObject_NEW(dspobject, &Dsptype);
390   if (self == NULL)
391     {
392       return NULL;
393     }
394   self->startFrame       = PyInt_FromLong(1);
395   self->endFrame         = PyInt_FromLong(250);
396   self->currentFrame     = PyInt_FromLong(1);
397   self->xResolution      = PyInt_FromLong(320);
398   self->yResolution      = PyInt_FromLong(256);
399   self->pixelAspectRatio = PyFloat_FromDouble(1.0);
400
401   return self;
402 }
403
404 static void
405 dsp_dealloc(dspobject* self)
406 {
407   dspobject* dsp = (dspobject*) self;
408
409   Py_DECREF(dsp->startFrame);
410   Py_DECREF(dsp->endFrame);
411   Py_DECREF(dsp->currentFrame);
412   Py_DECREF(dsp->xResolution);
413   Py_DECREF(dsp->yResolution);
414   Py_DECREF(dsp->pixelAspectRatio);
415
416   PyMem_DEL(self);
417 }
418
419 static int
420 dsp_print(dspobject* self, FILE* fp, int flags)
421 {
422   fprintf(fp, "DisplaySettings()\n");
423
424   return 0;
425 }
426
427 static PyObject*
428 dsp_repr(dspobject* self)
429 {
430   PyObject* s;
431
432   s = PyString_FromString("DisplaySettings()()\n");
433
434   return s;
435 }
436
437 static PyObject*
438 dsp_str(dspobject* self)
439 {
440   PyObject* s;
441
442   s = PyString_FromString("DisplaySettings()()\n");
443
444   return s;
445 }
446
447 #include "structmember.h"
448
449 static struct memberlist dsp_memberlist[] = {
450   /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
451   {"startFrame",       T_OBJECT, offsetof(dspobject, startFrame),       RO},
452   {"endFrame",         T_OBJECT, offsetof(dspobject, endFrame),         RO},
453   {"currentFrame",     T_OBJECT, offsetof(dspobject, currentFrame),     RO},
454   {"xResolution",      T_OBJECT, offsetof(dspobject, xResolution),      RO},
455   {"yResolution",      T_OBJECT, offsetof(dspobject, yResolution),      RO},
456   {"pixelAspectRatio", T_OBJECT, offsetof(dspobject, pixelAspectRatio), RO},
457   {NULL}
458 };
459
460 static PyObject*
461 dsp_getattr(dspobject* self, char* name)
462 {
463   PyObject* rv;
464
465   /* XXXX Add your own getattr code here */
466   rv = PyMember_Get((char*) self, dsp_memberlist, name);
467   if (rv)
468     {
469       return rv;
470     }
471   PyErr_Clear();
472
473   return Py_FindMethod(dsp_methods, (PyObject*)self, name);
474 }
475
476
477 static int
478 dsp_setattr(dspobject* self, char* name, PyObject* v)
479 {
480   /* XXXX Add your own setattr code here */
481   if ( v == NULL )
482     {
483       PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
484       return -1;
485     }
486
487   return PyMember_Set((char*)/*XXXX*/0, dsp_memberlist, name, v);
488 }
489
490 static char Dsptype__doc__[] =
491 ""
492 ;
493
494 static PyTypeObject Dsptype = {
495   PyObject_HEAD_INIT(&PyType_Type)
496   0,                            /*ob_size*/
497   "DisplaySettings",                    /*tp_name*/
498   sizeof(dspobject),    /*tp_basicsize*/
499   0,                            /*tp_itemsize*/
500   /* methods */
501   (destructor) dsp_dealloc,     /*tp_dealloc*/
502   (printfunc) dsp_print,        /*tp_print*/
503   (getattrfunc) dsp_getattr,    /*tp_getattr*/
504   (setattrfunc) dsp_setattr,    /*tp_setattr*/
505   (cmpfunc) 0,  /*tp_compare*/
506   (reprfunc) dsp_repr,          /*tp_repr*/
507   0,            /*tp_as_number*/
508   0,            /*tp_as_sequence*/
509   0,            /*tp_as_mapping*/
510   (hashfunc) 0,         /*tp_hash*/
511   (ternaryfunc) 0,      /*tp_call*/
512   (reprfunc) dsp_str,           /*tp_str*/
513
514   /* Space for future expansion */
515   0L,0L,0L,0L,
516   Dsptype__doc__ /* Documentation string */
517 };
518
519 /********/
520 /* Lamp */
521 /********/
522
523 static struct PyMethodDef lmp_methods[] = {
524   { NULL, NULL }
525 };
526
527 static lmpobject*
528 newlmpobject(char* name)
529 {
530   lmpobject* self;
531   ID*        list = NULL;
532
533   self = PyObject_NEW(lmpobject, &Lmptype);
534   if (self == NULL)
535     {
536       return NULL;
537     }
538   strcpy(self->name, name);
539   self->R = PyFloat_FromDouble(0.8);
540   self->G = PyFloat_FromDouble(0.8);
541   self->B = PyFloat_FromDouble(0.8);
542
543   return self;
544 }
545
546 static void
547 lmp_dealloc(lmpobject* self)
548 {
549   lmpobject* lmp = (lmpobject*) self;
550
551   Py_DECREF(lmp->R);
552   Py_DECREF(lmp->G);
553   Py_DECREF(lmp->B);
554
555   PyMem_DEL(self);
556 }
557
558 static int
559 lmp_print(lmpobject* self, FILE* fp, int flags)
560 {
561   fprintf(fp, "Lamp(name = \"%s\")\n", self->name);
562
563   return 0;
564 }
565
566 static PyObject*
567 lmp_repr(lmpobject* self)
568 {
569   PyObject* s;
570
571   s = PyString_FromString("Lamp()\n");
572
573   return s;
574 }
575
576 static PyObject*
577 lmp_str(lmpobject* self)
578 {
579   PyObject* s;
580
581   s = PyString_FromString("Lamp()\n");
582
583   return s;
584 }
585
586 #include "structmember.h"
587
588 static struct memberlist lmp_memberlist[] = {
589   /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
590   {"R", T_OBJECT, offsetof(lmpobject, R), RO},
591   {"G", T_OBJECT, offsetof(lmpobject, G), RO},
592   {"B", T_OBJECT, offsetof(lmpobject, B), RO},
593   {NULL}
594 };
595
596 static PyObject*
597 lmp_getattr(lmpobject* self, char* name)
598 {
599   PyObject* rv;
600
601   /* XXXX Add your own getattr code here */
602   rv = PyMember_Get((char*) self, lmp_memberlist, name);
603   if (rv)
604     {
605       return rv;
606     }
607   PyErr_Clear();
608
609   return Py_FindMethod(lmp_methods, (PyObject*)self, name);
610 }
611
612
613 static int
614 lmp_setattr(lmpobject* self, char* name, PyObject* v)
615 {
616   /* XXXX Add your own setattr code here */
617   if ( v == NULL )
618     {
619       PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
620       return -1;
621     }
622
623   return PyMember_Set((char*)/*XXXX*/0, lmp_memberlist, name, v);
624 }
625
626 static char Lmptype__doc__[] =
627 ""
628 ;
629
630 static PyTypeObject Lmptype = {
631   PyObject_HEAD_INIT(&PyType_Type)
632   0,                            /*ob_size*/
633   "Lamp",                       /*tp_name*/
634   sizeof(lmpobject),    /*tp_basicsize*/
635   0,                            /*tp_itemsize*/
636   /* methods */
637   (destructor) lmp_dealloc,     /*tp_dealloc*/
638   (printfunc) lmp_print,        /*tp_print*/
639   (getattrfunc) lmp_getattr,    /*tp_getattr*/
640   (setattrfunc) lmp_setattr,    /*tp_setattr*/
641   (cmpfunc) 0,  /*tp_compare*/
642   (reprfunc) lmp_repr,          /*tp_repr*/
643   0,            /*tp_as_number*/
644   0,            /*tp_as_sequence*/
645   0,            /*tp_as_mapping*/
646   (hashfunc) 0,         /*tp_hash*/
647   (ternaryfunc) 0,      /*tp_call*/
648   (reprfunc) lmp_str,           /*tp_str*/
649
650   /* Space for future expansion */
651   0L,0L,0L,0L,
652   Lmptype__doc__ /* Documentation string */
653 };
654
655 /************/
656 /* material */
657 /************/
658
659 static struct PyMethodDef mat_methods[] = {
660   { NULL, NULL }
661 };
662
663 static matobject*
664 newmatobject(char* name)
665 {
666   matobject* self;
667   ID*        list = NULL;
668
669   self = PyObject_NEW(matobject, &Mattype);
670   if (self == NULL)
671     {
672       return NULL;
673     }
674   strcpy(self->name, name);
675   self->R = PyFloat_FromDouble(0.8);
676   self->G = PyFloat_FromDouble(0.8);
677   self->B = PyFloat_FromDouble(0.8);
678
679   return self;
680 }
681
682 static void
683 mat_dealloc(matobject* self)
684 {
685   matobject* mat = (matobject*) self;
686
687   Py_DECREF(mat->R);
688   Py_DECREF(mat->G);
689   Py_DECREF(mat->B);
690
691   PyMem_DEL(self);
692 }
693
694 static int
695 mat_print(matobject* self, FILE* fp, int flags)
696 {
697   fprintf(fp, "Material(name = \"%s\")\n", self->name);
698
699   return 0;
700 }
701
702 static PyObject*
703 mat_repr(matobject* self)
704 {
705   PyObject* s;
706
707   s = PyString_FromString("Material()\n");
708
709   return s;
710 }
711
712 static PyObject*
713 mat_str(matobject* self)
714 {
715   PyObject* s;
716
717   s = PyString_FromString("Material()\n");
718
719   return s;
720 }
721
722 #include "structmember.h"
723
724 static struct memberlist mat_memberlist[] = {
725   /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
726   {"R", T_OBJECT, offsetof(matobject, R), RO},
727   {"G", T_OBJECT, offsetof(matobject, G), RO},
728   {"B", T_OBJECT, offsetof(matobject, B), RO},
729   {NULL}
730 };
731
732 static PyObject*
733 mat_getattr(matobject* self, char* name)
734 {
735   PyObject* rv;
736
737   /* XXXX Add your own getattr code here */
738   rv = PyMember_Get((char*) self, mat_memberlist, name);
739   if (rv)
740     {
741       return rv;
742     }
743   PyErr_Clear();
744
745   return Py_FindMethod(mat_methods, (PyObject*)self, name);
746 }
747
748
749 static int
750 mat_setattr(matobject* self, char* name, PyObject* v)
751 {
752   /* XXXX Add your own setattr code here */
753   if ( v == NULL )
754     {
755       PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
756       return -1;
757     }
758
759   return PyMember_Set((char*)/*XXXX*/0, mat_memberlist, name, v);
760 }
761
762 static char Mattype__doc__[] =
763 ""
764 ;
765
766 static PyTypeObject Mattype = {
767   PyObject_HEAD_INIT(&PyType_Type)
768   0,                            /*ob_size*/
769   "Material",                   /*tp_name*/
770   sizeof(matobject),    /*tp_basicsize*/
771   0,                            /*tp_itemsize*/
772   /* methods */
773   (destructor) mat_dealloc,     /*tp_dealloc*/
774   (printfunc) mat_print,        /*tp_print*/
775   (getattrfunc) mat_getattr,    /*tp_getattr*/
776   (setattrfunc) mat_setattr,    /*tp_setattr*/
777   (cmpfunc) 0,  /*tp_compare*/
778   (reprfunc) mat_repr,          /*tp_repr*/
779   0,            /*tp_as_number*/
780   0,            /*tp_as_sequence*/
781   0,            /*tp_as_mapping*/
782   (hashfunc) 0,         /*tp_hash*/
783   (ternaryfunc) 0,      /*tp_call*/
784   (reprfunc) mat_str,           /*tp_str*/
785
786   /* Space for future expansion */
787   0L,0L,0L,0L,
788   Mattype__doc__ /* Documentation string */
789 };
790
791 /********/
792 /* mesh */
793 /********/
794
795 static char msh_addFace__doc__[] =
796 "addFace(self, i1, i2, i3, i4, isSmooth, matIndex)"
797 ;
798
799 static PyObject*
800 msh_addFace(mshobject* self, PyObject* args)
801 {
802   int       index;
803   int       i1, i2, i3, i4;
804   int       isSmooth, matIndex;
805   PyObject* item = NULL;
806
807   if (!PyArg_ParseTuple(args, "iiiiii", &i1, &i2, &i3, &i4,
808                         &isSmooth, &matIndex))
809     {
810       return NULL;
811     }
812   item = PyList_New(6);
813   PyList_SetItem(item, 0, PyInt_FromLong(i1));
814   PyList_SetItem(item, 1, PyInt_FromLong(i2));
815   PyList_SetItem(item, 2, PyInt_FromLong(i3));
816   PyList_SetItem(item, 3, PyInt_FromLong(i4));
817   PyList_SetItem(item, 4, PyInt_FromLong(isSmooth));
818   PyList_SetItem(item, 5, PyInt_FromLong(matIndex));
819   PyList_Append(self->faces, item);
820   index = PyList_Size(self->faces) - 1;
821
822   return PyInt_FromLong(index);
823 }
824
825 static char msh_addTexCoords__doc__[] =
826 "addTexCoords(self, coords)"
827 ;
828
829 static PyObject*
830 msh_addTexCoords(mshobject* self, PyObject* args)
831 {
832   float     u, v;
833   PyObject* item = NULL;
834
835   if (!PyArg_ParseTuple(args, "ff",
836                         &u, &v))
837     {
838       return NULL;
839     }
840   if (u < 0.0)
841     {
842       u = 0.0;
843     }
844   if (u > 1.0)
845     {
846       u = 1.0;
847     }
848   if (v < 0.0)
849     {
850       v = 0.0;
851     }
852   if (v > 1.0)
853     {
854       v = 1.0;
855     }
856   item = PyList_New(2);
857   PyList_SetItem(item, 0, PyFloat_FromDouble(u));
858   PyList_SetItem(item, 1, PyFloat_FromDouble(v));
859   PyList_Append(self->texcoords, item);
860
861   Py_INCREF(Py_None);
862   return Py_None;
863 }
864
865 static char msh_addTexture__doc__[] =
866 "addTexture(self, filename)"
867 ;
868
869 static PyObject*
870 msh_addTexture(mshobject* self, PyObject* args)
871 {
872   char* filename = NULL;
873
874   if (!PyArg_ParseTuple(args, "s", &filename))
875     {
876       return NULL;
877     }
878   self->texture = PyString_FromString(filename);
879
880   Py_INCREF(Py_None);
881   return Py_None;
882 }
883
884 static char msh_addVertex__doc__[] =
885 "addVertex(self, x, y, z, nx, ny, nz, r = -1.0, g = 0.0, b = 0.0)"
886 ;
887
888 static PyObject*
889 msh_addVertex(mshobject* self, PyObject* args)
890 {
891   int       index;
892   float     x, y, z, nx, ny, nz;
893   float     r = -1.0, g = 0.0, b = 0.0;
894   PyObject* item1 = NULL;
895   PyObject* item2 = NULL;
896   PyObject* item3 = NULL;
897
898   if (!PyArg_ParseTuple(args, "ffffff|fff", &x, &y, &z, &nx, &ny, &nz,
899                         &r, &g, &b))
900     {
901       return NULL;
902     }
903   item1 = PyList_New(3);
904   item2 = PyList_New(3);
905   if (r != -1.0)
906     {
907       item3 = PyList_New(3);
908     }
909   PyList_SetItem(item1, 0, PyFloat_FromDouble(x));
910   PyList_SetItem(item1, 1, PyFloat_FromDouble(y));
911   PyList_SetItem(item1, 2, PyFloat_FromDouble(z));
912   PyList_SetItem(item2, 0, PyFloat_FromDouble(nx));
913   PyList_SetItem(item2, 1, PyFloat_FromDouble(ny));
914   PyList_SetItem(item2, 2, PyFloat_FromDouble(nz));
915   if (r != -1.0)
916     {
917       PyList_SetItem(item3, 0, PyFloat_FromDouble(r));
918       PyList_SetItem(item3, 1, PyFloat_FromDouble(g));
919       PyList_SetItem(item3, 2, PyFloat_FromDouble(b));
920     }
921   PyList_Append(self->vertices, item1);
922   PyList_Append(self->normals, item2);
923   if (r != -1.0)
924     {
925       PyList_Append(self->colors, item3);
926     }
927   index = PyList_Size(self->vertices) - 1;
928
929   return PyInt_FromLong(index);
930 }
931
932 static struct PyMethodDef msh_methods[] = {
933   {"addFace",   (PyCFunction)msh_addFace,
934    METH_VARARGS, msh_addFace__doc__},
935   {"addTexCoords", (PyCFunction)msh_addTexCoords,
936    METH_VARARGS, msh_addTexCoords__doc__},
937   {"addTexture", (PyCFunction)msh_addTexture,
938    METH_VARARGS, msh_addTexture__doc__},
939   {"addVertex", (PyCFunction)msh_addVertex,
940    METH_VARARGS, msh_addVertex__doc__},
941
942   { NULL, NULL }
943 };
944
945 static mshobject*
946 newmshobject(char* name)
947 {
948   mshobject* self;
949   ID*        list = NULL;
950
951   self = PyObject_NEW(mshobject, &Mshtype);
952   if (self == NULL)
953     {
954       return NULL;
955     }
956   strcpy(self->name, name);
957   self->vertices  = PyList_New(0);
958   self->normals   = PyList_New(0);
959   self->colors    = PyList_New(0);
960   self->faces     = PyList_New(0);
961   self->texcoords = PyList_New(0);
962   Py_INCREF(Py_None);
963   self->texture = Py_None;
964
965   return self;
966 }
967
968 static void
969 msh_dealloc(mshobject* self)
970 {
971   mshobject* msh = (mshobject*) self;
972
973   Py_DECREF(msh->vertices);
974   Py_DECREF(msh->normals);
975   Py_DECREF(msh->colors);
976   Py_DECREF(msh->faces);
977   Py_DECREF(msh->texture);
978   Py_DECREF(msh->texcoords);
979
980   PyMem_DEL(self);
981 }
982
983 static int
984 msh_print(mshobject* self, FILE* fp, int flags)
985 {
986   fprintf(fp, "Mesh(name = \"%s\",\n", self->name);
987   fprintf(fp, "     vertices = %d,\n", PyList_Size(self->vertices));
988   fprintf(fp, "     faces = %d)\n", PyList_Size(self->faces));
989
990   return 0;
991 }
992
993 static PyObject*
994 msh_repr(mshobject* self)
995 {
996   PyObject* s;
997
998   s = PyString_FromString("Mesh()\n");
999
1000   return s;
1001 }
1002
1003 static PyObject*
1004 msh_str(mshobject* self)
1005 {
1006   PyObject* s;
1007
1008   s = PyString_FromString("Mesh()\n");
1009
1010   return s;
1011 }
1012
1013 #include "structmember.h"
1014
1015 static struct memberlist msh_memberlist[] = {
1016   /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
1017   {"vertices",  T_OBJECT, offsetof(mshobject, vertices),  RO},
1018   {"normals",   T_OBJECT, offsetof(mshobject, normals),   RO},
1019   {"colors",    T_OBJECT, offsetof(mshobject, colors),    RO},
1020   {"faces",     T_OBJECT, offsetof(mshobject, faces),     RO},
1021   {"texture",   T_OBJECT, offsetof(mshobject, texture),   RO},
1022   {"texcoords", T_OBJECT, offsetof(mshobject, texcoords), RO},
1023   {NULL}
1024 };
1025
1026 static PyObject*
1027 msh_getattr(mshobject* self, char* name)
1028 {
1029   PyObject* rv;
1030
1031   /* XXXX Add your own getattr code here */
1032   rv = PyMember_Get((char*) self, msh_memberlist, name);
1033   if (rv)
1034     {
1035       return rv;
1036     }
1037   PyErr_Clear();
1038
1039   return Py_FindMethod(msh_methods, (PyObject*)self, name);
1040 }
1041
1042
1043 static int
1044 msh_setattr(mshobject* self, char* name, PyObject* v)
1045 {
1046   /* XXXX Add your own setattr code here */
1047   if ( v == NULL )
1048     {
1049       PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
1050       return -1;
1051     }
1052
1053   return PyMember_Set((char*)/*XXXX*/0, msh_memberlist, name, v);
1054 }
1055
1056 static char Mshtype__doc__[] =
1057 ""
1058 ;
1059
1060 static PyTypeObject Mshtype = {
1061   PyObject_HEAD_INIT(&PyType_Type)
1062   0,                            /*ob_size*/
1063   "Mesh",                       /*tp_name*/
1064   sizeof(mshobject),    /*tp_basicsize*/
1065   0,                            /*tp_itemsize*/
1066   /* methods */
1067   (destructor) msh_dealloc,     /*tp_dealloc*/
1068   (printfunc) msh_print,        /*tp_print*/
1069   (getattrfunc) msh_getattr,    /*tp_getattr*/
1070   (setattrfunc) msh_setattr,    /*tp_setattr*/
1071   (cmpfunc) 0,  /*tp_compare*/
1072   (reprfunc) msh_repr,          /*tp_repr*/
1073   0,            /*tp_as_number*/
1074   0,            /*tp_as_sequence*/
1075   0,            /*tp_as_mapping*/
1076   (hashfunc) 0,         /*tp_hash*/
1077   (ternaryfunc) 0,      /*tp_call*/
1078   (reprfunc) msh_str,           /*tp_str*/
1079
1080   /* Space for future expansion */
1081   0L,0L,0L,0L,
1082   Mshtype__doc__ /* Documentation string */
1083 };
1084
1085 /**********/
1086 /* object */
1087 /**********/
1088
1089 static struct PyMethodDef obj_methods[] = {
1090
1091   { NULL, NULL }
1092 };
1093
1094 static objobject*
1095 newobjobject(char* name)
1096 {
1097   objobject* self = NULL;
1098   PyObject*  row1 = NULL;
1099   PyObject*  row2 = NULL;
1100   PyObject*  row3 = NULL;
1101   PyObject*  row4 = NULL;
1102
1103   self = PyObject_NEW(objobject, &Objtype);
1104   if (self == NULL)
1105     {
1106       return NULL;
1107     }
1108   strcpy(self->name, name);
1109   self->matrix = PyList_New(4);
1110   row1 = PyList_New(4);
1111   row2 = PyList_New(4);
1112   row3 = PyList_New(4);
1113   row4 = PyList_New(4);
1114   PyList_SetItem(row1, 0, PyInt_FromLong(1));
1115   PyList_SetItem(row1, 1, PyInt_FromLong(0));
1116   PyList_SetItem(row1, 2, PyInt_FromLong(0));
1117   PyList_SetItem(row1, 3, PyInt_FromLong(0));
1118   PyList_SetItem(row2, 0, PyInt_FromLong(0));
1119   PyList_SetItem(row2, 1, PyInt_FromLong(1));
1120   PyList_SetItem(row2, 2, PyInt_FromLong(0));
1121   PyList_SetItem(row2, 3, PyInt_FromLong(0));
1122   PyList_SetItem(row3, 0, PyInt_FromLong(0));
1123   PyList_SetItem(row3, 1, PyInt_FromLong(0));
1124   PyList_SetItem(row3, 2, PyInt_FromLong(1));
1125   PyList_SetItem(row3, 3, PyInt_FromLong(0));
1126   PyList_SetItem(row4, 0, PyInt_FromLong(0));
1127   PyList_SetItem(row4, 1, PyInt_FromLong(0));
1128   PyList_SetItem(row4, 2, PyInt_FromLong(0));
1129   PyList_SetItem(row4, 3, PyInt_FromLong(1));
1130   PyList_SetItem(self->matrix, 0, row1);
1131   PyList_SetItem(self->matrix, 1, row2);
1132   PyList_SetItem(self->matrix, 2, row3);
1133   PyList_SetItem(self->matrix, 3, row4);
1134   self->inverseMatrix = PyList_New(4);
1135   row1 = PyList_New(4);
1136   row2 = PyList_New(4);
1137   row3 = PyList_New(4);
1138   row4 = PyList_New(4);
1139   PyList_SetItem(row1, 0, PyInt_FromLong(1));
1140   PyList_SetItem(row1, 1, PyInt_FromLong(0));
1141   PyList_SetItem(row1, 2, PyInt_FromLong(0));
1142   PyList_SetItem(row1, 3, PyInt_FromLong(0));
1143   PyList_SetItem(row2, 0, PyInt_FromLong(0));
1144   PyList_SetItem(row2, 1, PyInt_FromLong(1));
1145   PyList_SetItem(row2, 2, PyInt_FromLong(0));
1146   PyList_SetItem(row2, 3, PyInt_FromLong(0));
1147   PyList_SetItem(row3, 0, PyInt_FromLong(0));
1148   PyList_SetItem(row3, 1, PyInt_FromLong(0));
1149   PyList_SetItem(row3, 2, PyInt_FromLong(1));
1150   PyList_SetItem(row3, 3, PyInt_FromLong(0));
1151   PyList_SetItem(row4, 0, PyInt_FromLong(0));
1152   PyList_SetItem(row4, 1, PyInt_FromLong(0));
1153   PyList_SetItem(row4, 2, PyInt_FromLong(0));
1154   PyList_SetItem(row4, 3, PyInt_FromLong(1));
1155   PyList_SetItem(self->inverseMatrix, 0, row1);
1156   PyList_SetItem(self->inverseMatrix, 1, row2);
1157   PyList_SetItem(self->inverseMatrix, 2, row3);
1158   PyList_SetItem(self->inverseMatrix, 3, row4);
1159   self->materials = PyList_New(0);
1160   Py_INCREF(Py_None);
1161   self->data = Py_None;
1162   Py_INCREF(Py_None);
1163   self->type = Py_None;
1164
1165   return self;
1166 }
1167
1168 static void
1169 obj_dealloc(objobject* self)
1170 {
1171   objobject* obj = (objobject*) self;
1172
1173   Py_DECREF(obj->matrix);
1174   Py_DECREF(obj->inverseMatrix);
1175   Py_DECREF(obj->materials);
1176   Py_DECREF(obj->data);
1177   Py_DECREF(obj->type);
1178
1179   PyMem_DEL(self);
1180 }
1181
1182 static int
1183 obj_print(objobject* self, FILE* fp, int flags)
1184 {
1185   fprintf(fp, "Object(name = \"%s\",\n", self->name);
1186 /*    fprintf(fp, "       matrix = %s,\n", */
1187 /*        PyString_AsString(mtx_repr((mtxobject*) self->matrix))); */
1188   if (self->type == Py_None)
1189     {
1190       fprintf(fp, "       data = None)\n");
1191     }
1192   else
1193     {
1194       fprintf(fp, "       data = %s(\"%s\"))\n",
1195               PyString_AsString(self->type),
1196               PyString_AsString(self->data));
1197     }
1198
1199   return 0;
1200 }
1201
1202 static PyObject*
1203 obj_repr(objobject* self)
1204 {
1205   PyObject* s;
1206
1207   s = PyString_FromString("Object()\n");
1208
1209   return s;
1210 }
1211
1212 static PyObject*
1213 obj_str(objobject* self)
1214 {
1215   PyObject* s;
1216
1217   s = PyString_FromString("Object()\n");
1218
1219   return s;
1220 }
1221
1222 #include "structmember.h"
1223
1224 static struct memberlist obj_memberlist[] = {
1225   /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
1226   {"data",          T_OBJECT, offsetof(objobject, data),          RO},
1227   {"matrix",        T_OBJECT, offsetof(objobject, matrix),        RO},
1228   {"inverseMatrix", T_OBJECT, offsetof(objobject, inverseMatrix), RO},
1229   {"materials",     T_OBJECT, offsetof(objobject, materials),     RO},
1230   {"type",          T_OBJECT, offsetof(objobject, type),          RO},
1231   {NULL}
1232 };
1233
1234 static PyObject*
1235 obj_getattr(objobject* self, char* name)
1236 {
1237   PyObject* rv;
1238
1239   /* XXXX Add your own getattr code here */
1240   rv = PyMember_Get((char*) self, obj_memberlist, name);
1241   if (rv)
1242     {
1243       return rv;
1244     }
1245   PyErr_Clear();
1246
1247   return Py_FindMethod(obj_methods, (PyObject*)self, name);
1248 }
1249
1250
1251 static int
1252 obj_setattr(objobject* self, char* name, PyObject* v)
1253 {
1254   /* XXXX Add your own setattr code here */
1255   if ( v == NULL )
1256     {
1257       PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
1258       return -1;
1259     }
1260
1261   return PyMember_Set((char*)/*XXXX*/0, obj_memberlist, name, v);
1262 }
1263
1264 static char Objtype__doc__[] =
1265 ""
1266 ;
1267
1268 static PyTypeObject Objtype = {
1269   PyObject_HEAD_INIT(&PyType_Type)
1270   0,                            /*ob_size*/
1271   "Object",                     /*tp_name*/
1272   sizeof(objobject),    /*tp_basicsize*/
1273   0,                            /*tp_itemsize*/
1274   /* methods */
1275   (destructor) obj_dealloc,     /*tp_dealloc*/
1276   (printfunc) obj_print,        /*tp_print*/
1277   (getattrfunc) obj_getattr,    /*tp_getattr*/
1278   (setattrfunc) obj_setattr,    /*tp_setattr*/
1279   (cmpfunc) 0,  /*tp_compare*/
1280   (reprfunc) obj_repr,          /*tp_repr*/
1281   0,            /*tp_as_number*/
1282   0,            /*tp_as_sequence*/
1283   0,            /*tp_as_mapping*/
1284   (hashfunc) 0,         /*tp_hash*/
1285   (ternaryfunc) 0,      /*tp_call*/
1286   (reprfunc) obj_str,           /*tp_str*/
1287
1288   /* Space for future expansion */
1289   0L,0L,0L,0L,
1290   Objtype__doc__ /* Documentation string */
1291 };
1292
1293 /*********/
1294 /* scene */
1295 /*********/
1296
1297 static char sce_addObject__doc__[] =
1298 "addObject(self, object)"
1299 ;
1300
1301 static PyObject*
1302 sce_addObject(sceobject* self, PyObject* args)
1303 {
1304   int       index;
1305   PyObject* object = NULL;
1306
1307   if (!PyArg_ParseTuple(args, "O", &object))
1308     {
1309       return NULL;
1310     }
1311   PyList_Append(self->objects, object);
1312   index = PyList_Size(self->objects) - 1;
1313
1314   return PyInt_FromLong(index);
1315 }
1316
1317 static char sce_getCurrentCamera__doc__[] =
1318 "getCurrentCamera(self)"
1319 ;
1320
1321 static PyObject*
1322 sce_getCurrentCamera(sceobject* self, PyObject* args)
1323 {
1324   char*     name   = NULL;
1325   PyObject* camera = NULL;
1326
1327   if (!PyArg_ParseTuple(args, ""))
1328     {
1329       return NULL;
1330     }
1331   if (G.scene->camera)
1332     {
1333       name = G.scene->camera->id.name+2;
1334       camera = blend_getObject(NULL, 
1335                                Py_BuildValue("(O)", 
1336                                              PyString_FromString(name)));
1337       
1338       return camera;
1339     }
1340   else
1341     {
1342       Py_INCREF(Py_None);
1343       return Py_None;
1344     }
1345 }
1346
1347 static struct PyMethodDef sce_methods[] = {
1348   {"addObject",   (PyCFunction)sce_addObject,
1349    METH_VARARGS, sce_addObject__doc__},
1350   {"getCurrentCamera",   (PyCFunction)sce_getCurrentCamera,
1351    METH_VARARGS, sce_getCurrentCamera__doc__},
1352
1353   { NULL, NULL }
1354 };
1355
1356 static sceobject*
1357 newsceobject(char* name)
1358 {
1359   sceobject* self;
1360
1361   self = PyObject_NEW(sceobject, &Scetype);
1362   if (self == NULL)
1363     {
1364       return NULL;
1365     }
1366   strcpy(self->name, name);
1367   self->objects = PyList_New(0);
1368
1369   return self;
1370 }
1371
1372 static void
1373 sce_dealloc(sceobject* self)
1374 {
1375   sceobject* sce = (sceobject*) self;
1376
1377   Py_DECREF(sce->objects);
1378
1379   PyMem_DEL(self);
1380 }
1381
1382 static int
1383 sce_print(sceobject* self, FILE* fp, int flags)
1384 {
1385   fprintf(fp, "Scene(name = \"%s\",\n", self->name);
1386   fprintf(fp, "      objects = %d)\n", PyList_Size(self->objects));
1387
1388   return 0;
1389 }
1390
1391 static PyObject*
1392 sce_repr(sceobject* self)
1393 {
1394   PyObject* s;
1395
1396   s = PyString_FromString("Scene()\n");
1397
1398   return s;
1399 }
1400
1401 static PyObject*
1402 sce_str(sceobject* self)
1403 {
1404   PyObject* s;
1405
1406   s = PyString_FromString("Scene()\n");
1407
1408   return s;
1409 }
1410
1411 #include "structmember.h"
1412
1413 static struct memberlist sce_memberlist[] = {
1414   /* XXXX Add lines like { "foo", T_INT, OFF(foo), RO }  */
1415   {"objects", T_OBJECT, offsetof(sceobject, objects), RO},
1416   {NULL}
1417 };
1418
1419 static PyObject*
1420 sce_getattr(sceobject* self, char* name)
1421 {
1422   PyObject* rv;
1423
1424   /* XXXX Add your own getattr code here */
1425   rv = PyMember_Get((char*) self, sce_memberlist, name);
1426   if (rv)
1427     {
1428       return rv;
1429     }
1430   PyErr_Clear();
1431
1432   return Py_FindMethod(sce_methods, (PyObject*)self, name);
1433 }
1434
1435
1436 static int
1437 sce_setattr(sceobject* self, char* name, PyObject* v)
1438 {
1439   /* XXXX Add your own setattr code here */
1440   if ( v == NULL )
1441     {
1442       PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
1443       return -1;
1444     }
1445
1446   return PyMember_Set((char*)/*XXXX*/0, sce_memberlist, name, v);
1447 }
1448
1449 static char Scetype__doc__[] =
1450 ""
1451 ;
1452
1453 static PyTypeObject Scetype = {
1454   PyObject_HEAD_INIT(&PyType_Type)
1455   0,                            /*ob_size*/
1456   "Scene",                      /*tp_name*/
1457   sizeof(sceobject),    /*tp_basicsize*/
1458   0,                            /*tp_itemsize*/
1459   /* methods */
1460   (destructor) sce_dealloc,     /*tp_dealloc*/
1461   (printfunc) sce_print,        /*tp_print*/
1462   (getattrfunc) sce_getattr,    /*tp_getattr*/
1463   (setattrfunc) sce_setattr,    /*tp_setattr*/
1464   (cmpfunc) 0,  /*tp_compare*/
1465   (reprfunc) sce_repr,          /*tp_repr*/
1466   0,            /*tp_as_number*/
1467   0,            /*tp_as_sequence*/
1468   0,            /*tp_as_mapping*/
1469   (hashfunc) 0,         /*tp_hash*/
1470   (ternaryfunc) 0,      /*tp_call*/
1471   (reprfunc) sce_str,           /*tp_str*/
1472
1473   /* Space for future expansion */
1474   0L,0L,0L,0L,
1475   Scetype__doc__ /* Documentation string */
1476 };
1477
1478 static char blend_Mesh__doc__[] =
1479 "Creates an (empty) instance of a Blender mesh.\n\
1480     E.g.: \"m = Blender.Mesh('Plane')\"\n\
1481     To create faces first add vertices with \n\
1482     \"i1 = m.addVertex(x, y, z, nx, ny, nz, r = -1.0, r = 0.0, b = 0.0)\"\n\
1483     then create faces with \n\
1484     \"index = m.addFace(i1, i2, i3, i4, isSmooth, matIndex)\".\
1485 "
1486 ;
1487
1488 static PyObject*
1489 blend_Mesh(PyObject* self, PyObject* args)
1490 {
1491   if (!PyArg_ParseTuple(args, ""))
1492     {
1493       return NULL;
1494     }
1495
1496   Py_INCREF(Py_None);
1497   return Py_None;
1498 }
1499
1500 static char blend_Object__doc__[] =
1501 "Creates an instance of a Blender object"
1502 ;
1503
1504 static PyObject*
1505 blend_Object(PyObject* self, PyObject* args)
1506 {
1507   char* name = NULL;
1508
1509   if (!PyArg_ParseTuple(args, "s", &name))
1510     {
1511       return NULL;
1512     }
1513
1514   return ((PyObject*) newobjobject(name));
1515 }
1516
1517 static char blend_Scene__doc__[] =
1518 "Creates an instance of a Blender scene"
1519 ;
1520
1521 static PyObject*
1522 blend_Scene(PyObject* self, PyObject* args)
1523 {
1524   char* name = NULL;
1525
1526   if (!PyArg_ParseTuple(args, "s", &name))
1527     {
1528       return NULL;
1529     }
1530
1531   return ((PyObject*) newsceobject(name));
1532 }
1533
1534 static char blend_addMesh__doc__[] =
1535 "Blender.addMesh(type, sceneName)\n\
1536     where type is one of [\"Plane\"]"
1537 ;
1538
1539 static PyObject*
1540 blend_addMesh(PyObject* self, PyObject* args)
1541 {
1542   char*      type      = NULL;
1543   char*      sceneName = NULL;
1544   PyObject*  tuple     = NULL;
1545   PyObject*  object    = NULL;
1546   PyObject*  mesh      = NULL;
1547   PyObject*  index     = NULL;
1548   PyObject*  indices   = NULL;
1549   objobject* obj       = NULL;
1550   mshobject* msh       = NULL;
1551
1552   if (!PyArg_ParseTuple(args, "ss", &type, &sceneName))
1553     {
1554       return NULL;
1555     }
1556
1557   if (strcmp(type, "Plane") == 0)
1558     {
1559       obj = newobjobject(type);
1560       msh = newmshobject(type);
1561       object = (PyObject*) obj;
1562       mesh   = (PyObject*) msh;
1563       indices = PyList_New(6);
1564       /* vertices */
1565       index = msh_addVertex((mshobject*) mesh,
1566                             Py_BuildValue("ffffff",
1567                                           1.0, 1.0, 0.0, 0.0, 0.0, 1.0));
1568       PyList_SetItem(indices, 0, index);
1569       index = msh_addVertex((mshobject*) mesh,
1570                             Py_BuildValue("ffffff",
1571                                           1.0, -1.0, 0.0, 0.0, 0.0, 1.0));
1572       PyList_SetItem(indices, 1, index);
1573       index = msh_addVertex((mshobject*) mesh,
1574                             Py_BuildValue("ffffff",
1575                                           -1.0, -1.0, 0.0, 0.0, 0.0, 1.0));
1576       PyList_SetItem(indices, 2, index);
1577       index = msh_addVertex((mshobject*) mesh,
1578                             Py_BuildValue("ffffff",
1579                                           -1.0, 1.0, 0.0, 0.0, 0.0, 1.0));
1580       PyList_SetItem(indices, 3, index);
1581       PyList_SetItem(indices, 4, PyInt_FromLong(0)); /* smooth flag */
1582       PyList_SetItem(indices, 5, PyInt_FromLong(0)); /* material index */
1583       /* faces */
1584       msh_addFace((mshobject*) mesh,
1585                   Py_BuildValue("OOOOOO",
1586                                 PyList_GetItem(indices, 0),
1587                                 PyList_GetItem(indices, 3),
1588                                 PyList_GetItem(indices, 2),
1589                                 PyList_GetItem(indices, 1),
1590                                 PyList_GetItem(indices, 4),
1591                                 PyList_GetItem(indices, 5)));
1592       /* connection */
1593       blend_connect(self, Py_BuildValue("OO",
1594                                         PyString_FromString(obj->name),
1595                                         PyString_FromString(msh->name)));
1596       blend_connect(self, Py_BuildValue("OO",
1597                                         PyString_FromString(sceneName),
1598                                         PyString_FromString(obj->name)));
1599       /* return value */
1600       tuple = PyTuple_New(2);
1601       PyTuple_SetItem(tuple, 0, object);
1602       PyTuple_SetItem(tuple, 1, mesh);
1603
1604       return tuple;
1605     }
1606
1607   Py_INCREF(Py_None);
1608   return Py_None;
1609 }
1610
1611 static char blend_connect__doc__[] =
1612 "connect(obj1, obj2)"
1613 ;
1614
1615 static PyObject*
1616 blend_connect(PyObject* self, PyObject* args)
1617 {
1618   PyObject* obj1 = NULL;
1619   PyObject* obj2 = NULL;
1620
1621   if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2))
1622     {
1623       return NULL;
1624     }
1625   if (obj1->ob_type == &Objtype)
1626     {
1627       if (obj2->ob_type == &Mshtype)
1628         {
1629           Py_INCREF(obj2);
1630           ((objobject*) obj1)->data = obj2;
1631           ((objobject*) obj1)->type = PyString_FromString("Mesh");
1632         }
1633     }
1634   else if (obj1->ob_type == &Scetype)
1635     {
1636       if (obj2->ob_type == &Objtype)
1637         {
1638           sce_addObject((sceobject*) obj1, Py_BuildValue("(O)", obj2));
1639         }
1640     }
1641
1642   Py_INCREF(Py_None);
1643   return Py_None;
1644 }
1645
1646 static char blend_getCamera__doc__[] =
1647 "getCamera()"
1648 ;
1649
1650 static PyObject*
1651 blend_getCamera(PyObject* self, PyObject* args)
1652 {
1653   char*      name     = NULL;
1654   ID*        list     = NULL;
1655   Camera*    cam      = NULL;
1656   camobject* camera   = NULL;
1657
1658   if (!PyArg_ParseTuple(args, "s", &name))
1659     {
1660       return NULL;
1661     }
1662   list = find_name_in_list((ID*) G.main->camera.first, name);
1663   if (list)
1664     {
1665       cam = (Camera*) list;
1666       camera = newcamobject(cam->id.name+2);
1667       camera->Lens  = PyFloat_FromDouble(cam->lens);
1668       camera->ClSta = PyFloat_FromDouble(cam->clipsta);
1669       camera->ClEnd = PyFloat_FromDouble(cam->clipend);
1670
1671       return (PyObject*) camera;
1672     }
1673   else
1674     {
1675       Py_INCREF(Py_None);
1676       return Py_None;
1677     }
1678 }
1679
1680 static char blend_getCurrentScene__doc__[] =
1681 "getCurrentScene()"
1682 ;
1683
1684 static PyObject*
1685 blend_getCurrentScene(PyObject* self, PyObject* args)
1686 {
1687   char*      name   = NULL;
1688   sceobject* scene  = NULL;
1689   Base*      base   = NULL;
1690   Object*    obj    = NULL;
1691
1692   if (!PyArg_ParseTuple(args, ""))
1693     {
1694       return NULL;
1695     }
1696
1697   /* create scene in Python */
1698   name = G.scene->id.name+2;
1699   scene = newsceobject(name);
1700
1701   /* add existing objects */
1702   base = G.scene->base.first;
1703   while (base)
1704     {
1705       obj = base->object;
1706       PyList_Append(scene->objects, PyString_FromString(obj->id.name+2));
1707       base = base->next;
1708     }
1709
1710   return (PyObject*) scene;
1711 }
1712
1713 static char blend_getDisplaySettings__doc__[] =
1714 "getDisplaySettings()"
1715 ;
1716
1717 static PyObject*
1718 blend_getDisplaySettings(PyObject* self, PyObject* args)
1719 {
1720   RenderData* rd            = NULL;
1721   dspobject*  displayObject = NULL;
1722
1723   if (!PyArg_ParseTuple(args, ""))
1724     {
1725       return NULL;
1726     }
1727   rd = &(G.scene->r);
1728   displayObject = newdspobject();
1729   displayObject->startFrame       = PyInt_FromLong(rd->sfra);
1730   displayObject->endFrame         = PyInt_FromLong(rd->efra);
1731   displayObject->currentFrame     = PyInt_FromLong(rd->cfra);
1732   displayObject->xResolution      = PyInt_FromLong(rd->xsch);
1733   displayObject->yResolution      = PyInt_FromLong(rd->ysch);
1734   displayObject->pixelAspectRatio = PyInt_FromLong(rd->yasp / 
1735                                                    (1.0 * rd->xasp));
1736   
1737   return (PyObject*) displayObject;
1738 }
1739
1740 static char blend_getLamp__doc__[] =
1741 "getLamp(name)"
1742 ;
1743
1744 static PyObject*
1745 blend_getLamp(PyObject* self, PyObject* args)
1746 {
1747   char*      name = NULL;
1748   ID*        list = NULL;
1749   Lamp*      lmp  = NULL;
1750   lmpobject* lamp = NULL;
1751
1752   if (!PyArg_ParseTuple(args, "s", &name))
1753     {
1754       return NULL;
1755     }
1756   list = find_name_in_list((ID*) G.main->lamp.first, name);
1757   if (list)
1758     {
1759       lmp = (Lamp*) list;
1760       lamp = newlmpobject(lmp->id.name+2);
1761       lamp->R      = PyFloat_FromDouble(lmp->r);
1762       lamp->G      = PyFloat_FromDouble(lmp->g);
1763       lamp->B      = PyFloat_FromDouble(lmp->b);
1764 /*        lamp->Dist   = PyFloat_FromDouble(lmp->dist); */
1765 /*        lamp->SpoSi  = PyFloat_FromDouble(lmp->spotsize); */
1766 /*        lamp->SpoBl  = PyFloat_FromDouble(lmp->spotblend); */
1767 /*        lamp->Quad1  = PyFloat_FromDouble(lmp->att1); */
1768 /*        lamp->Quad2  = PyFloat_FromDouble(lmp->att2); */
1769 /*        lamp->HaInt  = PyFloat_FromDouble(lmp->haint); */
1770
1771 /*        lamp->OfsX   = PyFloat_FromDouble(lmp->); */
1772 /*        lamp->OfsY   = PyFloat_FromDouble(lmp->); */
1773 /*        lamp->OfsZ   = PyFloat_FromDouble(lmp->); */
1774 /*        lamp->SizeX  = PyFloat_FromDouble(lmp->); */
1775 /*        lamp->SizeY  = PyFloat_FromDouble(lmp->); */
1776 /*        lamp->SizeZ  = PyFloat_FromDouble(lmp->); */
1777 /*        lamp->texR   = PyFloat_FromDouble(lmp->); */
1778 /*        lamp->texG   = PyFloat_FromDouble(lmp->); */
1779 /*        lamp->texB   = PyFloat_FromDouble(lmp->); */
1780 /*        lamp->DefVar = PyFloat_FromDouble(lmp->); */
1781 /*        lamp->Col    = PyFloat_FromDouble(lmp->); */
1782 /*        lamp->Nor    = PyFloat_FromDouble(lmp->); */
1783 /*        lamp->Var    = PyFloat_FromDouble(lmp->); */
1784
1785       return (PyObject*) lamp;
1786     }
1787   else
1788     {
1789       Py_INCREF(Py_None);
1790       return Py_None;
1791     }
1792 }
1793
1794 static char blend_getMaterial__doc__[] =
1795 "getMaterial(name)"
1796 ;
1797
1798 static PyObject*
1799 blend_getMaterial(PyObject* self, PyObject* args)
1800 {
1801   char*      name     = NULL;
1802   ID*        list     = NULL;
1803   Material*  mat      = NULL;
1804   matobject* material = NULL;
1805
1806   if (!PyArg_ParseTuple(args, "s", &name))
1807     {
1808       return NULL;
1809     }
1810   list = find_name_in_list((ID*) G.main->mat.first, name);
1811   if (list)
1812     {
1813       mat = (Material*) list;
1814       material = newmatobject(mat->id.name+2);
1815       material->R = PyFloat_FromDouble(mat->r);
1816       material->G = PyFloat_FromDouble(mat->g);
1817       material->B = PyFloat_FromDouble(mat->b);
1818
1819       return (PyObject*) material;
1820     }
1821   else
1822     {
1823       Py_INCREF(Py_None);
1824       return Py_None;
1825     }
1826 }
1827
1828 static char blend_getMesh__doc__[] =
1829 "getMesh(name)"
1830 ;
1831
1832 static PyObject*
1833 blend_getMesh(PyObject* self, PyObject* args)
1834 {
1835   int        i;
1836   float      r, g, b;
1837   char       dummy[]  = "";
1838   char*      name     = NULL;
1839   char*      filename = NULL;
1840   uint*      mcol     = NULL;
1841   ID*        list     = NULL;
1842   Mesh*      msh      = NULL;
1843   mshobject* mesh     = NULL;
1844   MFace*     mface    = NULL;
1845   TFace*     tface    = NULL;
1846
1847   if (!PyArg_ParseTuple(args, "s", &name))
1848     {
1849       return NULL;
1850     }
1851   list = find_name_in_list((ID*) G.main->mesh.first, name);
1852   if (list)
1853     {
1854       msh = (Mesh*) list;
1855       mesh = newmshobject(msh->id.name+2);
1856       /* is there color information? */
1857       if (msh->mcol)
1858         {
1859           mcol = mcol_to_vcol(msh);
1860         }
1861       /* add vertices */
1862       for (i = 0; i < msh->totvert; i++)
1863         {
1864           if (msh->mcol && mcol)
1865             {
1866               mcol_to_rgb(*mcol, &r, &g, &b);
1867               msh_addVertex(mesh,
1868                             Py_BuildValue("fffffffff",
1869                                           msh->mvert[i].co[0],
1870                                           msh->mvert[i].co[1],
1871                                           msh->mvert[i].co[2],
1872                                           msh->mvert[i].no[0] / 32767.0,
1873                                           msh->mvert[i].no[1] / 32767.0,
1874                                           msh->mvert[i].no[2] / 32767.0,
1875                                           r, g, b));
1876               mcol++;
1877             }
1878           else
1879             {
1880               msh_addVertex(mesh,
1881                             Py_BuildValue("ffffff",
1882                                           msh->mvert[i].co[0],
1883                                           msh->mvert[i].co[1],
1884                                           msh->mvert[i].co[2],
1885                                           msh->mvert[i].no[0] / 32767.0,
1886                                           msh->mvert[i].no[1] / 32767.0,
1887                                           msh->mvert[i].no[2] / 32767.0));
1888             }
1889         }
1890       /* add faces */
1891       for (i = 0; i < msh->totface; i++)
1892         {
1893           mface = ((MFace*) msh->mface)+i;
1894           msh_addFace(mesh,
1895                       Py_BuildValue("iiiiii",
1896                                     mface->v1, mface->v2,
1897                                     mface->v3, mface->v4,
1898                                     mface->flag, mface->mat_nr));
1899         }
1900       /* add texture coordinates */
1901       if (msh->tface)
1902         {
1903           tface = (TFace*) msh->tface;
1904           if (tface->tpage)
1905             {
1906               filename = ((Image*) tface->tpage)->name;
1907             }
1908           else
1909             {
1910               filename = dummy;
1911             }
1912           msh_addTexture(mesh,
1913                          Py_BuildValue("(O)", PyString_FromString(filename)));
1914           for (i = 0; i < msh->totface; i++)
1915             {
1916               tface = (TFace*) msh->tface+i;
1917               msh_addTexCoords(mesh,
1918                                Py_BuildValue("ff",
1919                                              tface->uv[0][0], 
1920                                              tface->uv[0][1]));
1921               msh_addTexCoords(mesh,
1922                                Py_BuildValue("ff",
1923                                              tface->uv[1][0], 
1924                                              tface->uv[1][1]));
1925               msh_addTexCoords(mesh,
1926                                Py_BuildValue("ff",
1927                                              tface->uv[2][0], 
1928                                              tface->uv[2][1]));
1929               msh_addTexCoords(mesh,
1930                                Py_BuildValue("ff",
1931                                              tface->uv[3][0], 
1932                                              tface->uv[3][1]));
1933             }
1934         }
1935
1936       return (PyObject*) mesh;
1937     }
1938   else
1939     {
1940       Py_INCREF(Py_None);
1941       return Py_None;
1942     }
1943 }
1944
1945 static char blend_getObject__doc__[] =
1946 "getObject(name)"
1947 ;
1948
1949 static PyObject*
1950 blend_getObject(PyObject* self, PyObject* args)
1951 {
1952   int        i;
1953   float      inverse[4][4];
1954   char*      name   = NULL;
1955   ID*        list   = NULL;
1956   Object*    obj    = NULL;
1957   Mesh*      msh    = NULL;
1958   objobject* object = NULL;
1959   PyObject*  row1   = NULL;
1960   PyObject*  row2   = NULL;
1961   PyObject*  row3   = NULL;
1962   PyObject*  row4   = NULL;
1963
1964   if (!PyArg_ParseTuple(args, "s", &name))
1965     {
1966       return NULL;
1967     }
1968   list = find_name_in_list((ID*) G.main->object.first, name);
1969   if (list)
1970     {
1971       obj = (Object*) list;
1972       object = newobjobject(obj->id.name+2);
1973       Py_DECREF(object->matrix);
1974       object->matrix = PyList_New(4);
1975       row1 = PyList_New(4);
1976       row2 = PyList_New(4);
1977       row3 = PyList_New(4);
1978       row4 = PyList_New(4);
1979       PyList_SetItem(row1, 0, PyFloat_FromDouble(obj->obmat[0][0]));
1980       PyList_SetItem(row1, 1, PyFloat_FromDouble(obj->obmat[0][1]));
1981       PyList_SetItem(row1, 2, PyFloat_FromDouble(obj->obmat[0][2]));
1982       PyList_SetItem(row1, 3, PyFloat_FromDouble(obj->obmat[0][3]));
1983       PyList_SetItem(row2, 0, PyFloat_FromDouble(obj->obmat[1][0]));
1984       PyList_SetItem(row2, 1, PyFloat_FromDouble(obj->obmat[1][1]));
1985       PyList_SetItem(row2, 2, PyFloat_FromDouble(obj->obmat[1][2]));
1986       PyList_SetItem(row2, 3, PyFloat_FromDouble(obj->obmat[1][3]));
1987       PyList_SetItem(row3, 0, PyFloat_FromDouble(obj->obmat[2][0]));
1988       PyList_SetItem(row3, 1, PyFloat_FromDouble(obj->obmat[2][1]));
1989       PyList_SetItem(row3, 2, PyFloat_FromDouble(obj->obmat[2][2]));
1990       PyList_SetItem(row3, 3, PyFloat_FromDouble(obj->obmat[2][3]));
1991       PyList_SetItem(row4, 0, PyFloat_FromDouble(obj->obmat[3][0]));
1992       PyList_SetItem(row4, 1, PyFloat_FromDouble(obj->obmat[3][1]));
1993       PyList_SetItem(row4, 2, PyFloat_FromDouble(obj->obmat[3][2]));
1994       PyList_SetItem(row4, 3, PyFloat_FromDouble(obj->obmat[3][3]));
1995       PyList_SetItem(object->matrix, 0, row1);
1996       PyList_SetItem(object->matrix, 1, row2);
1997       PyList_SetItem(object->matrix, 2, row3);
1998       PyList_SetItem(object->matrix, 3, row4);
1999       /* inverse matrix */
2000       Mat4Invert(inverse, obj->obmat);
2001       Py_DECREF(object->inverseMatrix);
2002       object->inverseMatrix = PyList_New(4);
2003       row1 = PyList_New(4);
2004       row2 = PyList_New(4);
2005       row3 = PyList_New(4);
2006       row4 = PyList_New(4);
2007       PyList_SetItem(row1, 0, PyFloat_FromDouble(inverse[0][0]));
2008       PyList_SetItem(row1, 1, PyFloat_FromDouble(inverse[0][1]));
2009       PyList_SetItem(row1, 2, PyFloat_FromDouble(inverse[0][2]));
2010       PyList_SetItem(row1, 3, PyFloat_FromDouble(inverse[0][3]));
2011       PyList_SetItem(row2, 0, PyFloat_FromDouble(inverse[1][0]));
2012       PyList_SetItem(row2, 1, PyFloat_FromDouble(inverse[1][1]));
2013       PyList_SetItem(row2, 2, PyFloat_FromDouble(inverse[1][2]));
2014       PyList_SetItem(row2, 3, PyFloat_FromDouble(inverse[1][3]));
2015       PyList_SetItem(row3, 0, PyFloat_FromDouble(inverse[2][0]));
2016       PyList_SetItem(row3, 1, PyFloat_FromDouble(inverse[2][1]));
2017       PyList_SetItem(row3, 2, PyFloat_FromDouble(inverse[2][2]));
2018       PyList_SetItem(row3, 3, PyFloat_FromDouble(inverse[2][3]));
2019       PyList_SetItem(row4, 0, PyFloat_FromDouble(inverse[3][0]));
2020       PyList_SetItem(row4, 1, PyFloat_FromDouble(inverse[3][1]));
2021       PyList_SetItem(row4, 2, PyFloat_FromDouble(inverse[3][2]));
2022       PyList_SetItem(row4, 3, PyFloat_FromDouble(inverse[3][3]));
2023       PyList_SetItem(object->inverseMatrix, 0, row1);
2024       PyList_SetItem(object->inverseMatrix, 1, row2);
2025       PyList_SetItem(object->inverseMatrix, 2, row3);
2026       PyList_SetItem(object->inverseMatrix, 3, row4);
2027       Py_DECREF(object->materials);
2028       object->materials = PyList_New(obj->totcol);
2029       for (i = 0; i < obj->totcol; i++)
2030         {
2031           if (obj->mat[i])
2032             {
2033               PyList_SetItem(object->materials, i,
2034                              PyString_FromString(obj->mat[i]->id.name+2));
2035             }
2036           else
2037             {
2038               Py_INCREF(Py_None);
2039               PyList_SetItem(object->materials, i, Py_None);
2040             }
2041         }      /* check type */
2042       switch (obj->type)
2043         {
2044         case OB_EMPTY:
2045           printf("Empty\n");
2046           break;
2047         case OB_MESH:
2048           object->data = PyString_FromString(((Mesh*) obj->data)->id.name+2);
2049           object->type = PyString_FromString("Mesh");
2050           msh = (Mesh*) obj->data;
2051           for (i = 0; i < msh->totcol; i++)
2052             {
2053               if (msh->mat[i])
2054                 {
2055                   PyList_SetItem(object->materials, i,
2056                                  PyString_FromString(msh->mat[i]->id.name+2));
2057                 }
2058             }
2059           break;
2060         case OB_CURVE:
2061           printf("Curve\n");
2062           break;
2063         case OB_SURF:
2064           printf("Surface\n");
2065           break;
2066         case OB_FONT:
2067           printf("Font\n");
2068           break;
2069         case OB_MBALL:
2070           printf("Metaball\n");
2071           break;
2072         case OB_LAMP:
2073           object->data = PyString_FromString(((Lamp*) obj->data)->id.name+2);
2074           object->type = PyString_FromString("Lamp");
2075           break;
2076         case OB_CAMERA:
2077           object->data = PyString_FromString(((Camera*) obj->data)->id.name+2);
2078           object->type = PyString_FromString("Camera");
2079           break;
2080         case OB_IKA:
2081           printf("Ika\n");
2082           break;
2083         case OB_WAVE:
2084           printf("Wave\n");
2085           break;
2086         case OB_LATTICE:
2087           printf("Lattice\n");
2088           break;
2089         default:
2090           printf("ERROR: py_main.c:blend_getObject(...)\n");
2091           printf("       unknown type ...\n");
2092           break;
2093         }
2094
2095       return (PyObject*) object;
2096     }
2097   else
2098     {
2099       Py_INCREF(Py_None);
2100       return Py_None;
2101     }
2102 }
2103
2104 static char blend_isCamera__doc__[] =
2105 "isCamera(name)"
2106 ;
2107
2108 static PyObject*
2109 blend_isCamera(PyObject* self, PyObject* args)
2110 {
2111   char*      name   = NULL;
2112   ID*        list   = NULL;
2113   Object*    obj    = NULL;
2114
2115   if (!PyArg_ParseTuple(args, "s", &name))
2116     {
2117       return NULL;
2118     }
2119   list = find_name_in_list((ID*) G.main->object.first, name);
2120   if (list)
2121     {
2122       obj = (Object*) list;
2123       if (obj->type == OB_CAMERA)
2124         {
2125           return PyInt_FromLong(1);
2126         }
2127       else
2128         {
2129           return PyInt_FromLong(0);
2130         }
2131     }
2132   else
2133     {
2134       return NULL;
2135     }
2136 }
2137
2138 static char blend_isLamp__doc__[] =
2139 "isLamp(name)"
2140 ;
2141
2142 static PyObject*
2143 blend_isLamp(PyObject* self, PyObject* args)
2144 {
2145   char*      name   = NULL;
2146   ID*        list   = NULL;
2147   Object*    obj    = NULL;
2148
2149   if (!PyArg_ParseTuple(args, "s", &name))
2150     {
2151       return NULL;
2152     }
2153   list = find_name_in_list((ID*) G.main->object.first, name);
2154   if (list)
2155     {
2156       obj = (Object*) list;
2157       if (obj->type == OB_LAMP)
2158         {
2159           return PyInt_FromLong(1);
2160         }
2161       else
2162         {
2163           return PyInt_FromLong(0);
2164         }
2165     }
2166   else
2167     {
2168       return NULL;
2169     }
2170 }
2171
2172 static char blend_isMesh__doc__[] =
2173 "isMesh(name)"
2174 ;
2175
2176 static PyObject*
2177 blend_isMesh(PyObject* self, PyObject* args)
2178 {
2179   char*      name   = NULL;
2180   ID*        list   = NULL;
2181   Object*    obj    = NULL;
2182
2183   if (!PyArg_ParseTuple(args, "s", &name))
2184     {
2185       return NULL;
2186     }
2187   list = find_name_in_list((ID*) G.main->object.first, name);
2188   if (list)
2189     {
2190       obj = (Object*) list;
2191       if (obj->type == OB_MESH)
2192         {
2193           return PyInt_FromLong(1);
2194         }
2195       else
2196         {
2197           return PyInt_FromLong(0);
2198         }
2199     }
2200   else
2201     {
2202       return NULL;
2203     }
2204 }
2205
2206 static char blend_setCurrentFrame__doc__[] =
2207 "setCurrentFrame(frame)"
2208 ;
2209
2210 static PyObject*
2211 blend_setCurrentFrame(PyObject* self, PyObject* args)
2212 {
2213   int frame = -1;
2214
2215   if (!PyArg_ParseTuple(args, "i", &frame))
2216     {
2217       return NULL;
2218     }
2219   CFRA = frame;
2220   drawview3d();
2221
2222   Py_INCREF(Py_None);
2223   return Py_None;
2224 }
2225
2226 /* List of methods defined in the module */
2227
2228 static struct PyMethodDef blend_methods[] = {
2229   {"Mesh",               (PyCFunction) blend_Mesh,
2230    METH_VARARGS, blend_Mesh__doc__},
2231   {"Object",             (PyCFunction) blend_Object,
2232    METH_VARARGS, blend_Object__doc__},
2233   {"Scene",              (PyCFunction) blend_Scene,
2234    METH_VARARGS, blend_Scene__doc__},
2235   {"addMesh",            (PyCFunction) blend_addMesh,
2236    METH_VARARGS, blend_addMesh__doc__},
2237   {"connect",            (PyCFunction) blend_connect,
2238    METH_VARARGS, blend_connect__doc__},
2239   {"getCamera",          (PyCFunction) blend_getCamera,
2240    METH_VARARGS, blend_getCamera__doc__},
2241   {"getCurrentScene",    (PyCFunction) blend_getCurrentScene,
2242    METH_VARARGS, blend_getCurrentScene__doc__},
2243   {"getDisplaySettings", (PyCFunction) blend_getDisplaySettings,
2244    METH_VARARGS, blend_getDisplaySettings__doc__},
2245   {"getLamp",            (PyCFunction) blend_getLamp,
2246    METH_VARARGS, blend_getLamp__doc__},
2247   {"getMaterial",        (PyCFunction) blend_getMaterial,
2248    METH_VARARGS, blend_getMaterial__doc__},
2249   {"getMesh",            (PyCFunction) blend_getMesh,
2250    METH_VARARGS, blend_getMesh__doc__},
2251   {"getObject",          (PyCFunction) blend_getObject,
2252    METH_VARARGS, blend_getObject__doc__},
2253   {"isCamera",           (PyCFunction) blend_isCamera,
2254    METH_VARARGS, blend_isCamera__doc__},
2255   {"isLamp",             (PyCFunction) blend_isLamp,
2256    METH_VARARGS, blend_isLamp__doc__},
2257   {"isMesh",             (PyCFunction) blend_isMesh,
2258    METH_VARARGS, blend_isMesh__doc__},
2259   {"setCurrentFrame",    (PyCFunction) blend_setCurrentFrame,
2260    METH_VARARGS, blend_setCurrentFrame__doc__},
2261   { NULL,                (PyCFunction) NULL, 0, NULL }
2262 };
2263
2264 static char Blender_module_documentation[] =
2265 "This is the Python API for Blender"
2266 ;
2267
2268 void
2269 initBlender()
2270 {
2271   PyObject* m;
2272   PyObject* d;
2273
2274   /* Create the module and add the functions */
2275   m = Py_InitModule4("Blender", blend_methods,
2276                      Blender_module_documentation,
2277                      (PyObject*)NULL,PYTHON_API_VERSION);
2278
2279   /* Add some symbolic constants to the module */
2280   d = PyModule_GetDict(m);
2281   ErrorObject = PyString_FromString("Blender.error");
2282   PyDict_SetItemString(d, "error", ErrorObject);
2283
2284   /* XXXX Add constants here */
2285
2286   /* Check for errors */
2287   if (PyErr_Occurred())
2288     {
2289       Py_FatalError("can't initialize module Blender");
2290     }
2291 }
2292 /*  Jan Walter's stuff */