From cbebe4ad46082198b5a59fd21efeb99b4e6fd7be Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 24 Dec 2008 15:46:26 +0000 Subject: * bpy curve api wouldn't give correct errors for bad arguments when appending nurbs. * the radius on the curves first point was ignored. * mesh_edges2curves.py was giving all points a tilt of 1.0 --- release/scripts/mesh_edges2curves.py | 6 +- source/blender/python/api2_2x/CurNurb.c | 118 +++++++++++++------------------- source/blender/python/api2_2x/Curve.c | 2 - 3 files changed, 49 insertions(+), 77 deletions(-) diff --git a/release/scripts/mesh_edges2curves.py b/release/scripts/mesh_edges2curves.py index 006bdf10b49..670165dda51 100644 --- a/release/scripts/mesh_edges2curves.py +++ b/release/scripts/mesh_edges2curves.py @@ -112,7 +112,7 @@ def mesh2polys(): Window.EditMode(0) me = meshOb.getData(mesh=1) polygons= polysFromMesh(me) - w=t=1 + w = 1.0 cu= Curve.New() cu.name = me.name cu.setFlag(1) @@ -128,7 +128,7 @@ def mesh2polys(): vIdx= 0 v= poly[vIdx] - cu.appendNurb([v.co.x, v.co.y, v.co.z, w, t]) + cu.appendNurb((v.co.x, v.co.y, v.co.z, w)) vIdx += 1 cu[i].type= 0 # Poly Line @@ -139,7 +139,7 @@ def mesh2polys(): # Add all the points in the polyline. while vIdxpntsu; /* @@ -520,81 +517,58 @@ PyObject *CurNurb_appendPointToNurb( Nurb * nurb, PyObject * value ) } else if( PySequence_Check( value ) ) { - size = PySequence_Size( value ); -/* printf("\ndbg: got a sequence of size %d\n", size ); */ - if( size == 4 || size == 5 || size == 6) { - BPoint *tmp; - - tmp = nurb->bp; /* save old pts */ - - nurb->bp = - ( BPoint * ) MEM_mallocN( sizeof( BPoint ) * - ( npoints + 1 ), - "CurNurb_append1" ); - if( !nurb->bp ) - return ( EXPP_ReturnPyObjError - ( PyExc_MemoryError, - "allocation failed" ) ); - - memmove( nurb->bp, tmp, sizeof( BPoint ) * npoints ); - if( tmp ) - MEM_freeN( tmp ); - - ++nurb->pntsu; - /* initialize new BPoint from old */ - memcpy( nurb->bp + npoints, nurb->bp, - sizeof( BPoint ) ); - - for( i = 0; i < 4; ++i ) { - PyObject *item = PySequence_GetItem( value, i ); - - if (item == NULL) - return NULL; - - - nurb->bp[npoints].vec[i] = ( float ) PyFloat_AsDouble( item ); - Py_DECREF( item ); - } - - if (size >= 5) { - PyObject *item = PySequence_GetItem( value, 4 ); - - if (item == NULL) - return NULL; + float xco, yco, zco, wval, tilt=0.0f, radius=1.0f; + PyObject *args; + BPoint *tmp; + + if (PyTuple_Check(args)) { + args= value; + } + else { + args= PySequence_Tuple(value); + } + + if (!PyArg_ParseTuple(args, "ffff|ff", &xco, &yco, &zco, &wval, &tilt, &radius)) { + return EXPP_ReturnPyObjError( PyExc_TypeError, "expected a sequence of 4 to 6 floats" ); + } + + if (args != value) { + Py_DECREF(args); + } + tmp = nurb->bp; /* save old pts */ - nurb->bp[npoints].alfa = ( float ) PyFloat_AsDouble( item ); - Py_DECREF( item ); - } - else { - nurb->bp[npoints].alfa = 0.0f; - } - - if (size == 6) { - PyObject *item = PySequence_GetItem( value, 5 ); + nurb->bp = + ( BPoint * ) MEM_mallocN( sizeof( BPoint ) * + ( npoints + 1 ), + "CurNurb_append1" ); + if( !nurb->bp ) + return ( EXPP_ReturnPyObjError + ( PyExc_MemoryError, + "allocation failed" ) ); - if (item == NULL) - return NULL; + memmove( nurb->bp, tmp, sizeof( BPoint ) * npoints ); + if( tmp ) + MEM_freeN( tmp ); - nurb->bp[npoints].radius = ( float ) PyFloat_AsDouble( item ); - Py_DECREF( item ); - } - else { - nurb->bp[npoints].radius = 1.0f; - } - - nurb->bp[npoints].weight = 0.0; /* softbody weight TODO - add access to this, is zero elsewhere but through blender is 1.0 by default */ - - makeknots( nurb, 1, nurb->flagu >> 1 ); - - } else { - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a sequence of 4 or 6 floats" ); - } + ++nurb->pntsu; + /* initialize new BPoint from old */ + memcpy( nurb->bp + npoints, nurb->bp, + sizeof( BPoint ) ); + + tmp= nurb->bp+npoints; + tmp->vec[0] = xco; + tmp->vec[1] = yco; + tmp->vec[2] = zco; + tmp->vec[3] = wval; + tmp->alfa = tilt; + tmp->radius = radius; + tmp->weight = 0.0; /* softbody weight TODO - add access to this, is zero elsewhere but through blender is 1.0 by default */ + + makeknots( nurb, 1, nurb->flagu >> 1 ); } else { /* bail with error */ - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a sequence of 4 to 6 floats" ); + return EXPP_ReturnPyObjError( PyExc_TypeError, "expected a sequence of 4 to 6 floats" ); } diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c index d1abde19de9..26208e600e6 100644 --- a/source/blender/python/api2_2x/Curve.c +++ b/source/blender/python/api2_2x/Curve.c @@ -822,7 +822,6 @@ static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * value ) new_nurb->bezt->f2 = SELECT; new_nurb->bezt->f3 = SELECT; new_nurb->bezt->hide = 0; - new_nurb->bezt->radius = 1.0; /* calchandlesNurb( new_nurb ); */ } else { /* set up bp */ new_nurb->pntsv = 1; @@ -832,7 +831,6 @@ static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * value ) new_nurb->flagv = 0; new_nurb->bp->f1 = 0; new_nurb->bp->hide = 0; - new_nurb->bp->radius = 1.0; new_nurb->knotsu = 0; /*makenots( new_nurb, 1, new_nurb->flagu >> 1); */ } -- cgit v1.2.3