diff options
Diffstat (limited to 'source/blender/python/intern/bpy_rna.c')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 93a8af8b177..70ccd4f58c9 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -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 */ |