diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-04-25 23:27:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-04-25 23:27:59 +0400 |
commit | 873d4a3f05872bd32f40449a61de5f14e10a2f3d (patch) | |
tree | f1ed0b3786421d94bea7df636bdf1f11c5306950 /source/blender/python/generic/mathutils.c | |
parent | 4f6e3dad47946490facbb8121a35d7ac727d2416 (diff) |
py api
- mathutils.Color.hsv attribute. eg. material.diffuse_color.hsv = 0.2, 0.8, 0.4
- Vector/Euler/Quaternion/Color now only take a single seq arg.
- internal function for parsing arrays. (cleanup messy internal list/vector/tuple/seq parsing)
- didnt update rigify yet.
Diffstat (limited to 'source/blender/python/generic/mathutils.c')
-rw-r--r-- | source/blender/python/generic/mathutils.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/python/generic/mathutils.c b/source/blender/python/generic/mathutils.c index e1e1cd2ae69..a9a682bf998 100644 --- a/source/blender/python/generic/mathutils.c +++ b/source/blender/python/generic/mathutils.c @@ -29,6 +29,7 @@ /* Note: Changes to Mathutils since 2.4x * use radians rather then degrees + * - Mathutils.Vector/Euler/Quaternion(), now only take single sequence arguments. * - Mathutils.MidpointVecs --> vector.lerp(other, fac) * - Mathutils.AngleBetweenVecs --> vector.angle(other) * - Mathutils.ProjectVecs --> vector.project(other) @@ -55,6 +56,42 @@ static char M_Mathutils_doc[] = "This module provides access to matrices, eulers, quaternions and vectors."; +/* helper functionm returns length of the 'value', -1 on error */ +int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix) +{ + PyObject *value_fast= NULL; + + int i, size; + + /* non list/tuple cases */ + if(!(value_fast=PySequence_Fast(value, error_prefix))) { + /* PySequence_Fast sets the error */ + return -1; + } + + size= PySequence_Fast_GET_SIZE(value_fast); + + if(size > array_max || size < array_min) { + if (array_max == array_min) PyErr_Format(PyExc_ValueError, "%.200s: sequence size is %d, expected %d", error_prefix, size, array_max); + else PyErr_Format(PyExc_ValueError, "%.200s: sequence size is %d, expected [%d - %d]", error_prefix, size, array_min, array_max); + Py_DECREF(value_fast); + return -1; + } + + i= size; + do { + i--; + if(((array[i]= PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i))) == -1.0) && PyErr_Occurred()) { + PyErr_Format(PyExc_ValueError, "%.200s: sequence index %d is not a float", error_prefix, i); + Py_DECREF(value_fast); + return -1; + } + } while(i); + + Py_XDECREF(value_fast); + return size; +} + //-----------------------------METHODS---------------------------- //-----------------quat_rotation (internal)----------- //This function multiplies a vector/point * quat or vice versa |