Freestyle: use mathutils_array_parse() instead of its own helper functions.
Patch contribution by flokkievids (Folkert de Vries). Thanks!
This commit is contained in:
parent
252eaed483
commit
9563bde9a5
|
@ -718,7 +718,7 @@ bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r &vec)
|
|||
return true;
|
||||
}
|
||||
|
||||
// helper for argument parsing
|
||||
// helpers for argument parsing
|
||||
|
||||
bool float_array_from_PyObject(PyObject *obj, float *v, int n)
|
||||
{
|
||||
|
@ -745,6 +745,22 @@ bool float_array_from_PyObject(PyObject *obj, float *v, int n)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int convert_v4(PyObject *obj, void *v)
|
||||
{
|
||||
return mathutils_array_parse((float *)v, 4, 4, obj, "Error parsing 4D vector");
|
||||
}
|
||||
|
||||
int convert_v3(PyObject *obj, void *v)
|
||||
{
|
||||
return mathutils_array_parse((float *)v, 3, 3, obj, "Error parsing 3D vector");
|
||||
}
|
||||
|
||||
int convert_v2(PyObject *obj, void *v)
|
||||
{
|
||||
return mathutils_array_parse((float *)v, 2, 2, obj, "Error parsing 2D vector");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -170,6 +170,9 @@ bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r &vec);
|
|||
|
||||
bool float_array_from_PyObject(PyObject *obj, float *v, int n);
|
||||
|
||||
int convert_v4(PyObject *obj, void *v);
|
||||
int convert_v3(PyObject *obj, void *v);
|
||||
int convert_v2(PyObject *obj, void *v);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -138,14 +138,16 @@ static PyObject *Freestyle_blendRamp(PyObject *self, PyObject *args)
|
|||
PyErr_SetString(PyExc_TypeError, "argument 1 is an unknown ramp blend type");
|
||||
return NULL;
|
||||
}
|
||||
if (!float_array_from_PyObject(obj1, a, 3)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"argument 2 must be a 3D vector (either a tuple/list of 3 elements or Vector)");
|
||||
if (mathutils_array_parse(a, 3, 3, obj1,
|
||||
"argument 2 must be a 3D vector "
|
||||
"(either a tuple/list of 3 elements or Vector)") == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!float_array_from_PyObject(obj2, b, 3)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"argument 4 must be a 3D vector (either a tuple/list of 3 elements or Vector)");
|
||||
if (mathutils_array_parse(b, 3, 3, obj2,
|
||||
"argument 4 must be a 3D vector "
|
||||
"(either a tuple/list of 3 elements or Vector)") == -1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
ramp_blend(type, a, fac, b);
|
||||
|
|
|
@ -80,11 +80,6 @@ PyDoc_STRVAR(FrsMaterial_doc,
|
|||
" :arg shininess: The shininess coefficient.\n"
|
||||
" :type shininess: :class:float");
|
||||
|
||||
static int convert_v4(PyObject *obj, void *v)
|
||||
{
|
||||
return float_array_from_PyObject(obj, (float *)v, 4);
|
||||
}
|
||||
|
||||
static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
static const char *kwlist_1[] = {"brother", NULL};
|
||||
|
@ -299,8 +294,9 @@ static PyObject *FrsMaterial_diffuse_get(BPy_FrsMaterial *self, void *UNUSED(clo
|
|||
static int FrsMaterial_diffuse_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float color[4];
|
||||
if (!float_array_from_PyObject(value, color, 4)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
|
||||
if (mathutils_array_parse(color, 4, 4, value,
|
||||
"value must be a 4-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
self->m->setDiffuse(color[0], color[1], color[2], color[3]);
|
||||
|
@ -320,8 +316,9 @@ static PyObject *FrsMaterial_specular_get(BPy_FrsMaterial *self, void *UNUSED(cl
|
|||
static int FrsMaterial_specular_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float color[4];
|
||||
if (!float_array_from_PyObject(value, color, 4)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
|
||||
if (mathutils_array_parse(color, 4, 4, value,
|
||||
"value must be a 4-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
self->m->setSpecular(color[0], color[1], color[2], color[3]);
|
||||
|
@ -341,8 +338,9 @@ static PyObject *FrsMaterial_ambient_get(BPy_FrsMaterial *self, void *UNUSED(clo
|
|||
static int FrsMaterial_ambient_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float color[4];
|
||||
if (!float_array_from_PyObject(value, color, 4)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
|
||||
if (mathutils_array_parse(color, 4, 4, value,
|
||||
"value must be a 4-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
self->m->setAmbient(color[0], color[1], color[2], color[3]);
|
||||
|
@ -362,8 +360,9 @@ static PyObject *FrsMaterial_emission_get(BPy_FrsMaterial *self, void *UNUSED(cl
|
|||
static int FrsMaterial_emission_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float color[4];
|
||||
if (!float_array_from_PyObject(value, color, 4)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
|
||||
if (mathutils_array_parse(color, 4, 4, value,
|
||||
"value must be a 4-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
self->m->setEmission(color[0], color[1], color[2], color[3]);
|
||||
|
|
|
@ -525,8 +525,9 @@ static PyObject *StrokeAttribute_color_get(BPy_StrokeAttribute *self, void *UNUS
|
|||
static int StrokeAttribute_color_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float v[3];
|
||||
if (!float_array_from_PyObject(value, v, 3)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
|
||||
if (mathutils_array_parse(v, 3, 3, value,
|
||||
"value must be a 3-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
self->sa->setColor(v[0], v[1], v[2]);
|
||||
|
@ -549,8 +550,9 @@ static PyObject *StrokeAttribute_thickness_get(BPy_StrokeAttribute *self, void *
|
|||
static int StrokeAttribute_thickness_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float v[2];
|
||||
if (!float_array_from_PyObject(value, v, 2)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 2-dimensional vector");
|
||||
if (mathutils_array_parse(v, 2, 2, value,
|
||||
"value must be a 2-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
self->sa->setThickness(v[0], v[1]);
|
||||
|
|
|
@ -61,11 +61,6 @@ PyDoc_STRVAR(SVertex_doc,
|
|||
" :arg id: An Id object.\n"
|
||||
" :type id: :class:`Id`");
|
||||
|
||||
static int convert_v3(PyObject *obj, void *v)
|
||||
{
|
||||
return float_array_from_PyObject(obj, (float *)v, 3);
|
||||
}
|
||||
|
||||
static int SVertex_init(BPy_SVertex *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
static const char *kwlist_1[] = {"brother", NULL};
|
||||
|
@ -283,8 +278,9 @@ static PyObject *SVertex_point_3d_get(BPy_SVertex *self, void *UNUSED(closure))
|
|||
static int SVertex_point_3d_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float v[3];
|
||||
if (!float_array_from_PyObject(value, v, 3)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
|
||||
if (mathutils_array_parse(v, 3, 3, value,
|
||||
"value must be a 3-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Vec3r p(v[0], v[1], v[2]);
|
||||
|
@ -305,8 +301,9 @@ static PyObject *SVertex_point_2d_get(BPy_SVertex *self, void *UNUSED(closure))
|
|||
static int SVertex_point_2d_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float v[3];
|
||||
if (!float_array_from_PyObject(value, v, 3)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
|
||||
if (mathutils_array_parse(v, 3, 3, value,
|
||||
"value must be a 3-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Vec3r p(v[0], v[1], v[2]);
|
||||
|
|
|
@ -277,8 +277,9 @@ static PyObject *StrokeVertex_point_get(BPy_StrokeVertex *self, void *UNUSED(clo
|
|||
static int StrokeVertex_point_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float v[2];
|
||||
if (!float_array_from_PyObject(value, v, 2)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 2-dimensional vector");
|
||||
if (mathutils_array_parse(v, 2, 2, value,
|
||||
"value must be a 2-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
self->sv->setX(v[0]);
|
||||
|
|
|
@ -231,8 +231,9 @@ static PyObject *FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void *UNUSED(
|
|||
static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float v[3];
|
||||
if (!float_array_from_PyObject(value, v, 3)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
|
||||
if (mathutils_array_parse(v, 3, 3, value,
|
||||
"value must be a 3-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Vec3r p(v[0], v[1], v[2]);
|
||||
|
@ -253,8 +254,9 @@ static PyObject *FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void *UNUSED(c
|
|||
static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float v[3];
|
||||
if (!float_array_from_PyObject(value, v, 3)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
|
||||
if (mathutils_array_parse(v, 3, 3, value,
|
||||
"value must be a 3-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Vec3r p(v[0], v[1], v[2]);
|
||||
|
|
|
@ -164,8 +164,9 @@ static PyObject *FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *UNUSED(clos
|
|||
static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
float v[3];
|
||||
if (!float_array_from_PyObject(value, v, 3)) {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
|
||||
if (mathutils_array_parse(v, 3, 3, value,
|
||||
"value must be a 3-dimensional vector") == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Vec3r p(v[0], v[1], v[2]);
|
||||
|
|
|
@ -67,11 +67,6 @@ static char CalligraphicShader___doc__[] =
|
|||
" :arg stroke: A Stroke object.\n"
|
||||
" :type stroke: :class:`Stroke`\n";
|
||||
|
||||
static int convert_v2(PyObject *obj, void *v)
|
||||
{
|
||||
return float_array_from_PyObject(obj, (float *)v, 2);
|
||||
}
|
||||
|
||||
static int CalligraphicShader___init__(BPy_CalligraphicShader *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
static const char *kwlist[] = {"thickness_min", "thickness_max", "orientation", "clamp", NULL};
|
||||
|
|
Loading…
Reference in New Issue