| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | /* 
 | 
					
						
							| 
									
										
										
										
											2004-09-18 18:47:03 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +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-12 23:41:33 +00:00
										 |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA	02111-1307, USA. | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is a new part of Blender. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-01-16 23:40:14 +00:00
										 |  |  |  * Contributor(s): Willian P. Germano, Jordi Rovira i Bonet, Joseph Gilbert, | 
					
						
							| 
									
										
										
										
											2004-11-07 15:05:35 +00:00
										 |  |  |  * Bala Gi, Alexander Szakaly | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "NMesh.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-07 19:25:40 +00:00
										 |  |  | #include "DNA_key_types.h"
 | 
					
						
							|  |  |  | #include "DNA_listBase.h"
 | 
					
						
							|  |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_material_types.h"
 | 
					
						
							|  |  |  | #include "DNA_armature_types.h"
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BDR_editface.h"	/* make_tfaces */
 | 
					
						
							|  |  |  | #include "BIF_editdeform.h"
 | 
					
						
							|  |  |  | #include "BIF_editkey.h"	/* insert_meshkey */
 | 
					
						
							|  |  |  | #include "BIF_editmesh.h"	/* vertexnormals_mesh() : still needed???*/
 | 
					
						
							|  |  |  | #include "BIF_meshtools.h"   /* current loc of vertexnormals_mesh() */
 | 
					
						
							|  |  |  | #include "BIF_space.h"
 | 
					
						
							|  |  |  | #include "BKE_mesh.h"
 | 
					
						
							|  |  |  | #include "BKE_main.h"
 | 
					
						
							|  |  |  | #include "BKE_global.h"
 | 
					
						
							|  |  |  | #include "BKE_library.h"
 | 
					
						
							|  |  |  | #include "BKE_displist.h"
 | 
					
						
							|  |  |  | #include "BKE_screen.h"
 | 
					
						
							|  |  |  | #include "BKE_object.h"
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							|  |  |  | #include "BLI_arithb.h"
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "blendef.h"
 | 
					
						
							|  |  |  | #include "mydevice.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Object.h"
 | 
					
						
							|  |  |  | #include "vector.h"
 | 
					
						
							|  |  |  | #include "constant.h"
 | 
					
						
							|  |  |  | #include "gen_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-28 00:29:37 +00:00
										 |  |  | /* EXPP Mesh defines */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define EXPP_NMESH_MODE_NOPUNOFLIP	ME_NOPUNOFLIP
 | 
					
						
							|  |  |  | #define EXPP_NMESH_MODE_TWOSIDED		ME_TWOSIDED
 | 
					
						
							|  |  |  | #define EXPP_NMESH_MODE_AUTOSMOOTH	ME_AUTOSMOOTH
 | 
					
						
							|  |  |  | #define EXPP_NMESH_MODE_SUBSURF			ME_SUBSURF
 | 
					
						
							|  |  |  | #define EXPP_NMESH_MODE_OPTIMAL			ME_OPT_EDGES
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | #define NMESH_FRAME_MAX				18000
 | 
					
						
							|  |  |  | #define NMESH_SMOOTHRESH			30
 | 
					
						
							|  |  |  | #define NMESH_SMOOTHRESH_MIN	1
 | 
					
						
							|  |  |  | #define NMESH_SMOOTHRESH_MAX	80
 | 
					
						
							|  |  |  | #define NMESH_SUBDIV					1
 | 
					
						
							|  |  |  | #define NMESH_SUBDIV_MIN			1
 | 
					
						
							|  |  |  | #define NMESH_SUBDIV_MAX			6
 | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-07 19:25:40 +00:00
										 |  |  | /* Globals */ | 
					
						
							|  |  |  | static PyObject *g_nmeshmodule = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int unlink_existingMeshData( Mesh * mesh ); | 
					
						
							|  |  |  | static int convert_NMeshToMesh( Mesh * mesh, BPy_NMesh * nmesh ); | 
					
						
							|  |  |  | static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *NMesh_removeVertGroup( PyObject * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *NMesh_assignVertsToGroup( PyObject * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *NMesh_removeVertsFromGroup( PyObject * self, | 
					
						
							|  |  |  | 					     PyObject * args ); | 
					
						
							|  |  |  | static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *NMesh_renameVertGroup( PyObject * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *NMesh_getVertGroupNames( PyObject * self, PyObject * args ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | static char NMesh_addVertGroup_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"add a named and empty vertex(deform) Group to a mesh that has been linked\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | to an object. "; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_removeVertGroup_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"remove a named vertex(deform) Group from a mesh that has been linked\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | to an object.  Will remove all verts assigned to group."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_assignVertsToGroup_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"Adds an array (a python list) of vertex points (by index) to a named\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | vertex group.  The list will have an associated wieght assigned to them.\n\ | 
					
						
							|  |  |  | The weight represents the amount of influence this group has over these\n\ | 
					
						
							|  |  |  | vertex points. Weights should be in the range of 0.0 - 1.0.\n\ | 
					
						
							|  |  |  | The assignmode can be either 'add', 'subtract', or 'replace'.  If this vertex\n\ | 
					
						
							|  |  |  | is not assigned to the group 'add' creates a new association with the weight\n\ | 
					
						
							|  |  |  | specified, otherwise the weight given is added to the current weight of the\n\ | 
					
						
							|  |  |  | vertex.\n\ | 
					
						
							|  |  |  | 'subtract' will attempt to subtract the weight passed from a vertex already\n\ | 
					
						
							|  |  |  | associated with a group, else it does nothing. 'replace' attempts to replace\n\ | 
					
						
							|  |  |  | the weight with the new weight value for an already associated vertex/group,\n\ | 
					
						
							|  |  |  | else it does nothing. The mesh must have all it's vertex points set before\n\ | 
					
						
							|  |  |  | attempting to assign any vertex points to a vertex group."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_removeVertsFromGroup_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"Remove an array (a python list) of vertex points from a named group in a\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | mesh that has been linked to an object. If no list is given this will remove\n\ | 
					
						
							|  |  |  | all vertex point associations with the group passed"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getVertsFromGroup_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"By passing a python list of vertex indices and a named group, this will\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | return a python list representing the indeces that are a part of this vertex.\n\ | 
					
						
							|  |  |  | group. If no association was found for the index passed nothing will be\n\ | 
					
						
							|  |  |  | return for the index. An optional flag will also return the weights as well"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static char NMesh_renameVertGroup_doc[] = "Renames a vertex group"; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getVertGroupNames_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"Returns a list of all the vertex group names"; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static char M_NMesh_doc[] = "The Blender.NMesh submodule"; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static char M_NMesh_Col_doc[] = "([r, g, b, a]) - Get a new mesh color\n\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | [r=255, g=255, b=255, a=255] Specify the color components"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char M_NMesh_Face_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(vertexlist = None) - Get a new face, and pass optional vertex list"; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char NMFace_append_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(vert) - appends Vertex 'vert' to face vertex list"; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static char M_NMesh_Vert_doc[] = "([x, y, z]) - Get a new vertice\n\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | [x, y, z] Specify new coordinates"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getMaterials_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(i = -1) - Get this mesh's list of materials.\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | (i = -1) - int: determines the list's contents:\n\ | 
					
						
							|  |  |  | -1: return the current list, possibly modified by the script (default);\n\ | 
					
						
							|  |  |  |  0: get a fresh list from the Blender mesh -- modifications not included,\n\ | 
					
						
							|  |  |  |     unless the script called mesh.update() first;\n\ | 
					
						
							|  |  |  |  1: like 0, but does not ignore empty slots, returns them as 'None'."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_setMaterials_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(matlist) - Set this mesh's list of materials.  This method makes sure\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | the passed matlist is valid (can only include up to 16 materials and None's)."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_addMaterial_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(material) - add a new Blender Material 'material' to this Mesh's materials\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | list."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_insertKey_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(frame = None, type = 'relative') - inserts a Mesh key at the given frame\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | if called without arguments, it inserts the key at the current Scene frame.\n\ | 
					
						
							|  |  |  | (type) - 'relative' or 'absolute'.  Only relevant on the first call to this\n\ | 
					
						
							|  |  |  | function for each nmesh."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_removeAllKeys_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"() - removes all keys from this mesh\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | returns True if successful or False if this NMesh wasn't linked to a real\n\ | 
					
						
							|  |  |  | Blender Mesh yet or the Mesh had no keys"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getSelectedFaces_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(flag = None) - returns list of selected Faces\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | If flag = 1, return indices instead"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getActiveFace_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"returns the index of the active face "; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_hasVertexUV_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(flag = None) - returns 1 if Mesh has per vertex UVs ('Sticky')\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | The optional argument sets the Sticky flag"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_hasFaceUV_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(flag = None) - returns 1 if Mesh has textured faces\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | The optional argument sets the textured faces flag"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_hasVertexColours_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(flag = None) - returns 1 if Mesh has vertex colours.\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | The optional argument sets the vertex colour flag"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getVertexInfluences_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"Return a list of the influences of bones in the vertex \n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | specified by index. The list contains pairs with the \n\ | 
					
						
							|  |  |  | bone name and the weight."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_update_doc[] = "(recalc_normals = 0) - updates the Mesh.\n\
 | 
					
						
							|  |  |  | if recalc_normals is given and is equal to 1, normal vectors are recalculated."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getMode_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"() - get the mode flags of this nmesh as an or'ed int value."; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_setMode_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(none to 5 strings) - set the mode flags of this nmesh.\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | () - unset all flags."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getMaxSmoothAngle_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"() - get the max smooth angle for mesh auto smoothing."; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_setMaxSmoothAngle_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(int) - set the max smooth angle for mesh auto smoothing in the range\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | [1,80] in degrees."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_getSubDivLevels_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"() - get the subdivision levels for display and rendering: [display, render]"; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char NMesh_setSubDivLevels_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"([int, int]) - set the subdivision levels for [display, render] -- they are\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | clamped to the range [1,6]."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char M_NMesh_New_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"() - returns a new, empty NMesh mesh object\n"; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static char M_NMesh_GetRaw_doc[] = "([name]) - Get a raw mesh from Blender\n\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | [name] Name of the mesh to be returned\n\n\ | 
					
						
							|  |  |  | If name is not specified a new empty mesh is\n\ | 
					
						
							|  |  |  | returned, otherwise Blender returns an existing\n\ | 
					
						
							|  |  |  | mesh."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char M_NMesh_GetRawFromObject_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(name) - Get the raw mesh used by a Blender object\n\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | (name) Name of the object to get the mesh from\n\n\ | 
					
						
							|  |  |  | This returns the mesh as used by the object, which\n\ | 
					
						
							|  |  |  | means it contains all deformations and modifications."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char M_NMesh_PutRaw_doc[] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	"(mesh, [name, renormal]) - Return a raw mesh to Blender\n\n\
 | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | (mesh) The NMesh object to store\n\ | 
					
						
							|  |  |  | [name] The mesh to replace\n\ | 
					
						
							|  |  |  | [renormal=1] Flag to control vertex normal recalculation\n\n\ | 
					
						
							|  |  |  | If the name of a mesh to replace is not given a new\n\ | 
					
						
							|  |  |  | object is created and returned."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | void mesh_update( Mesh * mesh ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	edge_drawflags_mesh( mesh ); | 
					
						
							|  |  |  | 	tex_space_mesh( mesh ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************/ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | /*			Mesh Color Object		 */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | /*****************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void NMCol_dealloc( PyObject * self ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject_DEL( self ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static BPy_NMCol *newcol( char r, char g, char b, char a ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMCol *mc = ( BPy_NMCol * ) PyObject_NEW( BPy_NMCol, &NMCol_Type ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mc->r = r; | 
					
						
							|  |  |  | 	mc->g = g; | 
					
						
							|  |  |  | 	mc->b = b; | 
					
						
							|  |  |  | 	mc->a = a; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return mc; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_Col( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	short r = 255, g = 255, b = 255, a = 255; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( PyArg_ParseTuple( args, "|hhhh", &r, &g, &b, &a ) ) | 
					
						
							|  |  |  | 		return ( PyObject * ) newcol( r, g, b, a ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMCol_getattr( PyObject * self, char *name ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMCol *mc = ( BPy_NMCol * ) self; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( strcmp( name, "r" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mc->r ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "g" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mc->g ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "b" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mc->b ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "a" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mc->a ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "__members__" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "[s,s,s,s]", "r", "g", "b", "a" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_ReturnPyObjError( PyExc_AttributeError, name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int NMCol_setattr( PyObject * self, char *name, PyObject * v ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMCol *mc = ( BPy_NMCol * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	short ival; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_Parse( v, "h", &ival ) ) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	ival = ( short ) EXPP_ClampInt( ival, 0, 255 ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( strcmp( name, "r" ) == 0 ) | 
					
						
							|  |  |  | 		mc->r = ival; | 
					
						
							|  |  |  | 	else if( strcmp( name, "g" ) == 0 ) | 
					
						
							|  |  |  | 		mc->g = ival; | 
					
						
							|  |  |  | 	else if( strcmp( name, "b" ) == 0 ) | 
					
						
							|  |  |  | 		mc->b = ival; | 
					
						
							|  |  |  | 	else if( strcmp( name, "a" ) == 0 ) | 
					
						
							|  |  |  | 		mc->a = ival; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *NMCol_repr( BPy_NMCol * self ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	static char s[256]; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	sprintf( s, "[NMCol - <%d, %d, %d, %d>]", self->r, self->g, self->b, | 
					
						
							|  |  |  | 		 self->a ); | 
					
						
							|  |  |  | 	return Py_BuildValue( "s", s ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyTypeObject NMCol_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT( NULL ) 0,	/* ob_size */ | 
					
						
							|  |  |  | 	"Blender NMCol",	/* tp_name */ | 
					
						
							|  |  |  | 	sizeof( BPy_NMCol ),	/* tp_basicsize */ | 
					
						
							|  |  |  | 	0,			/* tp_itemsize */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	( destructor ) NMCol_dealloc,	/* tp_dealloc */ | 
					
						
							|  |  |  | 	( printfunc ) 0,	/* tp_print */ | 
					
						
							|  |  |  | 	( getattrfunc ) NMCol_getattr,	/* tp_getattr */ | 
					
						
							|  |  |  | 	( setattrfunc ) NMCol_setattr,	/* tp_setattr */ | 
					
						
							|  |  |  | 	0,			/* tp_compare */ | 
					
						
							|  |  |  | 	( reprfunc ) NMCol_repr,	/* tp_repr */ | 
					
						
							|  |  |  | 	0,			/* tp_as_number */ | 
					
						
							|  |  |  | 	0,			/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,			/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,			/* tp_hash */ | 
					
						
							|  |  |  | 	0,			/* tp_as_number */ | 
					
						
							|  |  |  | 	0,			/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,			/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,			/* tp_hash */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************/ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | /*		NMesh Python Object		 */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | /*****************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void NMFace_dealloc( PyObject * self ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMFace *mf = ( BPy_NMFace * ) self; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_DECREF( mf->v ); | 
					
						
							|  |  |  | 	Py_DECREF( mf->uv ); | 
					
						
							|  |  |  | 	Py_DECREF( mf->col ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject_DEL( self ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *new_NMFace( PyObject * vertexlist ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMFace *mf = PyObject_NEW( BPy_NMFace, &NMFace_Type ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	PyObject *vlcopy; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( vertexlist ) {	/* create a copy of the given vertex list */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		PyObject *item; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		int i, len = PyList_Size( vertexlist ); | 
					
						
							| 
									
										
										
										
											2003-08-05 03:45:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		vlcopy = PyList_New( len ); | 
					
						
							| 
									
										
										
										
											2003-08-05 03:45:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !vlcopy ) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_MemoryError, | 
					
						
							|  |  |  | 						      "couldn't create PyList" ); | 
					
						
							| 
									
										
										
										
											2003-08-05 03:45:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( i = 0; i < len; i++ ) { | 
					
						
							|  |  |  | 			item = PySequence_GetItem( vertexlist, i );	/* PySequence increfs */ | 
					
						
							| 
									
										
										
										
											2003-08-05 03:45:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( item ) | 
					
						
							|  |  |  | 				PyList_SET_ITEM( vlcopy, i, item ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 				return EXPP_ReturnPyObjError | 
					
						
							|  |  |  | 					( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					  "couldn't get vertex from a PyList" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else			/* create an empty vertex list */ | 
					
						
							|  |  |  | 		vlcopy = PyList_New( 0 ); | 
					
						
							| 
									
										
										
										
											2003-08-05 03:45:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mf->v = vlcopy; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mf->uv = PyList_New( 0 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mf->image = NULL; | 
					
						
							|  |  |  | 	mf->mode = TF_DYNAMIC + TF_TEX; | 
					
						
							|  |  |  | 	mf->flag = TF_SELECT; | 
					
						
							|  |  |  | 	mf->transp = TF_SOLID; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mf->col = PyList_New( 0 ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mf->smooth = 0; | 
					
						
							|  |  |  | 	mf->mat_nr = 0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( PyObject * ) mf; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_Face( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	PyObject *vertlist = NULL; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|O!", &PyList_Type, &vertlist ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected a list of vertices or nothing as argument" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | /*	if (!vertlist) vertlist = PyList_New(0); */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return new_NMFace( vertlist ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMFace_append( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	PyObject *vert; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMFace *f = ( BPy_NMFace * ) self; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "O!", &NMVert_Type, &vert ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected an NMVert object" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyList_Append( f->v, vert ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef MethodDef
 | 
					
						
							|  |  |  | #define MethodDef(func) {#func, NMFace_##func, METH_VARARGS, NMFace_##func##_doc}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static struct PyMethodDef NMFace_methods[] = { | 
					
						
							|  |  |  | 	MethodDef( append ), | 
					
						
							| 
									
										
										
										
											2004-06-06 22:42:51 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMFace_getattr( PyObject * self, char *name ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPy_NMFace *mf = ( BPy_NMFace * ) self; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( strcmp( name, "v" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "O", mf->v ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "col" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "O", mf->col ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "mat" ) == 0 )	// emulation XXX
 | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mf->mat_nr ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "materialIndex" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mf->mat_nr ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "smooth" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mf->smooth ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	else if( strcmp( name, "image" ) == 0 ) { | 
					
						
							|  |  |  | 		if( mf->image ) | 
					
						
							|  |  |  | 			return Image_CreatePyObject( mf->image ); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "mode" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mf->mode ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "flag" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mf->flag ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "transp" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "i", mf->transp ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "uv" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "O", mf->uv ); | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( ( strcmp( name, "normal" ) == 0 ) | 
					
						
							|  |  |  | 		 || ( strcmp( name, "no" ) == 0 ) ) { | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( EXPP_check_sequence_consistency( mf->v, &NMVert_Type ) == | 
					
						
							|  |  |  | 		    1 ) { | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			float fNormal[3] = { 0.0, 0.0, 0.0 }; | 
					
						
							|  |  |  | 			float *vco[4] = { NULL, NULL, NULL, NULL }; | 
					
						
							|  |  |  | 			int nSize = PyList_Size( mf->v ); | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 			int loop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( nSize != 3 && nSize != 4 ) | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError | 
					
						
							|  |  |  | 					( PyExc_AttributeError, | 
					
						
							|  |  |  | 					  "face must contain either 3 or 4 verts" ); | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			for( loop = 0; loop < nSize; loop++ ) { | 
					
						
							|  |  |  | 				BPy_NMVert *v = | 
					
						
							|  |  |  | 					( BPy_NMVert * ) PyList_GetItem( mf->v, | 
					
						
							|  |  |  | 									 loop ); | 
					
						
							|  |  |  | 				vco[loop] = ( float * ) v->co; | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( nSize == 4 ) | 
					
						
							|  |  |  | 				CalcNormFloat4( vco[0], vco[1], vco[2], vco[3], | 
					
						
							|  |  |  | 						fNormal ); | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 				CalcNormFloat( vco[0], vco[1], vco[2], | 
					
						
							|  |  |  | 					       fNormal ); | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			return Py_BuildValue( "[f,f,f]", fNormal[0], | 
					
						
							|  |  |  | 					      fNormal[1], fNormal[2] ); | 
					
						
							|  |  |  | 		} else		// EXPP_check_sequence_consistency failed
 | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 						      "this face does not contain a series of NMVerts" ); | 
					
						
							| 
									
										
										
										
											2003-10-19 03:15:43 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "__members__" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s]", | 
					
						
							|  |  |  | 				      "v", "col", "mat", "materialIndex", | 
					
						
							|  |  |  | 				      "smooth", "image", "mode", "flag", | 
					
						
							|  |  |  | 				      "transp", "uv", "normal" ); | 
					
						
							|  |  |  | 	return Py_FindMethod( NMFace_methods, ( PyObject * ) self, name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int NMFace_setattr( PyObject * self, char *name, PyObject * v ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMFace *mf = ( BPy_NMFace * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	short ival; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( strcmp( name, "v" ) == 0 ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( PySequence_Check( v ) ) { | 
					
						
							|  |  |  | 			Py_DECREF( mf->v ); | 
					
						
							|  |  |  | 			mf->v = EXPP_incr_ret( v ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else if( strcmp( name, "col" ) == 0 ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( PySequence_Check( v ) ) { | 
					
						
							|  |  |  | 			Py_DECREF( mf->col ); | 
					
						
							|  |  |  | 			mf->col = EXPP_incr_ret( v ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else if( !strcmp( name, "mat" ) || !strcmp( name, "materialIndex" ) ) { | 
					
						
							|  |  |  | 		PyArg_Parse( v, "h", &ival ); | 
					
						
							|  |  |  | 		mf->mat_nr = ival; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else if( strcmp( name, "smooth" ) == 0 ) { | 
					
						
							|  |  |  | 		PyArg_Parse( v, "h", &ival ); | 
					
						
							|  |  |  | 		mf->smooth = ival ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else if( strcmp( name, "uv" ) == 0 ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( PySequence_Check( v ) ) { | 
					
						
							|  |  |  | 			Py_DECREF( mf->uv ); | 
					
						
							|  |  |  | 			mf->uv = EXPP_incr_ret( v ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else if( strcmp( name, "flag" ) == 0 ) { | 
					
						
							|  |  |  | 		PyArg_Parse( v, "h", &ival ); | 
					
						
							|  |  |  | 		mf->flag = ival; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} else if( strcmp( name, "mode" ) == 0 ) { | 
					
						
							|  |  |  | 		PyArg_Parse( v, "h", &ival ); | 
					
						
							|  |  |  | 		mf->mode = ival; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} else if( strcmp( name, "transp" ) == 0 ) { | 
					
						
							|  |  |  | 		PyArg_Parse( v, "h", &ival ); | 
					
						
							|  |  |  | 		mf->transp = ival; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} else if( strcmp( name, "image" ) == 0 ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		PyObject *pyimg; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !PyArg_Parse( v, "O!", &Image_Type, &pyimg ) ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						    "expected image object" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( pyimg == Py_None ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			mf->image = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		mf->image = ( ( BPy_Image * ) pyimg )->image; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_ReturnIntError( PyExc_AttributeError, name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMFace_repr( PyObject * self ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return PyString_FromString( "[NMFace]" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int NMFace_len( BPy_NMFace * self ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return PySequence_Length( self->v ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMFace_item( BPy_NMFace * self, int i ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return PySequence_GetItem( self->v, i );	// new ref
 | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMFace_slice( BPy_NMFace * self, int begin, int end ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return PyList_GetSlice( self->v, begin, end );	// new ref
 | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PySequenceMethods NMFace_SeqMethods = { | 
					
						
							|  |  |  | 	( inquiry ) NMFace_len,	/* sq_length */ | 
					
						
							|  |  |  | 	( binaryfunc ) 0,	/* sq_concat */ | 
					
						
							|  |  |  | 	( intargfunc ) 0,	/* sq_repeat */ | 
					
						
							|  |  |  | 	( intargfunc ) NMFace_item,	/* sq_item */ | 
					
						
							|  |  |  | 	( intintargfunc ) NMFace_slice,	/* sq_slice */ | 
					
						
							|  |  |  | 	( intobjargproc ) 0,	/* sq_ass_item */ | 
					
						
							|  |  |  | 	( intintobjargproc ) 0,	/* sq_ass_slice */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyTypeObject NMFace_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT( NULL ) 0,	/*ob_size */ | 
					
						
							|  |  |  | 	"Blender NMFace",	/*tp_name */ | 
					
						
							|  |  |  | 	sizeof( BPy_NMFace ),	/*tp_basicsize */ | 
					
						
							|  |  |  | 	0,			/*tp_itemsize */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	( destructor ) NMFace_dealloc,	/*tp_dealloc */ | 
					
						
							|  |  |  | 	( printfunc ) 0,	/*tp_print */ | 
					
						
							|  |  |  | 	( getattrfunc ) NMFace_getattr,	/*tp_getattr */ | 
					
						
							|  |  |  | 	( setattrfunc ) NMFace_setattr,	/*tp_setattr */ | 
					
						
							|  |  |  | 	0,			/*tp_compare */ | 
					
						
							|  |  |  | 	( reprfunc ) NMFace_repr,	/*tp_repr */ | 
					
						
							|  |  |  | 	0,			/*tp_as_number */ | 
					
						
							|  |  |  | 	&NMFace_SeqMethods,	/*tp_as_sequence */ | 
					
						
							|  |  |  | 	0,			/*tp_as_mapping */ | 
					
						
							|  |  |  | 	0,			/*tp_hash */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static BPy_NMVert *newvert( float *co ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMVert *mv = PyObject_NEW( BPy_NMVert, &NMVert_Type ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mv->co[0] = co[0]; | 
					
						
							|  |  |  | 	mv->co[1] = co[1]; | 
					
						
							|  |  |  | 	mv->co[2] = co[2]; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mv->no[0] = mv->no[1] = mv->no[2] = 0.0; | 
					
						
							|  |  |  | 	mv->uvco[0] = mv->uvco[1] = mv->uvco[2] = 0.0; | 
					
						
							| 
									
										
										
										
											2004-01-20 04:57:47 +00:00
										 |  |  | 	mv->flag = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return mv; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_Vert( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	float co[3] = { 0.0, 0.0, 0.0 }; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|fff", &co[0], &co[1], &co[2] ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected three floats (or nothing) as arguments" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ( PyObject * ) newvert( co ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void NMVert_dealloc( PyObject * self ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject_DEL( self ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMVert_getattr( PyObject * self, char *name ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMVert *mv = ( BPy_NMVert * ) self; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !strcmp( name, "co" ) || !strcmp( name, "loc" ) ) | 
					
						
							| 
									
										
										
										
											2004-10-14 17:35:16 +00:00
										 |  |  | 		return newVectorProxy( mv->co, 3 ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "no" ) == 0 ) | 
					
						
							| 
									
										
										
										
											2004-10-14 17:35:16 +00:00
										 |  |  | 		return newVectorProxy( mv->no, 3 ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "uvco" ) == 0 ) | 
					
						
							| 
									
										
										
										
											2004-10-14 17:35:16 +00:00
										 |  |  | 		return newVectorProxy( mv->uvco, 3 ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "index" ) == 0 ) | 
					
						
							|  |  |  | 		return PyInt_FromLong( mv->index ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "sel" ) == 0 ) | 
					
						
							|  |  |  | 		return PyInt_FromLong( mv->flag & 1 ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "__members__" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "[s,s,s,s,s]", "co", "no", "uvco", | 
					
						
							|  |  |  | 				      "index", "sel" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_ReturnPyObjError( PyExc_AttributeError, name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int NMVert_setattr( PyObject * self, char *name, PyObject * v ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMVert *mv = ( BPy_NMVert * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if( strcmp( name, "index" ) == 0 ) { | 
					
						
							|  |  |  | 		PyArg_Parse( v, "i", &i ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		mv->index = i; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else if( strcmp( name, "sel" ) == 0 ) { | 
					
						
							|  |  |  | 		PyArg_Parse( v, "i", &i ); | 
					
						
							|  |  |  | 		mv->flag = i ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2004-01-20 04:57:47 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else if( strcmp( name, "uvco" ) == 0 ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !PyArg_ParseTuple( v, "ff|f", | 
					
						
							|  |  |  | 				       &( mv->uvco[0] ), &( mv->uvco[1] ), | 
					
						
							|  |  |  | 				       &( mv->uvco[2] ) ) ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_AttributeError, | 
					
						
							|  |  |  | 						    "Vector tuple or triple expected" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return EXPP_ReturnIntError( PyExc_AttributeError, name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int NMVert_len( BPy_NMVert * self ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return 3; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMVert_item( BPy_NMVert * self, int i ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( i < 0 || i >= 3 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_IndexError, | 
					
						
							|  |  |  | 					      "array index out of range" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return Py_BuildValue( "f", self->co[i] ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMVert_slice( BPy_NMVert * self, int begin, int end ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	PyObject *list; | 
					
						
							|  |  |  | 	int count; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( begin < 0 ) | 
					
						
							|  |  |  | 		begin = 0; | 
					
						
							|  |  |  | 	if( end > 3 ) | 
					
						
							|  |  |  | 		end = 3; | 
					
						
							|  |  |  | 	if( begin > end ) | 
					
						
							|  |  |  | 		begin = end; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list = PyList_New( end - begin ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( count = begin; count < end; count++ ) | 
					
						
							|  |  |  | 		PyList_SetItem( list, count - begin, | 
					
						
							|  |  |  | 				PyFloat_FromDouble( self->co[count] ) ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return list; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int NMVert_ass_item( BPy_NMVert * self, int i, PyObject * ob ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( i < 0 || i >= 3 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_IndexError, | 
					
						
							|  |  |  | 					    "array assignment index out of range" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyNumber_Check( ob ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_IndexError, | 
					
						
							|  |  |  | 					    "NMVert member must be a number" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	self->co[i] = PyFloat_AsDouble( ob ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int NMVert_ass_slice( BPy_NMVert * self, int begin, int end, | 
					
						
							|  |  |  | 			     PyObject * seq ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int count; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if( begin < 0 ) | 
					
						
							|  |  |  | 		begin = 0; | 
					
						
							|  |  |  | 	if( end > 3 ) | 
					
						
							|  |  |  | 		end = 3; | 
					
						
							|  |  |  | 	if( begin > end ) | 
					
						
							|  |  |  | 		begin = end; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PySequence_Check( seq ) ) | 
					
						
							|  |  |  | 		EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 				     "illegal argument type for built-in operation" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( PySequence_Length( seq ) != ( end - begin ) ) | 
					
						
							|  |  |  | 		EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 				     "size mismatch in slice assignment" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for( count = begin; count < end; count++ ) { | 
					
						
							|  |  |  | 		PyObject *ob = PySequence_GetItem( seq, count ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if( !PyArg_Parse( ob, "f", &self->co[count] ) ) { | 
					
						
							|  |  |  | 			Py_DECREF( ob ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		Py_DECREF( ob ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PySequenceMethods NMVert_SeqMethods = { | 
					
						
							|  |  |  | 	( inquiry ) NMVert_len,	/* sq_length */ | 
					
						
							|  |  |  | 	( binaryfunc ) 0,	/* sq_concat */ | 
					
						
							|  |  |  | 	( intargfunc ) 0,	/* sq_repeat */ | 
					
						
							|  |  |  | 	( intargfunc ) NMVert_item,	/* sq_item */ | 
					
						
							|  |  |  | 	( intintargfunc ) NMVert_slice,	/* sq_slice */ | 
					
						
							|  |  |  | 	( intobjargproc ) NMVert_ass_item,	/* sq_ass_item */ | 
					
						
							|  |  |  | 	( intintobjargproc ) NMVert_ass_slice,	/* sq_ass_slice */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyTypeObject NMVert_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT( NULL )  | 
					
						
							|  |  |  | 	0,	/*ob_size */ | 
					
						
							|  |  |  | 	"Blender NMVert",	/*tp_name */ | 
					
						
							|  |  |  | 	sizeof( BPy_NMVert ),	/*tp_basicsize */ | 
					
						
							|  |  |  | 	0,			/*tp_itemsize */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	( destructor ) NMVert_dealloc,	/*tp_dealloc */ | 
					
						
							|  |  |  | 	( printfunc ) 0,	/*tp_print */ | 
					
						
							|  |  |  | 	( getattrfunc ) NMVert_getattr,	/*tp_getattr */ | 
					
						
							|  |  |  | 	( setattrfunc ) NMVert_setattr,	/*tp_setattr */ | 
					
						
							|  |  |  | 	0,			/*tp_compare */ | 
					
						
							|  |  |  | 	( reprfunc ) 0,		/*tp_repr */ | 
					
						
							|  |  |  | 	0,			/*tp_as_number */ | 
					
						
							|  |  |  | 	&NMVert_SeqMethods,	/*tp_as_sequence */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void NMesh_dealloc( PyObject * self ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_DECREF( me->name ); | 
					
						
							|  |  |  | 	Py_DECREF( me->verts ); | 
					
						
							|  |  |  | 	Py_DECREF( me->faces ); | 
					
						
							|  |  |  | 	Py_DECREF( me->materials ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject_DEL( self ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getMaterials( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nm = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 	PyObject *list = NULL; | 
					
						
							|  |  |  | 	Mesh *me = nm->mesh; | 
					
						
							|  |  |  | 	int all = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|i", &all ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected nothing or an int (bool) as argument" ); | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( all >= 0 ) { | 
					
						
							|  |  |  | 		list = EXPP_PyList_fromMaterialList( me->mat, me->totcol, | 
					
						
							|  |  |  | 						     all ); | 
					
						
							|  |  |  | 		Py_DECREF( nm->materials );	/* update nmesh.materials attribute */ | 
					
						
							|  |  |  | 		nm->materials = EXPP_incr_ret( list ); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		list = EXPP_incr_ret( nm->materials ); | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return list; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_setMaterials( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 	PyObject *pymats = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "O!", &PyList_Type, &pymats ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected a list of materials (None's also accepted) as argument" ); | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !EXPP_check_sequence_consistency( pymats, &Material_Type ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "list should only contain materials (None's also accepted)" ); | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( PyList_Size( pymats ) > 16 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "list can't have more than 16 materials" ); | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_DECREF( me->materials ); | 
					
						
							|  |  |  | 	me->materials = EXPP_incr_ret( pymats ); | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2004-07-20 08:16:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_addMaterial( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	BPy_Material *pymat; | 
					
						
							|  |  |  | 	Material *mat; | 
					
						
							|  |  |  | 	PyObject *iter; | 
					
						
							|  |  |  | 	int i, len = 0; | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "O!", &Material_Type, &pymat ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected Blender Material PyObject" ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mat = pymat->material; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	len = PyList_Size( me->materials ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( len >= 16 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "object data material lists can't have more than 16 materials" ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < len; i++ ) { | 
					
						
							|  |  |  | 		iter = PyList_GetItem( me->materials, i ); | 
					
						
							|  |  |  | 		if( mat == Material_FromPyObject( iter ) ) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 						      "material already in the list" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyList_Append( me->materials, ( PyObject * ) pymat ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_removeAllKeys( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nm = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	Mesh *me = nm->mesh; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "" ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "this function expects no arguments" ); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !me || !me->key ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( Py_False ); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	me->key->id.us--; | 
					
						
							|  |  |  | 	me->key = 0; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_True ); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_insertKey( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int fra = -1, oldfra = -1; | 
					
						
							|  |  |  | 	char *type = NULL; | 
					
						
							|  |  |  | 	short typenum; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nm = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	Mesh *mesh = nm->mesh; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|is", &fra, &type ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected nothing or an int and optionally a string as arguments" ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !type || !strcmp( type, "relative" ) ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		typenum = 1; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( !strcmp( type, "absolute" ) ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		typenum = 2; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "if given, type should be 'relative' or 'absolute'" ); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( fra > 0 ) { | 
					
						
							|  |  |  | 		fra = EXPP_ClampInt( fra, 1, NMESH_FRAME_MAX ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		oldfra = G.scene->r.cfra; | 
					
						
							|  |  |  | 		G.scene->r.cfra = fra; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !mesh ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "update this NMesh first with its .update() method" ); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	insert_meshkey( mesh, typenum ); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( fra > 0 ) | 
					
						
							|  |  |  | 		G.scene->r.cfra = oldfra; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getSelectedFaces( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nm = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	Mesh *me = nm->mesh; | 
					
						
							|  |  |  | 	int flag = 0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	TFace *tf; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *l = PyList_New( 0 ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( me == NULL ) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	tf = me->tface; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( tf == 0 ) | 
					
						
							|  |  |  | 		return l; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|i", &flag ) ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( flag ) { | 
					
						
							|  |  |  | 		for( i = 0; i < me->totface; i++ ) { | 
					
						
							|  |  |  | 			if( tf[i].flag & TF_SELECT ) | 
					
						
							|  |  |  | 				PyList_Append( l, PyInt_FromLong( i ) ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( i = 0; i < me->totface; i++ ) { | 
					
						
							|  |  |  | 			if( tf[i].flag & TF_SELECT ) | 
					
						
							|  |  |  | 				PyList_Append( l, | 
					
						
							|  |  |  | 					       PyList_GetItem( nm->faces, | 
					
						
							|  |  |  | 							       i ) ); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return l; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getActiveFace( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( ( BPy_NMesh * ) self )->sel_face < 0 ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return Py_BuildValue( "i", ( ( BPy_NMesh * ) self )->sel_face ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_hasVertexUV( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int flag; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( args ) { | 
					
						
							|  |  |  | 		if( PyArg_ParseTuple( args, "i", &flag ) ) { | 
					
						
							|  |  |  | 			if( flag ) | 
					
						
							|  |  |  | 				me->flags |= NMESH_HASVERTUV; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				me->flags &= ~NMESH_HASVERTUV; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyErr_Clear(  ); | 
					
						
							|  |  |  | 	if( me->flags & NMESH_HASVERTUV ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( Py_True ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return EXPP_incr_ret( Py_False ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_hasFaceUV( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int flag = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|i", &flag ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected int argument (or nothing)" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	switch ( flag ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	case 0: | 
					
						
							| 
									
										
										
										
											2004-11-02 05:13:52 +00:00
										 |  |  | 		me->flags &= ~NMESH_HASFACEUV; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	case 1: | 
					
						
							| 
									
										
										
										
											2004-11-02 05:13:52 +00:00
										 |  |  | 		me->flags |= NMESH_HASFACEUV; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( me->flags & NMESH_HASFACEUV ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( Py_True ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return EXPP_incr_ret( Py_False ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_hasVertexColours( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int flag = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|i", &flag ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected int argument (or nothing)" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	switch ( flag ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	case 0: | 
					
						
							|  |  |  | 		me->flags &= ~NMESH_HASMCOL; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	case 1: | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		me->flags |= NMESH_HASMCOL; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( me->flags & NMESH_HASMCOL ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( Py_True ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return EXPP_incr_ret( Py_False ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_update( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int recalc_normals = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nmesh = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	Mesh *mesh = nmesh->mesh; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|i", &recalc_normals ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "expected nothing or an int (0 or 1) as argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( recalc_normals && recalc_normals != 1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "expected 0 or 1 as argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( mesh ) { | 
					
						
							|  |  |  | 		unlink_existingMeshData( mesh ); | 
					
						
							|  |  |  | 		convert_NMeshToMesh( mesh, nmesh ); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		nmesh->mesh = Mesh_fromNMesh( nmesh ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		mesh = nmesh->mesh; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( recalc_normals ) | 
					
						
							|  |  |  | 		vertexnormals_mesh( mesh, 0 ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mesh_update( mesh ); | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	nmesh_updateMaterials( nmesh ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( nmesh->name && nmesh->name != Py_None ) | 
					
						
							|  |  |  | 		new_id( &( G.main->mesh ), &mesh->id, | 
					
						
							|  |  |  | 			PyString_AsString( nmesh->name ) ); | 
					
						
							| 
									
										
										
										
											2003-08-07 04:12:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !during_script(  ) ) | 
					
						
							|  |  |  | 		allqueue( REDRAWVIEW3D, 0 ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return PyInt_FromLong( 1 ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | /** Implementation of the python method getVertexInfluence for an NMesh object.
 | 
					
						
							| 
									
										
										
										
											2003-07-30 21:15:41 +00:00
										 |  |  |  * This method returns a list of pairs (string,float) with bone names and | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  |  * influences that this vertex receives. | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  |  * @author Jordi Rovira i Bonet | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getVertexInfluences( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int index; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *influence_list = NULL; | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	/* Get a reference to the mesh object wrapped in here. */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Mesh *me = ( ( BPy_NMesh * ) self )->mesh; | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !me ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "unlinked nmesh: call its .update() method first" ); | 
					
						
							| 
									
										
										
										
											2003-07-13 16:28:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	/* Parse the parameters: only on integer (vertex index) */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "i", &index ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected int argument (index of the vertex)" ); | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	/* Proceed only if we have vertex deformation information and index is valid */ | 
					
						
							|  |  |  | 	if( me->dvert ) { | 
					
						
							|  |  |  | 		if( ( index >= 0 ) && ( index < me->totvert ) ) { | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			int i; | 
					
						
							|  |  |  | 			MDeformWeight *sweight = NULL; | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			/* Number of bones influencing the vertex */ | 
					
						
							|  |  |  | 			int totinfluences = me->dvert[index].totweight; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Build the list only with weights and names of the influent bones */ | 
					
						
							|  |  |  | 			/*influence_list = PyList_New(totinfluences); */ | 
					
						
							|  |  |  | 			influence_list = PyList_New( 0 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Get the reference of the first weight structure */ | 
					
						
							|  |  |  | 			sweight = me->dvert[index].dw; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for( i = 0; i < totinfluences; i++ ) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/*Add the weight and the name of the bone, which is used to identify it */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if( sweight->data ) | 
					
						
							|  |  |  | 					/* valid bone: return its name */ | 
					
						
							|  |  |  | 					/*  PyList_SetItem(influence_list, i,
 | 
					
						
							|  |  |  | 					   Py_BuildValue("[sf]", sweight->data->name, sweight->weight)); | 
					
						
							|  |  |  | 					   else // NULL bone: return Py_None instead
 | 
					
						
							|  |  |  | 					   PyList_SetItem(influence_list, i, | 
					
						
							|  |  |  | 					   Py_BuildValue("[Of]", Py_None, sweight->weight)); */ | 
					
						
							|  |  |  | 					PyList_Append( influence_list, | 
					
						
							|  |  |  | 						       Py_BuildValue( "[sf]", | 
					
						
							|  |  |  | 								      sweight-> | 
					
						
							|  |  |  | 								      data-> | 
					
						
							|  |  |  | 								      name, | 
					
						
							|  |  |  | 								      sweight-> | 
					
						
							|  |  |  | 								      weight ) ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* Next weight */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 				sweight++; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		} else		//influence_list = PyList_New(0);
 | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_IndexError, | 
					
						
							|  |  |  | 						      "vertex index out of range" ); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		influence_list = PyList_New( 0 ); | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return influence_list; | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | Mesh *Mesh_fromNMesh( BPy_NMesh * nmesh ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	Mesh *mesh = NULL; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mesh = add_mesh(  ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !mesh ) | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 				       "FATAL: could not create mesh object" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mesh->id.us = 0;	/* no user yet */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	G.totmesh++; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	convert_NMeshToMesh( mesh, nmesh ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return mesh; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *NMesh_link( PyObject * self, PyObject * args ) | 
					
						
							|  |  |  | {				/*
 | 
					
						
							|  |  |  | 				   BPy_Object *bl_obj; | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 				   if (!PyArg_ParseTuple(args, "O!", &Object_Type, &bl_obj)) | 
					
						
							|  |  |  | 				   return EXPP_ReturnPyErrorObj (PyExc_TypeError, | 
					
						
							|  |  |  | 				   "NMesh can only be linked to Objects"); | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 				   bl_obj->data = (PyObject *)self; */ | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Better use object.link(nmesh), no need for this nmesh.link(object) */ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getMaxSmoothAngle( BPy_NMesh * self ) | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *attr = PyInt_FromLong( self->smoothresh ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( attr ) | 
					
						
							|  |  |  | 		return attr; | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 				      "couldn't get NMesh.maxSmoothAngle attribute" ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_setMaxSmoothAngle( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	short value = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nmesh = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "h", &value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "expected an int in [1, 80] as argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	nmesh->smoothresh = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		( short ) EXPP_ClampInt( value, NMESH_SMOOTHRESH_MIN, | 
					
						
							|  |  |  | 					 NMESH_SMOOTHRESH_MAX ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_INCREF( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getSubDivLevels( BPy_NMesh * self ) | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *attr = | 
					
						
							|  |  |  | 		Py_BuildValue( "[h,h]", self->subdiv[0], self->subdiv[1] ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( attr ) | 
					
						
							|  |  |  | 		return attr; | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 				      "couldn't get NMesh.subDivLevels attribute" ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_setSubDivLevels( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	short display = 0, render = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nmesh = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "(hh)", &display, &render ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "expected a sequence [int, int] as argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	nmesh->subdiv[0] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		( short ) EXPP_ClampInt( display, NMESH_SUBDIV_MIN, | 
					
						
							|  |  |  | 					 NMESH_SUBDIV_MAX ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	nmesh->subdiv[1] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		( short ) EXPP_ClampInt( render, NMESH_SUBDIV_MIN, | 
					
						
							|  |  |  | 					 NMESH_SUBDIV_MAX ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_INCREF( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 	return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getMode( BPy_NMesh * self ) | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *attr = PyInt_FromLong( self->mode ); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( attr ) | 
					
						
							|  |  |  | 		return attr; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 				      "couldn't get NMesh.mode attribute" ); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_setMode( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nmesh = ( BPy_NMesh * ) self; | 
					
						
							|  |  |  | 	char *m[5] = { NULL, NULL, NULL, NULL, NULL }; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	short i, mode = 0; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple | 
					
						
							|  |  |  | 	    ( args, "|sssss", &m[0], &m[1], &m[2], &m[3], &m[4] ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "expected from none to 5 strings as argument(s)" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < 5; i++ ) { | 
					
						
							|  |  |  | 		if( !m[i] ) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		if( strcmp( m[i], "NoVNormalsFlip" ) == 0 ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			mode |= EXPP_NMESH_MODE_NOPUNOFLIP; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		else if( strcmp( m[i], "TwoSided" ) == 0 ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			mode |= EXPP_NMESH_MODE_TWOSIDED; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		else if( strcmp( m[i], "AutoSmooth" ) == 0 ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			mode |= EXPP_NMESH_MODE_AUTOSMOOTH; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		else if( strcmp( m[i], "SubSurf" ) == 0 ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			mode |= EXPP_NMESH_MODE_SUBSURF; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		else if( strcmp( m[i], "Optimal" ) == 0 ) | 
					
						
							| 
									
										
										
										
											2003-10-28 00:29:37 +00:00
										 |  |  | 			mode |= EXPP_NMESH_MODE_OPTIMAL; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 						      "unknown NMesh mode" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	nmesh->mode = mode; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_INCREF( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | #undef MethodDef
 | 
					
						
							|  |  |  | #define MethodDef(func) {#func, NMesh_##func, METH_VARARGS, NMesh_##func##_doc}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static struct PyMethodDef NMesh_methods[] = { | 
					
						
							|  |  |  | 	MethodDef( addVertGroup ), | 
					
						
							|  |  |  | 	MethodDef( removeVertGroup ), | 
					
						
							|  |  |  | 	MethodDef( assignVertsToGroup ), | 
					
						
							|  |  |  | 	MethodDef( removeVertsFromGroup ), | 
					
						
							|  |  |  | 	MethodDef( getVertsFromGroup ), | 
					
						
							|  |  |  | 	MethodDef( renameVertGroup ), | 
					
						
							|  |  |  | 	MethodDef( getVertGroupNames ), | 
					
						
							|  |  |  | 	MethodDef( hasVertexColours ), | 
					
						
							|  |  |  | 	MethodDef( hasFaceUV ), | 
					
						
							|  |  |  | 	MethodDef( hasVertexUV ), | 
					
						
							|  |  |  | 	MethodDef( getActiveFace ), | 
					
						
							|  |  |  | 	MethodDef( getSelectedFaces ), | 
					
						
							|  |  |  | 	MethodDef( getVertexInfluences ), | 
					
						
							|  |  |  | 	MethodDef( getMaterials ), | 
					
						
							|  |  |  | 	MethodDef( setMaterials ), | 
					
						
							|  |  |  | 	MethodDef( addMaterial ), | 
					
						
							|  |  |  | 	MethodDef( insertKey ), | 
					
						
							|  |  |  | 	MethodDef( removeAllKeys ), | 
					
						
							|  |  |  | 	MethodDef( update ), | 
					
						
							|  |  |  | 	MethodDef( setMode ), | 
					
						
							|  |  |  | 	MethodDef( setMaxSmoothAngle ), | 
					
						
							|  |  |  | 	MethodDef( setSubDivLevels ), | 
					
						
							|  |  |  | 	{"getMode", ( PyCFunction ) NMesh_getMode, METH_NOARGS, | 
					
						
							|  |  |  | 	 NMesh_getMode_doc}, | 
					
						
							|  |  |  | 	{"getMaxSmoothAngle", ( PyCFunction ) NMesh_getMaxSmoothAngle, | 
					
						
							|  |  |  | 	 METH_NOARGS, | 
					
						
							|  |  |  | 	 NMesh_getMaxSmoothAngle_doc}, | 
					
						
							|  |  |  | 	{"getSubDivLevels", ( PyCFunction ) NMesh_getSubDivLevels, METH_NOARGS, | 
					
						
							|  |  |  | 	 NMesh_getSubDivLevels_doc}, | 
					
						
							| 
									
										
										
										
											2004-06-06 22:42:51 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getattr( PyObject * self, char *name ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( strcmp( name, "name" ) == 0 ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( me->name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "mode" ) == 0 ) | 
					
						
							|  |  |  | 		return PyInt_FromLong( me->mode ); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "block_type" ) == 0 )	/* for compatibility */ | 
					
						
							|  |  |  | 		return PyString_FromString( "NMesh" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "materials" ) == 0 ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( me->materials ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "verts" ) == 0 ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( me->verts ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "maxSmoothAngle" ) == 0 ) | 
					
						
							|  |  |  | 		return PyInt_FromLong( me->smoothresh ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "subDivLevels" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "[h,h]", me->subdiv[0], me->subdiv[1] ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "users" ) == 0 ) { | 
					
						
							|  |  |  | 		if( me->mesh ) { | 
					
						
							|  |  |  | 			return PyInt_FromLong( me->mesh->id.us ); | 
					
						
							|  |  |  | 		} else {	/* it's a free mesh: */ | 
					
						
							|  |  |  | 			return Py_BuildValue( "i", 0 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "faces" ) == 0 ) | 
					
						
							|  |  |  | 		return EXPP_incr_ret( me->faces ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( strcmp( name, "__members__" ) == 0 ) | 
					
						
							|  |  |  | 		return Py_BuildValue( "[s,s,s,s,s,s,s]", | 
					
						
							|  |  |  | 				      "name", "materials", "verts", "users", | 
					
						
							|  |  |  | 				      "faces", "maxSmoothAngle", | 
					
						
							|  |  |  | 				      "subdivLevels" ); | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return Py_FindMethod( NMesh_methods, ( PyObject * ) self, name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int NMesh_setattr( PyObject * self, char *name, PyObject * v ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = ( BPy_NMesh * ) self; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !strcmp( name, "name" ) ) { | 
					
						
							| 
									
										
										
										
											2003-07-02 18:26:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !PyString_Check( v ) ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						    "expected string argument" ); | 
					
						
							| 
									
										
										
										
											2003-07-02 18:26:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		Py_DECREF( me->name ); | 
					
						
							|  |  |  | 		me->name = EXPP_incr_ret( v ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-07-02 18:26:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( !strcmp( name, "mode" ) ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		short mode; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !PyInt_Check( v ) ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						    "expected int argument" ); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		mode = ( short ) PyInt_AsLong( v ); | 
					
						
							|  |  |  | 		if( mode >= 0 ) | 
					
						
							|  |  |  | 			me->mode = mode; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 						    "expected positive int argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( !strcmp( name, "verts" ) || !strcmp( name, "faces" ) || | 
					
						
							|  |  |  | 		 !strcmp( name, "materials" ) ) { | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( PySequence_Check( v ) ) { | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( strcmp( name, "materials" ) == 0 ) { | 
					
						
							|  |  |  | 				Py_DECREF( me->materials ); | 
					
						
							|  |  |  | 				me->materials = EXPP_incr_ret( v ); | 
					
						
							|  |  |  | 			} else if( strcmp( name, "verts" ) == 0 ) { | 
					
						
							|  |  |  | 				Py_DECREF( me->verts ); | 
					
						
							|  |  |  | 				me->verts = EXPP_incr_ret( v ); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				Py_DECREF( me->faces ); | 
					
						
							|  |  |  | 				me->faces = EXPP_incr_ret( v ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						    "expected a sequence" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( !strcmp( name, "maxSmoothAngle" ) ) { | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 		short smoothresh = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !PyInt_Check( v ) ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						    "expected int argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		smoothresh = ( short ) PyInt_AsLong( v ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		me->smoothresh = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			EXPP_ClampInt( smoothresh, NMESH_SMOOTHRESH_MIN, | 
					
						
							|  |  |  | 				       NMESH_SMOOTHRESH_MAX ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( !strcmp( name, "subDivLevels" ) ) { | 
					
						
							|  |  |  | 		int subdiv[2] = { 0, 0 }; | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 		int i; | 
					
						
							|  |  |  | 		PyObject *tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !PySequence_Check( v ) || ( PySequence_Length( v ) != 2 ) ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						    "expected a list [int, int] as argument" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for( i = 0; i < 2; i++ ) { | 
					
						
							|  |  |  | 			tmp = PySequence_GetItem( v, i ); | 
					
						
							|  |  |  | 			if( tmp ) { | 
					
						
							|  |  |  | 				if( !PyInt_Check( tmp ) ) { | 
					
						
							|  |  |  | 					Py_DECREF( tmp ); | 
					
						
							|  |  |  | 					return EXPP_ReturnIntError | 
					
						
							|  |  |  | 						( PyExc_TypeError, | 
					
						
							|  |  |  | 						  "expected a list [int, int] as argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 				subdiv[i] = PyInt_AsLong( tmp ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 				me->subdiv[i] = | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 					( short ) EXPP_ClampInt( subdiv[i], | 
					
						
							|  |  |  | 								 NMESH_SUBDIV_MIN, | 
					
						
							|  |  |  | 								 NMESH_SUBDIV_MAX ); | 
					
						
							|  |  |  | 				Py_DECREF( tmp ); | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				return EXPP_ReturnIntError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 							    "couldn't retrieve subdiv values from list" ); | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return EXPP_ReturnIntError( PyExc_AttributeError, name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyTypeObject NMesh_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT( NULL ) 0,	/*ob_size */ | 
					
						
							|  |  |  | 	"Blender NMesh",	/*tp_name */ | 
					
						
							|  |  |  | 	sizeof( BPy_NMesh ),	/*tp_basicsize */ | 
					
						
							|  |  |  | 	0,			/*tp_itemsize */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	( destructor ) NMesh_dealloc,	/*tp_dealloc */ | 
					
						
							|  |  |  | 	( printfunc ) 0,	/*tp_print */ | 
					
						
							|  |  |  | 	( getattrfunc ) NMesh_getattr,	/*tp_getattr */ | 
					
						
							|  |  |  | 	( setattrfunc ) NMesh_setattr,	/*tp_setattr */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static BPy_NMFace *nmface_from_data( BPy_NMesh * mesh, int vidxs[4], | 
					
						
							|  |  |  | 				     char mat_nr, char flag, TFace * tface, | 
					
						
							|  |  |  | 				     MCol * col ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMFace *newf = PyObject_NEW( BPy_NMFace, &NMFace_Type ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int i, len; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( vidxs[3] ) | 
					
						
							|  |  |  | 		len = 4; | 
					
						
							|  |  |  | 	else if( vidxs[2] ) | 
					
						
							|  |  |  | 		len = 3; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		len = 2; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	newf->v = PyList_New( len ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < len; i++ ) | 
					
						
							|  |  |  | 		PyList_SetItem( newf->v, i, | 
					
						
							|  |  |  | 				EXPP_incr_ret( PyList_GetItem | 
					
						
							|  |  |  | 					       ( mesh->verts, vidxs[i] ) ) ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( tface ) { | 
					
						
							|  |  |  | 		newf->uv = PyList_New( len );	// per-face UV coordinates
 | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( i = 0; i < len; i++ ) { | 
					
						
							|  |  |  | 			PyList_SetItem( newf->uv, i, | 
					
						
							|  |  |  | 					Py_BuildValue( "(ff)", tface->uv[i][0], | 
					
						
							|  |  |  | 						       tface->uv[i][1] ) ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( tface->tpage )	/* pointer to image per face: */ | 
					
						
							|  |  |  | 			newf->image = ( Image * ) tface->tpage; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			newf->image = NULL; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		newf->mode = tface->mode;	/* draw mode */ | 
					
						
							|  |  |  | 		newf->flag = tface->flag;	/* select flag */ | 
					
						
							|  |  |  | 		newf->transp = tface->transp;	/* transparency flag */ | 
					
						
							|  |  |  | 		col = ( MCol * ) ( tface->col );	/* XXX weird, tface->col is uint[4] */ | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		newf->mode = TF_DYNAMIC;	/* just to initialize it to something meaninful, */ | 
					
						
							| 
									
										
										
										
											2003-11-08 02:19:09 +00:00
										 |  |  | 		/* since without tfaces there are no tface->mode's, obviously. */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		newf->image = NULL; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		newf->uv = PyList_New( 0 ); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	newf->mat_nr = mat_nr; | 
					
						
							|  |  |  | 	newf->smooth = flag & ME_SMOOTH; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( col ) { | 
					
						
							|  |  |  | 		newf->col = PyList_New( 4 ); | 
					
						
							|  |  |  | 		for( i = 0; i < 4; i++, col++ ) { | 
					
						
							|  |  |  | 			PyList_SetItem( newf->col, i, | 
					
						
							|  |  |  | 					( PyObject * ) newcol( col->b, col->g, | 
					
						
							|  |  |  | 							       col->r, | 
					
						
							|  |  |  | 							       col->a ) ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		newf->col = PyList_New( 0 ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return newf; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static BPy_NMVert *nmvert_from_data( BPy_NMesh * me, | 
					
						
							|  |  |  | 				     MVert * vert, MSticky * st, float *co, | 
					
						
							|  |  |  | 				     int idx, char flag ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMVert *mv = PyObject_NEW( BPy_NMVert, &NMVert_Type ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mv->co[0] = co[0]; | 
					
						
							|  |  |  | 	mv->co[1] = co[1]; | 
					
						
							|  |  |  | 	mv->co[2] = co[2]; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mv->no[0] = vert->no[0] / 32767.0; | 
					
						
							|  |  |  | 	mv->no[1] = vert->no[1] / 32767.0; | 
					
						
							|  |  |  | 	mv->no[2] = vert->no[2] / 32767.0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( st ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		mv->uvco[0] = st->co[0]; | 
					
						
							|  |  |  | 		mv->uvco[1] = st->co[1]; | 
					
						
							|  |  |  | 		mv->uvco[2] = 0.0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		mv->uvco[0] = mv->uvco[1] = mv->uvco[2] = 0.0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mv->index = idx; | 
					
						
							| 
									
										
										
										
											2004-01-20 04:57:47 +00:00
										 |  |  | 	mv->flag = flag & 1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return mv; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int get_active_faceindex( Mesh * me ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	TFace *tf; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( me == NULL ) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	tf = me->tface; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( tf == 0 ) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < me->totface; i++ ) | 
					
						
							|  |  |  | 		if( tf[i].flag & TF_ACTIVE ) | 
					
						
							|  |  |  | 			return i; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return -1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *new_NMesh_internal( Mesh * oldmesh, | 
					
						
							|  |  |  | 				     DispListMesh * dlm, float *extverts ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *me = PyObject_NEW( BPy_NMesh, &NMesh_Type ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	me->flags = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	me->mode = EXPP_NMESH_MODE_TWOSIDED;	/* default for new meshes */ | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 	me->subdiv[0] = NMESH_SUBDIV; | 
					
						
							|  |  |  | 	me->subdiv[1] = NMESH_SUBDIV; | 
					
						
							|  |  |  | 	me->smoothresh = NMESH_SMOOTHRESH; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	me->object = NULL;	/* not linked to any object yet */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !oldmesh ) { | 
					
						
							|  |  |  | 		me->name = EXPP_incr_ret( Py_None ); | 
					
						
							|  |  |  | 		me->materials = PyList_New( 0 ); | 
					
						
							|  |  |  | 		me->verts = PyList_New( 0 ); | 
					
						
							|  |  |  | 		me->faces = PyList_New( 0 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		me->mesh = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		MVert *mverts; | 
					
						
							|  |  |  | 		MSticky *msticky; | 
					
						
							|  |  |  | 		MFace *mfaces; | 
					
						
							|  |  |  | 		TFace *tfaces; | 
					
						
							|  |  |  | 		MCol *mcols; | 
					
						
							|  |  |  | 		int i, totvert, totface; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( dlm ) { | 
					
						
							|  |  |  | 			me->name = EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			me->mesh = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			msticky = NULL; | 
					
						
							|  |  |  | 			mfaces = NULL; | 
					
						
							|  |  |  | 			mverts = dlm->mvert; | 
					
						
							| 
									
										
										
										
											2004-03-14 21:21:08 +00:00
										 |  |  | 			mfaces = dlm->mface; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			tfaces = dlm->tface; | 
					
						
							|  |  |  | 			mcols = dlm->mcol; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			totvert = dlm->totvert; | 
					
						
							|  |  |  | 			totface = dlm->totface; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			me->name = PyString_FromString( oldmesh->id.name + 2 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			me->mesh = oldmesh; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			me->mode = oldmesh->flag;	/* yes, we save the mesh flags in nmesh->mode */ | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 			me->subdiv[0] = oldmesh->subdiv; | 
					
						
							|  |  |  | 			me->subdiv[1] = oldmesh->subdivr; | 
					
						
							|  |  |  | 			me->smoothresh = oldmesh->smoothresh; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			msticky = oldmesh->msticky; | 
					
						
							|  |  |  | 			mverts = oldmesh->mvert; | 
					
						
							|  |  |  | 			mfaces = oldmesh->mface; | 
					
						
							|  |  |  | 			tfaces = oldmesh->tface; | 
					
						
							|  |  |  | 			mcols = oldmesh->mcol; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			totvert = oldmesh->totvert; | 
					
						
							|  |  |  | 			totface = oldmesh->totface; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			me->sel_face = get_active_faceindex( oldmesh ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( msticky ) | 
					
						
							|  |  |  | 			me->flags |= NMESH_HASVERTUV; | 
					
						
							|  |  |  | 		if( tfaces ) | 
					
						
							|  |  |  | 			me->flags |= NMESH_HASFACEUV; | 
					
						
							|  |  |  | 		if( mcols ) | 
					
						
							|  |  |  | 			me->flags |= NMESH_HASMCOL; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		me->verts = PyList_New( totvert ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( i = 0; i < totvert; i++ ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			MVert *oldmv = &mverts[i]; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			MSticky *oldst = msticky ? &msticky[i] : NULL; | 
					
						
							|  |  |  | 			float *vco = extverts ? &extverts[i * 3] : oldmv->co; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			PyList_SetItem( me->verts, i, | 
					
						
							|  |  |  | 					( PyObject * ) nmvert_from_data( me, | 
					
						
							|  |  |  | 									 oldmv, | 
					
						
							|  |  |  | 									 oldst, | 
					
						
							|  |  |  | 									 vco, | 
					
						
							|  |  |  | 									 i, | 
					
						
							|  |  |  | 									 oldmv-> | 
					
						
							|  |  |  | 									 flag ) ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		me->faces = PyList_New( totface ); | 
					
						
							|  |  |  | 		for( i = 0; i < totface; i++ ) { | 
					
						
							|  |  |  | 			TFace *oldtf = tfaces ? &tfaces[i] : NULL; | 
					
						
							|  |  |  | 			MCol *oldmc = mcols ? &mcols[i * 4] : NULL; | 
					
						
							| 
									
										
										
										
											2004-03-14 21:21:08 +00:00
										 |  |  | 			MFace *oldmf = &mfaces[i]; | 
					
						
							|  |  |  | 			int vidxs[4]; | 
					
						
							|  |  |  | 			vidxs[0] = oldmf->v1; | 
					
						
							|  |  |  | 			vidxs[1] = oldmf->v2; | 
					
						
							|  |  |  | 			vidxs[2] = oldmf->v3; | 
					
						
							|  |  |  | 			vidxs[3] = oldmf->v4; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			PyList_SetItem( me->faces, i, | 
					
						
							|  |  |  | 					( PyObject * ) nmface_from_data( me, | 
					
						
							|  |  |  | 									 vidxs, | 
					
						
							|  |  |  | 									 oldmf-> | 
					
						
							|  |  |  | 									 mat_nr, | 
					
						
							|  |  |  | 									 oldmf-> | 
					
						
							|  |  |  | 									 flag, | 
					
						
							|  |  |  | 									 oldtf, | 
					
						
							|  |  |  | 									 oldmc ) ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		me->materials = | 
					
						
							|  |  |  | 			EXPP_PyList_fromMaterialList( oldmesh->mat, | 
					
						
							|  |  |  | 						      oldmesh->totcol, 0 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( PyObject * ) me; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *new_NMesh( Mesh * oldmesh ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return new_NMesh_internal( oldmesh, NULL, NULL ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_New( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	char *name = NULL; | 
					
						
							|  |  |  | 	PyObject *ret = NULL; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|s", &name ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected nothing or a string as argument" ); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	ret = new_NMesh( NULL ); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ret && name ) { | 
					
						
							|  |  |  | 		BPy_NMesh *nmesh = ( BPy_NMesh * ) ret; | 
					
						
							|  |  |  | 		Py_DECREF( nmesh->name ); | 
					
						
							|  |  |  | 		nmesh->name = PyString_FromString( name ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_GetRaw( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	char *name = NULL; | 
					
						
							|  |  |  | 	Mesh *oldmesh = NULL; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "|s", &name ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected string argument (or nothing)" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( name ) { | 
					
						
							|  |  |  | 		oldmesh = ( Mesh * ) GetIdFromList( &( G.main->mesh ), name ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !oldmesh ) | 
					
						
							|  |  |  | 			return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return new_NMesh( oldmesh ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | /* Note: NMesh.GetRawFromObject gets the display list mesh from Blender:
 | 
					
						
							|  |  |  |  * the vertices are already transformed / deformed. */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_GetRawFromObject( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	char *name; | 
					
						
							|  |  |  | 	Object *ob; | 
					
						
							|  |  |  | 	PyObject *nmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "s", &name ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected string argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	ob = ( Object * ) GetIdFromList( &( G.main->object ), name ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !ob ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, name ); | 
					
						
							|  |  |  | 	else if( ob->type != OB_MESH ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "Object does not have Mesh data" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		Mesh *me = ( Mesh * ) ob->data; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		DispList *dl; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( mesh_uses_displist( me ) | 
					
						
							|  |  |  | 		    && ( dl = find_displist( &me->disp, DL_MESH ) ) ) | 
					
						
							|  |  |  | 			nmesh = new_NMesh_internal( me, dl->mesh, NULL ); | 
					
						
							|  |  |  | 		else if( ( dl = find_displist( &ob->disp, DL_VERTS ) ) ) | 
					
						
							|  |  |  | 			nmesh = new_NMesh_internal( me, NULL, dl->verts ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			nmesh = new_NMesh( me ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | /* @hack: to mark that (deformed) mesh is readonly, so the update function
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  |  * will not try to write it. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	( ( BPy_NMesh * ) nmesh )->mesh = 0; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return nmesh; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void mvert_from_data( MVert * mv, MSticky * st, BPy_NMVert * from ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mv->co[0] = from->co[0]; | 
					
						
							|  |  |  | 	mv->co[1] = from->co[1]; | 
					
						
							|  |  |  | 	mv->co[2] = from->co[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mv->no[0] = from->no[0] * 32767.0; | 
					
						
							|  |  |  | 	mv->no[1] = from->no[1] * 32767.0; | 
					
						
							|  |  |  | 	mv->no[2] = from->no[2] * 32767.0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mv->flag = ( from->flag & 1 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mv->mat_nr = 0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( st ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		st->co[0] = from->uvco[0]; | 
					
						
							|  |  |  | 		st->co[1] = from->uvco[1]; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*@ TODO: this function is just a added hack. Don't look at the
 | 
					
						
							|  |  |  |  * RGBA/BRGA confusion, it just works, but will never work with | 
					
						
							|  |  |  |  * a restructured Blender */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void assign_perFaceColors( TFace * tf, BPy_NMFace * from ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	MCol *col; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	col = ( MCol * ) ( tf->col ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( col ) { | 
					
						
							|  |  |  | 		int len = PySequence_Length( from->col ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if( len > 4 ) | 
					
						
							|  |  |  | 			len = 4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for( i = 0; i < len; i++, col++ ) { | 
					
						
							|  |  |  | 			BPy_NMCol *mc = | 
					
						
							|  |  |  | 				( BPy_NMCol * ) PySequence_GetItem( from->col, | 
					
						
							|  |  |  | 								    i ); | 
					
						
							|  |  |  | 			if( !BPy_NMCol_Check( mc ) ) { | 
					
						
							|  |  |  | 				Py_DECREF( mc ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			col->r = mc->b; | 
					
						
							|  |  |  | 			col->b = mc->r; | 
					
						
							|  |  |  | 			col->g = mc->g; | 
					
						
							|  |  |  | 			col->a = mc->a; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			Py_DECREF( mc ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int assignFaceUV( TFace * tf, BPy_NMFace * nmface ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	PyObject *fuv, *tmp; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fuv = nmface->uv; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( PySequence_Length( fuv ) == 0 ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	/* fuv = [(u_1, v_1), ... (u_n, v_n)] */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < PySequence_Length( fuv ); i++ ) { | 
					
						
							|  |  |  | 		tmp = PyList_GetItem( fuv, i );	/* stolen reference ! */ | 
					
						
							|  |  |  | 		if( !PyArg_ParseTuple | 
					
						
							|  |  |  | 		    ( tmp, "ff", &( tf->uv[i][0] ), &( tf->uv[i][1] ) ) ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( nmface->image ) {	/* image assigned ? */ | 
					
						
							|  |  |  | 		tf->tpage = ( void * ) nmface->image; | 
					
						
							|  |  |  | 	} else | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		tf->tpage = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	tf->mode = nmface->mode;	/* copy mode */ | 
					
						
							|  |  |  | 	tf->flag = nmface->flag;	/* copy flag */ | 
					
						
							|  |  |  | 	tf->transp = nmface->transp;	/* copy transp flag */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* assign vertex colours */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	assign_perFaceColors( tf, nmface ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void mface_from_data( MFace * mf, TFace * tf, MCol * col, | 
					
						
							|  |  |  | 			     BPy_NMFace * from ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	BPy_NMVert *nmv; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	int i = PyList_Size( from->v ); | 
					
						
							|  |  |  | 	if( i >= 1 ) { | 
					
						
							|  |  |  | 		nmv = ( BPy_NMVert * ) PyList_GetItem( from->v, 0 ); | 
					
						
							|  |  |  | 		if( BPy_NMVert_Check( nmv ) && nmv->index != -1 ) | 
					
						
							|  |  |  | 			mf->v1 = nmv->index; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			mf->v1 = 0; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( i >= 2 ) { | 
					
						
							|  |  |  | 		nmv = ( BPy_NMVert * ) PyList_GetItem( from->v, 1 ); | 
					
						
							|  |  |  | 		if( BPy_NMVert_Check( nmv ) && nmv->index != -1 ) | 
					
						
							|  |  |  | 			mf->v2 = nmv->index; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			mf->v2 = 0; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( i >= 3 ) { | 
					
						
							|  |  |  | 		nmv = ( BPy_NMVert * ) PyList_GetItem( from->v, 2 ); | 
					
						
							|  |  |  | 		if( BPy_NMVert_Check( nmv ) && nmv->index != -1 ) | 
					
						
							|  |  |  | 			mf->v3 = nmv->index; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			mf->v3 = 0; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( i >= 4 ) { | 
					
						
							|  |  |  | 		nmv = ( BPy_NMVert * ) PyList_GetItem( from->v, 3 ); | 
					
						
							|  |  |  | 		if( BPy_NMVert_Check( nmv ) && nmv->index != -1 ) | 
					
						
							|  |  |  | 			mf->v4 = nmv->index; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			mf->v4 = 0; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( tf ) { | 
					
						
							|  |  |  | 		assignFaceUV( tf, from ); | 
					
						
							|  |  |  | 		if( PyErr_Occurred(  ) ) { | 
					
						
							|  |  |  | 			PyErr_Print(  ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		test_index_face( mf, tf, i ); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		test_index_mface( mf, i ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mf->puno = 0; | 
					
						
							|  |  |  | 	mf->mat_nr = from->mat_nr; | 
					
						
							|  |  |  | 	mf->edcode = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( from->smooth ) | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		mf->flag = ME_SMOOTH; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		mf->flag = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( col ) { | 
					
						
							|  |  |  | 		int len = PySequence_Length( from->col ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( len > 4 ) | 
					
						
							|  |  |  | 			len = 4; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( i = 0; i < len; i++, col++ ) { | 
					
						
							|  |  |  | 			BPy_NMCol *mc = | 
					
						
							|  |  |  | 				( BPy_NMCol * ) PySequence_GetItem( from->col, | 
					
						
							|  |  |  | 								    i ); | 
					
						
							|  |  |  | 			if( !BPy_NMCol_Check( mc ) ) { | 
					
						
							|  |  |  | 				Py_DECREF( mc ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			col->b = mc->r; | 
					
						
							|  |  |  | 			col->g = mc->g; | 
					
						
							|  |  |  | 			col->r = mc->b; | 
					
						
							|  |  |  | 			col->a = mc->a; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			Py_DECREF( mc ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* check for a valid UV sequence */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int check_validFaceUV( BPy_NMesh * nmesh ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	PyObject *faces; | 
					
						
							|  |  |  | 	BPy_NMFace *nmface; | 
					
						
							|  |  |  | 	int i, n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	faces = nmesh->faces; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < PySequence_Length( faces ); i++ ) { | 
					
						
							|  |  |  | 		nmface = ( BPy_NMFace * ) PyList_GetItem( faces, i ); | 
					
						
							|  |  |  | 		n = PySequence_Length( nmface->uv ); | 
					
						
							|  |  |  | 		if( n != PySequence_Length( nmface->v ) ) { | 
					
						
							|  |  |  | 			if( n > 0 ) | 
					
						
							|  |  |  | 				printf( "Warning: different length of vertex and UV coordinate " "list in face!\n" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | /* this is a copy of unlink_mesh in mesh.c, because ... */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | void EXPP_unlink_mesh( Mesh * me ) | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int a; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( me == 0 ) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( a = 0; a < me->totcol; a++ ) { | 
					
						
							|  |  |  | 		if( me->mat[a] ) | 
					
						
							|  |  |  | 			me->mat[a]->id.us--; | 
					
						
							|  |  |  | 		me->mat[a] = 0; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-11-07 15:05:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | /*	... here we want to preserve mesh keys */ | 
					
						
							| 
									
										
										
										
											2003-08-02 03:37:16 +00:00
										 |  |  | /* if users want to get rid of them, they can use mesh.removeAllKeys() */ | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	if(me->key) me->key->id.us--; | 
					
						
							|  |  |  | 	me->key= 0; | 
					
						
							| 
									
										
										
										
											2003-07-12 18:02:54 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( me->texcomesh ) | 
					
						
							|  |  |  | 		me->texcomesh = 0; | 
					
						
							| 
									
										
										
										
											2004-11-07 15:05:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	me->totcol = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int unlink_existingMeshData( Mesh * mesh ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	freedisplist( &mesh->disp ); | 
					
						
							|  |  |  | 	EXPP_unlink_mesh( mesh ); | 
					
						
							|  |  |  | 	if( mesh->mvert ) | 
					
						
							|  |  |  | 		MEM_freeN( mesh->mvert ); | 
					
						
							| 
									
										
										
										
											2004-11-08 19:58:04 +00:00
										 |  |  | 	if( mesh->medge ) | 
					
						
							|  |  |  | 		MEM_freeN( mesh->medge ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( mesh->mface ) | 
					
						
							|  |  |  | 		MEM_freeN( mesh->mface ); | 
					
						
							|  |  |  | 	if( mesh->mcol ) | 
					
						
							|  |  |  | 		MEM_freeN( mesh->mcol ); | 
					
						
							|  |  |  | 	if( mesh->msticky ) | 
					
						
							|  |  |  | 		MEM_freeN( mesh->msticky ); | 
					
						
							|  |  |  | 	if( mesh->mat ) | 
					
						
							|  |  |  | 		MEM_freeN( mesh->mat ); | 
					
						
							|  |  |  | 	if( mesh->tface ) | 
					
						
							|  |  |  | 		MEM_freeN( mesh->tface ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | Material **nmesh_updateMaterials( BPy_NMesh * nmesh ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	Material **matlist; | 
					
						
							|  |  |  | 	Mesh *mesh = nmesh->mesh; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	int len = PyList_Size( nmesh->materials ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !mesh ) { | 
					
						
							|  |  |  | 		printf( "FATAL INTERNAL ERROR: illegal call to updateMaterials()\n" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( len > 0 ) { | 
					
						
							|  |  |  | 		matlist = EXPP_newMaterialList_fromPyList( nmesh->materials ); | 
					
						
							|  |  |  | 		EXPP_incr_mats_us( matlist, len ); | 
					
						
							| 
									
										
										
										
											2003-07-05 01:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( mesh->mat ) | 
					
						
							|  |  |  | 			MEM_freeN( mesh->mat ); | 
					
						
							| 
									
										
										
										
											2003-07-05 01:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		mesh->mat = matlist; | 
					
						
							| 
									
										
										
										
											2003-07-05 01:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		matlist = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	mesh->totcol = len; | 
					
						
							| 
									
										
										
										
											2004-01-16 23:40:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**@ This is another ugly fix due to the weird material handling of blender.
 | 
					
						
							|  |  |  | 	* it makes sure that object material lists get updated (by their length) | 
					
						
							|  |  |  | 	* according to their data material lists, otherwise blender crashes. | 
					
						
							|  |  |  | 	* It just stupidly runs through all objects...BAD BAD BAD. | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	test_object_materials( ( ID * ) mesh ); | 
					
						
							| 
									
										
										
										
											2004-01-16 23:40:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return matlist; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *NMesh_assignMaterials_toObject( BPy_NMesh * nmesh, Object * ob ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	BPy_Material *pymat; | 
					
						
							|  |  |  | 	Material *ma; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	short old_matmask; | 
					
						
							|  |  |  | 	Mesh *mesh = nmesh->mesh; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	int nmats;		/* number of mats == len(nmesh->materials) */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	old_matmask = ob->colbits;	/*@ HACK: save previous colbits */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	ob->colbits = 0;	/* make assign_material work on mesh linked material */ | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	nmats = PyList_Size( nmesh->materials ); | 
					
						
							| 
									
										
										
										
											2003-07-02 18:26:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( nmats > 0 && !mesh->mat ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		ob->totcol = nmats; | 
					
						
							|  |  |  | 		mesh->totcol = nmats; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		mesh->mat = | 
					
						
							|  |  |  | 			MEM_callocN( sizeof( void * ) * nmats, "bpy_memats" ); | 
					
						
							| 
									
										
										
										
											2003-07-05 01:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( ob->mat ) | 
					
						
							|  |  |  | 			MEM_freeN( ob->mat ); | 
					
						
							|  |  |  | 		ob->mat = | 
					
						
							|  |  |  | 			MEM_callocN( sizeof( void * ) * nmats, "bpy_obmats" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-07-02 18:26:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < nmats; i++ ) { | 
					
						
							|  |  |  | 		pymat = ( BPy_Material * ) PySequence_GetItem( nmesh-> | 
					
						
							|  |  |  | 							       materials, i ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( Material_CheckPyObject( ( PyObject * ) pymat ) ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			ma = pymat->material; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			assign_material( ob, ma, i + 1 );	/*@ XXX don't use this function anymore */ | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			Py_DECREF( pymat ); | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 						      "expected Material type in attribute list 'materials'!" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		Py_DECREF( pymat ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	ob->colbits = old_matmask;	/*@ HACK */ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	ob->actcol = 1; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static int convert_NMeshToMesh( Mesh * mesh, BPy_NMesh * nmesh ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	MFace *newmf; | 
					
						
							|  |  |  | 	TFace *newtf; | 
					
						
							|  |  |  | 	MVert *newmv; | 
					
						
							|  |  |  | 	MSticky *newst; | 
					
						
							|  |  |  | 	MCol *newmc; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int i, j; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mesh->mvert = NULL; | 
					
						
							| 
									
										
										
										
											2004-11-08 19:58:04 +00:00
										 |  |  | 	mesh->medge = NULL; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mesh->mface = NULL; | 
					
						
							|  |  |  | 	mesh->mcol = NULL; | 
					
						
							|  |  |  | 	mesh->msticky = NULL; | 
					
						
							|  |  |  | 	mesh->tface = NULL; | 
					
						
							|  |  |  | 	mesh->mat = NULL; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 	/* Minor note: we used 'mode' because 'flag' was already used internally
 | 
					
						
							|  |  |  | 	 * by nmesh */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	mesh->flag = nmesh->mode; | 
					
						
							| 
									
										
										
										
											2003-10-26 06:03:18 +00:00
										 |  |  | 	mesh->smoothresh = nmesh->smoothresh; | 
					
						
							|  |  |  | 	mesh->subdiv = nmesh->subdiv[0]; | 
					
						
							|  |  |  | 	mesh->subdivr = nmesh->subdiv[1]; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	/*@ material assignment moved to PutRaw */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	mesh->totvert = PySequence_Length( nmesh->verts ); | 
					
						
							|  |  |  | 	if( mesh->totvert ) { | 
					
						
							|  |  |  | 		if( nmesh->flags & NMESH_HASVERTUV ) | 
					
						
							|  |  |  | 			mesh->msticky = | 
					
						
							|  |  |  | 				MEM_callocN( sizeof( MSticky ) * mesh->totvert, | 
					
						
							|  |  |  | 					     "msticky" ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		mesh->mvert = | 
					
						
							|  |  |  | 			MEM_callocN( sizeof( MVert ) * mesh->totvert, | 
					
						
							|  |  |  | 				     "mverts" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( mesh->totvert ) | 
					
						
							|  |  |  | 		mesh->totface = PySequence_Length( nmesh->faces ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		mesh->totface = 0; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( mesh->totface ) { | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | /*@ only create vertcol array if mesh has no texture faces */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*@ TODO: get rid of double storage of vertex colours. In a mesh,
 | 
					
						
							|  |  |  |  * vertex colors can be stored the following ways: | 
					
						
							|  |  |  |  * - per (TFace*)->col | 
					
						
							|  |  |  |  * - per (Mesh*)->mcol | 
					
						
							|  |  |  |  * This is stupid, but will reside for the time being -- at least until | 
					
						
							|  |  |  |  * a redesign of the internal Mesh structure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !( nmesh->flags & NMESH_HASFACEUV ) | 
					
						
							|  |  |  | 		    && ( nmesh->flags & NMESH_HASMCOL ) ) | 
					
						
							|  |  |  | 			mesh->mcol = | 
					
						
							|  |  |  | 				MEM_callocN( 4 * sizeof( MCol ) * | 
					
						
							|  |  |  | 					     mesh->totface, "mcol" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		mesh->mface = | 
					
						
							|  |  |  | 			MEM_callocN( sizeof( MFace ) * mesh->totface, | 
					
						
							|  |  |  | 				     "mfaces" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*@ This stuff here is to tag all the vertices referenced
 | 
					
						
							|  |  |  | 	 * by faces, then untag the vertices which are actually | 
					
						
							|  |  |  | 	 * in the vert list. Any vertices untagged will be ignored | 
					
						
							|  |  |  | 	 * by the mface_from_data function. It comes from my | 
					
						
							|  |  |  | 	 * screwed up decision to not make faces only store the | 
					
						
							|  |  |  | 	 * index. - Zr | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < mesh->totface; i++ ) { | 
					
						
							|  |  |  | 		BPy_NMFace *mf = | 
					
						
							|  |  |  | 			( BPy_NMFace * ) PySequence_GetItem( nmesh->faces, i ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		j = PySequence_Length( mf->v ); | 
					
						
							|  |  |  | 		while( j-- ) { | 
					
						
							|  |  |  | 			BPy_NMVert *mv = | 
					
						
							|  |  |  | 				( BPy_NMVert * ) PySequence_GetItem( mf->v, | 
					
						
							|  |  |  | 								     j ); | 
					
						
							|  |  |  | 			if( BPy_NMVert_Check( mv ) ) | 
					
						
							|  |  |  | 				mv->index = -1; | 
					
						
							|  |  |  | 			Py_DECREF( mv ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		Py_DECREF( mf ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < mesh->totvert; i++ ) { | 
					
						
							|  |  |  | 		BPy_NMVert *mv = | 
					
						
							|  |  |  | 			( BPy_NMVert * ) PySequence_GetItem( nmesh->verts, i ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		mv->index = i; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		Py_DECREF( mv ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	newmv = mesh->mvert; | 
					
						
							|  |  |  | 	newst = mesh->msticky; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( i = 0; i < mesh->totvert; i++ ) { | 
					
						
							|  |  |  | 		PyObject *mv = PySequence_GetItem( nmesh->verts, i ); | 
					
						
							|  |  |  | 		mvert_from_data( newmv, newst, ( BPy_NMVert * ) mv ); | 
					
						
							|  |  |  | 		Py_DECREF( mv ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		newmv++; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( newst ) | 
					
						
							|  |  |  | 			newst++; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*	assign per face texture UVs */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* check face UV flag, then check whether there was one 
 | 
					
						
							|  |  |  | 	 * UV coordinate assigned, if yes, make tfaces */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( nmesh->flags & NMESH_HASFACEUV ) | 
					
						
							|  |  |  | 	    || ( check_validFaceUV( nmesh ) ) ) { | 
					
						
							|  |  |  | 		make_tfaces( mesh );	/* initialize TFaces */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		newmc = mesh->mcol; | 
					
						
							|  |  |  | 		newmf = mesh->mface; | 
					
						
							|  |  |  | 		newtf = mesh->tface; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( i = 0; i < mesh->totface; i++ ) { | 
					
						
							|  |  |  | 			PyObject *mf = PySequence_GetItem( nmesh->faces, i ); | 
					
						
							|  |  |  | 			mface_from_data( newmf, newtf, newmc, | 
					
						
							|  |  |  | 					 ( BPy_NMFace * ) mf ); | 
					
						
							|  |  |  | 			Py_DECREF( mf ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			newtf++; | 
					
						
							|  |  |  | 			newmf++; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( newmc ) | 
					
						
							|  |  |  | 				newmc += 4; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		nmesh->flags |= NMESH_HASFACEUV; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		newmc = mesh->mcol; | 
					
						
							|  |  |  | 		newmf = mesh->mface; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( i = 0; i < mesh->totface; i++ ) { | 
					
						
							|  |  |  | 			PyObject *mf = PySequence_GetItem( nmesh->faces, i ); | 
					
						
							|  |  |  | 			mface_from_data( newmf, 0, newmc, | 
					
						
							|  |  |  | 					 ( BPy_NMFace * ) mf ); | 
					
						
							|  |  |  | 			Py_DECREF( mf ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			newmf++; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( newmc ) | 
					
						
							|  |  |  | 				newmc += 4;	/* there are 4 MCol's per face */ | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-01-15 12:55:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_PutRaw( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	char *name = NULL; | 
					
						
							|  |  |  | 	Mesh *mesh = NULL; | 
					
						
							|  |  |  | 	Object *ob = NULL; | 
					
						
							|  |  |  | 	BPy_NMesh *nmesh; | 
					
						
							|  |  |  | 	int recalc_normals = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "O!|si", | 
					
						
							|  |  |  | 			       &NMesh_Type, &nmesh, &name, &recalc_normals ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "expected an NMesh object and optionally also a string and an int" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PySequence_Check( nmesh->verts ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "nmesh vertices are not a sequence" ); | 
					
						
							|  |  |  | 	if( !PySequence_Check( nmesh->faces ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "nmesh faces are not a sequence" ); | 
					
						
							|  |  |  | 	if( !PySequence_Check( nmesh->materials ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "nmesh materials are not a sequence" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( EXPP_check_sequence_consistency( nmesh->verts, &NMVert_Type ) != | 
					
						
							|  |  |  | 	    1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "nmesh vertices must be NMVerts" ); | 
					
						
							|  |  |  | 	if( EXPP_check_sequence_consistency( nmesh->faces, &NMFace_Type ) != | 
					
						
							|  |  |  | 	    1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "nmesh faces must be NMFaces" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( name ) | 
					
						
							|  |  |  | 		mesh = ( Mesh * ) GetIdFromList( &( G.main->mesh ), name ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !mesh || mesh->id.us == 0 ) { | 
					
						
							|  |  |  | 		ob = add_object( OB_MESH ); | 
					
						
							|  |  |  | 		if( !ob ) { | 
					
						
							|  |  |  | 			PyErr_SetString( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					 "Fatal: could not create mesh object" ); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( !mesh ) | 
					
						
							|  |  |  | 			mesh = ( Mesh * ) ob->data; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			set_mesh( ob, mesh );	// also does id.us++
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( name ) | 
					
						
							|  |  |  | 		new_id( &( G.main->mesh ), &mesh->id, name ); | 
					
						
							|  |  |  | 	else if( nmesh->name && nmesh->name != Py_None ) | 
					
						
							|  |  |  | 		new_id( &( G.main->mesh ), &mesh->id, | 
					
						
							|  |  |  | 			PyString_AsString( nmesh->name ) ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	unlink_existingMeshData( mesh ); | 
					
						
							|  |  |  | 	convert_NMeshToMesh( mesh, nmesh ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	nmesh->mesh = mesh; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( recalc_normals ) | 
					
						
							|  |  |  | 		vertexnormals_mesh( mesh, 0 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mesh_update( mesh ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !during_script(  ) ) | 
					
						
							|  |  |  | 		allqueue( REDRAWVIEW3D, 0 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// @OK...this requires some explanation:
 | 
					
						
							|  |  |  | 	// Materials can be assigned two ways:
 | 
					
						
							|  |  |  | 	// a) to the object data (in this case, the mesh)
 | 
					
						
							|  |  |  | 	// b) to the Object
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Case a) is wanted, if Mesh data should be shared among objects,
 | 
					
						
							|  |  |  | 	// as well as its materials (up to 16)
 | 
					
						
							|  |  |  | 	// Case b) is wanted, when Mesh data should be shared, but not the
 | 
					
						
							|  |  |  | 	// materials. For example, you want several checker boards sharing their
 | 
					
						
							|  |  |  | 	// mesh data, but having different colors. So you would assign material
 | 
					
						
							|  |  |  | 	// index 0 to all even, index 1 to all odd faces and bind the materials
 | 
					
						
							|  |  |  | 	// to the Object instead (MaterialButtons: [OB] "link materials to object")
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This feature implies that pointers to materials can be stored in
 | 
					
						
							|  |  |  | 	// an object or a mesh. The number of total materials MUST be
 | 
					
						
							|  |  |  | 	// synchronized (ob->totcol <-> mesh->totcol). We avoid the dangerous
 | 
					
						
							|  |  |  | 	// direct access by calling blenderkernel/material.c:assign_material().
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// The flags setting the material binding is found in ob->colbits, where 
 | 
					
						
							|  |  |  | 	// each bit indicates the binding PER MATERIAL 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ob ) {		// we created a new object
 | 
					
						
							|  |  |  | 		nmesh->object = ob;	// linking so vgrouping methods know which obj to work on
 | 
					
						
							|  |  |  | 		NMesh_assignMaterials_toObject( nmesh, ob ); | 
					
						
							|  |  |  | 		EXPP_synchronizeMaterialLists( ob ); | 
					
						
							|  |  |  | 		return Object_CreatePyObject( ob ); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		mesh->mat = | 
					
						
							|  |  |  | 			EXPP_newMaterialList_fromPyList( nmesh->materials ); | 
					
						
							|  |  |  | 		EXPP_incr_mats_us( mesh->mat, | 
					
						
							|  |  |  | 				   PyList_Size( nmesh->materials ) ); | 
					
						
							|  |  |  | 		return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef MethodDef
 | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | #define MethodDef(func) \
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	{#func, M_NMesh_##func, METH_VARARGS, M_NMesh_##func##_doc} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct PyMethodDef M_NMesh_methods[] = { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	MethodDef( Col ), | 
					
						
							|  |  |  | 	MethodDef( Vert ), | 
					
						
							|  |  |  | 	MethodDef( Face ), | 
					
						
							|  |  |  | 	MethodDef( New ), | 
					
						
							|  |  |  | 	MethodDef( GetRaw ), | 
					
						
							|  |  |  | 	MethodDef( GetRawFromObject ), | 
					
						
							|  |  |  | 	MethodDef( PutRaw ), | 
					
						
							| 
									
										
										
										
											2004-06-06 22:42:51 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_Modes( void ) | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *Modes = M_constant_New(  ); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( Modes ) { | 
					
						
							|  |  |  | 		BPy_constant *d = ( BPy_constant * ) Modes; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		constant_insert( d, "NOVNORMALSFLIP", | 
					
						
							|  |  |  | 				 PyInt_FromLong | 
					
						
							|  |  |  | 				 ( EXPP_NMESH_MODE_NOPUNOFLIP ) ); | 
					
						
							|  |  |  | 		constant_insert( d, "TWOSIDED", | 
					
						
							|  |  |  | 				 PyInt_FromLong( EXPP_NMESH_MODE_TWOSIDED ) ); | 
					
						
							|  |  |  | 		constant_insert( d, "AUTOSMOOTH", | 
					
						
							|  |  |  | 				 PyInt_FromLong | 
					
						
							|  |  |  | 				 ( EXPP_NMESH_MODE_AUTOSMOOTH ) ); | 
					
						
							|  |  |  | 		constant_insert( d, "SUBSURF", | 
					
						
							|  |  |  | 				 PyInt_FromLong( EXPP_NMESH_MODE_SUBSURF ) ); | 
					
						
							|  |  |  | 		constant_insert( d, "OPTIMAL", | 
					
						
							|  |  |  | 				 PyInt_FromLong( EXPP_NMESH_MODE_OPTIMAL ) ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return Modes; | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | #undef EXPP_ADDCONST
 | 
					
						
							|  |  |  | #define EXPP_ADDCONST(dict, name) \
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			 constant_insert(dict, #name, PyInt_FromLong(TF_##name)) | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | /* Set constants for face drawing mode -- see drawmesh.c */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_FaceModesDict( void ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *FM = M_constant_New(  ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( FM ) { | 
					
						
							|  |  |  | 		BPy_constant *d = ( BPy_constant * ) FM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		constant_insert( d, "BILLBOARD", | 
					
						
							|  |  |  | 				 PyInt_FromLong( TF_BILLBOARD2 ) ); | 
					
						
							|  |  |  | 		constant_insert( d, "ALL", PyInt_FromLong( 0xffff ) ); | 
					
						
							|  |  |  | 		constant_insert( d, "HALO", PyInt_FromLong( TF_BILLBOARD ) ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, DYNAMIC ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, INVISIBLE ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, LIGHT ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, OBCOL ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, SHADOW ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, SHAREDVERT ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, SHAREDCOL ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, TEX ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, TILES ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, TWOSIDE ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return FM; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_FaceFlagsDict( void ) | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *FF = M_constant_New(  ); | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( FF ) { | 
					
						
							|  |  |  | 		BPy_constant *d = ( BPy_constant * ) FF; | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		EXPP_ADDCONST( d, SELECT ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, HIDE ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, ACTIVE ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return FF; | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NMesh_FaceTranspModesDict( void ) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *FTM = M_constant_New(  ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( FTM ) { | 
					
						
							|  |  |  | 		BPy_constant *d = ( BPy_constant * ) FTM; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		EXPP_ADDCONST( d, SOLID ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, ADD ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, ALPHA ); | 
					
						
							|  |  |  | 		EXPP_ADDCONST( d, SUB ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return FTM; | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *NMesh_Init( void ) | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	PyObject *submodule; | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *Modes = M_NMesh_Modes(  ); | 
					
						
							|  |  |  | 	PyObject *FaceFlags = M_NMesh_FaceFlagsDict(  ); | 
					
						
							|  |  |  | 	PyObject *FaceModes = M_NMesh_FaceModesDict(  ); | 
					
						
							|  |  |  | 	PyObject *FaceTranspModes = M_NMesh_FaceTranspModesDict(  ); | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	NMCol_Type.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 	NMFace_Type.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 	NMVert_Type.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 	NMesh_Type.ob_type = &PyType_Type; | 
					
						
							| 
									
										
										
										
											2003-06-02 20:15:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	submodule = | 
					
						
							|  |  |  | 		Py_InitModule3( "Blender.NMesh", M_NMesh_methods, | 
					
						
							|  |  |  | 				M_NMesh_doc ); | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( Modes ) | 
					
						
							|  |  |  | 		PyModule_AddObject( submodule, "Modes", Modes ); | 
					
						
							|  |  |  | 	if( FaceFlags ) | 
					
						
							|  |  |  | 		PyModule_AddObject( submodule, "FaceFlags", FaceFlags ); | 
					
						
							|  |  |  | 	if( FaceModes ) | 
					
						
							|  |  |  | 		PyModule_AddObject( submodule, "FaceModes", FaceModes ); | 
					
						
							|  |  |  | 	if( FaceTranspModes ) | 
					
						
							|  |  |  | 		PyModule_AddObject( submodule, "FaceTranspModes", | 
					
						
							|  |  |  | 				    FaceTranspModes ); | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	g_nmeshmodule = submodule; | 
					
						
							|  |  |  | 	return submodule; | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* These are needed by Object.c */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *NMesh_CreatePyObject( Mesh * me, Object * ob ) | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_NMesh *nmesh = ( BPy_NMesh * ) new_NMesh( me ); | 
					
						
							| 
									
										
										
										
											2003-09-18 00:54:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( nmesh ) | 
					
						
							|  |  |  | 		nmesh->object = ob;	/* linking nmesh and object for vgrouping methods */ | 
					
						
							| 
									
										
										
										
											2003-09-18 00:54:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( PyObject * ) nmesh; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | int NMesh_CheckPyObject( PyObject * pyobj ) | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( pyobj->ob_type == &NMesh_Type ); | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | Mesh *Mesh_FromPyObject( PyObject * pyobj, Object * ob ) | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( pyobj->ob_type == &NMesh_Type ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		Mesh *mesh; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		BPy_NMesh *nmesh = ( BPy_NMesh * ) pyobj; | 
					
						
							| 
									
										
										
										
											2003-09-18 00:54:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( nmesh->mesh ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			mesh = nmesh->mesh; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			unlink_existingMeshData( mesh ); | 
					
						
							|  |  |  | 			convert_NMeshToMesh( mesh, nmesh ); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			nmesh->mesh = Mesh_fromNMesh( nmesh ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 			mesh = nmesh->mesh; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-09-18 00:54:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		nmesh->object = ob;	/* linking for vgrouping methods */ | 
					
						
							| 
									
										
										
										
											2003-09-18 00:54:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( nmesh->name && nmesh->name != Py_None ) | 
					
						
							|  |  |  | 			new_id( &( G.main->mesh ), &mesh->id, | 
					
						
							|  |  |  | 				PyString_AsString( nmesh->name ) ); | 
					
						
							| 
									
										
										
										
											2003-09-20 03:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		mesh_update( mesh ); | 
					
						
							| 
									
										
										
										
											2004-01-16 23:40:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		nmesh_updateMaterials( nmesh ); | 
					
						
							| 
									
										
										
										
											2004-01-16 23:40:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 		return mesh; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-06-13 04:21:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *groupStr; | 
					
						
							|  |  |  | 	struct Object *object; | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 	PyObject *tempStr; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "s", &groupStr ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected string argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( ( BPy_NMesh * ) self )->object == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "mesh must be linked to an object first..." ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	object = ( ( BPy_NMesh * ) self )->object; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 	//get clamped name
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	tempStr = PyString_FromStringAndSize( groupStr, 32 ); | 
					
						
							|  |  |  | 	groupStr = PyString_AsString( tempStr ); | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	add_defgroup_name( object, groupStr ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	allqueue( REDRAWBUTSALL, 1 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_removeVertGroup( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *groupStr; | 
					
						
							|  |  |  | 	struct Object *object; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	int nIndex; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	bDeformGroup *pGroup; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "s", &groupStr ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected string argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( ( BPy_NMesh * ) self )->object == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "mesh must be linked to an object first..." ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	object = ( ( BPy_NMesh * ) self )->object; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	pGroup = get_named_vertexgroup( object, groupStr ); | 
					
						
							|  |  |  | 	if( pGroup == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "group does not exist!" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	nIndex = get_defgroup_num( object, pGroup ); | 
					
						
							|  |  |  | 	if( nIndex == -1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "no deform groups assigned to mesh" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	nIndex++; | 
					
						
							|  |  |  | 	object->actdef = nIndex; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	del_defgroup( object ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	allqueue( REDRAWBUTSALL, 1 ); | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_assignVertsToGroup( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	//listObject is an integer list of vertex indices to add to group
 | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	//groupStr = group name
 | 
					
						
							|  |  |  | 	//weight is a float defining the weight this group has on this vertex
 | 
					
						
							|  |  |  | 	//assignmode = "replace", "add", "subtract"
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	//                                                      replace weight - add addition weight to vertex for this group
 | 
					
						
							|  |  |  | 	//                              - remove group influence from this vertex
 | 
					
						
							| 
									
										
										
										
											2003-10-21 17:25:27 +00:00
										 |  |  | 	//the function will not like it if your in editmode...
 | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *groupStr; | 
					
						
							|  |  |  | 	char *assignmodeStr = NULL; | 
					
						
							|  |  |  | 	int nIndex; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int assignmode; | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 	float weight = 1.0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	struct Object *object; | 
					
						
							|  |  |  | 	bDeformGroup *pGroup; | 
					
						
							|  |  |  | 	PyObject *listObject; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int tempInt; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	int x; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( ( BPy_NMesh * ) self )->object == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "mesh must be linked to an object first..." ); | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple | 
					
						
							|  |  |  | 	    ( args, "sO!fs", &groupStr, &PyList_Type, &listObject, &weight, | 
					
						
							|  |  |  | 	      &assignmodeStr ) ) { | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected string, list,	float, string arguments" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	object = ( ( BPy_NMesh * ) self )->object; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( object->data == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "object contains no data..." ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	pGroup = get_named_vertexgroup( object, groupStr ); | 
					
						
							|  |  |  | 	if( pGroup == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "group does not exist!" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	nIndex = get_defgroup_num( object, pGroup ); | 
					
						
							|  |  |  | 	if( nIndex == -1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "no deform groups assigned to mesh" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( assignmodeStr == NULL ) | 
					
						
							|  |  |  | 		assignmode = 1;	/* default */ | 
					
						
							|  |  |  | 	else if( STREQ( assignmodeStr, "replace" ) ) | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 		assignmode = 1; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( STREQ( assignmodeStr, "add" ) ) | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 		assignmode = 2; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else if( STREQ( assignmodeStr, "subtract" ) ) | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 		assignmode = 3; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return EXPP_ReturnPyObjError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "bad assignment mode" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//makes a set of dVerts corresponding to the mVerts
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !( ( Mesh * ) object->data )->dvert ) { | 
					
						
							|  |  |  | 		create_dverts( ( Mesh * ) object->data ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	//loop list adding verts to group
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( x = 0; x < PyList_Size( listObject ); x++ ) { | 
					
						
							|  |  |  | 		if( ! | 
					
						
							|  |  |  | 		    ( PyArg_Parse | 
					
						
							|  |  |  | 		      ( ( PyList_GetItem( listObject, x ) ), "i", | 
					
						
							|  |  |  | 			&tempInt ) ) ) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 						      "python list integer not parseable" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( tempInt < 0 | 
					
						
							|  |  |  | 		    || tempInt >= ( ( Mesh * ) object->data )->totvert ) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_ValueError, | 
					
						
							|  |  |  | 						      "bad vertex index in list" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		add_vert_defnr( object, nIndex, tempInt, weight, assignmode ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_removeVertsFromGroup( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	//not passing a list will remove all verts from group
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *groupStr; | 
					
						
							|  |  |  | 	int nIndex; | 
					
						
							|  |  |  | 	struct Object *object; | 
					
						
							|  |  |  | 	bDeformGroup *pGroup; | 
					
						
							|  |  |  | 	PyObject *listObject; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int tempInt; | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 	int x, argc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* argc is the number of parameters passed in: 1 (no list given) or 2: */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	argc = PyObject_Length( args ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple | 
					
						
							|  |  |  | 	    ( args, "s|O!", &groupStr, &PyList_Type, &listObject ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected string and optional list argument" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( ( BPy_NMesh * ) self )->object == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "mesh must be linked to an object first..." ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	object = ( ( BPy_NMesh * ) self )->object; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( object->data == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "object contains no data..." ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( !( ( Mesh * ) object->data )->dvert ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "this mesh contains no deform vertices...'" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	pGroup = get_named_vertexgroup( object, groupStr ); | 
					
						
							|  |  |  | 	if( pGroup == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "group does not exist!" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	nIndex = get_defgroup_num( object, pGroup ); | 
					
						
							|  |  |  | 	if( nIndex == -1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "no deform groups assigned to mesh" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( argc == 1 ) {	/* no list given */ | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 		//enter editmode
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		if( ( G.obedit == 0 ) ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 			//set current object
 | 
					
						
							|  |  |  | 			BASACT->object = object; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			G.obedit = BASACT->object; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		//set current vertex group
 | 
					
						
							|  |  |  | 		nIndex++; | 
					
						
							|  |  |  | 		object->actdef = nIndex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//clear all dVerts in active group
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		remove_verts_defgroup( 1 ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		//exit editmode
 | 
					
						
							|  |  |  | 		G.obedit = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		if( G.obedit != 0 )	//remove_vert_def_nr doesn't like it if your in editmode
 | 
					
						
							|  |  |  | 			G.obedit = 0; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 		//loop list adding verts to group
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( x = 0; x < PyList_Size( listObject ); x++ ) { | 
					
						
							|  |  |  | 			if( ! | 
					
						
							|  |  |  | 			    ( PyArg_Parse | 
					
						
							|  |  |  | 			      ( ( PyList_GetItem( listObject, x ) ), "i", | 
					
						
							|  |  |  | 				&tempInt ) ) ) | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 							      "python list integer not parseable" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if( tempInt < 0 | 
					
						
							|  |  |  | 			    || tempInt >= | 
					
						
							|  |  |  | 			    ( ( Mesh * ) object->data )->totvert ) | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError( PyExc_ValueError, | 
					
						
							|  |  |  | 							      "bad vertex index in list" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			remove_vert_def_nr( object, nIndex, tempInt ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	//not passing a list will return all verts from group
 | 
					
						
							|  |  |  | 	//passing indecies not part of the group will not return data in pyList
 | 
					
						
							|  |  |  | 	//can be used as a index/group check for a vertex
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *groupStr; | 
					
						
							|  |  |  | 	int nIndex; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	int weightRet; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	struct Object *object; | 
					
						
							|  |  |  | 	bDeformGroup *pGroup; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	MVert *mvert; | 
					
						
							|  |  |  | 	MDeformVert *dvert; | 
					
						
							|  |  |  | 	float weight; | 
					
						
							|  |  |  | 	int i, k, l1, l2, count; | 
					
						
							|  |  |  | 	int num = 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *tempVertexList = NULL; | 
					
						
							|  |  |  | 	PyObject *vertexList; | 
					
						
							|  |  |  | 	PyObject *listObject; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 	int tempInt; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	int x; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	listObject = ( void * ) -2054456;	//can't use NULL macro because compiler thinks
 | 
					
						
							|  |  |  | 	//it's a 0 and we need to check 0 index vertex pos
 | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	l1 = FALSE; | 
					
						
							|  |  |  | 	l2 = FALSE; | 
					
						
							|  |  |  | 	weightRet = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "s|iO!", &groupStr, &weightRet, | 
					
						
							|  |  |  | 			       &PyList_Type, &listObject ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected string and optional int and list arguments" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( weightRet < 0 || weightRet > 1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "return weights flag must be 0 or 1..." ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( ( BPy_NMesh * ) self )->object == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "mesh must be linked to an object first..." ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	object = ( ( BPy_NMesh * ) self )->object; | 
					
						
							| 
									
										
										
										
											2003-10-12 23:41:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( object->data == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "object contains no data..." ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( ( !( ( Mesh * ) object->data )->dvert ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "this mesh contains no deform vertices...'" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	pGroup = get_named_vertexgroup( object, groupStr ); | 
					
						
							|  |  |  | 	if( pGroup == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "group does not exist!" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	nIndex = get_defgroup_num( object, pGroup ); | 
					
						
							|  |  |  | 	if( nIndex == -1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 					      "no deform groups assigned to mesh" ); | 
					
						
							| 
									
										
										
										
											2004-05-09 02:18:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	//temporary list
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	tempVertexList = PyList_New( ( ( Mesh * ) object->data )->totvert ); | 
					
						
							|  |  |  | 	if( tempVertexList == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "getVertsFromGroup: can't create pylist!" ); | 
					
						
							| 
									
										
										
										
											2004-05-09 02:18:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	count = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( listObject == ( void * ) -2054456 )	//do entire group
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		for( k = 0; k < ( ( Mesh * ) object->data )->totvert; k++ ) { | 
					
						
							|  |  |  | 			dvert = ( ( Mesh * ) object->data )->dvert + k; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for( i = 0; i < dvert->totweight; i++ ) { | 
					
						
							|  |  |  | 				if( dvert->dw[i].def_nr == nIndex ) { | 
					
						
							|  |  |  | 					mvert = ( ( Mesh * ) object->data )-> | 
					
						
							|  |  |  | 						mvert + k; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 					weight = dvert->dw[i].weight; | 
					
						
							|  |  |  | 					//printf("index =%3d weight:%10f\n", k, weight);
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					if( weightRet == 1 ) | 
					
						
							|  |  |  | 						PyList_SetItem( tempVertexList, | 
					
						
							|  |  |  | 								count, | 
					
						
							|  |  |  | 								Py_BuildValue | 
					
						
							|  |  |  | 								( "(i,f)", k, | 
					
						
							|  |  |  | 								  weight ) ); | 
					
						
							|  |  |  | 					else if( weightRet == 0 ) | 
					
						
							|  |  |  | 						PyList_SetItem( tempVertexList, | 
					
						
							|  |  |  | 								count, | 
					
						
							|  |  |  | 								Py_BuildValue | 
					
						
							|  |  |  | 								( "i", k ) ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					count++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} else			//do single vertex
 | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		//loop list adding verts to group
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		for( x = 0; x < PyList_Size( listObject ); x++ ) { | 
					
						
							|  |  |  | 			if( ! | 
					
						
							|  |  |  | 			    ( PyArg_Parse | 
					
						
							|  |  |  | 			      ( ( PyList_GetItem( listObject, x ) ), "i", | 
					
						
							|  |  |  | 				&tempInt ) ) ) | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 							      "python list integer not parseable" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if( tempInt < 0 | 
					
						
							|  |  |  | 			    || tempInt >= | 
					
						
							|  |  |  | 			    ( ( Mesh * ) object->data )->totvert ) | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError( PyExc_ValueError, | 
					
						
							|  |  |  | 							      "bad vertex index in list" ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			num = tempInt; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			dvert = ( ( Mesh * ) object->data )->dvert + num; | 
					
						
							|  |  |  | 			for( i = 0; i < dvert->totweight; i++ ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 				l1 = TRUE; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 				if( dvert->dw[i].def_nr == nIndex ) { | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 					l2 = TRUE; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 					mvert = ( ( Mesh * ) object->data )-> | 
					
						
							|  |  |  | 						mvert + num; | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					weight = dvert->dw[i].weight; | 
					
						
							|  |  |  | 					//printf("index =%3d weight:%10f\n", num, weight);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 					if( weightRet == 1 ) { | 
					
						
							|  |  |  | 						PyList_SetItem( tempVertexList, | 
					
						
							|  |  |  | 								count, | 
					
						
							|  |  |  | 								Py_BuildValue | 
					
						
							|  |  |  | 								( "(i,f)", num, | 
					
						
							|  |  |  | 								  weight ) ); | 
					
						
							|  |  |  | 					} else if( weightRet == 0 ) | 
					
						
							|  |  |  | 						PyList_SetItem( tempVertexList, | 
					
						
							|  |  |  | 								count, | 
					
						
							|  |  |  | 								Py_BuildValue | 
					
						
							|  |  |  | 								( "i", num ) ); | 
					
						
							| 
									
										
										
										
											2003-10-20 18:57:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 					count++; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 				if( l2 == FALSE ) | 
					
						
							|  |  |  | 					printf( "vertex at index %d is not part of passed group...\n", tempInt ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( l1 == FALSE ) | 
					
						
							|  |  |  | 				printf( "vertex at index %d is not assigned to a vertex group...\n", tempInt ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			l1 = l2 = FALSE;	//reset flags
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	//only return what we need
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	vertexList = PyList_GetSlice( tempVertexList, 0, count ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_DECREF( tempVertexList ); | 
					
						
							| 
									
										
										
										
											2004-05-09 02:18:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( vertexList ); | 
					
						
							| 
									
										
										
										
											2003-10-12 16:13:12 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_renameVertGroup( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *oldGr = NULL; | 
					
						
							|  |  |  | 	char *newGr = NULL; | 
					
						
							|  |  |  | 	bDeformGroup *defGroup = NULL; | 
					
						
							|  |  |  | 	/*PyObject *tempStr; */ | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !( ( BPy_NMesh * ) self )->object ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "This mesh must be linked to an object" ); | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "ss", &oldGr, &newGr ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "Expected string & string argument" ); | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	defGroup = | 
					
						
							|  |  |  | 		get_named_vertexgroup( ( ( BPy_NMesh * ) self )->object, | 
					
						
							|  |  |  | 				       oldGr ); | 
					
						
							|  |  |  | 	if( defGroup == NULL ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "Couldn't find the expected vertex group" ); | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//set name
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyOS_snprintf( defGroup->name, 32, newGr ); | 
					
						
							|  |  |  | 	unique_vertexgroup_name( defGroup, ( ( BPy_NMesh * ) self )->object ); | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return EXPP_incr_ret( Py_None ); | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *NMesh_getVertGroupNames( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	bDeformGroup *defGroup; | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 	PyObject *list; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !( ( BPy_NMesh * ) self )->object ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "This mesh must be linked to an object" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list = PyList_New( 0 ); | 
					
						
							|  |  |  | 	for( defGroup = ( ( ( BPy_NMesh * ) self )->object )->defbase.first; | 
					
						
							|  |  |  | 	     defGroup; defGroup = defGroup->next ) { | 
					
						
							|  |  |  | 		if( PyList_Append | 
					
						
							|  |  |  | 		    ( list, PyString_FromString( defGroup->name ) ) < 0 ) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 						      "Couldn't add item to list" ); | 
					
						
							| 
									
										
										
										
											2003-11-17 07:13:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return list; | 
					
						
							|  |  |  | } |