diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-07-25 15:27:18 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-07-25 15:27:18 +0400 |
commit | fec3ddabb1d75ee6a3a28589813f2acc85215e18 (patch) | |
tree | fd50e11cb9540fdcfad454458f6887091b330281 /source/blender/freestyle/intern/python/Interface1D | |
parent | d7bce7e10952ac47551132c93f64d9aa8e54f1db (diff) |
* Better support for vector-like objects in method arguments.
Now the following methods in the Freestyle Python API accept
not only Blender.Mathutils.Vector instances but also lists and
tuples having an appropriate number of elements.
FrsNoise::turbulence2()
FrsNoise::turbulence3()
FrsNoise::smoothNoise2()
FrsNoise::smoothNoise3()
SVertex::__init__()
SVertex::setPoint3D()
SVertex::setPoint2D()
SVertex::AddNormal()
FEdgeSharp::setNormalA()
FEdgeSharp::setNormalB()
FEdgeSmooth::setNormal()
CalligraphicShader::__init__()
StrokeAttribute::setAttributeVec2f()
StrokeAttribute::setAttributeVec3f()
StrokeAttribute::setColor()
StrokeVertex::setPoint()
* Added the following converters for the sake of the improvements
mentioned above.
Vec2f_ptr_from_PyObject()
Vec3f_ptr_from_PyObject()
Vec3r_ptr_from_PyObject()
Vec2f_ptr_from_PyList()
Vec3f_ptr_from_PyList()
Vec3r_ptr_from_PyList()
Vec2f_ptr_from_PyTuple()
Vec3f_ptr_from_PyTuple()
Vec3r_ptr_from_PyTuple()
Those converters with the suffixes _PyList and _PyTuple accept
only lists and tuples having an appropriate number of elements,
respectively, while those with the suffix _PyObject accept lists,
tuples, or Blender.Mathutils.Vector instances.
* Fixed a null pointer reference in Interface0D___dealloc__().
* Corrected the names of 3 methods in the FEdgeSmooth class.
Diffstat (limited to 'source/blender/freestyle/intern/python/Interface1D')
-rw-r--r-- | source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp | 34 | ||||
-rw-r--r-- | source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp | 23 |
2 files changed, 21 insertions, 36 deletions
diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp index c6bc201e37d..aa0ba7dfc46 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp @@ -184,20 +184,15 @@ PyObject * FEdgeSharp_bMaterial( BPy_FEdgeSharp *self ) { PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) { PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &obj) )) + if(!( PyArg_ParseTuple(args, "O", &obj) )) return NULL; - if( PyList_Size(obj) != 3 ) { - stringstream msg("FEdgeSharp::setNormalA() accepts a list of 3 elements ("); - msg << PyList_Size(obj) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *v = Vec3r_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ), - PyFloat_AsDouble( PyList_GetItem(obj,1) ), - PyFloat_AsDouble( PyList_GetItem(obj,2) ) ); - - self->fes->setNormalA( v ); + self->fes->setNormalA( *v ); + delete v; Py_RETURN_NONE; } @@ -205,20 +200,15 @@ PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) { PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args ) { PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &obj) )) + if(!( PyArg_ParseTuple(args, "O", &obj) )) return NULL; - if( PyList_Size(obj) != 3 ) { - stringstream msg("FEdgeSharp::setNormalB() accepts a list of 3 elements ("); - msg << PyList_Size(obj) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *v = Vec3r_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ), - PyFloat_AsDouble( PyList_GetItem(obj,1) ), - PyFloat_AsDouble( PyList_GetItem(obj,2) ) ); - - self->fes->setNormalB( v ); + self->fes->setNormalB( *v ); + delete v; Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp index bb0e6eef4e4..9913503db58 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp @@ -23,9 +23,9 @@ static PyObject * FEdgeSmooth_setMaterialIndex( BPy_FEdgeSmooth *self, PyObject static PyMethodDef BPy_FEdgeSmooth_methods[] = { {"normal", ( PyCFunction ) FEdgeSmooth_normal, METH_NOARGS, "() Returns the normal to the Face it is running accross."}, {"materialIndex", ( PyCFunction ) FEdgeSmooth_materialIndex, METH_NOARGS, "() Returns the index of the material of the face it is running accross. "}, - {"aMaterial", ( PyCFunction ) FEdgeSmooth_material, METH_NOARGS, "() Returns the material of the face it is running accross. "}, - {"setNormalA", ( PyCFunction ) FEdgeSmooth_setNormal, METH_VARARGS, "([x,y,z]) Sets the normal to the Face it is running accross."}, - {"setaMaterialIndex", ( PyCFunction ) FEdgeSmooth_setMaterialIndex, METH_VARARGS, "(unsigned int i) Sets the index of the material of the face it is running accross. "}, + {"material", ( PyCFunction ) FEdgeSmooth_material, METH_NOARGS, "() Returns the material of the face it is running accross. "}, + {"setNormal", ( PyCFunction ) FEdgeSmooth_setNormal, METH_VARARGS, "([x,y,z]) Sets the normal to the Face it is running accross."}, + {"setMaterialIndex", ( PyCFunction ) FEdgeSmooth_setMaterialIndex, METH_VARARGS, "(unsigned int i) Sets the index of the material of the face it is running accross. "}, {NULL, NULL, 0, NULL} }; @@ -162,20 +162,15 @@ PyObject * FEdgeSmooth_material( BPy_FEdgeSmooth *self ) { PyObject * FEdgeSmooth_setNormal( BPy_FEdgeSmooth *self, PyObject *args ) { PyObject *obj = 0; - if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &obj) )) + if(!( PyArg_ParseTuple(args, "O", &obj) )) return NULL; - if( PyList_Size(obj) != 3 ) { - stringstream msg("FEdgeSmooth::setNormal() accepts a list of 3 elements ("); - msg << PyList_Size(obj) << " found)"; - PyErr_SetString(PyExc_TypeError, msg.str().c_str()); + Vec3r *v = Vec3r_ptr_from_PyObject(obj); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); return NULL; } - - Vec3r v( PyFloat_AsDouble( PyList_GetItem(obj,0) ), - PyFloat_AsDouble( PyList_GetItem(obj,1) ), - PyFloat_AsDouble( PyList_GetItem(obj,2) ) ); - - self->fes->setNormal( v ); + self->fes->setNormal( *v ); + delete v; Py_RETURN_NONE; } |