diff options
author | Campbell Barton <ideasman42@gmail.com> | 2006-07-03 03:09:37 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2006-07-03 03:09:37 +0400 |
commit | aaf05a1d20dd991077d59645e963c5cbcbecd6dc (patch) | |
tree | ff3fb5d17d15fa600ec2e36aba702aae502fb7ba | |
parent | f000ce6fbad75de067a076bc12e4c3403b911eed (diff) |
Made geometrys polyfill work with all iterators (not just lists) and updated bpymeshes ngon to ignore polylines with <3 verts.
-rw-r--r-- | release/scripts/bpymodules/BPyMesh.py | 4 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Geometry.c | 48 |
2 files changed, 31 insertions, 21 deletions
diff --git a/release/scripts/bpymodules/BPyMesh.py b/release/scripts/bpymodules/BPyMesh.py index 780bc7ba2f4..5e111340217 100644 --- a/release/scripts/bpymodules/BPyMesh.py +++ b/release/scripts/bpymodules/BPyMesh.py @@ -755,6 +755,8 @@ def ngon(from_data, indices, PREF_FIX_LOOPS= True): for verts in loop_list: while verts and verts[0][1]==verts[-1][1]: verts.pop() + + loop_list= [verts for verts in loop_list if len(verts)>2] # DONE DEALING WITH LOOP FIXING @@ -767,7 +769,7 @@ def ngon(from_data, indices, PREF_FIX_LOOPS= True): vert_map[i+ii]= vert[2] ii+=len(verts) - fill= Blender.Geometry.PolyFill([ [v[0] for v in loop] for loop in loop_list if len(loop) > 2 ]) + fill= Blender.Geometry.PolyFill([ [v[0] for v in loop] for loop in loop_list ]) #draw_loops(loop_list) #raise 'done loop' # map to original indicies diff --git a/source/blender/python/api2_2x/Geometry.c b/source/blender/python/api2_2x/Geometry.c index a6de00a86a1..7d6ba48ca35 100644 --- a/source/blender/python/api2_2x/Geometry.c +++ b/source/blender/python/api2_2x/Geometry.c @@ -46,15 +46,15 @@ #include "gen_utils.h" -//-------------------------DOC STRINGS --------------------------- +/*-------------------------DOC STRINGS ---------------------------*/ static char M_Geometry_doc[] = "The Blender Geometry module\n\n"; static char M_Geometry_PolyFill_doc[] = "(veclist_list) - takes a list of polylines (each point a vector) and returns the point indicies for a polyline filled with triangles"; -//-----------------------METHOD DEFINITIONS ---------------------- +/*-----------------------METHOD DEFINITIONS ----------------------*/ struct PyMethodDef M_Geometry_methods[] = { {"PolyFill", ( PyCFunction ) M_Geometry_PolyFill, METH_VARARGS, M_Geometry_PolyFill_doc}, {NULL, NULL, 0, NULL} }; -//----------------------------MODULE INIT------------------------- +/*----------------------------MODULE INIT-------------------------*/ PyObject *Geometry_Init(void) { PyObject *submodule; @@ -64,12 +64,12 @@ PyObject *Geometry_Init(void) return (submodule); } -//----------------------------------Geometry.PolyFill() ------------------- +/*----------------------------------Geometry.PolyFill() -------------------*/ /* PolyFill function, uses Blenders scanfill to fill multiple poly lines */ PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * args ) { PyObject *tri_list; /*return this list of tri's */ - PyObject *polyLineList, *polyLine, *polyVec; + PyObject *polyLineSeq, *polyLine, *polyVec; int i, len_polylines, len_polypoints; /* display listbase */ @@ -82,27 +82,31 @@ PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * args ) dispbase.first= dispbase.last= NULL; - if( !PyArg_ParseTuple ( args, "O!", &PyList_Type, &polyLineList) ) { - freedisplist(&dispbase); + if(!PyArg_ParseTuple ( args, "O", &polyLineSeq) || !PySequence_Check(polyLineSeq)) { return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a list of poly lines" ); + "expected a sequence of poly lines" ); } - - if (EXPP_check_sequence_consistency( polyLineList, &PyList_Type ) != 1) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a list of lists of vectors" ); - - len_polylines = PySequence_Size( polyLineList ); + len_polylines = PySequence_Size( polyLineSeq ); for( i = 0; i < len_polylines; ++i ) { - polyLine= PySequence_GetItem( polyLineList, i ); + polyLine= PySequence_GetItem( polyLineSeq, i ); + if (!PySequence_Check(polyLineSeq)) { + freedisplist(&dispbase); + Py_DECREF(polyLine); + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected a sequence of poly lines" ); + } + len_polypoints= PySequence_Size( polyLine ); - if (len_polypoints>2) { /* dont bother adding edges as polylines */ - if (EXPP_check_sequence_consistency( polyLine, &vector_Type ) != 1) + if (len_polypoints>0) { /* dont bother adding edges as polylines */ + if (EXPP_check_sequence_consistency( polyLine, &vector_Type ) != 1) { + freedisplist(&dispbase); + Py_DECREF(polyLine); return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a list of poly lines" ); + "expected a sequence of poly lines" ); + } dl= MEM_callocN(sizeof(DispList), "poly disp"); BLI_addtail(&dispbase, dl); @@ -135,14 +139,18 @@ PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * args ) /* now make the list to return */ filldisplist(&dispbase, &dispbase); - /* The faces are stored in a new DisplayList thats added to the head of the listbase */ dl= dispbase.first; tri_list= PyList_New(dl->parts); - index= 0; + if( !tri_list ) { + freedisplist(&dispbase); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "PyList_New() failed" ); + } + index= 0; dl_face= dl->index; while(index < dl->parts) { PyList_SetItem(tri_list, index, Py_BuildValue("iii", dl_face[0], dl_face[1], dl_face[2]) ); |