Merged changes in the trunk up to revision 34335.
This commit is contained in:
@@ -33,8 +33,8 @@
|
||||
* writers to make OpenGL calls in their Python scripts for Blender. The
|
||||
* more important original comments are marked with an @ symbol. */
|
||||
|
||||
#ifndef EXPP_BGL_H
|
||||
#define EXPP_BGL_H
|
||||
#ifndef BGL_H
|
||||
#define BGL_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
@@ -337,4 +337,4 @@ extern PyTypeObject BGL_bufferType;
|
||||
return NULL;\
|
||||
}
|
||||
|
||||
#endif /* EXPP_BGL_H */
|
||||
#endif /* BGL_H */
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
*/
|
||||
//Include this file for access to vector, quat, matrix, euler, etc...
|
||||
|
||||
#ifndef EXPP_Mathutils_H
|
||||
#define EXPP_Mathutils_H
|
||||
#ifndef MATHUTILS_H
|
||||
#define MATHUTILS_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
@@ -66,9 +66,6 @@ PyMODINIT_FUNC BPyInit_mathutils(void);
|
||||
int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
|
||||
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
|
||||
|
||||
|
||||
#define Py_PI 3.14159265358979323846
|
||||
|
||||
#define Py_NEW 1
|
||||
#define Py_WRAP 2
|
||||
|
||||
@@ -104,4 +101,4 @@ int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index);
|
||||
/* utility func */
|
||||
int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
|
||||
|
||||
#endif /* EXPP_Mathutils_H */
|
||||
#endif /* MATHUTILS_H */
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EXPP_color_h
|
||||
#define EXPP_color_h
|
||||
#ifndef MATHUTILS_COLOR_H
|
||||
#define MATHUTILS_COLOR_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
@@ -49,4 +49,4 @@ blender (stored in blend_data). This is an either/or struct not both*/
|
||||
PyObject *newColorObject( float *col, int type, PyTypeObject *base_type);
|
||||
PyObject *newColorObject_cb(PyObject *cb_user, int cb_type, int cb_subtype);
|
||||
|
||||
#endif /* EXPP_color_h */
|
||||
#endif /* MATHUTILS_COLOR_H */
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EXPP_euler_h
|
||||
#define EXPP_euler_h
|
||||
#ifndef MATHUTILS_EULER_H
|
||||
#define MATHUTILS_EULER_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
@@ -54,4 +54,4 @@ PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_
|
||||
short euler_order_from_string(const char *str, const char *error_prefix);
|
||||
|
||||
|
||||
#endif /* EXPP_euler_h */
|
||||
#endif /* MATHUTILS_EULER_H */
|
||||
|
||||
@@ -28,12 +28,12 @@
|
||||
*/
|
||||
/*Include this file for access to vector, quat, matrix, euler, etc...*/
|
||||
|
||||
#ifndef EXPP_Geometry_H
|
||||
#define EXPP_Geometry_H
|
||||
#ifndef MATHUTILS_GEOMETRY_H
|
||||
#define MATHUTILS_GEOMETRY_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "mathutils.h"
|
||||
|
||||
PyMODINIT_FUNC BPyInit_mathutils_geometry(void);
|
||||
|
||||
#endif /* EXPP_Geometry_H */
|
||||
#endif /* MATHUTILS_GEOMETRY_H */
|
||||
|
||||
@@ -170,11 +170,11 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
|
||||
VectorObject *vec= NULL;
|
||||
char *axis= NULL;
|
||||
int matSize;
|
||||
float angle = 0.0f;
|
||||
double angle; /* use double because of precission problems at high values */
|
||||
float mat[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
if(!PyArg_ParseTuple(args, "fi|O", &angle, &matSize, &vec)) {
|
||||
if(!PyArg_ParseTuple(args, "di|O", &angle, &matSize, &vec)) {
|
||||
PyErr_SetString(PyExc_TypeError, "mathutils.RotationMatrix(angle, size, axis): expected float int and a string or vector");
|
||||
return NULL;
|
||||
}
|
||||
@@ -191,11 +191,9 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
while (angle<-(Py_PI*2))
|
||||
angle+=(Py_PI*2);
|
||||
while (angle>(Py_PI*2))
|
||||
angle-=(Py_PI*2);
|
||||
|
||||
/* clamp angle between -360 and 360 in radians */
|
||||
angle= fmod(angle + M_PI*2, M_PI*4) - M_PI*2;
|
||||
|
||||
if(matSize != 2 && matSize != 3 && matSize != 4) {
|
||||
PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): can only return a 2x2 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EXPP_matrix_h
|
||||
#define EXPP_matrix_h
|
||||
#ifndef MATHUTILS_MATRIX_H
|
||||
#define MATHUTILS_MATRIX_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
@@ -55,4 +55,4 @@ PyObject *newMatrixObject_cb(PyObject *user, int rowSize, int colSize, int cb_ty
|
||||
extern int mathutils_matrix_vector_cb_index;
|
||||
extern struct Mathutils_Callback mathutils_matrix_vector_cb;
|
||||
|
||||
#endif /* EXPP_matrix_H */
|
||||
#endif /* MATHUTILS_MATRIX_H */
|
||||
|
||||
@@ -782,22 +782,24 @@ static int Quaternion_setAngle(QuaternionObject * self, PyObject * value, void *
|
||||
float tquat[4];
|
||||
float len;
|
||||
|
||||
float axis[3];
|
||||
float angle;
|
||||
float axis[3], angle_dummy;
|
||||
double angle;
|
||||
|
||||
if(!BaseMath_ReadCallback(self))
|
||||
return -1;
|
||||
|
||||
len= normalize_qt_qt(tquat, self->quat);
|
||||
quat_to_axis_angle(axis, &angle, tquat);
|
||||
quat_to_axis_angle(axis, &angle_dummy, tquat);
|
||||
|
||||
angle = PyFloat_AsDouble(value);
|
||||
angle= PyFloat_AsDouble(value);
|
||||
|
||||
if(angle==-1.0f && PyErr_Occurred()) { /* parsed item not a number */
|
||||
PyErr_SetString(PyExc_TypeError, "quaternion.angle = value: float expected");
|
||||
return -1;
|
||||
}
|
||||
|
||||
angle= fmod(angle + M_PI*2, M_PI*4) - M_PI*2;
|
||||
|
||||
/* If the axis of rotation is 0,0,0 set it to 1,0,0 - for zero-degree rotations */
|
||||
if( EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
|
||||
EXPP_FloatsAreEqual(axis[1], 0.0f, 10) &&
|
||||
@@ -878,7 +880,7 @@ static int Quaternion_setAxisVec(QuaternionObject *self, PyObject *value, void *
|
||||
static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyObject *seq= NULL;
|
||||
float angle = 0.0f;
|
||||
double angle = 0.0f;
|
||||
float quat[QUAT_SIZE]= {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
|
||||
if(kwds && PyDict_Size(kwds)) {
|
||||
@@ -886,7 +888,7 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!PyArg_ParseTuple(args, "|Of:mathutils.Quaternion", &seq, &angle))
|
||||
if(!PyArg_ParseTuple(args, "|Od:mathutils.Quaternion", &seq, &angle))
|
||||
return NULL;
|
||||
|
||||
switch(PyTuple_GET_SIZE(args)) {
|
||||
@@ -899,7 +901,7 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
|
||||
case 2:
|
||||
if (mathutils_array_parse(quat, 3, 3, seq, "mathutils.Quaternion()") == -1)
|
||||
return NULL;
|
||||
|
||||
angle= fmod(angle + M_PI*2, M_PI*4) - M_PI*2; /* clamp because of precission issues */
|
||||
axis_angle_to_quat(quat, quat, angle);
|
||||
break;
|
||||
/* PyArg_ParseTuple assures no more then 2 */
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EXPP_quat_h
|
||||
#define EXPP_quat_h
|
||||
#ifndef MATHUTILS_QUAT_H
|
||||
#define MATHUTILS_QUAT_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
@@ -49,4 +49,4 @@ blender (stored in blend_data). This is an either/or struct not both*/
|
||||
PyObject *newQuaternionObject( float *quat, int type, PyTypeObject *base_type);
|
||||
PyObject *newQuaternionObject_cb(PyObject *cb_user, int cb_type, int cb_subtype);
|
||||
|
||||
#endif /* EXPP_quat_h */
|
||||
#endif /* MATHUTILS_QUAT_H */
|
||||
|
||||
@@ -832,48 +832,28 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end)
|
||||
static int Vector_ass_slice(VectorObject *self, int begin, int end,
|
||||
PyObject * seq)
|
||||
{
|
||||
int i, y, size = 0;
|
||||
float vec[4], scalar;
|
||||
PyObject *v;
|
||||
int y, size = 0;
|
||||
float vec[MAX_DIMENSIONS];
|
||||
|
||||
if(!BaseMath_ReadCallback(self))
|
||||
return -1;
|
||||
|
||||
|
||||
CLAMP(begin, 0, self->size);
|
||||
if (end<0) end= self->size+end+1;
|
||||
CLAMP(end, 0, self->size);
|
||||
begin = MIN2(begin,end);
|
||||
|
||||
size = PySequence_Size(seq);
|
||||
if(size != (end - begin)){
|
||||
PyErr_SetString(PyExc_TypeError, "vector[begin:end] = []: size mismatch in slice assignment");
|
||||
size = (end - begin);
|
||||
if(mathutils_array_parse(vec, size, size, seq, "vector[begin:end] = [...]:") == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
v = PySequence_GetItem(seq, i);
|
||||
if (v == NULL) { /* Failed to read sequence */
|
||||
PyErr_SetString(PyExc_RuntimeError, "vector[begin:end] = []: unable to read sequence");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((scalar=PyFloat_AsDouble(v)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
|
||||
Py_DECREF(v);
|
||||
PyErr_SetString(PyExc_TypeError, "vector[begin:end] = []: sequence argument not a number");
|
||||
return -1;
|
||||
}
|
||||
|
||||
vec[i] = scalar;
|
||||
Py_DECREF(v);
|
||||
}
|
||||
/*parsed well - now set in vector*/
|
||||
for(y = 0; y < size; y++){
|
||||
self->vec[begin + y] = vec[y];
|
||||
}
|
||||
|
||||
|
||||
if(!BaseMath_WriteCallback(self))
|
||||
return -1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*------------------------NUMERIC PROTOCOLS----------------------
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EXPP_vector_h
|
||||
#define EXPP_vector_h
|
||||
#ifndef MATHUTILS_VECTOR_H
|
||||
#define MATHUTILS_VECTOR_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
@@ -46,4 +46,4 @@ typedef struct {
|
||||
PyObject *newVectorObject(float *vec, int size, int type, PyTypeObject *base_type);
|
||||
PyObject *newVectorObject_cb(PyObject *user, int size, int callback_type, int subtype);
|
||||
|
||||
#endif /* EXPP_vector_h */
|
||||
#endif /* MATHUTILS_VECTOR_H */
|
||||
|
||||
@@ -1312,12 +1312,10 @@ static PyObject * pyrna_prop_array_to_py_index(BPy_PropertyArrayRNA *self, int i
|
||||
static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, PyObject *value)
|
||||
{
|
||||
int ret = 0;
|
||||
int totdim;
|
||||
PointerRNA *ptr= &self->ptr;
|
||||
PropertyRNA *prop= self->prop;
|
||||
int type = RNA_property_type(prop);
|
||||
|
||||
totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
||||
const int totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
||||
|
||||
if (totdim > 1) {
|
||||
/* char error_str[512]; */
|
||||
@@ -1328,7 +1326,7 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P
|
||||
}
|
||||
else {
|
||||
/* see if we can coorce into a python type - PropertyType */
|
||||
switch (type) {
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_BOOLEAN:
|
||||
{
|
||||
int param = PyLong_AsLong( value );
|
||||
|
||||
@@ -56,15 +56,15 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[]
|
||||
/* not the last dimension */
|
||||
if (dim + 1 < totdim) {
|
||||
/* check that a sequence contains dimsize[dim] items */
|
||||
|
||||
for (i= 0; i < PySequence_Size(seq); i++) {
|
||||
const int seq_size= PySequence_Size(seq);
|
||||
for (i= 0; i < seq_size; i++) {
|
||||
PyObject *item;
|
||||
int ok= 1;
|
||||
item= PySequence_GetItem(seq, i);
|
||||
|
||||
if (!PySequence_Check(item)) {
|
||||
/* BLI_snprintf(error_str, error_str_size, "expected a sequence of %s", item_type_str); */
|
||||
PyErr_Format(PyExc_TypeError, "%s expected a sequence of %s", error_prefix, item_type_str);
|
||||
PyErr_Format(PyExc_TypeError, "%s expected a sequence of %s, not %s", error_prefix, item_type_str, Py_TYPE(item)->tp_name);
|
||||
ok= 0;
|
||||
}
|
||||
/* arr[3][4][5]
|
||||
@@ -89,14 +89,15 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[]
|
||||
}
|
||||
else {
|
||||
/* check that items are of correct type */
|
||||
for (i= 0; i < PySequence_Size(seq); i++) {
|
||||
const int seq_size= PySequence_Size(seq);
|
||||
for (i= 0; i < seq_size; i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
|
||||
if (!check_item_type(item)) {
|
||||
Py_DECREF(item);
|
||||
|
||||
/* BLI_snprintf(error_str, error_str_size, "sequence items should be of type %s", item_type_str); */
|
||||
PyErr_Format(PyExc_TypeError, "sequence items should be of type %s", item_type_str);
|
||||
PyErr_Format(PyExc_TypeError, "expected sequence items of type %s, not %s", item_type_str, Py_TYPE(item)->tp_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -113,8 +114,9 @@ static int count_items(PyObject *seq)
|
||||
int totitem= 0;
|
||||
|
||||
if (PySequence_Check(seq)) {
|
||||
const int seq_size= PySequence_Size(seq);
|
||||
int i;
|
||||
for (i= 0; i < PySequence_Size(seq); i++) {
|
||||
for (i= 0; i < seq_size; i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
totitem += count_items(item);
|
||||
Py_DECREF(item);
|
||||
@@ -183,7 +185,7 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA
|
||||
|
||||
if (tot != len) {
|
||||
/* BLI_snprintf(error_str, error_str_size, "sequence must have length of %d", len); */
|
||||
PyErr_Format(PyExc_ValueError, "%s sequence must have %d items total", error_prefix, len);
|
||||
PyErr_Format(PyExc_ValueError, "%s sequence must have %d items total, not %d", error_prefix, len, tot);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -206,31 +208,39 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop,
|
||||
return validate_array_length(rvalue, ptr, prop, lvalue_dim, totitem, error_prefix);
|
||||
}
|
||||
|
||||
static char *copy_value_single(PyObject *item, PointerRNA *ptr, PropertyRNA *prop, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index)
|
||||
{
|
||||
if (!data) {
|
||||
char value[sizeof(int)];
|
||||
|
||||
convert_item(item, value);
|
||||
rna_set_index(ptr, prop, *index, value);
|
||||
*index = *index + 1;
|
||||
}
|
||||
else {
|
||||
convert_item(item, data);
|
||||
data += item_size;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index)
|
||||
{
|
||||
unsigned int i;
|
||||
int totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
||||
const int seq_size= PySequence_Size(seq);
|
||||
|
||||
for (i= 0; i < PySequence_Size(seq); i++) {
|
||||
for (i= 0; i < seq_size; i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
|
||||
if (dim + 1 < totdim) {
|
||||
data= copy_values(item, ptr, prop, dim + 1, data, item_size, index, convert_item, rna_set_index);
|
||||
}
|
||||
else {
|
||||
if (!data) {
|
||||
char value[sizeof(int)];
|
||||
|
||||
convert_item(item, value);
|
||||
rna_set_index(ptr, prop, *index, value);
|
||||
*index = *index + 1;
|
||||
}
|
||||
else {
|
||||
convert_item(item, data);
|
||||
data += item_size;
|
||||
}
|
||||
data= copy_value_single(item, ptr, prop, data, item_size, index, convert_item, rna_set_index);
|
||||
}
|
||||
|
||||
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
@@ -239,11 +249,11 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int
|
||||
|
||||
static int py_to_array(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, char *param_data, ItemTypeCheckFunc check_item_type, const char *item_type_str, int item_size, ItemConvertFunc convert_item, RNA_SetArrayFunc rna_set_array, const char *error_prefix)
|
||||
{
|
||||
int totdim, dim_size[MAX_ARRAY_DIMENSION];
|
||||
/*int totdim, dim_size[MAX_ARRAY_DIMENSION];*/
|
||||
int totitem;
|
||||
char *data= NULL;
|
||||
|
||||
totdim= RNA_property_array_dimension(ptr, prop, dim_size);
|
||||
/*totdim= RNA_property_array_dimension(ptr, prop, dim_size);*/ /*UNUSED*/
|
||||
|
||||
if (!validate_array(py, ptr, prop, 0, check_item_type, item_type_str, &totitem, error_prefix)) {
|
||||
return 0;
|
||||
@@ -302,12 +312,22 @@ static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, i
|
||||
|
||||
index += arrayoffset;
|
||||
|
||||
if (!validate_array(py, ptr, prop, lvalue_dim, check_item_type, item_type_str, &totitem, error_prefix))
|
||||
return 0;
|
||||
|
||||
if (totitem)
|
||||
copy_values(py, ptr, prop, lvalue_dim, NULL, 0, &index, convert_item, rna_set_index);
|
||||
if(lvalue_dim == totdim) { /* single item, assign directly */
|
||||
if(!check_item_type(py)) {
|
||||
PyErr_Format(PyExc_TypeError, "%s expected a %s type, not %s", error_prefix, item_type_str, Py_TYPE(py)->tp_name);
|
||||
return 0;
|
||||
}
|
||||
copy_value_single(py, ptr, prop, NULL, 0, &index, convert_item, rna_set_index);
|
||||
}
|
||||
else {
|
||||
if (!validate_array(py, ptr, prop, lvalue_dim, check_item_type, item_type_str, &totitem, error_prefix)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (totitem) {
|
||||
copy_values(py, ptr, prop, lvalue_dim, NULL, 0, &index, convert_item, rna_set_index);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -329,7 +349,7 @@ static void py_to_bool(PyObject *py, char *data)
|
||||
static int py_float_check(PyObject *py)
|
||||
{
|
||||
/* accept both floats and integers */
|
||||
return PyFloat_Check(py) || PyLong_Check(py);
|
||||
return PyNumber_Check(py);
|
||||
}
|
||||
|
||||
static int py_int_check(PyObject *py)
|
||||
|
||||
Reference in New Issue
Block a user