Merged changes in the trunk up to revision 43219.

Conflicts resolved:
source/blender/blenkernel/intern/scene.c
source/blender/blenloader/intern/readfile.c
source/blender/render/intern/source/pipeline.c
This commit is contained in:
2012-01-08 11:57:53 +00:00
149 changed files with 3699 additions and 2470 deletions

View File

@@ -4073,7 +4073,6 @@ static PyObject *pyrna_struct_as_pointer(BPy_StructRNA *self)
return PyLong_FromVoidPtr(self->ptr.data);
}
/* TODO, get (string, lib) pair */
PyDoc_STRVAR(pyrna_prop_collection_get_doc,
".. method:: get(key, default=None)\n"
"\n"
@@ -4120,6 +4119,51 @@ static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args
return Py_INCREF(def), def;
}
PyDoc_STRVAR(pyrna_prop_collection_find_doc,
".. method:: find(key)\n"
"\n"
" Returns the index of a key in a collection or -1 when not found\n"
" (matches pythons string find function of the same name).\n"
"\n"
" :arg key: The identifier for the collection member.\n"
" :type key: string\n"
" :return: index of the key.\n"
" :rtype: int\n"
);
static PyObject *pyrna_prop_collection_find(BPy_PropertyRNA *self, PyObject *key_ob)
{
Py_ssize_t key_len_ssize_t;
const char *key = _PyUnicode_AsStringAndSize(key_ob, &key_len_ssize_t);
const int key_len = (int)key_len_ssize_t; /* comare with same type */
char name[256], *nameptr;
int namelen;
int i = 0;
int index = -1;
PYRNA_PROP_CHECK_OBJ(self);
RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen);
if (nameptr) {
if ((key_len == namelen) && memcmp(nameptr, key, key_len) == 0) {
index = i;
break;
}
if (name != nameptr) {
MEM_freeN(nameptr);
}
}
i++;
}
RNA_PROP_END;
return PyLong_FromSsize_t(index);
}
static void foreach_attr_type( BPy_PropertyRNA *self, const char *attr,
/* values to assign */
RawPropertyType *raw_type, int *attr_tot, int *attr_signed)
@@ -4503,6 +4547,7 @@ static struct PyMethodDef pyrna_prop_collection_methods[] = {
{"values", (PyCFunction)pyrna_prop_collection_values, METH_NOARGS, pyrna_prop_collection_values_doc},
{"get", (PyCFunction)pyrna_prop_collection_get, METH_VARARGS, pyrna_prop_collection_get_doc},
{"find", (PyCFunction)pyrna_prop_collection_find, METH_O, pyrna_prop_collection_find_doc},
{NULL, NULL, 0, NULL}
};

View File

@@ -2409,13 +2409,13 @@ static int MatrixAccess_traverse(MatrixAccessObject *self, visitproc visit, void
return 0;
}
int MatrixAccess_clear(MatrixAccessObject *self)
static int MatrixAccess_clear(MatrixAccessObject *self)
{
Py_CLEAR(self->matrix_user);
return 0;
}
void MatrixAccess_dealloc(MatrixAccessObject *self)
static void MatrixAccess_dealloc(MatrixAccessObject *self)
{
if (self->matrix_user) {
PyObject_GC_UnTrack(self);
@@ -2434,6 +2434,38 @@ static int MatrixAccess_len(MatrixAccessObject *self)
self->matrix_user->num_col;
}
static PyObject *MatrixAccess_slice(MatrixAccessObject *self, int begin, int end)
{
PyObject *tuple;
int count;
/* row/col access */
MatrixObject *matrix_user = self->matrix_user;
int matrix_access_len;
PyObject *(*Matrix_item_new)(MatrixObject *, int);
if (self->type == MAT_ACCESS_ROW) {
matrix_access_len = matrix_user->num_row;
Matrix_item_new = Matrix_item_row;
}
else { /* MAT_ACCESS_ROW */
matrix_access_len = matrix_user->num_col;
Matrix_item_new = Matrix_item_col;
}
CLAMP(begin, 0, matrix_access_len);
if (end < 0) end = (matrix_access_len + 1) + end;
CLAMP(end, 0, matrix_access_len);
begin = MIN2(begin, end);
tuple = PyTuple_New(end - begin);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin, Matrix_item_new(matrix_user, count));
}
return tuple;
}
static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item)
{
MatrixObject *matrix_user = self->matrix_user;
@@ -2454,7 +2486,24 @@ static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item
return Matrix_item_col(matrix_user, i);
}
}
/* TODO, slice */
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
if (PySlice_GetIndicesEx((void *)item, MatrixAccess_len(self), &start, &stop, &step, &slicelength) < 0)
return NULL;
if (slicelength <= 0) {
return PyTuple_New(0);
}
else if (step == 1) {
return MatrixAccess_slice(self, start, stop);
}
else {
PyErr_SetString(PyExc_IndexError,
"slice steps not supported with matrix accessors");
return NULL;
}
}
else {
PyErr_Format(PyExc_TypeError,
"matrix indices must be integers, not %.200s",
@@ -2493,6 +2542,22 @@ static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item,
}
}
static PyObject *MatrixAccess_iter(MatrixAccessObject *self)
{
/* Try get values from a collection */
PyObject *ret;
PyObject *iter = NULL;
ret = MatrixAccess_slice(self, 0, MATRIX_MAX_DIM);
/* we know this is a tuple so no need to PyIter_Check
* otherwise it could be NULL (unlikely) if conversion failed */
if (ret) {
iter = PyObject_GetIter(ret);
Py_DECREF(ret);
}
return iter;
}
static PyMappingMethods MatrixAccess_AsMapping = {
(lenfunc)MatrixAccess_len,
@@ -2525,6 +2590,8 @@ PyTypeObject matrix_access_Type = {
(traverseproc)MatrixAccess_traverse, //tp_traverse
(inquiry)MatrixAccess_clear, //tp_clear
NULL /* (richcmpfunc)MatrixAccess_richcmpr */ /* TODO*/, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
(getiterfunc)MatrixAccess_iter, /* getiterfunc tp_iter; */
};
static PyObject *MatrixAccess_CreatePyObject(MatrixObject *matrix, const eMatrixAccess_t type)

View File

@@ -334,18 +334,18 @@ PyDoc_STRVAR(Vector_normalize_doc,
"\n"
" Normalize the vector, making the length of the vector always 1.0.\n"
"\n"
" .. warning:: Normalizing a vector where all values are zero results\n"
" in all axis having a nan value (not a number).\n"
" .. warning:: Normalizing a vector where all values are zero has no effect.\n"
"\n"
" .. note:: Normalize works for vectors of all sizes,\n"
" however 4D Vectors w axis is left untouched.\n"
);
static PyObject *Vector_normalize(VectorObject *self)
{
int size = (self->size == 4 ? 3 : self->size);
if (BaseMath_ReadCallback(self) == -1)
return NULL;
normalize_vn(self->vec, self->size);
normalize_vn(self->vec, size);
(void)BaseMath_WriteCallback(self);
Py_RETURN_NONE;
@@ -1480,10 +1480,10 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2)
mulplication*/
/* COLUMN VECTOR Multiplication (Vector X Matrix)
* [a] * [1][4][7]
* [b] * [2][5][8]
* [c] * [3][6][9]
/* COLUMN VECTOR Multiplication (Matrix X Vector)
* [1][4][7] [a]
* [2][5][8] * [b]
* [3][6][9] [c]
*
* note: vector/matrix multiplication IS NOT COMMUTATIVE!!!!
* note: assume read callbacks have been done first.
@@ -1500,8 +1500,8 @@ int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec,
else {
PyErr_SetString(PyExc_TypeError,
"matrix * vector: "
"matrix.row_size and len(vector) must be the same, "
"except for 3D vector * 4x4 matrix.");
"len(matrix.col) and len(vector) must be the same, "
"except for 4x4 matrix * 3D vector.");
return -1;
}
}