PyRNA API support for matrix types as Mathutils matrix (with callbacks) rather then a generic rna sequence of floats.
Any 3x3 or 4x4 rna matrix will automatically be returned as a Mathutils matrix.
This makes useful stuff like multiplying a vector location by an object matrix possible.
ob = bpy.data.scenes[0].objects[0]
print (ob.data.verts[0].co * ob.matrix)
Also added mathutils matrix types to the BGE GameObject.localOrientation, worldOrientation
* MT_Matrix3x3 added getValue3x3 and setValue3x3, assumed a 4x3 float array.
* KX_GameObject.cpp convenience functions NodeSetGlobalOrientation, NodeGetLocalOrientation, NodeGetLocalScaling, NodeGetLocalPosition.
* 2.5 python api now initializes modules BGL, Mathutils and Geometry
* modules py3 PyModuleDef's use PyModuleDef_HEAD_INIT, rather then {}, was making msvc fail to build.
* added macros for Vector_ReadCallback, Vector_WriteCallback etc. to check if the callback pointer is set before calling the function.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -44,9 +44,10 @@
|
||||
#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_vector_check(BPy_PropertyRNA *self)
|
||||
static int mathutils_rna_generic_check(BPy_PropertyRNA *self)
|
||||
{
|
||||
return self->prop?1:0;
|
||||
}
|
||||
@@ -88,13 +89,42 @@ static int mathutils_rna_vector_set_index(BPy_PropertyRNA *self, int subtype, fl
|
||||
}
|
||||
|
||||
Mathutils_Callback mathutils_rna_vector_cb = {
|
||||
mathutils_rna_vector_check,
|
||||
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 )
|
||||
@@ -206,15 +236,28 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
|
||||
|
||||
#ifdef USE_MATHUTILS
|
||||
/* return a mathutils vector where possible */
|
||||
if( RNA_property_type(prop)==PROP_FLOAT &&
|
||||
RNA_property_subtype(prop)==PROP_VECTOR &&
|
||||
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 */
|
||||
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;
|
||||
@@ -1749,6 +1792,7 @@ PyObject *BPY_rna_module( void )
|
||||
|
||||
#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 */
|
||||
|
||||
Reference in New Issue
Block a user