[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18046] trunk/blender: * bpy curve api wouldn' t give correct errors for bad arguments when appending nurbs.

Campbell Barton ideasman42 at gmail.com
Wed Dec 24 16:46:26 CET 2008


Revision: 18046
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18046
Author:   campbellbarton
Date:     2008-12-24 16:46:26 +0100 (Wed, 24 Dec 2008)

Log Message:
-----------
* 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

Modified Paths:
--------------
    trunk/blender/release/scripts/mesh_edges2curves.py
    trunk/blender/source/blender/python/api2_2x/CurNurb.c
    trunk/blender/source/blender/python/api2_2x/Curve.c

Modified: trunk/blender/release/scripts/mesh_edges2curves.py
===================================================================
--- trunk/blender/release/scripts/mesh_edges2curves.py	2008-12-24 14:52:17 UTC (rev 18045)
+++ trunk/blender/release/scripts/mesh_edges2curves.py	2008-12-24 15:46:26 UTC (rev 18046)
@@ -112,7 +112,7 @@
 	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 @@
 			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 @@
 		# Add all the points in the polyline.
 		while vIdx<len(poly):
 			v= poly[vIdx]
-			cu.appendPoint(i, [v.co.x, v.co.y, v.co.z, w])
+			cu.appendPoint(i, (v.co.x, v.co.y, v.co.z, w))
 			vIdx+=1
 		i+=1
 	Window.WaitCursor(0)

Modified: trunk/blender/source/blender/python/api2_2x/CurNurb.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/CurNurb.c	2008-12-24 14:52:17 UTC (rev 18045)
+++ trunk/blender/source/blender/python/api2_2x/CurNurb.c	2008-12-24 15:46:26 UTC (rev 18046)
@@ -467,9 +467,6 @@
 
 PyObject *CurNurb_appendPointToNurb( Nurb * nurb, PyObject * value )
 {
-
-	int i;
-	int size;
 	int npoints = nurb->pntsu;
 
 	/*
@@ -520,81 +517,58 @@
 
 	}
 	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;
+		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 */
 
-			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" ) );
 
-			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 );
 
-			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 ) );
+		
+		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 );
 
-			++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;
-
-				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 );
-
-				if (item == NULL)
-					return NULL;
-
-				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" );
-		}
-
 	} 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" );
 
 	}
 

Modified: trunk/blender/source/blender/python/api2_2x/Curve.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Curve.c	2008-12-24 14:52:17 UTC (rev 18045)
+++ trunk/blender/source/blender/python/api2_2x/Curve.c	2008-12-24 15:46:26 UTC (rev 18046)
@@ -822,7 +822,6 @@
 			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 @@
 			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); */
 		}





More information about the Bf-blender-cvs mailing list