Merged changes in the trunk up to revision 34574.
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) Blender Foundation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
#
|
||||
# Contributor(s): none yet.
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
#
|
||||
# Bounces make to subdirectories.
|
||||
|
||||
SOURCEDIR = source/blender/python
|
||||
DIRS = intern generic
|
||||
|
||||
include nan_subdirs.mk
|
||||
@@ -25,7 +25,7 @@ set(INC
|
||||
../../blenkernel
|
||||
../../../../intern/guardedalloc
|
||||
../../../../extern/glew/include
|
||||
${PYTHON_INC}
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(SRC
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
#
|
||||
# Contributor(s): none yet.
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
#
|
||||
#
|
||||
|
||||
LIBNAME = gen_python
|
||||
DIR = $(OCGDIR)/blender/$(LIBNAME)
|
||||
|
||||
include nan_compile.mk
|
||||
|
||||
CFLAGS += $(LEVEL_1_C_WARNINGS)
|
||||
|
||||
# OpenGL and Python
|
||||
CPPFLAGS += -I$(NAN_GLEW)/include
|
||||
CPPFLAGS += $(OGL_CPPFLAGS)
|
||||
CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
|
||||
|
||||
# PreProcessor stuff
|
||||
|
||||
CPPFLAGS += -I$(NAN_GHOST)/include
|
||||
CPPFLAGS += $(NAN_SDLCFLAGS)
|
||||
|
||||
# modules
|
||||
CPPFLAGS += -I../../editors/include
|
||||
CPPFLAGS += -I../../python
|
||||
CPPFLAGS += -I../../makesdna
|
||||
CPPFLAGS += -I../../makesrna
|
||||
CPPFLAGS += -I../../blenlib
|
||||
CPPFLAGS += -I../../blenkernel
|
||||
CPPFLAGS += -I../../nodes
|
||||
CPPFLAGS += -I../../imbuf
|
||||
CPPFLAGS += -I../../blenloader
|
||||
CPPFLAGS += -I../../windowmanager
|
||||
CPPFLAGS += -I../../render/extern/include
|
||||
|
||||
# path to the guarded memory allocator
|
||||
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
|
||||
CPPFLAGS += -I$(NAN_MEMUTIL)/include
|
||||
|
||||
# path to our own headerfiles
|
||||
CPPFLAGS += -I..
|
||||
@@ -598,6 +598,13 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
||||
return newMatrixObject(mat, matSize, matSize, Py_NEW, (PyTypeObject *)cls);
|
||||
}
|
||||
|
||||
static void matrix_as_3x3(float mat[3][3], MatrixObject *self)
|
||||
{
|
||||
copy_v3_v3(mat[0], self->matrix[0]);
|
||||
copy_v3_v3(mat[1], self->matrix[1]);
|
||||
copy_v3_v3(mat[2], self->matrix[2]);
|
||||
}
|
||||
|
||||
/* assumes rowsize == colsize is checked and the read callback has run */
|
||||
static float matrix_determinant(MatrixObject * self)
|
||||
{
|
||||
@@ -633,7 +640,7 @@ static PyObject *Matrix_toQuat(MatrixObject * self)
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if(self->colSize < 3 || self->rowSize < 3 || (self->colSize != self->rowSize)) {
|
||||
if((self->colSize < 3) || (self->rowSize < 3) || (self->colSize != self->rowSize)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.to_quat(): inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
@@ -807,21 +814,19 @@ static char Matrix_to_3x3_doc[] =
|
||||
" :rtype: :class:`Matrix`\n";
|
||||
PyObject *Matrix_to_3x3(MatrixObject * self)
|
||||
{
|
||||
float mat[3][3];
|
||||
|
||||
if(!BaseMath_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->colSize==3 && self->rowSize==3) {
|
||||
return (PyObject *)newMatrixObject(self->contigPtr, 3, 3, Py_NEW, Py_TYPE(self));
|
||||
if((self->colSize < 3) || (self->rowSize < 3)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.to_3x3(): inappropriate matrix size");
|
||||
return NULL;
|
||||
}
|
||||
else if(self->colSize==4 && self->rowSize==4) {
|
||||
float mat[3][3];
|
||||
copy_m3_m4(mat, (float (*)[4])self->contigPtr);
|
||||
return (PyObject *)newMatrixObject((float *)mat, 3, 3, Py_NEW, Py_TYPE(self));
|
||||
}
|
||||
/* TODO, 2x2 matrix */
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Matrix.to_3x3(): inappropriate matrix size");
|
||||
return NULL;
|
||||
matrix_as_3x3(mat, self);
|
||||
|
||||
return newMatrixObject((float *)mat, 3, 3, Py_NEW, Py_TYPE(self));
|
||||
}
|
||||
|
||||
/*---------------------------Matrix.translationPart() ------------*/
|
||||
@@ -838,7 +843,7 @@ PyObject *Matrix_TranslationPart(MatrixObject * self)
|
||||
if(!BaseMath_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->colSize < 3 || self->rowSize < 4){
|
||||
if((self->colSize < 3) || self->rowSize < 4){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.translation_part(): inappropriate matrix size");
|
||||
return NULL;
|
||||
}
|
||||
@@ -856,30 +861,21 @@ static char Matrix_RotationPart_doc[] =
|
||||
"\n"
|
||||
" .. note:: Note that the (4,4) element of a matrix can be used for uniform scaling too.\n";
|
||||
|
||||
PyObject *Matrix_RotationPart(MatrixObject * self)
|
||||
PyObject *Matrix_RotationPart(MatrixObject *self)
|
||||
{
|
||||
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};
|
||||
float mat[3][3];
|
||||
|
||||
if(!BaseMath_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->colSize < 3 || self->rowSize < 3){
|
||||
if((self->colSize < 3) || (self->rowSize < 3)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.rotation_part(): inappropriate matrix size");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mat[0] = self->matrix[0][0];
|
||||
mat[1] = self->matrix[0][1];
|
||||
mat[2] = self->matrix[0][2];
|
||||
mat[3] = self->matrix[1][0];
|
||||
mat[4] = self->matrix[1][1];
|
||||
mat[5] = self->matrix[1][2];
|
||||
mat[6] = self->matrix[2][0];
|
||||
mat[7] = self->matrix[2][1];
|
||||
mat[8] = self->matrix[2][2];
|
||||
matrix_as_3x3(mat, self);
|
||||
|
||||
return newMatrixObject(mat, 3, 3, Py_NEW, Py_TYPE(self));
|
||||
return newMatrixObject((float *)mat, 3, 3, Py_NEW, Py_TYPE(self));
|
||||
}
|
||||
/*---------------------------Matrix.scalePart() --------------------*/
|
||||
static char Matrix_scalePart_doc[] =
|
||||
@@ -894,31 +890,25 @@ static char Matrix_scalePart_doc[] =
|
||||
|
||||
PyObject *Matrix_scalePart(MatrixObject * self)
|
||||
{
|
||||
float scale[3], rot[3];
|
||||
float mat[3][3], imat[3][3], tmat[3][3];
|
||||
float rot[3][3];
|
||||
float mat[3][3];
|
||||
float size[3];
|
||||
|
||||
if(!BaseMath_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if(self->colSize == 4 && self->rowSize == 4)
|
||||
copy_m3_m4(mat, (float (*)[4])self->contigPtr);
|
||||
else if(self->colSize == 3 && self->rowSize == 3)
|
||||
copy_m3_m3(mat, (float (*)[3])self->contigPtr);
|
||||
else {
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.scale_part(): inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
if((self->colSize < 3) || (self->rowSize < 3)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.scale_part(): inappropriate matrix size, 3x3 minimum size");
|
||||
return NULL;
|
||||
}
|
||||
/* functionality copied from editobject.c apply_obmat */
|
||||
mat3_to_eul( rot,mat);
|
||||
eul_to_mat3( tmat,rot);
|
||||
invert_m3_m3(imat, tmat);
|
||||
mul_m3_m3m3(tmat, imat, mat);
|
||||
|
||||
scale[0]= tmat[0][0];
|
||||
scale[1]= tmat[1][1];
|
||||
scale[2]= tmat[2][2];
|
||||
return newVectorObject(scale, 3, Py_NEW, NULL);
|
||||
|
||||
matrix_as_3x3(mat, self);
|
||||
|
||||
/* compatible mat4_to_loc_rot_size */
|
||||
mat3_to_rot_size(rot, size, mat);
|
||||
|
||||
return newVectorObject(size, 3, Py_NEW, NULL);
|
||||
}
|
||||
|
||||
/*---------------------------Matrix.invert() ---------------------*/
|
||||
@@ -1688,15 +1678,13 @@ static PyObject *Matrix_getMedianScale(MatrixObject *self, void *UNUSED(closure)
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if(self->colSize == 4 && self->rowSize == 4)
|
||||
copy_m3_m4(mat, (float (*)[4])self->contigPtr);
|
||||
else if(self->colSize == 3 && self->rowSize == 3)
|
||||
copy_m3_m3(mat, (float (*)[3])self->contigPtr);
|
||||
else {
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.median_scale: inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
if((self->colSize < 3) || (self->rowSize < 3)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.median_scale: inappropriate matrix size, 3x3 minimum");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
matrix_as_3x3(mat, self);
|
||||
|
||||
return PyFloat_FromDouble(mat3_to_scale(mat));
|
||||
}
|
||||
|
||||
|
||||
@@ -76,11 +76,8 @@ static char Vector_Zero_doc[] =
|
||||
|
||||
static PyObject *Vector_Zero(VectorObject *self)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < self->size; i++) {
|
||||
self->vec[i] = 0.0f;
|
||||
}
|
||||
|
||||
fill_vn(self->vec, self->size, 0.0f);
|
||||
|
||||
(void)BaseMath_WriteCallback(self);
|
||||
Py_INCREF(self);
|
||||
return (PyObject*)self;
|
||||
@@ -780,7 +777,6 @@ static PyObject *Vector_item(VectorObject *self, int i)
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(self->vec[i]);
|
||||
|
||||
}
|
||||
/*----------------------------object[]-------------------------
|
||||
sequence accessor (set)*/
|
||||
@@ -861,43 +857,34 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end,
|
||||
addition*/
|
||||
static PyObject *Vector_add(PyObject * v1, PyObject * v2)
|
||||
{
|
||||
int i;
|
||||
float vec[4];
|
||||
|
||||
VectorObject *vec1 = NULL, *vec2 = NULL;
|
||||
|
||||
if VectorObject_Check(v1)
|
||||
vec1= (VectorObject *)v1;
|
||||
|
||||
if VectorObject_Check(v2)
|
||||
vec2= (VectorObject *)v2;
|
||||
|
||||
/* make sure v1 is always the vector */
|
||||
if (vec1 && vec2 ) {
|
||||
|
||||
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
/*VECTOR + VECTOR*/
|
||||
if(vec1->size != vec2->size) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector addition: vectors must have the same dimensions for this operation");
|
||||
return NULL;
|
||||
}
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
vec[i] = vec1->vec[i] + vec2->vec[i];
|
||||
}
|
||||
return newVectorObject(vec, vec1->size, Py_NEW, Py_TYPE(v1));
|
||||
float vec[MAX_DIMENSIONS];
|
||||
|
||||
if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector addition: arguments not valid for this operation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector addition: arguments not valid for this operation");
|
||||
return NULL;
|
||||
vec1 = (VectorObject*)v1;
|
||||
vec2 = (VectorObject*)v2;
|
||||
|
||||
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
/*VECTOR + VECTOR*/
|
||||
if(vec1->size != vec2->size) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector addition: vectors must have the same dimensions for this operation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
add_vn_vnvn(vec, vec1->vec, vec2->vec, vec1->size);
|
||||
|
||||
return newVectorObject(vec, vec1->size, Py_NEW, Py_TYPE(v1));
|
||||
}
|
||||
|
||||
/* ------------------------obj += obj------------------------------
|
||||
addition in place */
|
||||
static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
|
||||
{
|
||||
int i;
|
||||
VectorObject *vec1 = NULL, *vec2 = NULL;
|
||||
|
||||
if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) {
|
||||
@@ -915,12 +902,10 @@ static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
|
||||
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
vec1->vec[i] = vec1->vec[i] + vec2->vec[i];
|
||||
}
|
||||
add_vn_vn(vec1->vec, vec2->vec, vec1->size);
|
||||
|
||||
(void)BaseMath_WriteCallback(vec1);
|
||||
Py_INCREF( v1 );
|
||||
Py_INCREF(v1);
|
||||
return v1;
|
||||
}
|
||||
|
||||
@@ -928,9 +913,8 @@ static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
|
||||
subtraction*/
|
||||
static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
|
||||
{
|
||||
int i;
|
||||
float vec[4];
|
||||
VectorObject *vec1 = NULL, *vec2 = NULL;
|
||||
float vec[MAX_DIMENSIONS];
|
||||
|
||||
if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector subtraction: arguments not valid for this operation");
|
||||
@@ -946,9 +930,8 @@ static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector subtraction: vectors must have the same dimensions for this operation");
|
||||
return NULL;
|
||||
}
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
vec[i] = vec1->vec[i] - vec2->vec[i];
|
||||
}
|
||||
|
||||
sub_vn_vnvn(vec, vec1->vec, vec2->vec, vec1->size);
|
||||
|
||||
return newVectorObject(vec, vec1->size, Py_NEW, Py_TYPE(v1));
|
||||
}
|
||||
@@ -957,8 +940,7 @@ static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
|
||||
subtraction*/
|
||||
static PyObject *Vector_isub(PyObject * v1, PyObject * v2)
|
||||
{
|
||||
int i;
|
||||
VectorObject *vec1 = NULL, *vec2 = NULL;
|
||||
VectorObject *vec1= NULL, *vec2= NULL;
|
||||
|
||||
if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector subtraction: arguments not valid for this operation");
|
||||
@@ -975,12 +957,10 @@ static PyObject *Vector_isub(PyObject * v1, PyObject * v2)
|
||||
if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
vec1->vec[i] = vec1->vec[i] - vec2->vec[i];
|
||||
}
|
||||
sub_vn_vn(vec1->vec, vec2->vec, vec1->size);
|
||||
|
||||
(void)BaseMath_WriteCallback(vec1);
|
||||
Py_INCREF( v1 );
|
||||
Py_INCREF(v1);
|
||||
return v1;
|
||||
}
|
||||
|
||||
@@ -996,29 +976,29 @@ static PyObject *Vector_isub(PyObject * v1, PyObject * v2)
|
||||
* note: vector/matrix multiplication IS NOT COMMUTATIVE!!!!
|
||||
* note: assume read callbacks have been done first.
|
||||
*/
|
||||
static int column_vector_multiplication(float *rvec, VectorObject* vec, MatrixObject * mat)
|
||||
static int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec, MatrixObject * mat)
|
||||
{
|
||||
float vecCopy[4];
|
||||
float vec_cpy[MAX_DIMENSIONS];
|
||||
double dot = 0.0f;
|
||||
int x, y, z = 0;
|
||||
|
||||
if(mat->rowSize != vec->size){
|
||||
if(mat->rowSize == 4 && vec->size != 3){
|
||||
PyErr_SetString(PyExc_AttributeError, "matrix * vector: matrix row size and vector size must be the same");
|
||||
if(mat->rowSize == 4 && vec->size == 3) {
|
||||
vec_cpy[3] = 1.0f;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_AttributeError, "matrix * vector: matrix.row_size and len(vector) must be the same, except for 3D vector * 4x4 matrix.");
|
||||
return -1;
|
||||
}else{
|
||||
vecCopy[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
for(x = 0; x < vec->size; x++){
|
||||
vecCopy[x] = vec->vec[x];
|
||||
}
|
||||
memcpy(vec_cpy, vec->vec, vec->size * sizeof(float));
|
||||
|
||||
rvec[3] = 1.0f;
|
||||
|
||||
for(x = 0; x < mat->colSize; x++) {
|
||||
for(y = 0; y < mat->rowSize; y++) {
|
||||
dot += mat->matrix[y][x] * vecCopy[y];
|
||||
dot += mat->matrix[y][x] * vec_cpy[y];
|
||||
}
|
||||
rvec[z++] = (float)dot;
|
||||
dot = 0.0f;
|
||||
@@ -1030,11 +1010,7 @@ static int column_vector_multiplication(float *rvec, VectorObject* vec, MatrixOb
|
||||
static PyObject *vector_mul_float(VectorObject *vec, const float scalar)
|
||||
{
|
||||
float tvec[MAX_DIMENSIONS];
|
||||
int i;
|
||||
|
||||
for(i = 0; i < vec->size; i++) {
|
||||
tvec[i] = vec->vec[i] * scalar;
|
||||
}
|
||||
mul_vn_vn_fl(tvec, vec->vec, vec->size, scalar);
|
||||
return newVectorObject(tvec, vec->size, Py_NEW, Py_TYPE(vec));
|
||||
}
|
||||
|
||||
@@ -1493,7 +1469,7 @@ static PyObject *Vector_getLength(VectorObject *self, void *UNUSED(closure))
|
||||
return PyFloat_FromDouble(sqrt(dot));
|
||||
}
|
||||
|
||||
static int Vector_setLength(VectorObject *self, PyObject * value )
|
||||
static int Vector_setLength(VectorObject *self, PyObject *value)
|
||||
{
|
||||
double dot = 0.0f, param;
|
||||
int i;
|
||||
@@ -1511,9 +1487,7 @@ static int Vector_setLength(VectorObject *self, PyObject * value )
|
||||
return -1;
|
||||
}
|
||||
if (param == 0.0f) {
|
||||
for(i = 0; i < self->size; i++){
|
||||
self->vec[i]= 0;
|
||||
}
|
||||
fill_vn(self->vec, self->size, 0.0f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2052,7 +2026,7 @@ if len(unique) != len(items):
|
||||
//vector/matrix multiplication IS NOT COMMUTATIVE!!!!
|
||||
static int row_vector_multiplication(float rvec[4], VectorObject* vec, MatrixObject * mat)
|
||||
{
|
||||
float vecCopy[4];
|
||||
float vec_cpy[4];
|
||||
double dot = 0.0f;
|
||||
int x, y, z = 0, vec_size = vec->size;
|
||||
|
||||
@@ -2061,21 +2035,20 @@ static int row_vector_multiplication(float rvec[4], VectorObject* vec, MatrixObj
|
||||
PyErr_SetString(PyExc_AttributeError, "vector * matrix: matrix column size and the vector size must be the same");
|
||||
return -1;
|
||||
}else{
|
||||
vecCopy[3] = 1.0f;
|
||||
vec_cpy[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if(!BaseMath_ReadCallback(vec) || !BaseMath_ReadCallback(mat))
|
||||
return -1;
|
||||
|
||||
for(x = 0; x < vec_size; x++){
|
||||
vecCopy[x] = vec->vec[x];
|
||||
}
|
||||
|
||||
memcpy(vec_cpy, vec->vec, vec_size * sizeof(float));
|
||||
|
||||
rvec[3] = 1.0f;
|
||||
//muliplication
|
||||
for(x = 0; x < mat->rowSize; x++) {
|
||||
for(y = 0; y < mat->colSize; y++) {
|
||||
dot += mat->matrix[x][y] * vecCopy[y];
|
||||
dot += mat->matrix[x][y] * vec_cpy[y];
|
||||
}
|
||||
rvec[z++] = (float)dot;
|
||||
dot = 0.0f;
|
||||
@@ -2226,9 +2199,8 @@ PyTypeObject vector_Type = {
|
||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
||||
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
||||
(i.e. it must be created here with PyMEM_malloc())*/
|
||||
PyObject *newVectorObject(float *vec, int size, int type, PyTypeObject *base_type)
|
||||
PyObject *newVectorObject(float *vec, const int size, const int type, PyTypeObject *base_type)
|
||||
{
|
||||
int i;
|
||||
VectorObject *self;
|
||||
|
||||
if(size > 4 || size < 2)
|
||||
@@ -2247,16 +2219,14 @@ PyObject *newVectorObject(float *vec, int size, int type, PyTypeObject *base_typ
|
||||
self->vec = vec;
|
||||
self->wrapped = Py_WRAP;
|
||||
} else if (type == Py_NEW) {
|
||||
self->vec = PyMem_Malloc(size * sizeof(float));
|
||||
if(!vec) { /*new empty*/
|
||||
for(i = 0; i < size; i++){
|
||||
self->vec[i] = 0.0f;
|
||||
}
|
||||
if(size == 4) /* do the homogenous thing */
|
||||
self->vec= PyMem_Malloc(size * sizeof(float));
|
||||
if(vec) {
|
||||
memcpy(self->vec, vec, size * sizeof(float));
|
||||
}
|
||||
else { /* new empty */
|
||||
fill_vn(self->vec, size, 0.0f);
|
||||
if(size == 4) { /* do the homogenous thing */
|
||||
self->vec[3] = 1.0f;
|
||||
}else{
|
||||
for(i = 0; i < size; i++){
|
||||
self->vec[i] = vec[i];
|
||||
}
|
||||
}
|
||||
self->wrapped = Py_NEW;
|
||||
|
||||
@@ -43,7 +43,7 @@ typedef struct {
|
||||
} VectorObject;
|
||||
|
||||
/*prototypes*/
|
||||
PyObject *newVectorObject(float *vec, int size, int type, PyTypeObject *base_type);
|
||||
PyObject *newVectorObject(float *vec, const int size, const int type, PyTypeObject *base_type);
|
||||
PyObject *newVectorObject_cb(PyObject *user, int size, int callback_type, int subtype);
|
||||
|
||||
#endif /* MATHUTILS_VECTOR_H */
|
||||
|
||||
@@ -34,7 +34,7 @@ set(INC
|
||||
../../freestyle/intern/python
|
||||
../../../../intern/guardedalloc
|
||||
../../../../intern/audaspace/intern
|
||||
${PYTHON_INC}
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(SRC
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
#
|
||||
# Contributor(s): none yet.
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
#
|
||||
#
|
||||
|
||||
LIBNAME = python
|
||||
DIR = $(OCGDIR)/blender/$(LIBNAME)
|
||||
|
||||
include nan_compile.mk
|
||||
|
||||
CFLAGS += $(LEVEL_1_C_WARNINGS)
|
||||
|
||||
# OpenGL and Python
|
||||
CPPFLAGS += $(OGL_CPPFLAGS)
|
||||
CPPFLAGS += -I$(NAN_GLEW)/include
|
||||
CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
|
||||
|
||||
# PreProcessor stuff
|
||||
|
||||
CPPFLAGS += -I$(NAN_GHOST)/include
|
||||
CPPFLAGS += $(NAN_SDLCFLAGS)
|
||||
|
||||
# modules
|
||||
CPPFLAGS += -I../../editors/include
|
||||
CPPFLAGS += -I../../python
|
||||
CPPFLAGS += -I../../makesdna
|
||||
CPPFLAGS += -I../../makesrna
|
||||
CPPFLAGS += -I../../blenlib
|
||||
CPPFLAGS += -I../../blenkernel
|
||||
CPPFLAGS += -I../../nodes
|
||||
CPPFLAGS += -I../../imbuf
|
||||
CPPFLAGS += -I../../blenloader
|
||||
CPPFLAGS += -I../../windowmanager
|
||||
CPPFLAGS += -I../../render/extern/include
|
||||
CPPFLAGS += -I$(NAN_AUDASPACE)/include
|
||||
|
||||
# path to the guarded memory allocator
|
||||
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
|
||||
CPPFLAGS += -I$(NAN_MEMUTIL)/include
|
||||
|
||||
# path to our own headerfiles
|
||||
CPPFLAGS += -I..
|
||||
@@ -692,13 +692,17 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
|
||||
{
|
||||
StructRNA *srna;
|
||||
|
||||
srna= srna_from_self(value, "BoolProperty(...):");
|
||||
srna= srna_from_self(value, "");
|
||||
if(!srna) {
|
||||
|
||||
PyObject *msg= PyC_ExceptionBuffer();
|
||||
char *msg_char= _PyUnicode_AsString(msg);
|
||||
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from IDPropertyGroup, failed with: %s", error_prefix, msg_char);
|
||||
Py_DECREF(msg);
|
||||
if(PyErr_Occurred()) {
|
||||
PyObject *msg= PyC_ExceptionBuffer();
|
||||
char *msg_char= _PyUnicode_AsString(msg);
|
||||
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from IDPropertyGroup, failed with: %s", error_prefix, msg_char);
|
||||
Py_DECREF(msg);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from IDPropertyGroup, failed with type '%s'", error_prefix, Py_TYPE(value)->tp_name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -1075,13 +1075,14 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
|
||||
PyObject *value_coerce= NULL;
|
||||
int subtype= RNA_property_subtype(prop);
|
||||
if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
|
||||
/* TODO, get size */
|
||||
param= PyC_UnicodeAsByte(value, &value_coerce);
|
||||
}
|
||||
else {
|
||||
param= _PyUnicode_AsString(value);
|
||||
}
|
||||
#else // USE_STRING_COERCE
|
||||
param= _PyUnicode_AsString(value);
|
||||
param= _PyUnicode_AsStringSize(value);
|
||||
#endif // USE_STRING_COERCE
|
||||
|
||||
if (param==NULL) {
|
||||
@@ -2705,6 +2706,18 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self)
|
||||
|
||||
BLI_freelistN(&lb);
|
||||
}
|
||||
|
||||
{
|
||||
/* set(), this is needed to remove-doubles because the deferred
|
||||
* register-props will be in both the python __dict__ and accessed as RNA */
|
||||
|
||||
PyObject *set= PySet_New(ret);
|
||||
|
||||
Py_DECREF(ret);
|
||||
ret= PySequence_List(set);
|
||||
Py_DECREF(set);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2830,14 +2843,38 @@ static int pyrna_is_deferred_prop(PyObject *value)
|
||||
return PyTuple_CheckExact(value) && PyTuple_GET_SIZE(value)==2 && PyCallable_Check(PyTuple_GET_ITEM(value, 0)) && PyDict_CheckExact(PyTuple_GET_ITEM(value, 1));
|
||||
}
|
||||
|
||||
static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *pyname)
|
||||
static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr)
|
||||
{
|
||||
return PyType_Type.tp_getattro(cls, pyname);
|
||||
PyObject *ret= PyType_Type.tp_getattro(cls, attr);
|
||||
|
||||
/* Allows:
|
||||
* >>> bpy.types.Scene.foo = BoolProperty()
|
||||
* >>> bpy.types.Scene.foo
|
||||
* <bpy_struct, BooleanProperty("foo")>
|
||||
* ...rather then returning the defered class register tuple as checked by pyrna_is_deferred_prop()
|
||||
*
|
||||
* Disable for now, this is faking internal behavior in a way thats too tricky to maintain well. */
|
||||
#if 0
|
||||
if(ret == NULL) { // || pyrna_is_deferred_prop(ret)
|
||||
StructRNA *srna= srna_from_self(cls, "StructRNA.__getattr__");
|
||||
if(srna) {
|
||||
PropertyRNA *prop= RNA_struct_type_find_property(srna, _PyUnicode_AsString(attr));
|
||||
if(prop) {
|
||||
PointerRNA tptr;
|
||||
PyErr_Clear(); /* clear error from tp_getattro */
|
||||
RNA_pointer_create(NULL, &RNA_Property, prop, &tptr);
|
||||
ret= pyrna_struct_CreatePyObject(&tptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyObject *value)
|
||||
{
|
||||
StructRNA *srna= srna_from_self(cls, "");
|
||||
StructRNA *srna= srna_from_self(cls, "StructRNA.__setattr__");
|
||||
|
||||
if(srna == NULL) {
|
||||
if(value && pyrna_is_deferred_prop(value)) {
|
||||
@@ -2854,9 +2891,14 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb
|
||||
/* check if the value is a property */
|
||||
if(pyrna_is_deferred_prop(value)) {
|
||||
int ret= deferred_register_prop(srna, attr, value);
|
||||
if(ret < 0)
|
||||
if(ret == -1) {
|
||||
/* error set */
|
||||
return ret;
|
||||
/* pass through, when the value isn't assigned it still works but gets confusing from script writers POV */
|
||||
}
|
||||
|
||||
/* pass through and assign to the classes __dict__ as well
|
||||
* when the value isn't assigned it still creates the RNA property
|
||||
* but gets confusing from script writers POV if the assigned value cant be read back. */
|
||||
}
|
||||
else {
|
||||
/* remove existing property if its set or we also end up with confusement */
|
||||
@@ -2873,7 +2915,7 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* fallback to standard py, delattr/setattr */
|
||||
return PyType_Type.tp_setattro(cls, attr, value);
|
||||
}
|
||||
@@ -4950,12 +4992,10 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr
|
||||
|
||||
/* Orphan functions, not sure where they should go */
|
||||
/* get the srna for methods attached to types */
|
||||
/* */
|
||||
/*
|
||||
* Caller needs to raise error.*/
|
||||
StructRNA *srna_from_self(PyObject *self, const char *error_prefix)
|
||||
{
|
||||
/* a bit sloppy but would cause a very confusing bug if
|
||||
* an error happened to be set here */
|
||||
PyErr_Clear();
|
||||
|
||||
if(self==NULL) {
|
||||
return NULL;
|
||||
@@ -4966,10 +5006,24 @@ StructRNA *srna_from_self(PyObject *self, const char *error_prefix)
|
||||
else if (PyType_Check(self)==0) {
|
||||
return NULL;
|
||||
}
|
||||
/* These cases above not errors, they just mean the type was not compatible
|
||||
* After this any errors will be raised in the script */
|
||||
else {
|
||||
/* These cases above not errors, they just mean the type was not compatible
|
||||
* After this any errors will be raised in the script */
|
||||
|
||||
return pyrna_struct_as_srna(self, 0, error_prefix);
|
||||
PyObject *error_type, *error_value, *error_traceback;
|
||||
StructRNA *srna;
|
||||
|
||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||
PyErr_Clear();
|
||||
|
||||
srna= pyrna_struct_as_srna(self, 0, error_prefix);
|
||||
|
||||
if(!PyErr_Occurred()) {
|
||||
PyErr_Restore(error_type, error_value, error_traceback);
|
||||
}
|
||||
|
||||
return srna;
|
||||
}
|
||||
}
|
||||
|
||||
static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item)
|
||||
@@ -5140,7 +5194,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
}
|
||||
|
||||
/* verify callback functions */
|
||||
lb= RNA_struct_defined_functions(srna);
|
||||
lb= RNA_struct_type_functions(srna);
|
||||
i= 0;
|
||||
for(link=lb->first; link; link=link->next) {
|
||||
func= (FunctionRNA*)link;
|
||||
@@ -5199,7 +5253,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
}
|
||||
|
||||
/* verify properties */
|
||||
lb= RNA_struct_defined_properties(srna);
|
||||
lb= RNA_struct_type_properties(srna);
|
||||
for(link=lb->first; link; link=link->next) {
|
||||
const char *identifier;
|
||||
prop= (PropertyRNA*)link;
|
||||
@@ -5642,26 +5696,25 @@ static PyObject *pyrna_basetype_register(PyObject *UNUSED(self), PyObject *py_cl
|
||||
|
||||
static int pyrna_srna_contains_pointer_prop_srna(StructRNA *srna_props, StructRNA *srna, const char **prop_identifier)
|
||||
{
|
||||
PointerRNA tptr;
|
||||
PropertyRNA *iterprop;
|
||||
RNA_pointer_create(NULL, &RNA_Struct, srna_props, &tptr);
|
||||
|
||||
iterprop= RNA_struct_find_property(&tptr, "properties");
|
||||
PropertyRNA *prop;
|
||||
LinkData *link;
|
||||
|
||||
RNA_PROP_BEGIN(&tptr, itemptr, iterprop) {
|
||||
PropertyRNA *prop= itemptr.data;
|
||||
if(RNA_property_type(prop) == PROP_POINTER) {
|
||||
if (strcmp(RNA_property_identifier(prop), "rna_type") == 0) {
|
||||
/* pass */
|
||||
}
|
||||
else if(RNA_property_pointer_type(&tptr, prop) == srna) {
|
||||
/* verify properties */
|
||||
const ListBase *lb= RNA_struct_type_properties(srna);
|
||||
|
||||
for(link=lb->first; link; link=link->next) {
|
||||
prop= (PropertyRNA*)link;
|
||||
if(RNA_property_type(prop) == PROP_POINTER && !(RNA_property_flag(prop) & PROP_BUILTIN)) {
|
||||
PointerRNA tptr;
|
||||
RNA_pointer_create(NULL, &RNA_Struct, srna_props, &tptr);
|
||||
|
||||
if(RNA_property_pointer_type(&tptr, prop) == srna) {
|
||||
*prop_identifier= RNA_property_identifier(prop);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
RNA_PROP_END;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user