At last... this merge should finally do the trick!
21073 to 21145
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: BPY_extern.h 12334 2007-10-21 23:00:29Z aligorith $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
@@ -50,6 +50,8 @@ struct bConstraintTarget; /* DNA_constraint_types.h*/
|
||||
struct Script; /* DNA_screen_types.h */
|
||||
struct BPyMenu;
|
||||
struct bContext;
|
||||
struct ReportList;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* $Id: BPY_menus.h 12931 2007-12-17 18:20:48Z theeth $
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano, Matt Ebb
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef BPY_MENUS_H
|
||||
#define BPY_MENUS_H
|
||||
|
||||
/* This header exposes BPyMenu related public declarations. The implementation
|
||||
* adds 'dynamic' menus to Blender, letting scripts register themselves in any
|
||||
* of a few pre-defined (trivial to upgrade) places in menus. These places or
|
||||
* slots are called groups here (Import, Export, etc). This is how it works:
|
||||
* - scripts at dirs user pref U.pythondir and .blender/scripts/ are scanned
|
||||
* for registration info.
|
||||
* - this data is also saved to a Bpymenus file at the user's .blender/ dir and
|
||||
* only re-created when the scripts folder gets modified.
|
||||
* - on start-up Blender uses this info to fill a table, which is used to
|
||||
* create the menu entries when they are needed (see header_info.c or
|
||||
* header_script.c, under source/blender/src/, for examples).
|
||||
*/
|
||||
|
||||
/* These two structs hold py menu/submenu info.
|
||||
* BPyMenu holds a script's name (as should appear in the menu) and filename,
|
||||
* plus an optional list of submenus. Each submenu is related to a string
|
||||
* (arg) that the script can get from the __script__ pydict, to know which
|
||||
* submenu was chosen. */
|
||||
|
||||
typedef struct BPySubMenu {
|
||||
char *name;
|
||||
char *arg;
|
||||
struct BPySubMenu *next;
|
||||
} BPySubMenu;
|
||||
|
||||
typedef struct BPyMenu {
|
||||
char *name;
|
||||
char *filename;
|
||||
char *tooltip;
|
||||
short version; /* Blender version */
|
||||
int dir; /* 0: default, 1: U.pythondir */
|
||||
struct BPySubMenu *submenus;
|
||||
struct BPyMenu *next;
|
||||
} BPyMenu;
|
||||
|
||||
/* Scripts can be added to only a few pre-defined places in menus, like
|
||||
* File->Import, File->Export, etc. (for speed and better control).
|
||||
* To make a new menu 'slot' available for scripts:
|
||||
* - add an entry to the enum below, before PYMENU_TOTAL, of course;
|
||||
* - update the bpymenu_group_atoi() and BPyMenu_group_itoa() functions in
|
||||
* BPY_menus.c;
|
||||
* - add the necessary code to the header_***.c file in
|
||||
* source/blender/src/, like done in header_info.c for import/export;
|
||||
*/
|
||||
typedef enum {
|
||||
PYMENU_ADD,/* creates new objects */
|
||||
PYMENU_ANIMATION,
|
||||
PYMENU_EXPORT,
|
||||
PYMENU_IMPORT,
|
||||
PYMENU_MATERIALS,
|
||||
PYMENU_MESH,
|
||||
PYMENU_MISC,
|
||||
PYMENU_OBJECT,
|
||||
PYMENU_RENDER,/* exporters to external renderers */
|
||||
PYMENU_SYSTEM,
|
||||
PYMENU_THEMES,
|
||||
PYMENU_UV,/* UV editing tools, to go in UV/Image editor space, 'UV' menu */
|
||||
PYMENU_IMAGE,/* Image editing tools, to go in UV/Image editor space, 'Image' menu */
|
||||
PYMENU_WIZARDS,/* complex 'app' scripts */
|
||||
|
||||
/* entries put after Wizards don't appear at the Scripts win->Scripts menu;
|
||||
* see define right below */
|
||||
|
||||
PYMENU_FACESELECT,
|
||||
PYMENU_WEIGHTPAINT,
|
||||
PYMENU_VERTEXPAINT,
|
||||
PYMENU_UVCALCULATION,
|
||||
PYMENU_ARMATURE,
|
||||
PYMENU_SCRIPTTEMPLATE,
|
||||
PYMENU_HELP,/*Main Help menu items - prob best to leave for 'official' ones*/
|
||||
PYMENU_HELPSYSTEM,/* Resources, troubleshooting, system tools */
|
||||
PYMENU_HELPWEBSITES,/* Help -> Websites submenu */
|
||||
PYMENU_MESHFACEKEY, /* face key in mesh editmode */
|
||||
PYMENU_ADDMESH, /* adds mesh */
|
||||
PYMENU_TOTAL
|
||||
} PYMENUHOOKS;
|
||||
|
||||
#define PYMENU_SCRIPTS_MENU_TOTAL (PYMENU_WIZARDS + 1)
|
||||
|
||||
/* BPyMenuTable holds all registered pymenus, as linked lists for each menu
|
||||
* where they can appear (see PYMENUHOOKS enum above).
|
||||
*/
|
||||
extern BPyMenu *BPyMenuTable[]; /* defined in BPY_menus.c */
|
||||
|
||||
/* public functions: */
|
||||
int BPyMenu_Init( int usedir );
|
||||
void BPyMenu_RemoveAllEntries( void );
|
||||
void BPyMenu_PrintAllEntries( void );
|
||||
char *BPyMenu_CreatePupmenuStr( BPyMenu * pym, short group );
|
||||
char *BPyMenu_group_itoa( short group );
|
||||
struct BPyMenu *BPyMenu_GetEntry( short group, short pos );
|
||||
|
||||
#endif /* BPY_MENUS_H */
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: Makefile 14444 2008-04-16 22:40:48Z hos $
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: BGL.c 20922 2009-06-16 07:16:51Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
@@ -1087,7 +1087,7 @@ static struct PyMethodDef BGL_methods[] = {
|
||||
|
||||
#if (PY_VERSION_HEX >= 0x03000000)
|
||||
static struct PyModuleDef BGL_module_def = {
|
||||
{}, /* m_base */
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"BGL", /* m_name */
|
||||
0, /* m_doc */
|
||||
0, /* m_size */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: BGL.h 19717 2009-04-14 17:19:09Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Geometry.c 20922 2009-06-16 07:16:51Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
@@ -80,7 +80,7 @@ struct PyMethodDef M_Geometry_methods[] = {
|
||||
|
||||
#if (PY_VERSION_HEX >= 0x03000000)
|
||||
static struct PyModuleDef M_Geometry_module_def = {
|
||||
{}, /* m_base */
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"Geometry", /* m_name */
|
||||
M_Geometry_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Geometry.h 20007 2009-04-30 12:45:13Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: Makefile 11904 2007-08-31 16:16:33Z sirdude $
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Mathutils.c 20922 2009-06-16 07:16:51Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
@@ -96,7 +96,7 @@ struct PyMethodDef M_Mathutils_methods[] = {
|
||||
|
||||
#if (PY_VERSION_HEX >= 0x03000000)
|
||||
static struct PyModuleDef M_Mathutils_module_def = {
|
||||
{}, /* m_base */
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"Mathutils", /* m_name */
|
||||
M_Mathutils_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
@@ -137,81 +137,12 @@ PyObject *Mathutils_Init(const char *from)
|
||||
PyModule_AddObject( submodule, "Euler", (PyObject *)&euler_Type );
|
||||
PyModule_AddObject( submodule, "Quaternion", (PyObject *)&quaternion_Type );
|
||||
|
||||
mathutils_matrix_vector_cb_index= Mathutils_RegisterCallback(&mathutils_matrix_vector_cb);
|
||||
|
||||
return (submodule);
|
||||
}
|
||||
|
||||
//-----------------------------METHODS----------------------------
|
||||
//----------------column_vector_multiplication (internal)---------
|
||||
//COLUMN VECTOR Multiplication (Matrix X Vector)
|
||||
// [1][2][3] [a]
|
||||
// [4][5][6] * [b]
|
||||
// [7][8][9] [c]
|
||||
//vector/matrix multiplication IS NOT COMMUTATIVE!!!!
|
||||
PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec)
|
||||
{
|
||||
float vecNew[4], vecCopy[4];
|
||||
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");
|
||||
return NULL;
|
||||
}else{
|
||||
vecCopy[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
for(x = 0; x < vec->size; x++){
|
||||
vecCopy[x] = vec->vec[x];
|
||||
}
|
||||
|
||||
for(x = 0; x < mat->rowSize; x++) {
|
||||
for(y = 0; y < mat->colSize; y++) {
|
||||
dot += mat->matrix[x][y] * vecCopy[y];
|
||||
}
|
||||
vecNew[z++] = (float)dot;
|
||||
dot = 0.0f;
|
||||
}
|
||||
return newVectorObject(vecNew, vec->size, Py_NEW);
|
||||
}
|
||||
|
||||
//-----------------row_vector_multiplication (internal)-----------
|
||||
//ROW VECTOR Multiplication - Vector X Matrix
|
||||
//[x][y][z] * [1][2][3]
|
||||
// [4][5][6]
|
||||
// [7][8][9]
|
||||
//vector/matrix multiplication IS NOT COMMUTATIVE!!!!
|
||||
PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat)
|
||||
{
|
||||
float vecNew[4], vecCopy[4];
|
||||
double dot = 0.0f;
|
||||
int x, y, z = 0, vec_size = vec->size;
|
||||
|
||||
if(mat->colSize != vec_size){
|
||||
if(mat->rowSize == 4 && vec_size != 3){
|
||||
PyErr_SetString(PyExc_AttributeError, "vector * matrix: matrix column size and the vector size must be the same");
|
||||
return NULL;
|
||||
}else{
|
||||
vecCopy[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
for(x = 0; x < vec_size; x++){
|
||||
vecCopy[x] = vec->vec[x];
|
||||
}
|
||||
|
||||
//muliplication
|
||||
for(x = 0; x < mat->colSize; x++) {
|
||||
for(y = 0; y < mat->rowSize; y++) {
|
||||
dot += mat->matrix[y][x] * vecCopy[y];
|
||||
}
|
||||
vecNew[z++] = (float)dot;
|
||||
dot = 0.0f;
|
||||
}
|
||||
return newVectorObject(vecNew, vec_size, Py_NEW);
|
||||
}
|
||||
|
||||
//-----------------quat_rotation (internal)-----------
|
||||
//This function multiplies a vector/point * quat or vice versa
|
||||
//to rotate the point/vector by the quaternion
|
||||
@@ -226,6 +157,10 @@ PyObject *quat_rotation(PyObject *arg1, PyObject *arg2)
|
||||
quat = (QuaternionObject*)arg1;
|
||||
if(VectorObject_Check(arg2)){
|
||||
vec = (VectorObject*)arg2;
|
||||
|
||||
if(!Vector_ReadCallback(vec))
|
||||
return NULL;
|
||||
|
||||
rot[0] = quat->quat[0]*quat->quat[0]*vec->vec[0] + 2*quat->quat[2]*quat->quat[0]*vec->vec[2] -
|
||||
2*quat->quat[3]*quat->quat[0]*vec->vec[1] + quat->quat[1]*quat->quat[1]*vec->vec[0] +
|
||||
2*quat->quat[2]*quat->quat[1]*vec->vec[1] + 2*quat->quat[3]*quat->quat[1]*vec->vec[2] -
|
||||
@@ -242,6 +177,10 @@ PyObject *quat_rotation(PyObject *arg1, PyObject *arg2)
|
||||
}
|
||||
}else if(VectorObject_Check(arg1)){
|
||||
vec = (VectorObject*)arg1;
|
||||
|
||||
if(!Vector_ReadCallback(vec))
|
||||
return NULL;
|
||||
|
||||
if(QuaternionObject_Check(arg2)){
|
||||
quat = (QuaternionObject*)arg2;
|
||||
rot[0] = quat->quat[0]*quat->quat[0]*vec->vec[0] + 2*quat->quat[2]*quat->quat[0]*vec->vec[2] -
|
||||
@@ -308,6 +247,9 @@ static PyObject *M_Mathutils_AngleBetweenVecs(PyObject * self, PyObject * args)
|
||||
if(vec1->size != vec2->size)
|
||||
goto AttributeError1; //bad sizes
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
//since size is the same....
|
||||
size = vec1->size;
|
||||
|
||||
@@ -353,6 +295,9 @@ static PyObject *M_Mathutils_MidpointVecs(PyObject * self, PyObject * args)
|
||||
PyErr_SetString(PyExc_AttributeError, "Mathutils.MidpointVecs(): expects (2) vector objects of the same size\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
for(x = 0; x < vec1->size; x++) {
|
||||
vec[x] = 0.5f * (vec1->vec[x] + vec2->vec[x]);
|
||||
@@ -377,6 +322,10 @@ static PyObject *M_Mathutils_ProjectVecs(PyObject * self, PyObject * args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
|
||||
//since they are the same size...
|
||||
size = vec1->size;
|
||||
|
||||
@@ -439,6 +388,10 @@ static PyObject *M_Mathutils_RotationMatrix(PyObject * self, PyObject * args)
|
||||
PyErr_SetString(PyExc_AttributeError, "Mathutils.RotationMatrix(): the arbitrary axis must be a 3D vector\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec))
|
||||
return NULL;
|
||||
|
||||
}
|
||||
//convert to radians
|
||||
angle = angle * (float) (Py_PI / 180);
|
||||
@@ -538,6 +491,10 @@ static PyObject *M_Mathutils_TranslationMatrix(PyObject * self, VectorObject * v
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.TranslationMatrix(): vector must be 3D or 4D\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec))
|
||||
return NULL;
|
||||
|
||||
//create a identity matrix and add translation
|
||||
Mat4One((float(*)[4]) mat);
|
||||
mat[12] = vec->vec[0];
|
||||
@@ -570,6 +527,10 @@ static PyObject *M_Mathutils_ScaleMatrix(PyObject * self, PyObject * args)
|
||||
PyErr_SetString(PyExc_AttributeError, "Mathutils.ScaleMatrix(): please use 2D vectors when scaling in 2D\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec))
|
||||
return NULL;
|
||||
|
||||
}
|
||||
if(vec == NULL) { //scaling along axis
|
||||
if(matSize == 2) {
|
||||
@@ -645,6 +606,10 @@ static PyObject *M_Mathutils_OrthoProjectionMatrix(PyObject * self, PyObject * a
|
||||
PyErr_SetString(PyExc_AttributeError, "Mathutils.OrthoProjectionMatrix(): please use 2D vectors when scaling in 2D\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec))
|
||||
return NULL;
|
||||
|
||||
}
|
||||
if(vec == NULL) { //ortho projection onto cardinal plane
|
||||
if(((strcmp(plane, "x") == 0)
|
||||
@@ -891,6 +856,9 @@ static PyObject *M_Mathutils_Intersect( PyObject * self, PyObject * args )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2) || !Vector_ReadCallback(vec3) || !Vector_ReadCallback(ray) || !Vector_ReadCallback(ray_off))
|
||||
return NULL;
|
||||
|
||||
VECCOPY(v1, vec1->vec);
|
||||
VECCOPY(v2, vec2->vec);
|
||||
VECCOPY(v3, vec3->vec);
|
||||
@@ -959,6 +927,10 @@ static PyObject *M_Mathutils_LineIntersect( PyObject * self, PyObject * args )
|
||||
PyErr_SetString( PyExc_TypeError,"vectors must be of the same size\n" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2) || !Vector_ReadCallback(vec3) || !Vector_ReadCallback(vec4))
|
||||
return NULL;
|
||||
|
||||
if( vec1->size == 3 || vec1->size == 2) {
|
||||
int result;
|
||||
|
||||
@@ -1029,6 +1001,10 @@ static PyObject *M_Mathutils_QuadNormal( PyObject * self, PyObject * args )
|
||||
PyErr_SetString( PyExc_TypeError, "only 3D vectors\n" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2) || !Vector_ReadCallback(vec3) || !Vector_ReadCallback(vec4))
|
||||
return NULL;
|
||||
|
||||
VECCOPY(v1, vec1->vec);
|
||||
VECCOPY(v2, vec2->vec);
|
||||
VECCOPY(v3, vec3->vec);
|
||||
@@ -1073,6 +1049,9 @@ static PyObject *M_Mathutils_TriangleNormal( PyObject * self, PyObject * args )
|
||||
PyErr_SetString( PyExc_TypeError, "only 3D vectors\n" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2) || !Vector_ReadCallback(vec3))
|
||||
return NULL;
|
||||
|
||||
VECCOPY(v1, vec1->vec);
|
||||
VECCOPY(v2, vec2->vec);
|
||||
@@ -1105,6 +1084,9 @@ static PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args )
|
||||
PyErr_SetString( PyExc_TypeError, "vectors must be of the same size\n" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2) || !Vector_ReadCallback(vec3))
|
||||
return NULL;
|
||||
|
||||
if (vec1->size == 3) {
|
||||
VECCOPY(v1, vec1->vec);
|
||||
@@ -1154,8 +1136,8 @@ int EXPP_FloatsAreEqual(float A, float B, int floatSteps)
|
||||
}
|
||||
/*---------------------- EXPP_VectorsAreEqual -------------------------
|
||||
Builds on EXPP_FloatsAreEqual to test vectors */
|
||||
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps){
|
||||
|
||||
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps)
|
||||
{
|
||||
int x;
|
||||
for (x=0; x< size; x++){
|
||||
if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0)
|
||||
@@ -1165,6 +1147,95 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps){
|
||||
}
|
||||
|
||||
|
||||
/* Mathutils Callbacks */
|
||||
|
||||
//#######################################################################
|
||||
//#############################DEPRECATED################################
|
||||
/* for mathutils internal use only, eventually should re-alloc but to start with we only have a few users */
|
||||
Mathutils_Callback *mathutils_callbacks[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
||||
|
||||
int Mathutils_RegisterCallback(Mathutils_Callback *cb)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* find the first free slot */
|
||||
for(i= 0; mathutils_callbacks[i]; i++) {
|
||||
if(mathutils_callbacks[i]==cb) /* alredy registered? */
|
||||
return i;
|
||||
}
|
||||
|
||||
mathutils_callbacks[i] = cb;
|
||||
return i;
|
||||
}
|
||||
|
||||
/* use macros to check for NULL */
|
||||
int _Vector_ReadCallback(VectorObject *self)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->get(self->cb_user, self->cb_subtype, self->vec)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_SystemError, "Vector user has become invalid");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _Vector_WriteCallback(VectorObject *self)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->set(self->cb_user, self->cb_subtype, self->vec)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_SystemError, "Vector user has become invalid");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _Vector_ReadIndexCallback(VectorObject *self, int index)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->get_index(self->cb_user, self->cb_subtype, self->vec, index)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_SystemError, "Vector user has become invalid");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _Vector_WriteIndexCallback(VectorObject *self, int index)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->set_index(self->cb_user, self->cb_subtype, self->vec, index)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_SystemError, "Vector user has become invalid");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* matrix callbacks */
|
||||
int _Matrix_ReadCallback(MatrixObject *self)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->get(self->cb_user, self->cb_subtype, self->contigPtr)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_SystemError, "Matrix user has become invalid");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _Matrix_WriteCallback(MatrixObject *self)
|
||||
{
|
||||
Mathutils_Callback *cb= mathutils_callbacks[self->cb_type];
|
||||
if(cb->set(self->cb_user, self->cb_subtype, self->contigPtr)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_SystemError, "Matrix user has become invalid");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Mathutils.h 20332 2009-05-22 03:22:56Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
@@ -40,8 +40,6 @@
|
||||
|
||||
PyObject *Mathutils_Init( const char * from );
|
||||
|
||||
PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat);
|
||||
PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec);
|
||||
PyObject *quat_rotation(PyObject *arg1, PyObject *arg2);
|
||||
|
||||
int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
|
||||
@@ -49,8 +47,9 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
|
||||
|
||||
|
||||
#define Py_PI 3.14159265358979323846
|
||||
#define Py_WRAP 1024
|
||||
#define Py_NEW 2048
|
||||
|
||||
#define Py_NEW 1
|
||||
#define Py_WRAP 2
|
||||
|
||||
|
||||
/* Mathutils is used by the BGE and Blender so have to define
|
||||
@@ -65,4 +64,33 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
|
||||
#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
|
||||
#endif
|
||||
|
||||
typedef struct Mathutils_Callback Mathutils_Callback;
|
||||
struct Mathutils_Callback {
|
||||
int (*check)(PyObject *user); /* checks the user is still valid */
|
||||
int (*get)(PyObject *user, int subtype, float *from); /* gets the vector from the user */
|
||||
int (*set)(PyObject *user, int subtype, float *to); /* sets the users vector values once the vector is modified */
|
||||
int (*get_index)(PyObject *user, int subtype, float *from,int index); /* same as above but only for an index */
|
||||
int (*set_index)(PyObject *user, int subtype, float *to, int index); /* same as above but only for an index */
|
||||
};
|
||||
|
||||
int Mathutils_RegisterCallback(Mathutils_Callback *cb);
|
||||
|
||||
int _Vector_ReadCallback(VectorObject *self);
|
||||
int _Vector_WriteCallback(VectorObject *self);
|
||||
int _Vector_ReadIndexCallback(VectorObject *self, int index);
|
||||
int _Vector_WriteIndexCallback(VectorObject *self, int index);
|
||||
|
||||
/* since this is called so often avoid where possible */
|
||||
#define Vector_ReadCallback(_self) (((_self)->cb_user ? _Vector_ReadCallback(_self):1))
|
||||
#define Vector_WriteCallback(_self) (((_self)->cb_user ?_Vector_WriteCallback(_self):1))
|
||||
#define Vector_ReadIndexCallback(_self, _index) (((_self)->cb_user ? _Vector_ReadIndexCallback(_self, _index):1))
|
||||
#define Vector_WriteIndexCallback(_self, _index) (((_self)->cb_user ? _Vector_WriteIndexCallback(_self, _index):1))
|
||||
|
||||
|
||||
int _Matrix_ReadCallback(MatrixObject *self);
|
||||
int _Matrix_WriteCallback(MatrixObject *self);
|
||||
|
||||
#define Matrix_ReadCallback(_self) (((_self)->cb_user ?_Matrix_ReadCallback(_self):1))
|
||||
#define Matrix_WriteCallback(_self) (((_self)->cb_user ?_Matrix_WriteCallback(_self):1))
|
||||
|
||||
#endif /* EXPP_Mathutils_H */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: bpy_internal_import.c 20434 2009-05-26 18:06:09Z campbellbarton $
|
||||
* $Id$
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: bpy_internal_import.h 20434 2009-05-26 18:06:09Z campbellbarton $
|
||||
* $Id$
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: euler.c 20248 2009-05-18 04:11:54Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: euler.h 20248 2009-05-18 04:11:54Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: matrix.c 20249 2009-05-18 04:27:48Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
@@ -31,6 +31,71 @@
|
||||
#include "BLI_arithb.h"
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec); /* utility func */
|
||||
|
||||
|
||||
/* matrix vector callbacks */
|
||||
int mathutils_matrix_vector_cb_index= -1;
|
||||
|
||||
static int mathutils_matrix_vector_check(MatrixObject *self)
|
||||
{
|
||||
return Matrix_ReadCallback(self);
|
||||
}
|
||||
|
||||
static int mathutils_matrix_vector_get(MatrixObject *self, int subtype, float *vec_from)
|
||||
{
|
||||
int i;
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return 0;
|
||||
|
||||
for(i=0; i<self->colSize; i++)
|
||||
vec_from[i]= self->matrix[subtype][i];
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mathutils_matrix_vector_set(MatrixObject *self, int subtype, float *vec_to)
|
||||
{
|
||||
int i;
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return 0;
|
||||
|
||||
for(i=0; i<self->colSize; i++)
|
||||
self->matrix[subtype][i]= vec_to[i];
|
||||
|
||||
Matrix_WriteCallback(self);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mathutils_matrix_vector_get_index(MatrixObject *self, int subtype, float *vec_from, int index)
|
||||
{
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return 0;
|
||||
|
||||
vec_from[index]= self->matrix[subtype][index];
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mathutils_matrix_vector_set_index(MatrixObject *self, int subtype, float *vec_to, int index)
|
||||
{
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return 0;
|
||||
|
||||
self->matrix[subtype][index]= vec_to[index];
|
||||
|
||||
Matrix_WriteCallback(self);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Mathutils_Callback mathutils_matrix_vector_cb = {
|
||||
mathutils_matrix_vector_check,
|
||||
mathutils_matrix_vector_get,
|
||||
mathutils_matrix_vector_set,
|
||||
mathutils_matrix_vector_get_index,
|
||||
mathutils_matrix_vector_set_index
|
||||
};
|
||||
/* matrix vector callbacks, this is so you can do matrix[i][j] = val */
|
||||
|
||||
/*-------------------------DOC STRINGS ---------------------------*/
|
||||
static char Matrix_Zero_doc[] = "() - set all values in the matrix to 0";
|
||||
static char Matrix_Identity_doc[] = "() - set the square matrix to it's identity matrix";
|
||||
@@ -99,6 +164,8 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
argObject = PyTuple_GET_ITEM(args, 0);
|
||||
if(MatrixObject_Check(argObject)){
|
||||
mat = (MatrixObject*)argObject;
|
||||
if(!Matrix_ReadCallback(mat))
|
||||
return NULL;
|
||||
|
||||
argSize = mat->rowSize; //rows
|
||||
seqSize = mat->colSize; //col
|
||||
@@ -158,6 +225,9 @@ static PyObject *Matrix_toQuat(MatrixObject * self)
|
||||
{
|
||||
float quat[4];
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if(self->colSize < 3 || self->rowSize < 3 || (self->colSize != self->rowSize)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.toQuat(): inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
@@ -178,6 +248,9 @@ PyObject *Matrix_toEuler(MatrixObject * self, PyObject *args)
|
||||
EulerObject *eul_compat = NULL;
|
||||
int x;
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "|O!:toEuler", &euler_Type, &eul_compat))
|
||||
return NULL;
|
||||
|
||||
@@ -213,17 +286,20 @@ PyObject *Matrix_Resize4x4(MatrixObject * self)
|
||||
{
|
||||
int x, first_row_elem, curr_pos, new_pos, blank_columns, blank_rows, index;
|
||||
|
||||
if(self->data.blend_data){
|
||||
PyErr_SetString(PyExc_TypeError, "cannot resize wrapped data - only python matrices");
|
||||
if(self->wrapped==Py_WRAP){
|
||||
PyErr_SetString(PyExc_TypeError, "cannot resize wrapped data - make a copy and resize that");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->data.py_data = PyMem_Realloc(self->data.py_data, (sizeof(float) * 16));
|
||||
if(self->data.py_data == NULL) {
|
||||
if(self->cb_user){
|
||||
PyErr_SetString(PyExc_TypeError, "cannot resize owned data - make a copy and resize that");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->contigPtr = PyMem_Realloc(self->contigPtr, (sizeof(float) * 16));
|
||||
if(self->contigPtr == NULL) {
|
||||
PyErr_SetString(PyExc_MemoryError, "matrix.resize4x4(): problem allocating pointer space");
|
||||
return NULL;
|
||||
}
|
||||
self->contigPtr = self->data.py_data; /*force*/
|
||||
self->matrix = PyMem_Realloc(self->matrix, (sizeof(float *) * 4));
|
||||
if(self->matrix == NULL) {
|
||||
PyErr_SetString(PyExc_MemoryError, "matrix.resize4x4(): problem allocating pointer space");
|
||||
@@ -266,7 +342,10 @@ PyObject *Matrix_Resize4x4(MatrixObject * self)
|
||||
PyObject *Matrix_TranslationPart(MatrixObject * self)
|
||||
{
|
||||
float vec[4];
|
||||
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->colSize < 3 || self->rowSize < 4){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.translationPart: inappropriate matrix size");
|
||||
return NULL;
|
||||
@@ -284,6 +363,9 @@ 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};
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->colSize < 3 || self->rowSize < 3){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.rotationPart: inappropriate matrix size\n");
|
||||
return NULL;
|
||||
@@ -307,6 +389,9 @@ PyObject *Matrix_scalePart(MatrixObject * self)
|
||||
float scale[3], rot[3];
|
||||
float mat[3][3], imat[3][3], tmat[3][3];
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
/*must be 3-4 cols, 3-4 rows, square matrix*/
|
||||
if(self->colSize == 4 && self->rowSize == 4)
|
||||
Mat3CpyMat4(mat, (float (*)[4])*self->matrix);
|
||||
@@ -337,6 +422,9 @@ PyObject *Matrix_Invert(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};
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->rowSize != self->colSize){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.invert(ed): only square matrices are supported");
|
||||
return NULL;
|
||||
@@ -377,6 +465,7 @@ PyObject *Matrix_Invert(MatrixObject * self)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Matrix_WriteCallback(self);
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
@@ -387,6 +476,9 @@ PyObject *Matrix_Determinant(MatrixObject * self)
|
||||
{
|
||||
float det = 0.0f;
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->rowSize != self->colSize){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.determinant: only square matrices are supported");
|
||||
return NULL;
|
||||
@@ -412,6 +504,9 @@ PyObject *Matrix_Transpose(MatrixObject * self)
|
||||
{
|
||||
float t = 0.0f;
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->rowSize != self->colSize){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.transpose(d): only square matrices are supported");
|
||||
return NULL;
|
||||
@@ -427,6 +522,7 @@ PyObject *Matrix_Transpose(MatrixObject * self)
|
||||
Mat4Transp((float (*)[4])*self->matrix);
|
||||
}
|
||||
|
||||
Matrix_WriteCallback(self);
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
@@ -436,18 +532,25 @@ PyObject *Matrix_Transpose(MatrixObject * self)
|
||||
PyObject *Matrix_Zero(MatrixObject * self)
|
||||
{
|
||||
int row, col;
|
||||
|
||||
|
||||
for(row = 0; row < self->rowSize; row++) {
|
||||
for(col = 0; col < self->colSize; col++) {
|
||||
self->matrix[row][col] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if(!Matrix_WriteCallback(self))
|
||||
return NULL;
|
||||
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
/*---------------------------Matrix.identity(() ------------------*/
|
||||
PyObject *Matrix_Identity(MatrixObject * self)
|
||||
{
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(self->rowSize != self->colSize){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix.identity: only square matrices are supported\n");
|
||||
return NULL;
|
||||
@@ -464,6 +567,9 @@ PyObject *Matrix_Identity(MatrixObject * self)
|
||||
Mat4One((float (*)[4]) *self->matrix);
|
||||
}
|
||||
|
||||
if(!Matrix_WriteCallback(self))
|
||||
return NULL;
|
||||
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
@@ -471,6 +577,9 @@ PyObject *Matrix_Identity(MatrixObject * self)
|
||||
/*---------------------------Matrix.inverted() ------------------*/
|
||||
PyObject *Matrix_copy(MatrixObject * self)
|
||||
{
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
return (PyObject*)(MatrixObject*)newMatrixObject((float (*))*self->matrix, self->rowSize, self->colSize, Py_NEW);
|
||||
}
|
||||
|
||||
@@ -480,9 +589,10 @@ static void Matrix_dealloc(MatrixObject * self)
|
||||
{
|
||||
PyMem_Free(self->matrix);
|
||||
/*only free py_data*/
|
||||
if(self->data.py_data){
|
||||
PyMem_Free(self->data.py_data);
|
||||
}
|
||||
if(self->wrapped==Py_WRAP)
|
||||
PyMem_Free(self->contigPtr);
|
||||
|
||||
Py_XDECREF(self->cb_user);
|
||||
PyObject_DEL(self);
|
||||
}
|
||||
|
||||
@@ -493,6 +603,9 @@ static PyObject *Matrix_repr(MatrixObject * self)
|
||||
int x, y;
|
||||
char buffer[48], str[1024];
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
BLI_strncpy(str,"",1024);
|
||||
for(x = 0; x < self->rowSize; x++){
|
||||
sprintf(buffer, "[");
|
||||
@@ -529,6 +642,9 @@ static PyObject* Matrix_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
matA = (MatrixObject*)objectA;
|
||||
matB = (MatrixObject*)objectB;
|
||||
|
||||
if(!Matrix_ReadCallback(matA) || !Matrix_ReadCallback(matB))
|
||||
return NULL;
|
||||
|
||||
if (matA->colSize != matB->colSize || matA->rowSize != matB->rowSize){
|
||||
if (comparison_type == Py_NE){
|
||||
Py_RETURN_TRUE;
|
||||
@@ -576,11 +692,14 @@ static int Matrix_len(MatrixObject * self)
|
||||
the wrapped vector gives direct access to the matrix data*/
|
||||
static PyObject *Matrix_item(MatrixObject * self, int i)
|
||||
{
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if(i < 0 || i >= self->rowSize) {
|
||||
PyErr_SetString(PyExc_IndexError, "matrix[attribute]: array index out of range");
|
||||
return NULL;
|
||||
}
|
||||
return newVectorObject(self->matrix[i], self->colSize, Py_WRAP);
|
||||
return newVectorObject_cb((PyObject *)self, self->colSize, mathutils_matrix_vector_cb_index, i);
|
||||
}
|
||||
/*----------------------------object[]-------------------------
|
||||
sequence accessor (set)*/
|
||||
@@ -590,6 +709,9 @@ static int Matrix_ass_item(MatrixObject * self, int i, PyObject * ob)
|
||||
float vec[4];
|
||||
PyObject *m, *f;
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return -1;
|
||||
|
||||
if(i >= self->rowSize || i < 0){
|
||||
PyErr_SetString(PyExc_TypeError, "matrix[attribute] = x: bad row\n");
|
||||
return -1;
|
||||
@@ -623,6 +745,8 @@ static int Matrix_ass_item(MatrixObject * self, int i, PyObject * ob)
|
||||
for(y = 0; y < size; y++){
|
||||
self->matrix[i][y] = vec[y];
|
||||
}
|
||||
|
||||
Matrix_WriteCallback(self);
|
||||
return 0;
|
||||
}else{
|
||||
PyErr_SetString(PyExc_TypeError, "matrix[attribute] = x: expects a sequence of column size\n");
|
||||
@@ -636,6 +760,9 @@ static PyObject *Matrix_slice(MatrixObject * self, int begin, int end)
|
||||
|
||||
PyObject *list = NULL;
|
||||
int count;
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
CLAMP(begin, 0, self->rowSize);
|
||||
CLAMP(end, 0, self->rowSize);
|
||||
@@ -644,7 +771,8 @@ static PyObject *Matrix_slice(MatrixObject * self, int begin, int end)
|
||||
list = PyList_New(end - begin);
|
||||
for(count = begin; count < end; count++) {
|
||||
PyList_SetItem(list, count - begin,
|
||||
newVectorObject(self->matrix[count], self->colSize, Py_WRAP));
|
||||
newVectorObject_cb((PyObject *)self, self->colSize, mathutils_matrix_vector_cb_index, count));
|
||||
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -659,6 +787,9 @@ static int Matrix_ass_slice(MatrixObject * self, int begin, int end,
|
||||
PyObject *subseq;
|
||||
PyObject *m;
|
||||
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return -1;
|
||||
|
||||
CLAMP(begin, 0, self->rowSize);
|
||||
CLAMP(end, 0, self->rowSize);
|
||||
begin = MIN2(begin,end);
|
||||
@@ -716,6 +847,8 @@ static int Matrix_ass_slice(MatrixObject * self, int begin, int end,
|
||||
for(x = 0; x < (size * sub_size); x++){
|
||||
self->matrix[begin + (int)floor(x / self->colSize)][x % self->colSize] = mat[x];
|
||||
}
|
||||
|
||||
Matrix_WriteCallback(self);
|
||||
return 0;
|
||||
}else{
|
||||
PyErr_SetString(PyExc_TypeError, "matrix[begin:end] = []: illegal argument type for built-in operation\n");
|
||||
@@ -738,6 +871,10 @@ static PyObject *Matrix_add(PyObject * m1, PyObject * m2)
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix addition: arguments not valid for this operation....");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Matrix_ReadCallback(mat1) || !Matrix_ReadCallback(mat2))
|
||||
return NULL;
|
||||
|
||||
if(mat1->rowSize != mat2->rowSize || mat1->colSize != mat2->colSize){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix addition: matrices must have the same dimensions for this operation");
|
||||
return NULL;
|
||||
@@ -767,6 +904,10 @@ static PyObject *Matrix_sub(PyObject * m1, PyObject * m2)
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix addition: arguments not valid for this operation....");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Matrix_ReadCallback(mat1) || !Matrix_ReadCallback(mat2))
|
||||
return NULL;
|
||||
|
||||
if(mat1->rowSize != mat2->rowSize || mat1->colSize != mat2->colSize){
|
||||
PyErr_SetString(PyExc_AttributeError, "Matrix addition: matrices must have the same dimensions for this operation");
|
||||
return NULL;
|
||||
@@ -791,8 +932,16 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
|
||||
double dot = 0.0f;
|
||||
MatrixObject *mat1 = NULL, *mat2 = NULL;
|
||||
|
||||
if(MatrixObject_Check(m1)) mat1 = (MatrixObject*)m1;
|
||||
if(MatrixObject_Check(m2)) mat2 = (MatrixObject*)m2;
|
||||
if(MatrixObject_Check(m1)) {
|
||||
mat1 = (MatrixObject*)m1;
|
||||
if(!Matrix_ReadCallback(mat1))
|
||||
return NULL;
|
||||
}
|
||||
if(MatrixObject_Check(m2)) {
|
||||
mat2 = (MatrixObject*)m2;
|
||||
if(!Matrix_ReadCallback(mat2))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(mat1 && mat2) { /*MATRIX * MATRIX*/
|
||||
if(mat1->colSize != mat2->rowSize){
|
||||
@@ -829,7 +978,7 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
|
||||
else /* if(mat1) { */ {
|
||||
|
||||
if(VectorObject_Check(m2)) { /* MATRIX*VECTOR */
|
||||
return column_vector_multiplication(mat1, (VectorObject *)m2);
|
||||
return column_vector_multiplication(mat1, (VectorObject *)m2); /* vector update done inside the function */
|
||||
}
|
||||
else {
|
||||
scalar= PyFloat_AsDouble(m2);
|
||||
@@ -851,6 +1000,9 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
|
||||
}
|
||||
static PyObject* Matrix_inv(MatrixObject *self)
|
||||
{
|
||||
if(!Matrix_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
return Matrix_Invert(self);
|
||||
}
|
||||
|
||||
@@ -900,6 +1052,17 @@ static PyObject *Matrix_getColSize( MatrixObject * self, void *type )
|
||||
return PyLong_FromLong((long) self->colSize);
|
||||
}
|
||||
|
||||
static PyObject *Matrix_getOwner( MatrixObject * self, void *type )
|
||||
{
|
||||
if(self->cb_user==NULL) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
else {
|
||||
Py_INCREF(self->cb_user);
|
||||
return self->cb_user;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *Matrix_getWrapped( MatrixObject * self, void *type )
|
||||
{
|
||||
if (self->wrapped == Py_WRAP)
|
||||
@@ -915,6 +1078,7 @@ static PyGetSetDef Matrix_getseters[] = {
|
||||
{"rowSize", (getter)Matrix_getRowSize, (setter)NULL, "", NULL},
|
||||
{"colSize", (getter)Matrix_getColSize, (setter)NULL, "", NULL},
|
||||
{"wrapped", (getter)Matrix_getWrapped, (setter)NULL, "", NULL},
|
||||
{"__owner__",(getter)Matrix_getOwner, (setter)NULL, "Read only owner for vectors that depend on another object", NULL},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
@@ -984,7 +1148,7 @@ self->matrix self->contiguous_ptr (reference to data.xxx)
|
||||
[4]
|
||||
[5]
|
||||
....
|
||||
self->matrix[1][1] = self->contiguous_ptr[4] = self->data.xxx_data[4]*/
|
||||
self->matrix[1][1] = self->contigPtr[4] */
|
||||
|
||||
/*pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
|
||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
||||
@@ -1002,14 +1166,15 @@ PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type)
|
||||
}
|
||||
|
||||
self = PyObject_NEW(MatrixObject, &matrix_Type);
|
||||
self->data.blend_data = NULL;
|
||||
self->data.py_data = NULL;
|
||||
self->rowSize = rowSize;
|
||||
self->colSize = colSize;
|
||||
|
||||
/* init callbacks as NULL */
|
||||
self->cb_user= NULL;
|
||||
self->cb_type= self->cb_subtype= 0;
|
||||
|
||||
if(type == Py_WRAP){
|
||||
self->data.blend_data = mat;
|
||||
self->contigPtr = self->data.blend_data;
|
||||
self->contigPtr = mat;
|
||||
/*create pointer array*/
|
||||
self->matrix = PyMem_Malloc(rowSize * sizeof(float *));
|
||||
if(self->matrix == NULL) { /*allocation failure*/
|
||||
@@ -1022,16 +1187,15 @@ PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type)
|
||||
}
|
||||
self->wrapped = Py_WRAP;
|
||||
}else if (type == Py_NEW){
|
||||
self->data.py_data = PyMem_Malloc(rowSize * colSize * sizeof(float));
|
||||
if(self->data.py_data == NULL) { /*allocation failure*/
|
||||
self->contigPtr = PyMem_Malloc(rowSize * colSize * sizeof(float));
|
||||
if(self->contigPtr == NULL) { /*allocation failure*/
|
||||
PyErr_SetString( PyExc_MemoryError, "matrix(): problem allocating pointer space\n");
|
||||
return NULL;
|
||||
}
|
||||
self->contigPtr = self->data.py_data;
|
||||
/*create pointer array*/
|
||||
self->matrix = PyMem_Malloc(rowSize * sizeof(float *));
|
||||
if(self->matrix == NULL) { /*allocation failure*/
|
||||
PyMem_Free(self->data.py_data);
|
||||
PyMem_Free(self->contigPtr);
|
||||
PyErr_SetString( PyExc_MemoryError, "matrix(): problem allocating pointer space");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1056,3 +1220,53 @@ PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type)
|
||||
}
|
||||
return (PyObject *) self;
|
||||
}
|
||||
|
||||
PyObject *newMatrixObject_cb(PyObject *cb_user, int rowSize, int colSize, int cb_type, int cb_subtype)
|
||||
{
|
||||
MatrixObject *self= (MatrixObject *)newMatrixObject(NULL, rowSize, colSize, Py_NEW);
|
||||
if(self) {
|
||||
Py_INCREF(cb_user);
|
||||
self->cb_user= cb_user;
|
||||
self->cb_type= (unsigned char)cb_type;
|
||||
self->cb_subtype= (unsigned char)cb_subtype;
|
||||
}
|
||||
return (PyObject *) self;
|
||||
}
|
||||
|
||||
//----------------column_vector_multiplication (internal)---------
|
||||
//COLUMN VECTOR Multiplication (Matrix X Vector)
|
||||
// [1][2][3] [a]
|
||||
// [4][5][6] * [b]
|
||||
// [7][8][9] [c]
|
||||
//vector/matrix multiplication IS NOT COMMUTATIVE!!!!
|
||||
static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec)
|
||||
{
|
||||
float vecNew[4], vecCopy[4];
|
||||
double dot = 0.0f;
|
||||
int x, y, z = 0;
|
||||
|
||||
if(!Matrix_ReadCallback(mat) || !Vector_ReadCallback(vec))
|
||||
return NULL;
|
||||
|
||||
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");
|
||||
return NULL;
|
||||
}else{
|
||||
vecCopy[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
for(x = 0; x < vec->size; x++){
|
||||
vecCopy[x] = vec->vec[x];
|
||||
}
|
||||
|
||||
for(x = 0; x < mat->rowSize; x++) {
|
||||
for(y = 0; y < mat->colSize; y++) {
|
||||
dot += mat->matrix[x][y] * vecCopy[y];
|
||||
}
|
||||
vecNew[z++] = (float)dot;
|
||||
dot = 0.0f;
|
||||
}
|
||||
return newVectorObject(vecNew, vec->size, Py_NEW);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: matrix.h 20248 2009-05-18 04:11:54Z campbellbarton $
|
||||
* $Id$
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -39,15 +39,14 @@ extern PyTypeObject matrix_Type;
|
||||
typedef float **ptRow;
|
||||
typedef struct _Matrix {
|
||||
PyObject_VAR_HEAD
|
||||
struct{
|
||||
float *py_data; /*python managed*/
|
||||
float *blend_data; /*blender managed*/
|
||||
}data;
|
||||
ptRow matrix; /*ptr to the contigPtr (accessor)*/
|
||||
float *contigPtr; /*1D array of data (alias)*/
|
||||
int rowSize;
|
||||
int colSize;
|
||||
int wrapped; /*is wrapped data?*/
|
||||
ptRow matrix; /*ptr to the contigPtr (accessor)*/
|
||||
float* contigPtr; /*1D array of data (alias)*/
|
||||
PyObject* cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */
|
||||
unsigned char rowSize;
|
||||
unsigned char colSize;
|
||||
unsigned char wrapped; /*is wrapped data?*/
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */
|
||||
unsigned int cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */
|
||||
} MatrixObject;
|
||||
|
||||
/*struct data contains a pointer to the actual data that the
|
||||
@@ -57,5 +56,9 @@ blender (stored in blend_data). This is an either/or struct not both*/
|
||||
|
||||
/*prototypes*/
|
||||
PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type);
|
||||
PyObject *newMatrixObject_cb(PyObject *user, int rowSize, int colSize, int cb_type, int cb_subtype);
|
||||
|
||||
extern int mathutils_matrix_vector_cb_index;
|
||||
extern struct Mathutils_Callback mathutils_matrix_vector_cb;
|
||||
|
||||
#endif /* EXPP_matrix_H */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: quat.c 20332 2009-05-22 03:22:56Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
@@ -75,7 +75,7 @@ static struct PyMethodDef Quaternion_methods[] = {
|
||||
//----------------------------------Mathutils.Quaternion() --------------
|
||||
static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyObject *listObject = NULL, *n, *q, *f;
|
||||
PyObject *listObject = NULL, *n, *q;
|
||||
int size, i;
|
||||
float quat[4], scalar;
|
||||
double norm = 0.0f, angle = 0.0f;
|
||||
@@ -159,7 +159,6 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
|
||||
}
|
||||
|
||||
quat[i] = scalar;
|
||||
Py_DECREF(f);
|
||||
Py_DECREF(q);
|
||||
}
|
||||
if(size == 3){ //calculate the quat based on axis/angle
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: quat.h 20332 2009-05-22 03:22:56Z campbellbarton $
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: vector.c 20332 2009-05-22 03:22:56Z campbellbarton $
|
||||
* $Id$
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -39,6 +39,8 @@
|
||||
#define SWIZZLE_VALID_AXIS 0x4
|
||||
#define SWIZZLE_AXIS 0x3
|
||||
|
||||
static PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat); /* utility func */
|
||||
|
||||
/*-------------------------DOC STRINGS ---------------------------*/
|
||||
static char Vector_Zero_doc[] = "() - set all values in the vector to 0";
|
||||
static char Vector_Normalize_doc[] = "() - normalize the vector";
|
||||
@@ -60,7 +62,7 @@ static PyObject *Vector_Resize2D( VectorObject * self );
|
||||
static PyObject *Vector_Resize3D( VectorObject * self );
|
||||
static PyObject *Vector_Resize4D( VectorObject * self );
|
||||
static PyObject *Vector_ToTrackQuat( VectorObject * self, PyObject * args );
|
||||
static PyObject *Vector_Reflect( VectorObject * self, PyObject * value );
|
||||
static PyObject *Vector_Reflect( VectorObject *self, VectorObject *value );
|
||||
static PyObject *Vector_Cross( VectorObject * self, VectorObject * value );
|
||||
static PyObject *Vector_Dot( VectorObject * self, VectorObject * value );
|
||||
static PyObject *Vector_copy( VectorObject * self );
|
||||
@@ -70,8 +72,8 @@ static struct PyMethodDef Vector_methods[] = {
|
||||
{"normalize", (PyCFunction) Vector_Normalize, METH_NOARGS, Vector_Normalize_doc},
|
||||
{"negate", (PyCFunction) Vector_Negate, METH_NOARGS, Vector_Negate_doc},
|
||||
{"resize2D", (PyCFunction) Vector_Resize2D, METH_NOARGS, Vector_Resize2D_doc},
|
||||
{"resize3D", (PyCFunction) Vector_Resize3D, METH_NOARGS, Vector_Resize2D_doc},
|
||||
{"resize4D", (PyCFunction) Vector_Resize4D, METH_NOARGS, Vector_Resize2D_doc},
|
||||
{"resize3D", (PyCFunction) Vector_Resize3D, METH_NOARGS, Vector_Resize3D_doc},
|
||||
{"resize4D", (PyCFunction) Vector_Resize4D, METH_NOARGS, Vector_Resize4D_doc},
|
||||
{"toTrackQuat", ( PyCFunction ) Vector_ToTrackQuat, METH_VARARGS, Vector_ToTrackQuat_doc},
|
||||
{"reflect", ( PyCFunction ) Vector_Reflect, METH_O, Vector_Reflect_doc},
|
||||
{"cross", ( PyCFunction ) Vector_Cross, METH_O, Vector_Dot_doc},
|
||||
@@ -141,6 +143,8 @@ static PyObject *Vector_Zero(VectorObject * self)
|
||||
for(i = 0; i < self->size; i++) {
|
||||
self->vec[i] = 0.0f;
|
||||
}
|
||||
|
||||
Vector_WriteCallback(self);
|
||||
Py_INCREF(self);
|
||||
return (PyObject*)self;
|
||||
}
|
||||
@@ -151,6 +155,9 @@ static PyObject *Vector_Normalize(VectorObject * self)
|
||||
int i;
|
||||
float norm = 0.0f;
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < self->size; i++) {
|
||||
norm += self->vec[i] * self->vec[i];
|
||||
}
|
||||
@@ -158,6 +165,8 @@ static PyObject *Vector_Normalize(VectorObject * self)
|
||||
for(i = 0; i < self->size; i++) {
|
||||
self->vec[i] /= norm;
|
||||
}
|
||||
|
||||
Vector_WriteCallback(self);
|
||||
Py_INCREF(self);
|
||||
return (PyObject*)self;
|
||||
}
|
||||
@@ -171,6 +180,11 @@ static PyObject *Vector_Resize2D(VectorObject * self)
|
||||
PyErr_SetString(PyExc_TypeError, "vector.resize2d(): cannot resize wrapped data - only python vectors\n");
|
||||
return NULL;
|
||||
}
|
||||
if(self->cb_user) {
|
||||
PyErr_SetString(PyExc_TypeError, "vector.resize4d(): cannot resize a vector that has an owner");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->vec = PyMem_Realloc(self->vec, (sizeof(float) * 2));
|
||||
if(self->vec == NULL) {
|
||||
PyErr_SetString(PyExc_MemoryError, "vector.resize2d(): problem allocating pointer space\n\n");
|
||||
@@ -189,6 +203,11 @@ static PyObject *Vector_Resize3D(VectorObject * self)
|
||||
PyErr_SetString(PyExc_TypeError, "vector.resize3d(): cannot resize wrapped data - only python vectors\n");
|
||||
return NULL;
|
||||
}
|
||||
if(self->cb_user) {
|
||||
PyErr_SetString(PyExc_TypeError, "vector.resize4d(): cannot resize a vector that has an owner");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->vec = PyMem_Realloc(self->vec, (sizeof(float) * 3));
|
||||
if(self->vec == NULL) {
|
||||
PyErr_SetString(PyExc_MemoryError, "vector.resize3d(): problem allocating pointer space\n\n");
|
||||
@@ -210,6 +229,11 @@ static PyObject *Vector_Resize4D(VectorObject * self)
|
||||
PyErr_SetString(PyExc_TypeError, "vector.resize4d(): cannot resize wrapped data - only python vectors");
|
||||
return NULL;
|
||||
}
|
||||
if(self->cb_user) {
|
||||
PyErr_SetString(PyExc_TypeError, "vector.resize4d(): cannot resize a vector that has an owner");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->vec = PyMem_Realloc(self->vec, (sizeof(float) * 4));
|
||||
if(self->vec == NULL) {
|
||||
PyErr_SetString(PyExc_MemoryError, "vector.resize4d(): problem allocating pointer space\n\n");
|
||||
@@ -241,6 +265,9 @@ static PyObject *Vector_ToTrackQuat( VectorObject * self, PyObject * args )
|
||||
PyErr_SetString( PyExc_TypeError, "only for 3D vectors\n" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
if (strack) {
|
||||
if (strlen(strack) == 2) {
|
||||
@@ -342,9 +369,8 @@ static PyObject *Vector_ToTrackQuat( VectorObject * self, PyObject * args )
|
||||
return a reflected vector on the mirror normal
|
||||
((2 * DotVecs(vec, mirror)) * mirror) - vec
|
||||
using arithb.c would be nice here */
|
||||
static PyObject *Vector_Reflect( VectorObject * self, PyObject * value )
|
||||
static PyObject *Vector_Reflect( VectorObject * self, VectorObject * value )
|
||||
{
|
||||
VectorObject *mirrvec;
|
||||
float mirror[3];
|
||||
float vec[3];
|
||||
float reflect[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
@@ -358,11 +384,13 @@ static PyObject *Vector_Reflect( VectorObject * self, PyObject * value )
|
||||
PyErr_SetString( PyExc_TypeError, "vec.reflect(value): expected a vector argument" );
|
||||
return NULL;
|
||||
}
|
||||
mirrvec = (VectorObject *)value;
|
||||
|
||||
mirror[0] = mirrvec->vec[0];
|
||||
mirror[1] = mirrvec->vec[1];
|
||||
if (mirrvec->size > 2) mirror[2] = mirrvec->vec[2];
|
||||
if(!Vector_ReadCallback(self) || !Vector_ReadCallback(value))
|
||||
return NULL;
|
||||
|
||||
mirror[0] = value->vec[0];
|
||||
mirror[1] = value->vec[1];
|
||||
if (value->size > 2) mirror[2] = value->vec[2];
|
||||
else mirror[2] = 0.0;
|
||||
|
||||
/* normalize, whos idea was it not to use arithb.c? :-/ */
|
||||
@@ -403,6 +431,9 @@ static PyObject *Vector_Cross( VectorObject * self, VectorObject * value )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(self) || !Vector_ReadCallback(value))
|
||||
return NULL;
|
||||
|
||||
vecCross = (VectorObject *)newVectorObject(NULL, 3, Py_NEW);
|
||||
Crossf(vecCross->vec, self->vec, value->vec);
|
||||
return (PyObject *)vecCross;
|
||||
@@ -423,6 +454,9 @@ static PyObject *Vector_Dot( VectorObject * self, VectorObject * value )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(self) || !Vector_ReadCallback(value))
|
||||
return NULL;
|
||||
|
||||
for(x = 0; x < self->size; x++) {
|
||||
dot += self->vec[x] * value->vec[x];
|
||||
}
|
||||
@@ -433,6 +467,9 @@ static PyObject *Vector_Dot( VectorObject * self, VectorObject * value )
|
||||
return a copy of the vector */
|
||||
static PyObject *Vector_copy(VectorObject * self)
|
||||
{
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
return newVectorObject(self->vec, self->size, Py_NEW);
|
||||
}
|
||||
|
||||
@@ -441,9 +478,10 @@ static PyObject *Vector_copy(VectorObject * self)
|
||||
static void Vector_dealloc(VectorObject * self)
|
||||
{
|
||||
/* only free non wrapped */
|
||||
if(self->wrapped != Py_WRAP){
|
||||
if(self->wrapped != Py_WRAP)
|
||||
PyMem_Free(self->vec);
|
||||
}
|
||||
|
||||
Py_XDECREF(self->cb_user);
|
||||
PyObject_DEL(self);
|
||||
}
|
||||
|
||||
@@ -454,6 +492,9 @@ static PyObject *Vector_repr(VectorObject * self)
|
||||
int i;
|
||||
char buffer[48], str[1024];
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
BLI_strncpy(str,"[",1024);
|
||||
for(i = 0; i < self->size; i++){
|
||||
if(i < (self->size - 1)){
|
||||
@@ -484,6 +525,9 @@ static PyObject *Vector_item(VectorObject * self, int i)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadIndexCallback(self, i))
|
||||
return NULL;
|
||||
|
||||
return PyFloat_FromDouble(self->vec[i]);
|
||||
|
||||
}
|
||||
@@ -502,6 +546,9 @@ static int Vector_ass_item(VectorObject * self, int i, PyObject * ob)
|
||||
return -1;
|
||||
}
|
||||
self->vec[i] = scalar;
|
||||
|
||||
if(!Vector_WriteIndexCallback(self, i))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -512,6 +559,9 @@ static PyObject *Vector_slice(VectorObject * self, int begin, int end)
|
||||
PyObject *list = NULL;
|
||||
int count;
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
CLAMP(begin, 0, self->size);
|
||||
if (end<0) end= self->size+end+1;
|
||||
CLAMP(end, 0, self->size);
|
||||
@@ -534,6 +584,9 @@ static int Vector_ass_slice(VectorObject * self, int begin, int end,
|
||||
float vec[4], scalar;
|
||||
PyObject *v;
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return -1;
|
||||
|
||||
CLAMP(begin, 0, self->size);
|
||||
if (end<0) end= self->size+end+1;
|
||||
CLAMP(end, 0, self->size);
|
||||
@@ -566,6 +619,10 @@ static int Vector_ass_slice(VectorObject * self, int begin, int end,
|
||||
for(y = 0; y < size; y++){
|
||||
self->vec[begin + y] = vec[y];
|
||||
}
|
||||
|
||||
if(!Vector_WriteCallback(self))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*------------------------NUMERIC PROTOCOLS----------------------
|
||||
@@ -586,6 +643,10 @@ static PyObject *Vector_add(PyObject * v1, PyObject * v2)
|
||||
|
||||
/* make sure v1 is always the vector */
|
||||
if (vec1 && vec2 ) {
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_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\n");
|
||||
@@ -617,6 +678,10 @@ static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
|
||||
|
||||
/* make sure v1 is always the vector */
|
||||
if (vec1 && vec2 ) {
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_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\n");
|
||||
@@ -629,6 +694,7 @@ static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
|
||||
return v1;
|
||||
}
|
||||
|
||||
Vector_WriteCallback(vec1);
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector addition: arguments not valid for this operation....\n");
|
||||
return NULL;
|
||||
}
|
||||
@@ -648,6 +714,9 @@ static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
|
||||
vec1 = (VectorObject*)v1;
|
||||
vec2 = (VectorObject*)v2;
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
if(vec1->size != vec2->size) {
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector subtraction: vectors must have the same dimensions for this operation\n");
|
||||
return NULL;
|
||||
@@ -663,7 +732,7 @@ static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
|
||||
subtraction*/
|
||||
static PyObject *Vector_isub(PyObject * v1, PyObject * v2)
|
||||
{
|
||||
int i, size;
|
||||
int i;
|
||||
VectorObject *vec1 = NULL, *vec2 = NULL;
|
||||
|
||||
if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) {
|
||||
@@ -677,12 +746,15 @@ static PyObject *Vector_isub(PyObject * v1, PyObject * v2)
|
||||
PyErr_SetString(PyExc_AttributeError, "Vector subtraction: vectors must have the same dimensions for this operation\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec1) || !Vector_ReadCallback(vec2))
|
||||
return NULL;
|
||||
|
||||
size = vec1->size;
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
vec1->vec[i] = vec1->vec[i] - vec2->vec[i];
|
||||
}
|
||||
|
||||
Vector_WriteCallback(vec1);
|
||||
Py_INCREF( v1 );
|
||||
return v1;
|
||||
}
|
||||
@@ -694,11 +766,17 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
|
||||
VectorObject *vec1 = NULL, *vec2 = NULL;
|
||||
float scalar;
|
||||
|
||||
if VectorObject_Check(v1)
|
||||
if VectorObject_Check(v1) {
|
||||
vec1= (VectorObject *)v1;
|
||||
|
||||
if VectorObject_Check(v2)
|
||||
if(!Vector_ReadCallback(vec1))
|
||||
return NULL;
|
||||
}
|
||||
if VectorObject_Check(v2) {
|
||||
vec2= (VectorObject *)v2;
|
||||
if(!Vector_ReadCallback(vec2))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* make sure v1 is always the vector */
|
||||
if (vec1 && vec2 ) {
|
||||
@@ -757,6 +835,9 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
|
||||
int i;
|
||||
float scalar;
|
||||
|
||||
if(!Vector_ReadCallback(vec))
|
||||
return NULL;
|
||||
|
||||
/* only support vec*=float and vec*=mat
|
||||
vec*=vec result is a float so that wont work */
|
||||
if (MatrixObject_Check(v2)) {
|
||||
@@ -764,6 +845,9 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
|
||||
int x,y, size = vec->size;
|
||||
MatrixObject *mat= (MatrixObject*)v2;
|
||||
|
||||
if(!Vector_ReadCallback(mat))
|
||||
return NULL;
|
||||
|
||||
if(mat->colSize != size){
|
||||
if(mat->rowSize == 4 && vec->size != 3){
|
||||
PyErr_SetString(PyExc_AttributeError, "vector * matrix: matrix column size and the vector size must be the same");
|
||||
@@ -787,22 +871,21 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
|
||||
}
|
||||
vec->vec[i] = (float)dot;
|
||||
}
|
||||
Py_INCREF( v1 );
|
||||
return v1;
|
||||
}
|
||||
else if (((scalar= PyFloat_AsDouble(v2)) == -1.0 && PyErr_Occurred())==0) { /* VEC*=FLOAT */
|
||||
|
||||
for(i = 0; i < vec->size; i++) {
|
||||
vec->vec[i] *= scalar;
|
||||
}
|
||||
|
||||
Py_INCREF( v1 );
|
||||
return v1;
|
||||
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "Vector multiplication: arguments not acceptable for this operation\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Vector multiplication: arguments not acceptable for this operation\n");
|
||||
return NULL;
|
||||
Vector_WriteCallback(vec);
|
||||
Py_INCREF( v1 );
|
||||
return v1;
|
||||
}
|
||||
|
||||
/*------------------------obj / obj------------------------------
|
||||
@@ -819,6 +902,9 @@ static PyObject *Vector_div(PyObject * v1, PyObject * v2)
|
||||
}
|
||||
vec1 = (VectorObject*)v1; /* vector */
|
||||
|
||||
if(!Vector_ReadCallback(vec1))
|
||||
return NULL;
|
||||
|
||||
scalar = (float)PyFloat_AsDouble(v2);
|
||||
if(scalar== -1.0f && PyErr_Occurred()) { /* parsed item not a number */
|
||||
PyErr_SetString(PyExc_TypeError, "Vector division: Vector must be divided by a float\n");
|
||||
@@ -842,14 +928,10 @@ static PyObject *Vector_idiv(PyObject * v1, PyObject * v2)
|
||||
{
|
||||
int i;
|
||||
float scalar;
|
||||
VectorObject *vec1 = NULL;
|
||||
VectorObject *vec1 = (VectorObject*)v1;
|
||||
|
||||
/*if(!VectorObject_Check(v1)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Vector division: Vector must be divided by a float\n");
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
vec1 = (VectorObject*)v1; /* vector */
|
||||
if(!Vector_ReadCallback(vec1))
|
||||
return NULL;
|
||||
|
||||
scalar = (float)PyFloat_AsDouble(v2);
|
||||
if(scalar==-1.0f && PyErr_Occurred()) { /* parsed item not a number */
|
||||
@@ -864,6 +946,9 @@ static PyObject *Vector_idiv(PyObject * v1, PyObject * v2)
|
||||
for(i = 0; i < vec1->size; i++) {
|
||||
vec1->vec[i] /= scalar;
|
||||
}
|
||||
|
||||
Vector_WriteCallback(vec1);
|
||||
|
||||
Py_INCREF( v1 );
|
||||
return v1;
|
||||
}
|
||||
@@ -874,6 +959,10 @@ static PyObject *Vector_neg(VectorObject *self)
|
||||
{
|
||||
int i;
|
||||
float vec[4];
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < self->size; i++){
|
||||
vec[i] = -self->vec[i];
|
||||
}
|
||||
@@ -919,6 +1008,9 @@ static PyObject* Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
vecA = (VectorObject*)objectA;
|
||||
vecB = (VectorObject*)objectB;
|
||||
|
||||
if(!Vector_ReadCallback(vecA) || !Vector_ReadCallback(vecB))
|
||||
return NULL;
|
||||
|
||||
if (vecA->size != vecB->size){
|
||||
if (comparison_type == Py_NE){
|
||||
Py_RETURN_TRUE;
|
||||
@@ -1045,66 +1137,12 @@ static PyNumberMethods Vector_NumMethods = {
|
||||
|
||||
static PyObject *Vector_getAxis( VectorObject * self, void *type )
|
||||
{
|
||||
switch( (long)type ) {
|
||||
case 'X': /* these are backwards, but that how it works */
|
||||
return PyFloat_FromDouble(self->vec[0]);
|
||||
case 'Y':
|
||||
return PyFloat_FromDouble(self->vec[1]);
|
||||
case 'Z': /* these are backwards, but that how it works */
|
||||
if(self->size < 3) {
|
||||
PyErr_SetString(PyExc_AttributeError, "vector.z: error, cannot get this axis for a 2D vector\n");
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
return PyFloat_FromDouble(self->vec[2]);
|
||||
}
|
||||
case 'W':
|
||||
if(self->size < 4) {
|
||||
PyErr_SetString(PyExc_AttributeError, "vector.w: error, cannot get this axis for a 3D vector\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyFloat_FromDouble(self->vec[3]);
|
||||
default:
|
||||
{
|
||||
PyErr_SetString( PyExc_RuntimeError, "undefined type in Vector_getAxis" );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return Vector_item(self, (int)type);
|
||||
}
|
||||
|
||||
static int Vector_setAxis( VectorObject * self, PyObject * value, void * type )
|
||||
{
|
||||
float param= (float)PyFloat_AsDouble( value );
|
||||
|
||||
if (param==-1 && PyErr_Occurred()) {
|
||||
PyErr_SetString( PyExc_TypeError, "expected a number for the vector axis" );
|
||||
return -1;
|
||||
}
|
||||
switch( (long)type ) {
|
||||
case 'X': /* these are backwards, but that how it works */
|
||||
self->vec[0]= param;
|
||||
break;
|
||||
case 'Y':
|
||||
self->vec[1]= param;
|
||||
break;
|
||||
case 'Z': /* these are backwards, but that how it works */
|
||||
if(self->size < 3) {
|
||||
PyErr_SetString(PyExc_AttributeError, "vector.z: error, cannot get this axis for a 2D vector\n");
|
||||
return -1;
|
||||
}
|
||||
self->vec[2]= param;
|
||||
break;
|
||||
case 'W':
|
||||
if(self->size < 4) {
|
||||
PyErr_SetString(PyExc_AttributeError, "vector.w: error, cannot get this axis for a 3D vector\n");
|
||||
return -1;
|
||||
}
|
||||
self->vec[3]= param;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return Vector_ass_item(self, (int)type, value);
|
||||
}
|
||||
|
||||
/* vector.length */
|
||||
@@ -1113,6 +1151,9 @@ static PyObject *Vector_getLength( VectorObject * self, void *type )
|
||||
double dot = 0.0f;
|
||||
int i;
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < self->size; i++){
|
||||
dot += (self->vec[i] * self->vec[i]);
|
||||
}
|
||||
@@ -1124,6 +1165,9 @@ static int Vector_setLength( VectorObject * self, PyObject * value )
|
||||
double dot = 0.0f, param;
|
||||
int i;
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return -1;
|
||||
|
||||
param= PyFloat_AsDouble( value );
|
||||
if(param==-1.0 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "length must be set to a number");
|
||||
@@ -1159,6 +1203,8 @@ static int Vector_setLength( VectorObject * self, PyObject * value )
|
||||
self->vec[i]= self->vec[i] / (float)dot;
|
||||
}
|
||||
|
||||
Vector_WriteCallback(self); /* checked alredy */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1170,6 +1216,16 @@ static PyObject *Vector_getWrapped( VectorObject * self, void *type )
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *Vector_getOwner( VectorObject * self, void *type )
|
||||
{
|
||||
if(self->cb_user==NULL) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
else {
|
||||
Py_INCREF(self->cb_user);
|
||||
return self->cb_user;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get a new Vector according to the provided swizzle. This function has little
|
||||
error checking, as we are in control of the inputs: the closure is set by us
|
||||
@@ -1181,6 +1237,9 @@ static PyObject *Vector_getSwizzle(VectorObject * self, void *closure)
|
||||
float vec[MAX_DIMENSIONS];
|
||||
unsigned int swizzleClosure;
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
/* Unpack the axes from the closure into an array. */
|
||||
axisA = 0;
|
||||
swizzleClosure = (unsigned int) closure;
|
||||
@@ -1218,6 +1277,9 @@ static int Vector_setSwizzle(VectorObject * self, PyObject * value, void *closur
|
||||
|
||||
float vecTemp[MAX_DIMENSIONS];
|
||||
|
||||
if(!Vector_ReadCallback(self))
|
||||
return -1;
|
||||
|
||||
/* Check that the closure can be used with this vector: even 2D vectors have
|
||||
swizzles defined for axes z and w, but they would be invalid. */
|
||||
swizzleClosure = (unsigned int) closure;
|
||||
@@ -1247,7 +1309,7 @@ static int Vector_setSwizzle(VectorObject * self, PyObject * value, void *closur
|
||||
axisB++;
|
||||
}
|
||||
memcpy(self->vec, vecTemp, axisB * sizeof(float));
|
||||
return 0;
|
||||
/* continue with Vector_WriteCallback at the end */
|
||||
}
|
||||
else if (PyList_Check(value))
|
||||
{
|
||||
@@ -1273,7 +1335,7 @@ static int Vector_setSwizzle(VectorObject * self, PyObject * value, void *closur
|
||||
axisB++;
|
||||
}
|
||||
memcpy(self->vec, vecTemp, axisB * sizeof(float));
|
||||
return 0;
|
||||
/* continue with Vector_WriteCallback at the end */
|
||||
}
|
||||
else if (((scalarVal = (float)PyFloat_AsDouble(value)) == -1.0 && PyErr_Occurred())==0)
|
||||
{
|
||||
@@ -1286,13 +1348,17 @@ static int Vector_setSwizzle(VectorObject * self, PyObject * value, void *closur
|
||||
|
||||
swizzleClosure = swizzleClosure >> SWIZZLE_BITS_PER_AXIS;
|
||||
}
|
||||
return 0;
|
||||
/* continue with Vector_WriteCallback at the end */
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
PyErr_SetString( PyExc_TypeError, "Expected a Vector, list or scalar value." );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!Vector_WriteCallback(vecVal))
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -1302,19 +1368,19 @@ static PyGetSetDef Vector_getseters[] = {
|
||||
{"x",
|
||||
(getter)Vector_getAxis, (setter)Vector_setAxis,
|
||||
"Vector X axis",
|
||||
(void *)'X'},
|
||||
(void *)0},
|
||||
{"y",
|
||||
(getter)Vector_getAxis, (setter)Vector_setAxis,
|
||||
"Vector Y axis",
|
||||
(void *)'Y'},
|
||||
(void *)1},
|
||||
{"z",
|
||||
(getter)Vector_getAxis, (setter)Vector_setAxis,
|
||||
"Vector Z axis",
|
||||
(void *)'Z'},
|
||||
(void *)2},
|
||||
{"w",
|
||||
(getter)Vector_getAxis, (setter)Vector_setAxis,
|
||||
"Vector Z axis",
|
||||
(void *)'W'},
|
||||
(void *)3},
|
||||
{"length",
|
||||
(getter)Vector_getLength, (setter)Vector_setLength,
|
||||
"Vector Length",
|
||||
@@ -1327,6 +1393,10 @@ static PyGetSetDef Vector_getseters[] = {
|
||||
(getter)Vector_getWrapped, (setter)NULL,
|
||||
"True when this wraps blenders internal data",
|
||||
NULL},
|
||||
{"__owner__",
|
||||
(getter)Vector_getOwner, (setter)NULL,
|
||||
"Read only owner for vectors that depend on another object",
|
||||
NULL},
|
||||
|
||||
/* autogenerated swizzle attrs, see python script below */
|
||||
{"xx", (getter)Vector_getSwizzle, (setter)Vector_setSwizzle, Vector_swizzle_doc, (void *)((unsigned int)((0|SWIZZLE_VALID_AXIS) | ((0|SWIZZLE_VALID_AXIS)<<SWIZZLE_BITS_PER_AXIS)))}, /* 36 */
|
||||
@@ -1819,6 +1889,10 @@ PyObject *newVectorObject(float *vec, int size, int type)
|
||||
if(size > 4 || size < 2)
|
||||
return NULL;
|
||||
self->size = size;
|
||||
|
||||
/* init callbacks as NULL */
|
||||
self->cb_user= NULL;
|
||||
self->cb_type= self->cb_subtype= 0;
|
||||
|
||||
if(type == Py_WRAP) {
|
||||
self->vec = vec;
|
||||
@@ -1843,20 +1917,72 @@ PyObject *newVectorObject(float *vec, int size, int type)
|
||||
return (PyObject *) self;
|
||||
}
|
||||
|
||||
/*
|
||||
#############################DEPRECATED################################
|
||||
#######################################################################
|
||||
----------------------------Vector.negate() --------------------
|
||||
PyObject *newVectorObject_cb(PyObject *cb_user, int size, int cb_type, int cb_subtype)
|
||||
{
|
||||
float dummy[4] = {0.0, 0.0, 0.0, 0.0}; /* dummy init vector, callbacks will be used on access */
|
||||
VectorObject *self= newVectorObject(dummy, size, Py_NEW);
|
||||
if(self) {
|
||||
Py_INCREF(cb_user);
|
||||
self->cb_user= cb_user;
|
||||
self->cb_type= (unsigned char)cb_type;
|
||||
self->cb_subtype= (unsigned char)cb_subtype;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
//-----------------row_vector_multiplication (internal)-----------
|
||||
//ROW VECTOR Multiplication - Vector X Matrix
|
||||
//[x][y][z] * [1][2][3]
|
||||
// [4][5][6]
|
||||
// [7][8][9]
|
||||
//vector/matrix multiplication IS NOT COMMUTATIVE!!!!
|
||||
static PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat)
|
||||
{
|
||||
float vecNew[4], vecCopy[4];
|
||||
double dot = 0.0f;
|
||||
int x, y, z = 0, vec_size = vec->size;
|
||||
|
||||
if(mat->colSize != vec_size){
|
||||
if(mat->rowSize == 4 && vec_size != 3){
|
||||
PyErr_SetString(PyExc_AttributeError, "vector * matrix: matrix column size and the vector size must be the same");
|
||||
return NULL;
|
||||
}else{
|
||||
vecCopy[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if(!Vector_ReadCallback(vec) || !Matrix_ReadCallback(mat))
|
||||
return NULL;
|
||||
|
||||
for(x = 0; x < vec_size; x++){
|
||||
vecCopy[x] = vec->vec[x];
|
||||
}
|
||||
|
||||
//muliplication
|
||||
for(x = 0; x < mat->colSize; x++) {
|
||||
for(y = 0; y < mat->rowSize; y++) {
|
||||
dot += mat->matrix[y][x] * vecCopy[y];
|
||||
}
|
||||
vecNew[z++] = (float)dot;
|
||||
dot = 0.0f;
|
||||
}
|
||||
return newVectorObject(vecNew, vec_size, Py_NEW);
|
||||
}
|
||||
|
||||
/*----------------------------Vector.negate() --------------------
|
||||
set the vector to it's negative -x, -y, -z */
|
||||
static PyObject *Vector_Negate(VectorObject * self)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < self->size; i++) {
|
||||
if(!Vector_ReadCallback(self))
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < self->size; i++)
|
||||
self->vec[i] = -(self->vec[i]);
|
||||
}
|
||||
/*printf("Vector.negate(): Deprecated: use -vector instead\n");*/
|
||||
|
||||
Vector_WriteCallback(self); // alredy checked for error
|
||||
|
||||
Py_INCREF(self);
|
||||
return (PyObject*)self;
|
||||
}
|
||||
/*###################################################################
|
||||
###########################DEPRECATED##############################*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: vector.h 20332 2009-05-22 03:22:56Z campbellbarton $
|
||||
/* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
@@ -39,12 +39,17 @@ extern PyTypeObject vector_Type;
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
float *vec; /*1D array of data (alias), wrapped status depends on wrapped status */
|
||||
short size; /* vec size 2,3 or 4 */
|
||||
short wrapped; /* is wrapped data? */
|
||||
float *vec; /*1D array of data (alias), wrapped status depends on wrapped status */
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */
|
||||
unsigned char size; /* vec size 2,3 or 4 */
|
||||
unsigned char wrapped; /* wrapped data type? */
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */
|
||||
|
||||
} VectorObject;
|
||||
|
||||
/*prototypes*/
|
||||
PyObject *newVectorObject(float *vec, int size, int type);
|
||||
PyObject *newVectorObject_cb(PyObject *user, int size, int callback_type, int subtype);
|
||||
|
||||
#endif /* EXPP_vector_h */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: Makefile 11904 2007-08-31 16:16:33Z sirdude $
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
|
||||
@@ -37,6 +37,11 @@
|
||||
#include "BPY_extern.h"
|
||||
|
||||
#include "../generic/bpy_internal_import.h" // our own imports
|
||||
/* external util modukes */
|
||||
|
||||
#include "../generic/Mathutils.h"
|
||||
#include "../generic/Geometry.h"
|
||||
#include "../generic/BGL.h"
|
||||
|
||||
|
||||
void BPY_free_compiled_text( struct Text *text )
|
||||
@@ -61,11 +66,17 @@ static void bpy_init_modules( void )
|
||||
PyModule_AddObject( mod, "types", BPY_rna_types() );
|
||||
PyModule_AddObject( mod, "props", BPY_rna_props() );
|
||||
PyModule_AddObject( mod, "ops", BPY_operator_module() );
|
||||
PyModule_AddObject( mod, "ui", BPY_ui_module() ); // XXX very experemental, consider this a test, especially PyCObject is not meant to be perminant
|
||||
PyModule_AddObject( mod, "ui", BPY_ui_module() ); // XXX very experimental, consider this a test, especially PyCObject is not meant to be permanent
|
||||
|
||||
/* add the module so we can import it */
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "bpy", mod);
|
||||
Py_DECREF(mod);
|
||||
|
||||
|
||||
/* stand alone utility modules not related to blender directly */
|
||||
Geometry_Init("Geometry");
|
||||
Mathutils_Init("Mathutils");
|
||||
BGL_Init("BGL");
|
||||
}
|
||||
|
||||
#if (PY_VERSION_HEX < 0x02050000)
|
||||
|
||||
@@ -107,15 +107,9 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
|
||||
|
||||
/* Assign instance attributes from operator properties */
|
||||
{
|
||||
PropertyRNA *prop, *iterprop;
|
||||
CollectionPropertyIterator iter;
|
||||
const char *arg_name;
|
||||
|
||||
iterprop= RNA_struct_iterator_property(op->ptr->type);
|
||||
RNA_property_collection_begin(op->ptr, iterprop, &iter);
|
||||
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
prop= iter.ptr.data;
|
||||
RNA_STRUCT_BEGIN(op->ptr, prop) {
|
||||
arg_name= RNA_property_identifier(prop);
|
||||
|
||||
if (strcmp(arg_name, "rna_type")==0) continue;
|
||||
@@ -124,8 +118,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
|
||||
PyObject_SetAttrString(py_class_instance, arg_name, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
RNA_property_collection_end(&iter);
|
||||
RNA_STRUCT_END;
|
||||
}
|
||||
|
||||
/* set operator pointer RNA as instance "__operator__" attribute */
|
||||
|
||||
@@ -39,6 +39,94 @@
|
||||
#include "BKE_global.h" /* evil G.* */
|
||||
#include "BKE_report.h"
|
||||
|
||||
#define USE_MATHUTILS
|
||||
|
||||
#ifdef USE_MATHUTILS
|
||||
#include "../generic/Mathutils.h" /* so we can have mathutils callbacks */
|
||||
|
||||
/* bpyrna vector callbacks */
|
||||
static int mathutils_rna_vector_cb_index= -1; /* index for our callbacks */
|
||||
|
||||
static int mathutils_rna_generic_check(BPy_PropertyRNA *self)
|
||||
{
|
||||
return self->prop?1:0;
|
||||
}
|
||||
|
||||
static int mathutils_rna_vector_get(BPy_PropertyRNA *self, int subtype, float *vec_from)
|
||||
{
|
||||
if(self->prop==NULL)
|
||||
return 0;
|
||||
|
||||
RNA_property_float_get_array(&self->ptr, self->prop, vec_from);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mathutils_rna_vector_set(BPy_PropertyRNA *self, int subtype, float *vec_to)
|
||||
{
|
||||
if(self->prop==NULL)
|
||||
return 0;
|
||||
|
||||
RNA_property_float_set_array(&self->ptr, self->prop, vec_to);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mathutils_rna_vector_get_index(BPy_PropertyRNA *self, int subtype, float *vec_from, int index)
|
||||
{
|
||||
if(self->prop==NULL)
|
||||
return 0;
|
||||
|
||||
vec_from[index]= RNA_property_float_get_index(&self->ptr, self->prop, index);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mathutils_rna_vector_set_index(BPy_PropertyRNA *self, int subtype, float *vec_to, int index)
|
||||
{
|
||||
if(self->prop==NULL)
|
||||
return 0;
|
||||
|
||||
RNA_property_float_set_index(&self->ptr, self->prop, index, vec_to[index]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Mathutils_Callback mathutils_rna_vector_cb = {
|
||||
mathutils_rna_generic_check,
|
||||
mathutils_rna_vector_get,
|
||||
mathutils_rna_vector_set,
|
||||
mathutils_rna_vector_get_index,
|
||||
mathutils_rna_vector_set_index
|
||||
};
|
||||
|
||||
/* bpyrna matrix callbacks */
|
||||
static int mathutils_rna_matrix_cb_index= -1; /* index for our callbacks */
|
||||
|
||||
static int mathutils_rna_matrix_get(BPy_PropertyRNA *self, int subtype, float *mat_from)
|
||||
{
|
||||
if(self->prop==NULL)
|
||||
return 0;
|
||||
|
||||
RNA_property_float_get_array(&self->ptr, self->prop, mat_from);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mathutils_rna_matrix_set(BPy_PropertyRNA *self, int subtype, float *mat_to)
|
||||
{
|
||||
if(self->prop==NULL)
|
||||
return 0;
|
||||
|
||||
RNA_property_float_set_array(&self->ptr, self->prop, mat_to);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Mathutils_Callback mathutils_rna_matrix_cb = {
|
||||
mathutils_rna_generic_check,
|
||||
mathutils_rna_matrix_get,
|
||||
mathutils_rna_matrix_set,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static int pyrna_struct_compare( BPy_StructRNA * a, BPy_StructRNA * b )
|
||||
{
|
||||
return (a->ptr.data==b->ptr.data) ? 0 : -1;
|
||||
@@ -73,14 +161,15 @@ static PyObject *pyrna_prop_richcmp(BPy_PropertyRNA * a, BPy_PropertyRNA * b, in
|
||||
/*----------------------repr--------------------------------------------*/
|
||||
static PyObject *pyrna_struct_repr( BPy_StructRNA * self )
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
char str[512];
|
||||
PyObject *pyob;
|
||||
char *name;
|
||||
|
||||
/* print name if available */
|
||||
prop= RNA_struct_name_property(self->ptr.type);
|
||||
if(prop) {
|
||||
RNA_property_string_get(&self->ptr, prop, str);
|
||||
return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(self->ptr.type), str);
|
||||
name= RNA_struct_name_get_alloc(&self->ptr, NULL, 0);
|
||||
if(name) {
|
||||
pyob= PyUnicode_FromFormat( "[BPy_StructRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(self->ptr.type), name);
|
||||
MEM_freeN(name);
|
||||
return pyob;
|
||||
}
|
||||
|
||||
return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\"]", RNA_struct_identifier(self->ptr.type));
|
||||
@@ -88,20 +177,19 @@ static PyObject *pyrna_struct_repr( BPy_StructRNA * self )
|
||||
|
||||
static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self )
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
PyObject *pyob;
|
||||
PointerRNA ptr;
|
||||
char str[512];
|
||||
char *name;
|
||||
|
||||
/* if a pointer, try to print name of pointer target too */
|
||||
if(RNA_property_type(self->prop) == PROP_POINTER) {
|
||||
ptr= RNA_property_pointer_get(&self->ptr, self->prop);
|
||||
name= RNA_struct_name_get_alloc(&ptr, NULL, 0);
|
||||
|
||||
if(ptr.data) {
|
||||
prop= RNA_struct_name_property(ptr.type);
|
||||
if(prop) {
|
||||
RNA_property_string_get(&ptr, prop, str);
|
||||
return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" -> \"%s\" ]", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), str);
|
||||
}
|
||||
if(name) {
|
||||
pyob= PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" -> \"%s\" ]", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), name);
|
||||
MEM_freeN(name);
|
||||
return pyob;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,9 +218,8 @@ static void pyrna_struct_dealloc( BPy_StructRNA * self )
|
||||
static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
const EnumPropertyItem *item;
|
||||
int totitem;
|
||||
|
||||
RNA_property_enum_items(ptr, prop, &item, &totitem);
|
||||
RNA_property_enum_items(ptr, prop, &item, NULL);
|
||||
return (char*)BPy_enum_as_string((EnumPropertyItem*)item);
|
||||
}
|
||||
|
||||
@@ -144,7 +231,35 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
|
||||
|
||||
if (len > 0) {
|
||||
/* resolve the array from a new pytype */
|
||||
return pyrna_prop_CreatePyObject(ptr, prop);
|
||||
PyObject *ret = pyrna_prop_CreatePyObject(ptr, prop);
|
||||
|
||||
#ifdef USE_MATHUTILS
|
||||
/* return a mathutils vector where possible */
|
||||
if(RNA_property_type(prop)==PROP_FLOAT) {
|
||||
if(RNA_property_subtype(prop)==PROP_VECTOR) {
|
||||
if(len>=2 && len <= 4) {
|
||||
PyObject *vec_cb= newVectorObject_cb(ret, len, mathutils_rna_vector_cb_index, 0);
|
||||
Py_DECREF(ret); /* the vector owns now */
|
||||
ret= vec_cb; /* return the vector instead */
|
||||
}
|
||||
}
|
||||
else if(RNA_property_subtype(prop)==PROP_MATRIX) {
|
||||
if(len==16) {
|
||||
PyObject *mat_cb= newMatrixObject_cb(ret, 4,4, mathutils_rna_vector_cb_index, 0);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= mat_cb; /* return the matrix instead */
|
||||
}
|
||||
else if (len==9) {
|
||||
PyObject *mat_cb= newMatrixObject_cb(ret, 3,3, mathutils_rna_vector_cb_index, 0);
|
||||
Py_DECREF(ret); /* the matrix owns now */
|
||||
ret= mat_cb; /* return the matrix instead */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* see if we can coorce into a python type - PropertyType */
|
||||
@@ -213,17 +328,9 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefi
|
||||
const char *arg_name= NULL;
|
||||
PyObject *item;
|
||||
|
||||
PropertyRNA *prop, *iterprop;
|
||||
CollectionPropertyIterator iter;
|
||||
|
||||
iterprop= RNA_struct_iterator_property(ptr->type);
|
||||
RNA_property_collection_begin(ptr, iterprop, &iter);
|
||||
|
||||
totkw = kw ? PyDict_Size(kw):0;
|
||||
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
prop= iter.ptr.data;
|
||||
|
||||
RNA_STRUCT_BEGIN(ptr, prop) {
|
||||
arg_name= RNA_property_identifier(prop);
|
||||
|
||||
if (strcmp(arg_name, "rna_type")==0) continue;
|
||||
@@ -249,8 +356,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefi
|
||||
|
||||
totkw--;
|
||||
}
|
||||
|
||||
RNA_property_collection_end(&iter);
|
||||
RNA_STRUCT_END;
|
||||
|
||||
if (error_val==0 && totkw > 0) { /* some keywords were given that were not used :/ */
|
||||
PyObject *key, *value;
|
||||
@@ -294,14 +400,29 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
|
||||
|
||||
if (len > 0) {
|
||||
PyObject *item;
|
||||
int py_len = -1;
|
||||
int i;
|
||||
|
||||
if (!PySequence_Check(value)) {
|
||||
|
||||
#ifdef USE_MATHUTILS
|
||||
if(MatrixObject_Check(value)) {
|
||||
MatrixObject *mat = (MatrixObject*)value;
|
||||
if(!Matrix_ReadCallback(mat))
|
||||
return -1;
|
||||
|
||||
py_len = mat->rowSize * mat->colSize;
|
||||
} else // continue...
|
||||
#endif
|
||||
if (PySequence_Check(value)) {
|
||||
py_len= (int)PySequence_Length(value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a python sequence type assigned to an RNA array.");
|
||||
return -1;
|
||||
}
|
||||
/* done getting the length */
|
||||
|
||||
if ((int)PySequence_Length(value) != len) {
|
||||
if (py_len != len) {
|
||||
PyErr_SetString(PyExc_AttributeError, "python sequence length did not match the RNA array.");
|
||||
return -1;
|
||||
}
|
||||
@@ -368,14 +489,21 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
|
||||
else param_arr = MEM_mallocN(sizeof(float) * len, "pyrna float array");
|
||||
|
||||
|
||||
|
||||
/* collect the variables */
|
||||
for (i=0; i<len; i++) {
|
||||
item = PySequence_GetItem(value, i);
|
||||
param_arr[i] = (float)PyFloat_AsDouble(item); /* deal with any errors later */
|
||||
Py_DECREF(item);
|
||||
#ifdef USE_MATHUTILS
|
||||
if(MatrixObject_Check(value) && RNA_property_subtype(prop) == PROP_MATRIX) {
|
||||
MatrixObject *mat = (MatrixObject*)value;
|
||||
memcpy(param_arr, mat->contigPtr, sizeof(float) * len);
|
||||
} else // continue...
|
||||
#endif
|
||||
{
|
||||
/* collect the variables */
|
||||
for (i=0; i<len; i++) {
|
||||
item = PySequence_GetItem(value, i);
|
||||
param_arr[i] = (float)PyFloat_AsDouble(item); /* deal with any errors later */
|
||||
Py_DECREF(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
if(data==NULL)
|
||||
MEM_freeN(param_arr);
|
||||
@@ -804,7 +932,6 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
|
||||
PyObject *pystring;
|
||||
|
||||
/* for looping over attrs and funcs */
|
||||
CollectionPropertyIterator iter;
|
||||
PropertyRNA *iterprop;
|
||||
|
||||
/* Include this incase this instance is a subtype of a python class
|
||||
@@ -833,26 +960,23 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
|
||||
/*
|
||||
* Collect RNA attributes
|
||||
*/
|
||||
PropertyRNA *nameprop;
|
||||
char name[256], *nameptr;
|
||||
|
||||
iterprop= RNA_struct_iterator_property(self->ptr.type);
|
||||
RNA_property_collection_begin(&self->ptr, iterprop, &iter);
|
||||
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) {
|
||||
nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
|
||||
|
||||
RNA_PROP_BEGIN(&self->ptr, itemptr, iterprop) {
|
||||
nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name));
|
||||
|
||||
if(nameptr) {
|
||||
pystring = PyUnicode_FromString(nameptr);
|
||||
PyList_Append(ret, pystring);
|
||||
Py_DECREF(pystring);
|
||||
|
||||
if ((char *)&name != nameptr)
|
||||
if(name != nameptr)
|
||||
MEM_freeN(nameptr);
|
||||
}
|
||||
}
|
||||
RNA_property_collection_end(&iter);
|
||||
|
||||
RNA_PROP_END;
|
||||
}
|
||||
|
||||
|
||||
@@ -865,15 +989,12 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
|
||||
RNA_pointer_create(NULL, &RNA_Struct, self->ptr.type, &tptr);
|
||||
iterprop= RNA_struct_find_property(&tptr, "functions");
|
||||
|
||||
RNA_property_collection_begin(&tptr, iterprop, &iter);
|
||||
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
pystring = PyUnicode_FromString(RNA_function_identifier(iter.ptr.data));
|
||||
RNA_PROP_BEGIN(&tptr, itemptr, iterprop) {
|
||||
pystring = PyUnicode_FromString(RNA_function_identifier(itemptr.data));
|
||||
PyList_Append(ret, pystring);
|
||||
Py_DECREF(pystring);
|
||||
}
|
||||
|
||||
RNA_property_collection_end(&iter);
|
||||
RNA_PROP_END;
|
||||
}
|
||||
|
||||
if(self->ptr.type == &RNA_Context) {
|
||||
@@ -986,28 +1107,25 @@ PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
|
||||
ret = NULL;
|
||||
} else {
|
||||
PyObject *item;
|
||||
CollectionPropertyIterator iter;
|
||||
PropertyRNA *nameprop;
|
||||
char name[256], *nameptr;
|
||||
|
||||
ret = PyList_New(0);
|
||||
|
||||
RNA_property_collection_begin(&self->ptr, self->prop, &iter);
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) {
|
||||
nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
|
||||
|
||||
RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
|
||||
nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name));
|
||||
|
||||
if(nameptr) {
|
||||
/* add to python list */
|
||||
item = PyUnicode_FromString( nameptr );
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
/* done */
|
||||
|
||||
if ((char *)&name != nameptr)
|
||||
if(name != nameptr)
|
||||
MEM_freeN(nameptr);
|
||||
}
|
||||
}
|
||||
RNA_property_collection_end(&iter);
|
||||
RNA_PROP_END;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -1021,28 +1139,25 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self)
|
||||
ret = NULL;
|
||||
} else {
|
||||
PyObject *item;
|
||||
CollectionPropertyIterator iter;
|
||||
PropertyRNA *nameprop;
|
||||
char name[256], *nameptr;
|
||||
int i= 0;
|
||||
|
||||
ret = PyList_New(0);
|
||||
|
||||
RNA_property_collection_begin(&self->ptr, self->prop, &iter);
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
if(iter.ptr.data) {
|
||||
RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
|
||||
if(itemptr.data) {
|
||||
/* add to python list */
|
||||
item= PyTuple_New(2);
|
||||
if(nameprop = RNA_struct_name_property(iter.ptr.type)) {
|
||||
nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
|
||||
nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name));
|
||||
if(nameptr) {
|
||||
PyTuple_SET_ITEM(item, 0, PyUnicode_FromString( nameptr ));
|
||||
if ((char *)&name != nameptr)
|
||||
if(name != nameptr)
|
||||
MEM_freeN(nameptr);
|
||||
}
|
||||
else {
|
||||
PyTuple_SET_ITEM(item, 0, PyLong_FromSsize_t(i)); /* a bit strange but better then returning an empty list */
|
||||
}
|
||||
PyTuple_SET_ITEM(item, 1, pyrna_struct_CreatePyObject(&iter.ptr));
|
||||
PyTuple_SET_ITEM(item, 1, pyrna_struct_CreatePyObject(&itemptr));
|
||||
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
@@ -1050,7 +1165,7 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
RNA_property_collection_end(&iter);
|
||||
RNA_PROP_END;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -1066,18 +1181,14 @@ PyObject *pyrna_prop_values(BPy_PropertyRNA *self)
|
||||
ret = NULL;
|
||||
} else {
|
||||
PyObject *item;
|
||||
CollectionPropertyIterator iter;
|
||||
PropertyRNA *iterprop;
|
||||
ret = PyList_New(0);
|
||||
|
||||
//iterprop= RNA_struct_iterator_property(self->ptr.type);
|
||||
RNA_property_collection_begin(&self->ptr, self->prop, &iter);
|
||||
for(; iter.valid; RNA_property_collection_next(&iter)) {
|
||||
item = pyrna_struct_CreatePyObject(&iter.ptr);
|
||||
RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
|
||||
item = pyrna_struct_CreatePyObject(&itemptr);
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
RNA_property_collection_end(&iter);
|
||||
RNA_PROP_END;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -1674,6 +1785,11 @@ PyObject *BPY_rna_module( void )
|
||||
{
|
||||
PointerRNA ptr;
|
||||
|
||||
#ifdef USE_MATHUTILS // register mathutils callbacks, ok to run more then once.
|
||||
mathutils_rna_vector_cb_index= Mathutils_RegisterCallback(&mathutils_rna_vector_cb);
|
||||
mathutils_rna_matrix_cb_index= Mathutils_RegisterCallback(&mathutils_rna_matrix_cb);
|
||||
#endif
|
||||
|
||||
/* This can't be set in the pytype struct because some compilers complain */
|
||||
pyrna_prop_Type.tp_getattro = PyObject_GenericGetAttr;
|
||||
pyrna_prop_Type.tp_setattro = PyObject_GenericSetAttr;
|
||||
@@ -1883,7 +1999,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
char *id, *name="", *description="";
|
||||
int def=0;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssi:IntProperty", kwlist, &id, &name, &description, &def))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssi:BoolProperty", kwlist, &id, &name, &description, &def))
|
||||
return NULL;
|
||||
|
||||
if (PyTuple_Size(args) > 0) {
|
||||
@@ -1897,7 +2013,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
Py_RETURN_NONE;
|
||||
} else {
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_IntProperty, NULL));
|
||||
PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_BoolProperty, NULL));
|
||||
PyTuple_SET_ITEM(ret, 1, kw);
|
||||
Py_INCREF(kw);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user