* 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.
This commit is contained in:
2009-07-25 11:27:18 +00:00
parent d7bce7e109
commit fec3ddabb1
10 changed files with 218 additions and 176 deletions

View File

@@ -376,6 +376,39 @@ Nature::EdgeNature EdgeNature_from_BPy_Nature( PyObject* obj ) {
return static_cast<Nature::EdgeNature>( PyInt_AsLong(obj) );
}
Vec2f * Vec2f_ptr_from_PyObject( PyObject* obj ) {
Vec2f *v;
if( (v = Vec2f_ptr_from_Vector( obj )) )
return v;
if( (v = Vec2f_ptr_from_PyList( obj )) )
return v;
if( (v = Vec2f_ptr_from_PyTuple( obj )) )
return v;
return NULL;
}
Vec3f * Vec3f_ptr_from_PyObject( PyObject* obj ) {
Vec3f *v;
if( (v = Vec3f_ptr_from_Vector( obj )) )
return v;
if( (v = Vec3f_ptr_from_PyList( obj )) )
return v;
if( (v = Vec3f_ptr_from_PyTuple( obj )) )
return v;
return NULL;
}
Vec3r * Vec3r_ptr_from_PyObject( PyObject* obj ) {
Vec3r *v;
if( (v = Vec3r_ptr_from_Vector( obj )) )
return v;
if( (v = Vec3r_ptr_from_PyList( obj )) )
return v;
if( (v = Vec3r_ptr_from_PyTuple( obj )) )
return v;
return NULL;
}
Vec2f * Vec2f_ptr_from_Vector( PyObject* obj ) {
PyObject *v;
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2)
@@ -424,6 +457,58 @@ Vec3r * Vec3r_ptr_from_Vector( PyObject* obj ) {
return new Vec3r(x,y,z);
}
Vec2f * Vec2f_ptr_from_PyList( PyObject* obj ) {
if( !PyList_Check(obj) || PyList_Size(obj) != 2 )
return NULL;
float x = PyFloat_AsDouble(PyList_GetItem(obj, 0));
float y = PyFloat_AsDouble(PyList_GetItem(obj, 1));
return new Vec2f(x,y);
}
Vec3f * Vec3f_ptr_from_PyList( PyObject* obj ) {
if( !PyList_Check(obj) || PyList_Size(obj) != 3 )
return NULL;
float x = PyFloat_AsDouble(PyList_GetItem(obj, 0));
float y = PyFloat_AsDouble(PyList_GetItem(obj, 1));
float z = PyFloat_AsDouble(PyList_GetItem(obj, 2));
return new Vec3f(x,y,z);
}
Vec3r * Vec3r_ptr_from_PyList( PyObject* obj ) {
if( !PyList_Check(obj) || PyList_Size(obj) != 3 )
return NULL;
float x = PyFloat_AsDouble(PyList_GetItem(obj, 0));
float y = PyFloat_AsDouble(PyList_GetItem(obj, 1));
float z = PyFloat_AsDouble(PyList_GetItem(obj, 2));
return new Vec3r(x,y,z);
}
Vec2f * Vec2f_ptr_from_PyTuple( PyObject* obj ) {
if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 2 )
return NULL;
float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0));
float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1));
return new Vec2f(x,y);
}
Vec3f * Vec3f_ptr_from_PyTuple( PyObject* obj ) {
if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 3 )
return NULL;
float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0));
float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1));
float z = PyFloat_AsDouble(PyTuple_GetItem(obj, 2));
return new Vec3f(x,y,z);
}
Vec3r * Vec3r_ptr_from_PyTuple( PyObject* obj ) {
if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 3 )
return NULL;
float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0));
float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1));
float z = PyFloat_AsDouble(PyTuple_GetItem(obj, 2));
return new Vec3r(x,y,z);
}
///////////////////////////////////////////////////////////////////////////////////////////