| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /* 
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL/BL DUAL 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. The Blender | 
					
						
							|  |  |  |  * Foundation also sells licenses for use in proprietary software under | 
					
						
							|  |  |  |  * the Blender License.  See http://www.blender.org/BL/ for information
 | 
					
						
							|  |  |  |  * about this. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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, | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA	02111-1307, USA. | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is a new part of Blender. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-07-13 16:28:17 +00:00
										 |  |  |  * Contributor(s): Willian P. Germano, Jacques Guignot | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <BKE_main.h>
 | 
					
						
							|  |  |  | #include <BKE_global.h>
 | 
					
						
							|  |  |  | #include <BKE_scene.h>
 | 
					
						
							|  |  |  | #include <BKE_library.h>
 | 
					
						
							|  |  |  | #include <BLI_blenlib.h>
 | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | #include <BSE_headerbuttons.h> /* for copy_scene */
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | #include <BIF_drawscene.h>		 /* for set_scene */
 | 
					
						
							|  |  |  | #include <BIF_space.h>				 /* for copy_view3d_lock() */
 | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | #include <MEM_guardedalloc.h>  /* for MEM_callocN */
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | #include <mydevice.h>					 /* for #define REDRAW */
 | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "Object.h"
 | 
					
						
							| 
									
										
										
										
											2003-06-24 07:21:17 +00:00
										 |  |  | #include "bpy_types.h"
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "Scene.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | static Base *EXPP_Scene_getObjectBase (Scene *scene, Object *object); | 
					
						
							|  |  |  | PyObject *M_Object_Get (PyObject *self, PyObject *args); /* from Object.c */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Python BPy_Scene defaults:																								 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | #define EXPP_SCENE_FRAME_MAX 18000
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | #define EXPP_SCENE_RENDER_WINRESOLUTION_MIN 4
 | 
					
						
							|  |  |  | #define EXPP_SCENE_RENDER_WINRESOLUTION_MAX 10000
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Python API function prototypes for the Scene module.											 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *M_Scene_New (PyObject *self, PyObject *args, | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 															 PyObject *keywords); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | static PyObject *M_Scene_Get (PyObject *self, PyObject *args); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | static PyObject *M_Scene_GetCurrent (PyObject *self); | 
					
						
							|  |  |  | static PyObject *M_Scene_Unlink (PyObject *self, PyObject *arg); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* The following string definitions are used for documentation strings.			 */ | 
					
						
							|  |  |  | /* In Python these will be written to the console when doing a							 */ | 
					
						
							|  |  |  | /* Blender.Scene.__doc__																										 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | static char M_Scene_doc[] = | 
					
						
							|  |  |  | "The Blender.Scene submodule"; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | static char M_Scene_New_doc[] = | 
					
						
							|  |  |  | "(name = 'Scene') - Create a new Scene called 'name' in Blender."; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | static char M_Scene_Get_doc[] = | 
					
						
							|  |  |  | "(name = None) - Return the scene called 'name'.\n\
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 					 If 'name' is None, return a list with all Scenes."; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | static char M_Scene_GetCurrent_doc[] = | 
					
						
							|  |  |  | "() - Return the currently active Scene in Blender."; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | static char M_Scene_Unlink_doc[] = | 
					
						
							|  |  |  | "(scene) - Unlink (delete) scene 'Scene' from Blender.\n\
 | 
					
						
							|  |  |  | (scene) is of type Blender scene."; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Python method structure definition for Blender.Scene module:							 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | struct PyMethodDef M_Scene_methods[] = { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	{"New",(PyCFunction)M_Scene_New, METH_VARARGS|METH_KEYWORDS, | 
					
						
							|  |  |  | 					M_Scene_New_doc}, | 
					
						
							|  |  |  | 	{"Get",					M_Scene_Get,				 METH_VARARGS, M_Scene_Get_doc}, | 
					
						
							|  |  |  | 	{"get",					M_Scene_Get,				 METH_VARARGS, M_Scene_Get_doc}, | 
					
						
							|  |  |  | 	{"GetCurrent",(PyCFunction)M_Scene_GetCurrent, | 
					
						
							|  |  |  | 														 METH_NOARGS,  M_Scene_GetCurrent_doc}, | 
					
						
							|  |  |  | 	{"getCurrent",(PyCFunction)M_Scene_GetCurrent, | 
					
						
							|  |  |  | 														 METH_NOARGS,  M_Scene_GetCurrent_doc}, | 
					
						
							|  |  |  | 	{"Unlink",			M_Scene_Unlink,			 METH_VARARGS, M_Scene_Unlink_doc}, | 
					
						
							|  |  |  | 	{"unlink",			M_Scene_Unlink,			 METH_VARARGS, M_Scene_Unlink_doc}, | 
					
						
							|  |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Python BPy_Scene methods declarations:																		 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *Scene_getName(BPy_Scene *self); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | static PyObject *Scene_setName(BPy_Scene *self, PyObject *arg); | 
					
						
							| 
									
										
										
										
											2003-07-10 22:03:27 +00:00
										 |  |  | static PyObject *Scene_getWinSize(BPy_Scene *self); | 
					
						
							|  |  |  | static PyObject *Scene_setWinSize(BPy_Scene *self, PyObject *arg); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | static PyObject *Scene_copy(BPy_Scene *self, PyObject *arg); | 
					
						
							|  |  |  | static PyObject *Scene_startFrame(BPy_Scene *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *Scene_endFrame(BPy_Scene *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *Scene_currentFrame(BPy_Scene *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *Scene_frameSettings (BPy_Scene *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *Scene_makeCurrent(BPy_Scene *self); | 
					
						
							| 
									
										
										
										
											2003-08-06 19:25:06 +00:00
										 |  |  | static PyObject *Scene_update(BPy_Scene *self, PyObject *args); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | static PyObject *Scene_link(BPy_Scene *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *Scene_unlink(BPy_Scene *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *Scene_getRenderdir(BPy_Scene *self); | 
					
						
							|  |  |  | static PyObject *Scene_getBackbufdir(BPy_Scene *self); | 
					
						
							|  |  |  | static PyObject *Scene_getChildren(BPy_Scene *self); | 
					
						
							|  |  |  | static PyObject *Scene_getCurrentCamera(BPy_Scene *self); | 
					
						
							|  |  |  | static PyObject *Scene_setCurrentCamera(BPy_Scene *self, PyObject *args); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Python BPy_Scene methods table:																					 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyMethodDef BPy_Scene_methods[] = { | 
					
						
							|  |  |  |  /* name, method, flags, doc */ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	{"getName", (PyCFunction)Scene_getName, METH_NOARGS, | 
					
						
							|  |  |  | 			"() - Return Scene name"}, | 
					
						
							|  |  |  | 	{"setName", (PyCFunction)Scene_setName, METH_VARARGS, | 
					
						
							|  |  |  | 					"(str) - Change Scene name"}, | 
					
						
							|  |  |  | 	{"getWinSize", (PyCFunction)Scene_getWinSize, METH_NOARGS, | 
					
						
							|  |  |  | 			"() - Return Render window [x,y] dimensions"}, | 
					
						
							|  |  |  | 	{"setWinSize", (PyCFunction)Scene_setWinSize, METH_VARARGS, | 
					
						
							|  |  |  | 					"(str) - Change Render window [x,y] dimensions"}, | 
					
						
							|  |  |  | 	{"copy",		(PyCFunction)Scene_copy, METH_VARARGS, | 
					
						
							|  |  |  | 					"(duplicate_objects = 1) - Return a copy of this scene\n" | 
					
						
							|  |  |  | 	"The optional argument duplicate_objects defines how the scene\n" | 
					
						
							|  |  |  | 	"children are duplicated:\n\t0: Link Objects\n\t1: Link Object Data" | 
					
						
							|  |  |  | 	"\n\t2: Full copy\n"}, | 
					
						
							|  |  |  | 	{"startFrame", (PyCFunction)Scene_startFrame, METH_VARARGS, | 
					
						
							|  |  |  | 					"(frame) - If frame is given, the start frame is set and" | 
					
						
							|  |  |  | 									"\nreturned in any case"}, | 
					
						
							|  |  |  | 	{"endFrame", (PyCFunction)Scene_endFrame, METH_VARARGS, | 
					
						
							|  |  |  | 					"(frame) - If frame is given, the end frame is set and" | 
					
						
							|  |  |  | 									"\nreturned in any case"}, | 
					
						
							|  |  |  | 	{"currentFrame", (PyCFunction)Scene_currentFrame, METH_VARARGS, | 
					
						
							|  |  |  | 					"(frame) - If frame is given, the current frame is set and" | 
					
						
							|  |  |  | 									"\nreturned in any case"}, | 
					
						
							|  |  |  | 	{"frameSettings", (PyCFunction)Scene_frameSettings, METH_VARARGS, | 
					
						
							|  |  |  | 					"(start, end, current) - Sets or retrieves the Scene's frame" | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 					" settings.\nIf the frame arguments are specified, they are set. " | 
					
						
							|  |  |  | 					"A tuple (start, end, current) is returned in any case."}, | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	{"makeCurrent", (PyCFunction)Scene_makeCurrent, METH_NOARGS, | 
					
						
							|  |  |  | 					"() - Make self the current scene"}, | 
					
						
							|  |  |  | 	{"update", (PyCFunction)Scene_update, METH_VARARGS, | 
					
						
							|  |  |  | 					"(full = 0) - Update scene self.\n" | 
					
						
							| 
									
										
										
										
											2003-08-06 19:25:06 +00:00
										 |  |  | 					"full = 0: sort the base list of objects." | 
					
						
							|  |  |  | 					"full = 1: full update -- also regroups, does ipos, ikas, keys"}, | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	{"link", (PyCFunction)Scene_link, METH_VARARGS, | 
					
						
							|  |  |  | 					"(obj) - Link Object obj to this scene"}, | 
					
						
							|  |  |  | 	{"unlink", (PyCFunction)Scene_unlink, METH_VARARGS, | 
					
						
							|  |  |  | 					"(obj) - Unlink Object obj from this scene"}, | 
					
						
							|  |  |  | 	{"getRenderdir", (PyCFunction)Scene_getRenderdir, METH_NOARGS, | 
					
						
							|  |  |  | 					"() - Return directory where rendered images are saved to"}, | 
					
						
							|  |  |  | 	{"getBackbufdir", (PyCFunction)Scene_getBackbufdir, METH_NOARGS, | 
					
						
							|  |  |  | 					"() - Return location of the backbuffer image"}, | 
					
						
							|  |  |  | 	{"getChildren", (PyCFunction)Scene_getChildren, METH_NOARGS, | 
					
						
							|  |  |  | 					"() - Return list of all objects linked to scene self"}, | 
					
						
							|  |  |  | 	{"getCurrentCamera", (PyCFunction)Scene_getCurrentCamera, METH_NOARGS, | 
					
						
							|  |  |  | 					"() - Return current active Camera"}, | 
					
						
							|  |  |  | 	{"setCurrentCamera", (PyCFunction)Scene_setCurrentCamera, METH_VARARGS, | 
					
						
							|  |  |  | 					"() - Set the currently active Camera"}, | 
					
						
							|  |  |  | 	{0} | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Python Scene_Type callback function prototypes:													 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static void Scene_dealloc (BPy_Scene *self); | 
					
						
							|  |  |  | static int Scene_setAttr (BPy_Scene *self, char *name, PyObject *v); | 
					
						
							|  |  |  | static int Scene_compare (BPy_Scene *a, BPy_Scene *b); | 
					
						
							|  |  |  | static PyObject *Scene_getAttr (BPy_Scene *self, char *name); | 
					
						
							|  |  |  | static PyObject *Scene_repr (BPy_Scene *self); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Python Scene_Type structure definition:																	 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyTypeObject Scene_Type = | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyObject_HEAD_INIT(NULL) | 
					
						
							|  |  |  | 	0,																			/* ob_size */ | 
					
						
							|  |  |  | 	"Scene",																/* tp_name */ | 
					
						
							|  |  |  | 	sizeof (BPy_Scene),											/* tp_basicsize */ | 
					
						
							|  |  |  | 	0,																			/* tp_itemsize */ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	(destructor)Scene_dealloc,							/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,																			/* tp_print */ | 
					
						
							|  |  |  | 	(getattrfunc)Scene_getAttr,							/* tp_getattr */ | 
					
						
							|  |  |  | 	(setattrfunc)Scene_setAttr,							/* tp_setattr */ | 
					
						
							|  |  |  | 	(cmpfunc)Scene_compare,									/* tp_compare */ | 
					
						
							|  |  |  | 	(reprfunc)Scene_repr,										/* tp_repr */ | 
					
						
							|  |  |  | 	0,																			/* tp_as_number */ | 
					
						
							|  |  |  | 	0,																			/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,																			/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,																			/* tp_as_hash */ | 
					
						
							|  |  |  | 	0,0,0,0,0,0, | 
					
						
							|  |  |  | 	0,																			/* tp_doc */  | 
					
						
							|  |  |  | 	0,0,0,0,0,0, | 
					
						
							|  |  |  | 	BPy_Scene_methods,											/* tp_methods */ | 
					
						
							|  |  |  | 	0,																			/* tp_members */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *M_Scene_New(PyObject *self, PyObject *args, PyObject *kword) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	char		 *name = "Scene"; | 
					
						
							|  |  |  | 	char		 *kw[] = {"name", NULL}; | 
					
						
							|  |  |  | 	PyObject *pyscene; /* for the Scene object wrapper in Python */ | 
					
						
							|  |  |  | 	Scene		 *blscene; /* for the actual Scene we create in Blender */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTupleAndKeywords(args, kword, "|s", kw, &name)) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_AttributeError, | 
					
						
							|  |  |  | 						"expected a string or an empty argument list")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	blscene = add_scene(name); /* first create the Scene in Blender */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-11 10:13:04 +00:00
										 |  |  | 	if (blscene){  | 
					
						
							| 
									
										
										
										
											2003-11-12 07:46:07 +00:00
										 |  |  | 	  /* normally, for most objects, we set the user count to zero here.
 | 
					
						
							|  |  |  | 	   * Scene is different than most objs since it is the container | 
					
						
							|  |  |  | 	   * for all the others. Since add_scene() has already set  | 
					
						
							|  |  |  | 	   * the user count to one, we leave it alone. | 
					
						
							|  |  |  | 	   */  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-11 10:13:04 +00:00
										 |  |  | 	  /* now create the wrapper obj in Python */ | 
					
						
							|  |  |  | 	  pyscene = Scene_CreatePyObject (blscene); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 														"couldn't create Scene obj in Blender")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (pyscene == NULL) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  | 														"couldn't create Scene PyObject")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return pyscene; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *M_Scene_Get(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	char	*name = NULL; | 
					
						
							|  |  |  | 	Scene *scene_iter; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "|s", &name)) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected string argument (or nothing)")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	scene_iter = G.main->scene.first; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (name) { /* (name) - Search scene by name */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		PyObject *wanted_scene = NULL; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		while ((scene_iter) && (wanted_scene == NULL)) { | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 			if (strcmp (name, scene_iter->id.name+2) == 0) | 
					
						
							|  |  |  | 				wanted_scene = Scene_CreatePyObject (scene_iter); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 			scene_iter = scene_iter->id.next; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		if (wanted_scene == NULL) { /* Requested scene doesn't exist */ | 
					
						
							|  |  |  | 			char error_msg[64]; | 
					
						
							|  |  |  | 			PyOS_snprintf(error_msg, sizeof(error_msg), | 
					
						
							|  |  |  | 											"Scene \"%s\" not found", name); | 
					
						
							|  |  |  | 			return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		return wanted_scene; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	else { /* () - return a list with wrappers for all scenes in Blender */ | 
					
						
							|  |  |  | 		int index = 0; | 
					
						
							|  |  |  | 		PyObject *sce_pylist, *pyobj; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		sce_pylist = PyList_New (BLI_countlist (&(G.main->scene))); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		if (sce_pylist == NULL) | 
					
						
							|  |  |  | 			return (PythonReturnErrorObject (PyExc_MemoryError, | 
					
						
							|  |  |  | 							"couldn't create PyList")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		while (scene_iter) { | 
					
						
							|  |  |  | 			pyobj = Scene_CreatePyObject (scene_iter); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 			if (!pyobj) | 
					
						
							|  |  |  | 				return (PythonReturnErrorObject (PyExc_MemoryError, | 
					
						
							|  |  |  | 									"couldn't create PyString")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 			PyList_SET_ITEM (sce_pylist, index, pyobj); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 			scene_iter = scene_iter->id.next; | 
					
						
							|  |  |  | 			index++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		return sce_pylist; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | static PyObject *M_Scene_GetCurrent (PyObject *self) | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return Scene_CreatePyObject ((Scene *)G.scene); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | static PyObject *M_Scene_Unlink (PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | {  | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyObject *pyobj; | 
					
						
							|  |  |  | 	Scene		 *scene; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple (args, "O!", &Scene_Type, &pyobj)) | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 								"expected Scene PyType object"); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	scene = ((BPy_Scene *)pyobj)->scene; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (scene == G.scene) | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError (PyExc_SystemError, | 
					
						
							|  |  |  | 								"current Scene cannot be removed!"); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	free_libblock(&G.main->scene, scene); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-24 07:21:17 +00:00
										 |  |  | PyObject *Scene_Init (void) | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyObject	*submodule; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Scene_Type.ob_type = &PyType_Type; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	submodule = Py_InitModule3("Blender.Scene", | 
					
						
							|  |  |  | 									M_Scene_methods, M_Scene_doc); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return submodule; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject *Scene_CreatePyObject (Scene *scene) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	BPy_Scene *pyscene; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	pyscene = (BPy_Scene *)PyObject_NEW (BPy_Scene, &Scene_Type); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!pyscene) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  | 						"couldn't create BPy_Scene object"); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	pyscene->scene = scene; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return (PyObject *)pyscene; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Scene_CheckPyObject (PyObject *pyobj) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return (pyobj->ob_type == &Scene_Type); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Scene *Scene_FromPyObject (PyObject *pyobj) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return ((BPy_Scene *)pyobj)->scene; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-27 15:56:32 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Description: Returns the object with the name specified by the argument	 */ | 
					
						
							|  |  |  | /*							name. Note that the calling function has to remove the first */ | 
					
						
							|  |  |  | /*							two characters of the object name. These two characters			 */ | 
					
						
							|  |  |  | /*							specify the type of the object (OB, ME, WO, ...)						 */ | 
					
						
							|  |  |  | /*							The function will return NULL when no object with the given  */ | 
					
						
							|  |  |  | /*							name is found.																							 */ | 
					
						
							| 
									
										
										
										
											2003-07-27 15:56:32 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | Scene * GetSceneByName (char * name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Scene	* scene_iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	scene_iter = G.main->scene.first; | 
					
						
							|  |  |  | 	while (scene_iter) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (StringEqual (name, GetIdName (&(scene_iter->id)))) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return (scene_iter); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		scene_iter = scene_iter->id.next; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* There is no object with the given name */ | 
					
						
							|  |  |  | 	return (NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* Python BPy_Scene methods:																								 */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *Scene_getName(BPy_Scene *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyObject *attr = PyString_FromString(self->scene->id.name+2); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (attr) return attr; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return (EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 																	 "couldn't get Scene.name attribute")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_setName(BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	char *name; | 
					
						
							|  |  |  | 	char buf[21]; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s", &name)) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 																		 "expected string argument")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyOS_snprintf(buf, sizeof(buf), "%s", name); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	rename_id(&self->scene->id, buf); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-10 22:03:27 +00:00
										 |  |  | static PyObject *Scene_getWinSize(BPy_Scene *self) | 
					
						
							| 
									
										
										
										
											2003-07-10 13:00:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyObject* list = PyList_New (0); | 
					
						
							|  |  |  | 	Scene *scene = self->scene; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyList_Append (list, PyInt_FromLong(scene->r.xsch)); | 
					
						
							|  |  |  | 	PyList_Append (list, PyInt_FromLong(scene->r.ysch)); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return list; | 
					
						
							| 
									
										
										
										
											2003-07-10 13:00:44 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-10 22:03:27 +00:00
										 |  |  | static PyObject *Scene_setWinSize(BPy_Scene *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-07-10 13:00:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	int xres = -1, yres = -1; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "(ii)", &xres, &yres)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 							"expected a [x, y] list as argument"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (xres > 0) | 
					
						
							|  |  |  | 		self->scene->r.xsch = EXPP_ClampInt(xres, | 
					
						
							|  |  |  | 										EXPP_SCENE_RENDER_WINRESOLUTION_MIN, | 
					
						
							|  |  |  | 										EXPP_SCENE_RENDER_WINRESOLUTION_MAX); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (yres > 0) | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 		self->scene->r.ysch = EXPP_ClampInt(yres, | 
					
						
							|  |  |  | 										EXPP_SCENE_RENDER_WINRESOLUTION_MIN, | 
					
						
							|  |  |  | 										EXPP_SCENE_RENDER_WINRESOLUTION_MAX); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-07-10 13:00:44 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | static PyObject *Scene_copy (BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	short dup_objs = 1; | 
					
						
							|  |  |  | 	Scene *scene = self->scene; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!scene) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 						"Blender Scene was deleted!"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple (args, "|h", &dup_objs)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected int in [0,2] or nothing as argument"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return Scene_CreatePyObject (copy_scene (scene, dup_objs)); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Blender seems to accept any positive value up to 18000 for start, end and
 | 
					
						
							|  |  |  |  * current frames, independently. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_currentFrame (BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	short frame = -1; | 
					
						
							|  |  |  | 	RenderData *rd = &self->scene->r; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple (args, "|h", &frame)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected int argument or nothing"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (frame > 0) rd->cfra = EXPP_ClampInt(frame, 1, EXPP_SCENE_FRAME_MAX); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return PyInt_FromLong (rd->cfra); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_startFrame (BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	short frame = -1; | 
					
						
							|  |  |  | 	RenderData *rd = &self->scene->r; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple (args, "|h", &frame)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected int argument or nothing"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (frame > 0) rd->sfra = EXPP_ClampInt (frame, 1, EXPP_SCENE_FRAME_MAX); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return PyInt_FromLong (rd->sfra); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_endFrame (BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	short frame = -1; | 
					
						
							|  |  |  | 	RenderData *rd = &self->scene->r; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple (args, "|h", &frame)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected int argument or nothing"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (frame > 0) rd->efra = EXPP_ClampInt (frame, 1, EXPP_SCENE_FRAME_MAX); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return PyInt_FromLong (rd->efra); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_makeCurrent (BPy_Scene *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Scene *scene = self->scene; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (scene) set_scene (scene); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_INCREF (Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-06 19:25:06 +00:00
										 |  |  | static PyObject *Scene_update (BPy_Scene *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Scene *scene = self->scene; | 
					
						
							| 
									
										
										
										
											2003-08-06 19:25:06 +00:00
										 |  |  | 	int full = 0; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!scene) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 							"Blender Scene was deleted!"); | 
					
						
							| 
									
										
										
										
											2003-08-06 19:25:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple (args, "|i", &full)) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 							"expected nothing or int (0 or 1) argument"); | 
					
						
							| 
									
										
										
										
											2003-08-06 19:25:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-18 00:54:43 +00:00
										 |  |  | /* Under certain circunstances, sort_baselist *here* can crash Blender.
 | 
					
						
							|  |  |  |  * A "RuntimeError: max recursion limit" happens when a scriptlink | 
					
						
							|  |  |  |  * on frame change has scene.update(1). | 
					
						
							|  |  |  |  * Investigate better how to avoid this. */ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!full) | 
					
						
							| 
									
										
										
										
											2003-08-06 19:25:06 +00:00
										 |  |  | 		sort_baselist (scene); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	else if (full == 1) | 
					
						
							|  |  |  | 			set_scene_bg (scene); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 			"in method scene.update(full), full should be:\n" | 
					
						
							|  |  |  | 			"0: to only sort scene elements (old behavior); or\n" | 
					
						
							|  |  |  | 			"1: for a full update (regroups, does ipos, ikas, keys, etc.)"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_INCREF (Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_link (BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Scene *scene = self->scene; | 
					
						
							|  |  |  | 	BPy_Object *bpy_obj; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!scene) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"Blender Scene was deleted!"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple (args, "O!", &Object_Type, &bpy_obj)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 			"expected Object argument"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	else { /* Ok, all is fine, let's try to link it */ | 
					
						
							|  |  |  | 		Object *object = bpy_obj->object; | 
					
						
							|  |  |  | 		Base *base; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		/* We need to link the object to a 'Base', then link this base
 | 
					
						
							|  |  |  | 		 * to the scene.	See DNA_scene_types.h ... */ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		/* First, check if the object isn't already in the scene */ | 
					
						
							|  |  |  | 		base = EXPP_Scene_getObjectBase (scene, object); | 
					
						
							|  |  |  | 		/* if base is not NULL ... */ | 
					
						
							|  |  |  | 		if (base) /* ... the object is already in one of the Scene Bases */ | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 							"object already in scene!"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		/* not linked, go get mem for a new base object */ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		base = MEM_callocN(sizeof(Base), "newbase"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		if (!base) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  | 							"couldn't allocate new Base for object"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* check if this object has obdata, case not, try to create it */ | 
					
						
							|  |  |  | 		if (!object->data && (object->type != OB_EMPTY)) | 
					
						
							|  |  |  | 			EXPP_add_obdata(object); /* returns -1 on error, defined in Object.c */ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		base->object = object; /* link object to the new base */ | 
					
						
							|  |  |  | 		base->lay = object->lay; | 
					
						
							|  |  |  | 		base->flag = object->flag; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		object->id.us += 1; /* incref the object user count in Blender */ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		BLI_addhead(&scene->base, base); /* finally, link new base to scene */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_INCREF (Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_unlink (BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | {  | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	BPy_Object *bpy_obj = NULL; | 
					
						
							|  |  |  | 	Object *object; | 
					
						
							|  |  |  | 	Scene *scene = self->scene; | 
					
						
							|  |  |  | 	Base *base; | 
					
						
							|  |  |  | 	short retval = 0; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!scene) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 						"Blender scene was deleted!"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O!", &Object_Type, &bpy_obj)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected Object as argument"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	object = bpy_obj->object; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* is the object really in the scene? */ | 
					
						
							|  |  |  | 	base = EXPP_Scene_getObjectBase(scene, object); | 
					
						
							|  |  |  | 	  | 
					
						
							|  |  |  | 	if (base) { /* if it is, remove it: */ | 
					
						
							|  |  |  | 		BLI_remlink(&scene->base, base); | 
					
						
							|  |  |  | 		object->id.us -= 1; | 
					
						
							|  |  |  | 		MEM_freeN (base); | 
					
						
							|  |  |  | 		scene->basact = 0; /* in case the object was selected */ | 
					
						
							|  |  |  | 		retval = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return Py_BuildValue ("i", PyInt_FromLong (retval)); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_getRenderdir (BPy_Scene *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (self->scene) | 
					
						
							|  |  |  | 		return PyString_FromString (self->scene->r.pic); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 						"Blender Scene was deleted!"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_getBackbufdir (BPy_Scene *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (self->scene) | 
					
						
							|  |  |  | 		return PyString_FromString (self->scene->r.backbuf); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 						"Blender Scene already deleted"); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_frameSettings (BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | {	 | 
					
						
							|  |  |  | 	int start = -1; | 
					
						
							|  |  |  | 	int end = -1; | 
					
						
							|  |  |  | 	int current = -1; | 
					
						
							|  |  |  | 	RenderData *rd = NULL; | 
					
						
							|  |  |  | 	Scene *scene = self->scene; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!scene) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 						"Blender Scene was deleted!"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rd = &scene->r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple (args, "|iii", &start, &end, ¤t)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected three ints or nothing as arguments"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (start > 0)	 rd->sfra = EXPP_ClampInt (start, 1, EXPP_SCENE_FRAME_MAX); | 
					
						
							|  |  |  | 	if (end > 0)		 rd->efra = EXPP_ClampInt (end, 1, EXPP_SCENE_FRAME_MAX); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 	if (current > 0) rd->cfra = EXPP_ClampInt (current, 1, EXPP_SCENE_FRAME_MAX); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Py_BuildValue("(iii)", rd->sfra, rd->efra, rd->cfra); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_getChildren (BPy_Scene *self) | 
					
						
							|  |  |  | {	 | 
					
						
							|  |  |  | 	Scene *scene = self->scene; | 
					
						
							|  |  |  | 	PyObject *pylist= PyList_New(0); | 
					
						
							|  |  |  | 	PyObject *bpy_obj; | 
					
						
							|  |  |  | 	Object *object; | 
					
						
							|  |  |  | 	Base *base; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!scene) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 						"Blender Scene was deleted!"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	base = scene->base.first; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (base) { | 
					
						
							|  |  |  | 		object = base->object; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bpy_obj = M_Object_Get(Py_None, | 
					
						
							|  |  |  | 										Py_BuildValue ("(s)", object->id.name+2)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!bpy_obj) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 								"couldn't create new object wrapper"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		PyList_Append (pylist, bpy_obj); | 
					
						
							|  |  |  | 		Py_XDECREF (bpy_obj); /* PyList_Append incref'ed it */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		base = base->next; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return pylist; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_getCurrentCamera (BPy_Scene *self) | 
					
						
							|  |  |  | {	 | 
					
						
							|  |  |  | 	Object *cam_obj; | 
					
						
							|  |  |  | 	Scene *scene = self->scene; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!scene) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 						"Blender Scene was deleted!"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cam_obj = scene->camera; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (cam_obj) /* if found, return a wrapper for it */ | 
					
						
							|  |  |  | 		return M_Object_Get (Py_None, Py_BuildValue ("(s)", cam_obj->id.name+2)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_INCREF(Py_None); /* none found */ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Scene_setCurrentCamera (BPy_Scene *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *object; | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | 	BPy_Object *cam_obj; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 	Scene  *scene = self->scene; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!scene) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  | 						"Blender Scene was deleted!"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O!", &Object_Type, &cam_obj)) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected Camera Object as argument"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	object = cam_obj->object; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	scene->camera = object; /* set the current Camera */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if this is the current scene, update its window now */ | 
					
						
							|  |  |  | 	if (scene == G.scene) copy_view3d_lock(REDRAW); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* XXX copy_view3d_lock(REDRAW) prints "bad call to addqueue: 0 (18, 1)".
 | 
					
						
							|  |  |  |  * The same happens in bpython. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static void Scene_dealloc (BPy_Scene *self) | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyObject_DEL (self); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static PyObject *Scene_getAttr (BPy_Scene *self, char *name) | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyObject *attr = Py_None; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (strcmp(name, "name") == 0) | 
					
						
							|  |  |  | 		attr = PyString_FromString(self->scene->id.name+2); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	else if (strcmp(name, "__members__") == 0) | 
					
						
							|  |  |  | 		attr = Py_BuildValue("[s]", "name"); | 
					
						
							| 
									
										
										
										
											2003-07-10 13:00:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!attr) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  | 											"couldn't create PyObject")); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (attr != Py_None) return attr; /* member attribute found, return it */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	/* not an attribute, search the methods table */ | 
					
						
							|  |  |  | 	return Py_FindMethod(BPy_Scene_methods, (PyObject *)self, name); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static int Scene_setAttr (BPy_Scene *self, char *name, PyObject *value) | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	PyObject *valtuple;  | 
					
						
							|  |  |  | 	PyObject *error = NULL; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | /* We're playing a trick on the Python API users here.	Even if they use
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |  * Scene.member = val instead of Scene.setMember(val), we end up using the | 
					
						
							|  |  |  |  * function anyway, since it already has error checking, clamps to the right | 
					
						
							|  |  |  |  * interval and updates the Blender Scene structure when necessary. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* First we put "value" in a tuple, because we want to pass it to functions
 | 
					
						
							|  |  |  |  * that only accept PyTuples. Using "N" doesn't increment value's ref count */ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	valtuple = Py_BuildValue("(O)", value); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (!valtuple) /* everything OK with our PyObject? */ | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError(PyExc_MemoryError, | 
					
						
							|  |  |  | 												 "SceneSetAttr: couldn't create PyTuple"); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Now we just compare "name" with all possible BPy_Scene member variables */ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (strcmp (name, "name") == 0) | 
					
						
							|  |  |  | 		error = Scene_setName (self, valtuple); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	else { /* Error: no member with the given name was found */ | 
					
						
							|  |  |  | 		Py_DECREF(valtuple); | 
					
						
							|  |  |  | 		return (EXPP_ReturnIntError (PyExc_AttributeError, name)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* valtuple won't be returned to the caller, so we need to DECREF it */ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_DECREF(valtuple); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	if (error != Py_None) return -1; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Py_None was incref'ed by the called Scene_set* function. We probably
 | 
					
						
							|  |  |  |  * don't need to decref Py_None (!), but since Python/C API manual tells us | 
					
						
							|  |  |  |  * to treat it like any other PyObject regarding ref counting ... */ | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Py_DECREF(Py_None); | 
					
						
							|  |  |  | 	return 0; /* normal exit */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static int Scene_compare (BPy_Scene *a, BPy_Scene *b) | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Scene *pa = a->scene, *pb = b->scene; | 
					
						
							|  |  |  | 	return (pa == pb) ? 0:-1; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static PyObject *Scene_repr (BPy_Scene *self) | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return PyString_FromFormat("[Scene \"%s\"]", self->scene->id.name+2); | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | Base *EXPP_Scene_getObjectBase(Scene *scene, Object *object) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	Base *base = scene->base.first; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	while (base) { | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		if (object == base->object) return base; /* found it? */ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 		base = base->next; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-24 17:08:59 +00:00
										 |  |  | 	return NULL; /* object isn't linked to this scene */ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } |