Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/CMakeLists.txt1
-rw-r--r--source/blender/python/Makefile4
-rw-r--r--source/blender/python/SConscript5
-rw-r--r--source/blender/python/doc/epy/Geometry.py2
-rw-r--r--source/blender/python/doc/examples/mathutils.py4
-rw-r--r--source/blender/python/doc/sphinx_doc_gen.py40
-rw-r--r--source/blender/python/generic/Makefile2
-rw-r--r--source/blender/python/generic/bgl.c8
-rw-r--r--source/blender/python/generic/blf_api.c8
-rw-r--r--source/blender/python/generic/bpy_internal_import.c27
-rw-r--r--source/blender/python/generic/bpy_internal_import.h2
-rw-r--r--source/blender/python/generic/geometry.c4
-rw-r--r--source/blender/python/generic/mathutils.c514
-rw-r--r--source/blender/python/generic/mathutils.h16
-rw-r--r--source/blender/python/generic/mathutils_color.c16
-rw-r--r--source/blender/python/generic/mathutils_euler.c10
-rw-r--r--source/blender/python/generic/mathutils_matrix.c449
-rw-r--r--source/blender/python/generic/mathutils_quat.c134
-rw-r--r--source/blender/python/generic/mathutils_vector.c35
-rw-r--r--source/blender/python/intern/Makefile3
-rw-r--r--source/blender/python/intern/bpy.c39
-rw-r--r--source/blender/python/intern/bpy_app.c2
-rw-r--r--source/blender/python/intern/bpy_interface.c74
-rw-r--r--source/blender/python/intern/bpy_operator.c4
-rw-r--r--source/blender/python/intern/bpy_operator_wrap.c23
-rw-r--r--source/blender/python/intern/bpy_props.c2
-rw-r--r--source/blender/python/intern/bpy_rna.c488
-rw-r--r--source/blender/python/intern/bpy_rna.h6
-rw-r--r--source/blender/python/intern/bpy_rna_callback.c29
-rw-r--r--source/blender/python/intern/bpy_util.c26
-rw-r--r--source/blender/python/intern/bpy_util.h2
31 files changed, 1126 insertions, 853 deletions
diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/CMakeLists.txt
index 3c79e9d3056..dcfc8678faa 100644
--- a/source/blender/python/CMakeLists.txt
+++ b/source/blender/python/CMakeLists.txt
@@ -36,6 +36,7 @@ SET(INC
../windowmanager
../editors/include
../../../intern/guardedalloc
+ ../../../intern/audaspace/intern
${PYTHON_INC}
)
diff --git a/source/blender/python/Makefile b/source/blender/python/Makefile
index b120dc6ad46..43b6f91369b 100644
--- a/source/blender/python/Makefile
+++ b/source/blender/python/Makefile
@@ -1,5 +1,5 @@
#
-# $Id: Makefile 21094 2009-06-23 00:09:26Z gsrb3d $
+# $Id$
#
# ***** BEGIN GPL LICENSE BLOCK *****
#
@@ -15,7 +15,7 @@
#
# 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.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) Blender Foundation.
# All rights reserved.
diff --git a/source/blender/python/SConscript b/source/blender/python/SConscript
index ca742a3646a..f062f64249c 100644
--- a/source/blender/python/SConscript
+++ b/source/blender/python/SConscript
@@ -6,10 +6,13 @@ sources = env.Glob('intern/*.c')
incs = '. ../editors/include ../makesdna ../makesrna ../blenlib ../blenkernel ../nodes'
incs += ' ../imbuf ../blenloader ../render/extern/include ../windowmanager'
incs += ' #intern/guardedalloc #intern/memutil #extern/glew/include'
-incs += ' ' + env['BF_PYTHON_INC']
+incs += ' #intern/audaspace/intern ' + env['BF_PYTHON_INC']
defs = []
+if env['BF_BUILDINFO']:
+ defs.append('BUILD_DATE')
+
if env['OURPLATFORM'] in ('win32-mingw', 'win32-vc','win64-vc') and env['BF_DEBUG']:
defs.append('_DEBUG')
diff --git a/source/blender/python/doc/epy/Geometry.py b/source/blender/python/doc/epy/Geometry.py
index 717c147b215..f8752a135c3 100644
--- a/source/blender/python/doc/epy/Geometry.py
+++ b/source/blender/python/doc/epy/Geometry.py
@@ -90,7 +90,7 @@ def LineIntersect(vec1, vec2, vec3, vec4):
def PolyFill(polylines):
"""
Takes a list of polylines and calculates triangles that would fill in the polylines.
- Multiple lines can be used to make holes inside a polyline, or fill in 2 seperate lines at once.
+ Multiple lines can be used to make holes inside a polyline, or fill in 2 separate lines at once.
@type polylines: List of lists containing vectors, each representing a closed polyline.
@rtype: list
@return: a list if tuples each a tuple of 3 ints representing a triangle indexing the points given.
diff --git a/source/blender/python/doc/examples/mathutils.py b/source/blender/python/doc/examples/mathutils.py
index 4a5de5887c9..0b30a0f4505 100644
--- a/source/blender/python/doc/examples/mathutils.py
+++ b/source/blender/python/doc/examples/mathutils.py
@@ -3,8 +3,8 @@ from math import radians
vec = mathutils.Vector((1.0, 2.0, 3.0))
-mat_rot = mathutils.RotationMatrix(radians(90), 4, 'X')
-mat_trans = mathutils.TranslationMatrix(vec)
+mat_rot = mathutils.Matrix.Rotation(radians(90), 4, 'X')
+mat_trans = mathutils.Matrix.Translation(vec)
mat = mat_trans * mat_rot
mat.invert()
diff --git a/source/blender/python/doc/sphinx_doc_gen.py b/source/blender/python/doc/sphinx_doc_gen.py
index 27524c66c36..06d1a9021b8 100644
--- a/source/blender/python/doc/sphinx_doc_gen.py
+++ b/source/blender/python/doc/sphinx_doc_gen.py
@@ -45,6 +45,7 @@ import rna_info
reload(rna_info)
# lame, python wont give some access
+ClassMethodDescriptorType = type(dict.__dict__['fromkeys'])
MethodDescriptorType = type(dict.get)
GetSetDescriptorType = type(int.real)
@@ -143,7 +144,9 @@ def pyfunc2sphinx(ident, fw, identifier, py_func, is_class=True):
def py_descr2sphinx(ident, fw, descr, module_name, type_name, identifier):
-
+ if identifier.startswith("_"):
+ return
+
doc = descr.__doc__
if not doc:
doc = undocumented_message(module_name, type_name, identifier)
@@ -151,10 +154,10 @@ def py_descr2sphinx(ident, fw, descr, module_name, type_name, identifier):
if type(descr) == GetSetDescriptorType:
fw(ident + ".. attribute:: %s\n\n" % identifier)
write_indented_lines(ident + " ", fw, doc, False)
- elif type(descr) == MethodDescriptorType: # GetSetDescriptorType's are not documented yet
+ elif type(descr) in (MethodDescriptorType, ClassMethodDescriptorType):
write_indented_lines(ident, fw, doc, False)
else:
- raise TypeError("type was not GetSetDescriptorType or MethodDescriptorType")
+ raise TypeError("type was not GetSetDescriptorType, MethodDescriptorType or ClassMethodDescriptorType")
write_example_ref(ident, fw, module_name + "." + type_name + "." + identifier)
fw("\n")
@@ -268,7 +271,11 @@ def pymodule2sphinx(BASEPATH, module_name, module, title):
descr_items = [(key, descr) for key, descr in sorted(value.__dict__.items()) if not key.startswith("__")]
for key, descr in descr_items:
- if type(descr) == MethodDescriptorType: # GetSetDescriptorType's are not documented yet
+ if type(descr) == ClassMethodDescriptorType:
+ py_descr2sphinx(" ", fw, descr, module_name, type_name, key)
+
+ for key, descr in descr_items:
+ if type(descr) == MethodDescriptorType:
py_descr2sphinx(" ", fw, descr, module_name, type_name, key)
for key, descr in descr_items:
@@ -346,6 +353,7 @@ def rna2sphinx(BASEPATH):
fw(" * data API, access to attributes of blender data such as mesh verts, material color, timeline frames and scene objects\n")
fw(" * user interface functions for defining buttons, creation of menus, headers, panels\n")
fw(" * modules: bgl, mathutils and geometry\n")
+ fw(" * game engine modules\n")
fw("\n")
fw("===================\n")
@@ -360,6 +368,7 @@ def rna2sphinx(BASEPATH):
# py modules
fw(" bpy.utils.rst\n\n")
+ fw(" bpy.path.rst\n\n")
fw(" bpy.app.rst\n\n")
# C modules
@@ -375,6 +384,7 @@ def rna2sphinx(BASEPATH):
fw(" mathutils.rst\n\n")
fw(" blf.rst\n\n")
+ fw(" aud.rst\n\n")
# game engine
fw("===================\n")
@@ -440,6 +450,9 @@ def rna2sphinx(BASEPATH):
from bpy import utils as module
pymodule2sphinx(BASEPATH, "bpy.utils", module, "Utilities (bpy.utils)")
+ from bpy import path as module
+ pymodule2sphinx(BASEPATH, "bpy.path", module, "Path Utilities (bpy.path)")
+
# C modules
from bpy import app as module
pymodule2sphinx(BASEPATH, "bpy.app", module, "Application Data (bpy.app)")
@@ -454,6 +467,10 @@ def rna2sphinx(BASEPATH):
import blf as module
pymodule2sphinx(BASEPATH, "blf", module, "Font Drawing (blf)")
del module
+
+ import aud as module
+ pymodule2sphinx(BASEPATH, "aud", module, "Audio System (aud)")
+ del module
# game engine
import shutil
@@ -553,10 +570,9 @@ def rna2sphinx(BASEPATH):
fw(" %s\n\n" % struct.description)
# properties sorted in alphabetical order
- zip_props_ids = zip(struct.properties, [prop.identifier for prop in struct.properties])
- zip_props_ids = sorted(zip_props_ids, key=lambda p: p[1])
- sorted_struct_properties = [x[0] for x in zip_props_ids]
-
+ sorted_struct_properties = struct.properties[:]
+ sorted_struct_properties.sort(key=lambda prop: prop.identifier)
+
for prop in sorted_struct_properties:
type_descr = prop.get_type_description(class_fmt=":class:`%s`")
# readonly properties use "data" directive, variables properties use "attribute" directive
@@ -578,7 +594,7 @@ def rna2sphinx(BASEPATH):
for func in struct.functions:
args_str = ", ".join([prop.get_arg_default(force=False) for prop in func.args])
- fw(" .. method:: %s(%s)\n\n" % (func.identifier, args_str))
+ fw(" .. %s:: %s(%s)\n\n" % ("classmethod" if func.is_classmethod else "method", func.identifier, args_str))
fw(" %s\n\n" % func.description)
for prop in func.args:
@@ -756,7 +772,8 @@ def rna2sphinx(BASEPATH):
file.close()
-if __name__ == '__main__':
+def main():
+ import bpy
if 'bpy' not in dir():
print("\nError, this script must run from inside blender2.5")
print(script_help_msg)
@@ -826,3 +843,6 @@ if __name__ == '__main__':
import sys
sys.exit()
+
+if __name__ == '__main__':
+ main()
diff --git a/source/blender/python/generic/Makefile b/source/blender/python/generic/Makefile
index dc674478dab..0df98046f63 100644
--- a/source/blender/python/generic/Makefile
+++ b/source/blender/python/generic/Makefile
@@ -15,7 +15,7 @@
#
# 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.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 9bd3b4831db..8ac2107f8d2 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -27,9 +27,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/* This file is the Blender.BGL part of opy_draw.c, from the old
- * bpython/intern dir, with minor changes to adapt it to the new Python
- * implementation. The BGL submodule "wraps" OpenGL functions and constants,
+/* This file is the 'bgl' module.
+ * The BGL submodule "wraps" OpenGL functions and constants,
* allowing script writers to make OpenGL calls in their Python scripts. */
#include "bgl.h" /*This must come first */
@@ -1118,7 +1117,7 @@ PyObject *BGL_Init(void)
{
PyObject *mod, *dict, *item;
mod = PyModule_Create(&BGL_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), BGL_module_def.m_name, mod);
+ PyDict_SetItemString(PyImport_GetModuleDict(), BGL_module_def.m_name, mod);
dict= PyModule_GetDict(mod);
if( PyType_Ready( &BGL_bufferType) < 0)
@@ -1613,3 +1612,4 @@ PyObject *BGL_Init(void)
return mod;
}
+
diff --git a/source/blender/python/generic/blf_api.c b/source/blender/python/generic/blf_api.c
index db3ce06554e..a5f5f8815c7 100644
--- a/source/blender/python/generic/blf_api.c
+++ b/source/blender/python/generic/blf_api.c
@@ -39,7 +39,7 @@ static char py_blf_position_doc[] =
" :arg y: Y axis position to draw the text.\n"
" :type y: float\n"
" :arg z: Z axis position to draw the text.\n"
-" :type x: float\n";
+" :type z: float\n";
static PyObject *py_blf_position(PyObject *self, PyObject *args)
{
@@ -153,7 +153,7 @@ static PyObject *py_blf_draw(PyObject *self, PyObject *args)
static char py_blf_dimensions_doc[] =
".. function:: dimensions(fontid, text)\n"
"\n"
-" Return the width and hight of the text.\n"
+" Return the width and height of the text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
@@ -261,7 +261,7 @@ static char py_blf_rotation_doc[] =
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg angle: The angle for text drawing to use.\n"
-" :type aspect: float\n";
+" :type angle: float\n";
static PyObject *py_blf_rotation(PyObject *self, PyObject *args)
{
@@ -394,7 +394,7 @@ PyObject *BLF_Init(void)
PyObject *submodule;
submodule = PyModule_Create(&BLF_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), BLF_module_def.m_name, submodule);
+ PyDict_SetItemString(PyImport_GetModuleDict(), BLF_module_def.m_name, submodule);
PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION);
PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING);
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c
index ffd34139cf5..5240daf76cb 100644
--- a/source/blender/python/generic/bpy_internal_import.c
+++ b/source/blender/python/generic/bpy_internal_import.c
@@ -200,7 +200,7 @@ static PyObject *blender_import( PyObject * self, PyObject * args, PyObject * k
&name, &globals, &locals, &fromlist, &dummy_val) )
return NULL;
- /* import existing builtin modules or modules that have been imported alredy */
+ /* import existing builtin modules or modules that have been imported already */
newmodule = PyImport_ImportModuleEx( name, globals, locals, fromlist );
if(newmodule)
@@ -304,7 +304,7 @@ PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", (PyCFunction)blender_reloa
void bpy_text_clear_modules(int clear_all)
{
- PyObject *modules= PySys_GetObject("modules");
+ PyObject *modules= PyImport_GetModuleDict();
char *fname;
char *file_extension;
@@ -350,3 +350,26 @@ void bpy_text_clear_modules(int clear_all)
Py_DECREF(list); /* removes all references from append */
}
#endif
+
+
+/*****************************************************************************
+* Description: This function creates a new Python dictionary object.
+* note: dict is owned by sys.modules["__main__"] module, reference is borrowed
+* note: important we use the dict from __main__, this is what python expects
+ for 'pickle' to work as well as strings like this...
+ >> foo = 10
+ >> print(__import__("__main__").foo)
+*****************************************************************************/
+PyObject *bpy_namespace_dict_new(const char *filename)
+{
+ PyInterpreterState *interp= PyThreadState_GET()->interp;
+ PyObject *mod_main= PyModule_New("__main__");
+ PyDict_SetItemString(interp->modules, "__main__", mod_main);
+ Py_DECREF(mod_main); /* sys.modules owns now */
+ PyModule_AddStringConstant(mod_main, "__name__", "__main__");
+ if(filename)
+ PyModule_AddStringConstant(mod_main, "__file__", filename); /* __file__ only for nice UI'ness */
+ PyModule_AddObject(mod_main, "__builtins__", interp->builtins);
+ Py_INCREF(interp->builtins); /* AddObject steals a reference */
+ return PyModule_GetDict(mod_main);
+}
diff --git a/source/blender/python/generic/bpy_internal_import.h b/source/blender/python/generic/bpy_internal_import.h
index fc4b31a917c..cbd4c881217 100644
--- a/source/blender/python/generic/bpy_internal_import.h
+++ b/source/blender/python/generic/bpy_internal_import.h
@@ -60,5 +60,7 @@ extern PyMethodDef bpy_reload_meth[];
struct Main *bpy_import_main_get(void);
void bpy_import_main_set(struct Main *maggie);
+/* name namespace function for bpy & bge */
+PyObject *bpy_namespace_dict_new(const char *filename);
#endif /* EXPP_bpy_import_h */
diff --git a/source/blender/python/generic/geometry.c b/source/blender/python/generic/geometry.c
index 586c6a3406d..0e98760314d 100644
--- a/source/blender/python/generic/geometry.c
+++ b/source/blender/python/generic/geometry.c
@@ -634,7 +634,7 @@ static int boxPack_FromPyObject(PyObject * value, boxPack **boxarray )
boxPack *box;
- /* Error checking must alredy be done */
+ /* Error checking must already be done */
if( !PyList_Check( value ) ) {
PyErr_SetString( PyExc_TypeError, "can only back a list of [x,y,x,w]" );
return -1;
@@ -835,7 +835,7 @@ PyObject *Geometry_Init(void)
PyObject *submodule;
submodule = PyModule_Create(&M_Geometry_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), M_Geometry_module_def.m_name, submodule);
+ PyDict_SetItemString(PyImport_GetModuleDict(), M_Geometry_module_def.m_name, submodule);
return (submodule);
}
diff --git a/source/blender/python/generic/mathutils.c b/source/blender/python/generic/mathutils.c
index f0571f32f58..a643e6621b2 100644
--- a/source/blender/python/generic/mathutils.c
+++ b/source/blender/python/generic/mathutils.c
@@ -44,6 +44,14 @@
* - toEuler --> to_euler
* - toQuat --> to_quat
* - Vector.toTrackQuat --> Vector.to_track_quat
+ * - Quaternion * Quaternion --> cross product (not dot product)
+ *
+ * moved into class functions.
+ * - Mathutils.RotationMatrix -> mathutils.Matrix.Rotation
+ * - Mathutils.ScaleMatrix -> mathutils.Matrix.Scale
+ * - Mathutils.ShearMatrix -> mathutils.Matrix.Shear
+ * - Mathutils.TranslationMatrix -> mathutils.Matrix.Translation
+ * - Mathutils.OrthoProjectionMatrix -> mathutils.Matrix.OrthoProjection
*
* Moved to Geometry module: Intersect, TriangleArea, TriangleNormal, QuadNormal, LineIntersect
*/
@@ -92,503 +100,8 @@ int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *
return size;
}
-//-----------------------------METHODS----------------------------
-//-----------------quat_rotation (internal)-----------
-//This function multiplies a vector/point * quat or vice versa
-//to rotate the point/vector by the quaternion
-//arguments should all be 3D
-PyObject *quat_rotation(PyObject *arg1, PyObject *arg2)
-{
- float rot[3];
- QuaternionObject *quat = NULL;
- VectorObject *vec = NULL;
-
- if(QuaternionObject_Check(arg1)){
- quat = (QuaternionObject*)arg1;
- if(!BaseMath_ReadCallback(quat))
- return NULL;
-
- if(VectorObject_Check(arg2)){
- vec = (VectorObject*)arg2;
-
- if(!BaseMath_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] -
- quat->quat[3]*quat->quat[3]*vec->vec[0] - quat->quat[2]*quat->quat[2]*vec->vec[0];
- rot[1] = 2*quat->quat[1]*quat->quat[2]*vec->vec[0] + quat->quat[2]*quat->quat[2]*vec->vec[1] +
- 2*quat->quat[3]*quat->quat[2]*vec->vec[2] + 2*quat->quat[0]*quat->quat[3]*vec->vec[0] -
- quat->quat[3]*quat->quat[3]*vec->vec[1] + quat->quat[0]*quat->quat[0]*vec->vec[1] -
- 2*quat->quat[1]*quat->quat[0]*vec->vec[2] - quat->quat[1]*quat->quat[1]*vec->vec[1];
- rot[2] = 2*quat->quat[1]*quat->quat[3]*vec->vec[0] + 2*quat->quat[2]*quat->quat[3]*vec->vec[1] +
- quat->quat[3]*quat->quat[3]*vec->vec[2] - 2*quat->quat[0]*quat->quat[2]*vec->vec[0] -
- quat->quat[2]*quat->quat[2]*vec->vec[2] + 2*quat->quat[0]*quat->quat[1]*vec->vec[1] -
- quat->quat[1]*quat->quat[1]*vec->vec[2] + quat->quat[0]*quat->quat[0]*vec->vec[2];
- return newVectorObject(rot, 3, Py_NEW, NULL);
- }
- }else if(VectorObject_Check(arg1)){
- vec = (VectorObject*)arg1;
-
- if(!BaseMath_ReadCallback(vec))
- return NULL;
-
- if(QuaternionObject_Check(arg2)){
- quat = (QuaternionObject*)arg2;
- if(!BaseMath_ReadCallback(quat))
- 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] -
- quat->quat[3]*quat->quat[3]*vec->vec[0] - quat->quat[2]*quat->quat[2]*vec->vec[0];
- rot[1] = 2*quat->quat[1]*quat->quat[2]*vec->vec[0] + quat->quat[2]*quat->quat[2]*vec->vec[1] +
- 2*quat->quat[3]*quat->quat[2]*vec->vec[2] + 2*quat->quat[0]*quat->quat[3]*vec->vec[0] -
- quat->quat[3]*quat->quat[3]*vec->vec[1] + quat->quat[0]*quat->quat[0]*vec->vec[1] -
- 2*quat->quat[1]*quat->quat[0]*vec->vec[2] - quat->quat[1]*quat->quat[1]*vec->vec[1];
- rot[2] = 2*quat->quat[1]*quat->quat[3]*vec->vec[0] + 2*quat->quat[2]*quat->quat[3]*vec->vec[1] +
- quat->quat[3]*quat->quat[3]*vec->vec[2] - 2*quat->quat[0]*quat->quat[2]*vec->vec[0] -
- quat->quat[2]*quat->quat[2]*vec->vec[2] + 2*quat->quat[0]*quat->quat[1]*vec->vec[1] -
- quat->quat[1]*quat->quat[1]*vec->vec[2] + quat->quat[0]*quat->quat[0]*vec->vec[2];
- return newVectorObject(rot, 3, Py_NEW, NULL);
- }
- }
-
- PyErr_SetString(PyExc_RuntimeError, "quat_rotation(internal): internal problem rotating vector/point\n");
- return NULL;
-
-}
-
//----------------------------------MATRIX FUNCTIONS--------------------
-//----------------------------------mathutils.RotationMatrix() ----------
-//mat is a 1D array of floats - row[0][0],row[0][1], row[1][0], etc.
-static char M_Mathutils_RotationMatrix_doc[] =
-".. function:: RotationMatrix(angle, size, axis)\n"
-"\n"
-" Create a matrix representing a rotation.\n"
-"\n"
-" :arg angle: The angle of rotation desired, in radians.\n"
-" :type angle: float\n"
-" :arg size: The size of the rotation matrix to construct [2, 4].\n"
-" :type size: int\n"
-" :arg axis: a string in ['X', 'Y', 'Z'] or a 3D Vector Object (optional when size is 2).\n"
-" :type axis: string or :class:`Vector`\n"
-" :return: A new rotation matrix.\n"
-" :rtype: :class:`Matrix`\n";
-
-static PyObject *M_Mathutils_RotationMatrix(PyObject * self, PyObject * args)
-{
- VectorObject *vec= NULL;
- char *axis= NULL;
- int matSize;
- float angle = 0.0f;
- 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(!PyArg_ParseTuple(args, "fi|O", &angle, &matSize, &vec)) {
- PyErr_SetString(PyExc_TypeError, "mathutils.RotationMatrix(angle, size, axis): expected float int and a string or vector\n");
- return NULL;
- }
-
- if(vec && !VectorObject_Check(vec)) {
- axis= _PyUnicode_AsString((PyObject *)vec);
- if(axis==NULL || axis[0]=='\0' || axis[1]!='\0' || axis[0] < 'X' || axis[0] > 'Z') {
- PyErr_SetString(PyExc_TypeError, "mathutils.RotationMatrix(): 3rd argument axis value must be a 3D vector or a string in 'X', 'Y', 'Z'\n");
- return NULL;
- }
- else {
- /* use the string */
- vec= NULL;
- }
- }
- while (angle<-(Py_PI*2))
- angle+=(Py_PI*2);
- while (angle>(Py_PI*2))
- angle-=(Py_PI*2);
-
- if(matSize != 2 && matSize != 3 && matSize != 4) {
- PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): can only return a 2x2 3x3 or 4x4 matrix\n");
- return NULL;
- }
- if(matSize == 2 && (vec != NULL)) {
- PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): cannot create a 2x2 rotation matrix around arbitrary axis\n");
- return NULL;
- }
- if((matSize == 3 || matSize == 4) && (axis == NULL) && (vec == NULL)) {
- PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): please choose an axis of rotation for 3d and 4d matrices\n");
- return NULL;
- }
- if(vec) {
- if(vec->size != 3) {
- PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): the vector axis must be a 3D vector\n");
- return NULL;
- }
-
- if(!BaseMath_ReadCallback(vec))
- return NULL;
-
- }
-
- /* check for valid vector/axis above */
- if(vec) {
- axis_angle_to_mat3( (float (*)[3])mat,vec->vec, angle);
- }
- else if(matSize == 2) {
- //2D rotation matrix
- mat[0] = (float) cos (angle);
- mat[1] = (float) sin (angle);
- mat[2] = -((float) sin(angle));
- mat[3] = (float) cos(angle);
- } else if(strcmp(axis, "X") == 0) {
- //rotation around X
- mat[0] = 1.0f;
- mat[4] = (float) cos(angle);
- mat[5] = (float) sin(angle);
- mat[7] = -((float) sin(angle));
- mat[8] = (float) cos(angle);
- } else if(strcmp(axis, "Y") == 0) {
- //rotation around Y
- mat[0] = (float) cos(angle);
- mat[2] = -((float) sin(angle));
- mat[4] = 1.0f;
- mat[6] = (float) sin(angle);
- mat[8] = (float) cos(angle);
- } else if(strcmp(axis, "Z") == 0) {
- //rotation around Z
- mat[0] = (float) cos(angle);
- mat[1] = (float) sin(angle);
- mat[3] = -((float) sin(angle));
- mat[4] = (float) cos(angle);
- mat[8] = 1.0f;
- }
- else {
- /* should never get here */
- PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): unknown error\n");
- return NULL;
- }
-
- if(matSize == 4) {
- //resize matrix
- mat[10] = mat[8];
- mat[9] = mat[7];
- mat[8] = mat[6];
- mat[7] = 0.0f;
- mat[6] = mat[5];
- mat[5] = mat[4];
- mat[4] = mat[3];
- mat[3] = 0.0f;
- }
- //pass to matrix creation
- return newMatrixObject(mat, matSize, matSize, Py_NEW, NULL);
-}
-
-static char M_Mathutils_TranslationMatrix_doc[] =
-".. function:: TranslationMatrix(vector)\n"
-"\n"
-" Create a matrix representing a translation.\n"
-"\n"
-" :arg vector: The translation vector.\n"
-" :type vector: :class:`Vector`\n"
-" :return: An identity matrix with a translation.\n"
-" :rtype: :class:`Matrix`\n";
-
-static PyObject *M_Mathutils_TranslationMatrix(PyObject * self, VectorObject * vec)
-{
- 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(!VectorObject_Check(vec)) {
- PyErr_SetString(PyExc_TypeError, "mathutils.TranslationMatrix(): expected vector\n");
- return NULL;
- }
- if(vec->size != 3 && vec->size != 4) {
- PyErr_SetString(PyExc_TypeError, "mathutils.TranslationMatrix(): vector must be 3D or 4D\n");
- return NULL;
- }
-
- if(!BaseMath_ReadCallback(vec))
- return NULL;
-
- //create a identity matrix and add translation
- unit_m4((float(*)[4]) mat);
- mat[12] = vec->vec[0];
- mat[13] = vec->vec[1];
- mat[14] = vec->vec[2];
-
- return newMatrixObject(mat, 4, 4, Py_NEW, NULL);
-}
-//----------------------------------mathutils.ScaleMatrix() -------------
-//mat is a 1D array of floats - row[0][0],row[0][1], row[1][0], etc.
-static char M_Mathutils_ScaleMatrix_doc[] =
-".. function:: ScaleMatrix(factor, size, axis)\n"
-"\n"
-" Create a matrix representing a scaling.\n"
-"\n"
-" :arg factor: The factor of scaling to apply.\n"
-" :type factor: float\n"
-" :arg size: The size of the scale matrix to construct [2, 4].\n"
-" :type size: int\n"
-" :arg axis: Direction to influence scale. (optional).\n"
-" :type axis: :class:`Vector`\n"
-" :return: A new scale matrix.\n"
-" :rtype: :class:`Matrix`\n";
-
-static PyObject *M_Mathutils_ScaleMatrix(PyObject * self, PyObject * args)
-{
- VectorObject *vec = NULL;
- float norm = 0.0f, factor;
- int matSize, x;
- 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(!PyArg_ParseTuple(args, "fi|O!", &factor, &matSize, &vector_Type, &vec)) {
- PyErr_SetString(PyExc_TypeError, "mathutils.ScaleMatrix(): expected float int and optional vector\n");
- return NULL;
- }
- if(matSize != 2 && matSize != 3 && matSize != 4) {
- PyErr_SetString(PyExc_AttributeError, "mathutils.ScaleMatrix(): can only return a 2x2 3x3 or 4x4 matrix\n");
- return NULL;
- }
- if(vec) {
- if(vec->size > 2 && matSize == 2) {
- PyErr_SetString(PyExc_AttributeError, "mathutils.ScaleMatrix(): please use 2D vectors when scaling in 2D\n");
- return NULL;
- }
-
- if(!BaseMath_ReadCallback(vec))
- return NULL;
-
- }
- if(vec == NULL) { //scaling along axis
- if(matSize == 2) {
- mat[0] = factor;
- mat[3] = factor;
- } else {
- mat[0] = factor;
- mat[4] = factor;
- mat[8] = factor;
- }
- } else { //scaling in arbitrary direction
- //normalize arbitrary axis
- for(x = 0; x < vec->size; x++) {
- norm += vec->vec[x] * vec->vec[x];
- }
- norm = (float) sqrt(norm);
- for(x = 0; x < vec->size; x++) {
- vec->vec[x] /= norm;
- }
- if(matSize == 2) {
- mat[0] = 1 +((factor - 1) *(vec->vec[0] * vec->vec[0]));
- mat[1] =((factor - 1) *(vec->vec[0] * vec->vec[1]));
- mat[2] =((factor - 1) *(vec->vec[0] * vec->vec[1]));
- mat[3] = 1 + ((factor - 1) *(vec->vec[1] * vec->vec[1]));
- } else {
- mat[0] = 1 + ((factor - 1) *(vec->vec[0] * vec->vec[0]));
- mat[1] =((factor - 1) *(vec->vec[0] * vec->vec[1]));
- mat[2] =((factor - 1) *(vec->vec[0] * vec->vec[2]));
- mat[3] =((factor - 1) *(vec->vec[0] * vec->vec[1]));
- mat[4] = 1 + ((factor - 1) *(vec->vec[1] * vec->vec[1]));
- mat[5] =((factor - 1) *(vec->vec[1] * vec->vec[2]));
- mat[6] =((factor - 1) *(vec->vec[0] * vec->vec[2]));
- mat[7] =((factor - 1) *(vec->vec[1] * vec->vec[2]));
- mat[8] = 1 + ((factor - 1) *(vec->vec[2] * vec->vec[2]));
- }
- }
- if(matSize == 4) {
- //resize matrix
- mat[10] = mat[8];
- mat[9] = mat[7];
- mat[8] = mat[6];
- mat[7] = 0.0f;
- mat[6] = mat[5];
- mat[5] = mat[4];
- mat[4] = mat[3];
- mat[3] = 0.0f;
- }
- //pass to matrix creation
- return newMatrixObject(mat, matSize, matSize, Py_NEW, NULL);
-}
-//----------------------------------mathutils.OrthoProjectionMatrix() ---
-//mat is a 1D array of floats - row[0][0],row[0][1], row[1][0], etc.
-static char M_Mathutils_OrthoProjectionMatrix_doc[] =
-".. function:: OrthoProjectionMatrix(plane, size, axis)\n"
-"\n"
-" Create a matrix to represent an orthographic projection.\n"
-"\n"
-" :arg plane: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ', 'R'], where a single axis is for a 2D matrix and 'R' requires axis is given.\n"
-" :type plane: string\n"
-" :arg size: The size of the projection matrix to construct [2, 4].\n"
-" :type size: int\n"
-" :arg axis: Arbitrary perpendicular plane vector (optional).\n"
-" :type axis: :class:`Vector`\n"
-" :return: A new projection matrix.\n"
-" :rtype: :class:`Matrix`\n";
-static PyObject *M_Mathutils_OrthoProjectionMatrix(PyObject * self, PyObject * args)
-{
- VectorObject *vec = NULL;
- char *plane;
- int matSize, x;
- float norm = 0.0f;
- 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(!PyArg_ParseTuple(args, "si|O!", &plane, &matSize, &vector_Type, &vec)) {
- PyErr_SetString(PyExc_TypeError, "mathutils.OrthoProjectionMatrix(): expected string and int and optional vector\n");
- return NULL;
- }
- if(matSize != 2 && matSize != 3 && matSize != 4) {
- PyErr_SetString(PyExc_AttributeError,"mathutils.OrthoProjectionMatrix(): can only return a 2x2 3x3 or 4x4 matrix\n");
- return NULL;
- }
- if(vec) {
- if(vec->size > 2 && matSize == 2) {
- PyErr_SetString(PyExc_AttributeError, "mathutils.OrthoProjectionMatrix(): please use 2D vectors when scaling in 2D\n");
- return NULL;
- }
-
- if(!BaseMath_ReadCallback(vec))
- return NULL;
-
- }
- if(vec == NULL) { //ortho projection onto cardinal plane
- if((strcmp(plane, "X") == 0) && matSize == 2) {
- mat[0] = 1.0f;
- } else if((strcmp(plane, "Y") == 0) && matSize == 2) {
- mat[3] = 1.0f;
- } else if((strcmp(plane, "XY") == 0) && matSize > 2) {
- mat[0] = 1.0f;
- mat[4] = 1.0f;
- } else if((strcmp(plane, "XZ") == 0) && matSize > 2) {
- mat[0] = 1.0f;
- mat[8] = 1.0f;
- } else if((strcmp(plane, "YZ") == 0) && matSize > 2) {
- mat[4] = 1.0f;
- mat[8] = 1.0f;
- } else {
- PyErr_SetString(PyExc_AttributeError, "mathutils.OrthoProjectionMatrix(): unknown plane - expected: X, Y, XY, XZ, YZ\n");
- return NULL;
- }
- } else { //arbitrary plane
- //normalize arbitrary axis
- for(x = 0; x < vec->size; x++) {
- norm += vec->vec[x] * vec->vec[x];
- }
- norm = (float) sqrt(norm);
- for(x = 0; x < vec->size; x++) {
- vec->vec[x] /= norm;
- }
- if((strcmp(plane, "R") == 0) && matSize == 2) {
- mat[0] = 1 - (vec->vec[0] * vec->vec[0]);
- mat[1] = -(vec->vec[0] * vec->vec[1]);
- mat[2] = -(vec->vec[0] * vec->vec[1]);
- mat[3] = 1 - (vec->vec[1] * vec->vec[1]);
- } else if((strcmp(plane, "R") == 0) && matSize > 2) {
- mat[0] = 1 - (vec->vec[0] * vec->vec[0]);
- mat[1] = -(vec->vec[0] * vec->vec[1]);
- mat[2] = -(vec->vec[0] * vec->vec[2]);
- mat[3] = -(vec->vec[0] * vec->vec[1]);
- mat[4] = 1 - (vec->vec[1] * vec->vec[1]);
- mat[5] = -(vec->vec[1] * vec->vec[2]);
- mat[6] = -(vec->vec[0] * vec->vec[2]);
- mat[7] = -(vec->vec[1] * vec->vec[2]);
- mat[8] = 1 - (vec->vec[2] * vec->vec[2]);
- } else {
- PyErr_SetString(PyExc_AttributeError, "mathutils.OrthoProjectionMatrix(): unknown plane - expected: 'r' expected for axis designation\n");
- return NULL;
- }
- }
- if(matSize == 4) {
- //resize matrix
- mat[10] = mat[8];
- mat[9] = mat[7];
- mat[8] = mat[6];
- mat[7] = 0.0f;
- mat[6] = mat[5];
- mat[5] = mat[4];
- mat[4] = mat[3];
- mat[3] = 0.0f;
- }
- //pass to matrix creation
- return newMatrixObject(mat, matSize, matSize, Py_NEW, NULL);
-}
-
-static char M_Mathutils_ShearMatrix_doc[] =
-".. function:: ShearMatrix(plane, factor, size)\n"
-"\n"
-" Create a matrix to represent an shear transformation.\n"
-"\n"
-" :arg plane: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ'], where a single axis is for a 2D matrix.\n"
-" :type plane: string\n"
-" :arg factor: The factor of shear to apply.\n"
-" :type factor: float\n"
-" :arg size: The size of the shear matrix to construct [2, 4].\n"
-" :type size: int\n"
-" :return: A new shear matrix.\n"
-" :rtype: :class:`Matrix`\n";
-
-static PyObject *M_Mathutils_ShearMatrix(PyObject * self, PyObject * args)
-{
- int matSize;
- char *plane;
- float factor;
- 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(!PyArg_ParseTuple(args, "sfi", &plane, &factor, &matSize)) {
- PyErr_SetString(PyExc_TypeError,"mathutils.ShearMatrix(): expected string float and int\n");
- return NULL;
- }
- if(matSize != 2 && matSize != 3 && matSize != 4) {
- PyErr_SetString(PyExc_AttributeError,"mathutils.ShearMatrix(): can only return a 2x2 3x3 or 4x4 matrix\n");
- return NULL;
- }
-
- if((strcmp(plane, "X") == 0)
- && matSize == 2) {
- mat[0] = 1.0f;
- mat[2] = factor;
- mat[3] = 1.0f;
- } else if((strcmp(plane, "Y") == 0) && matSize == 2) {
- mat[0] = 1.0f;
- mat[1] = factor;
- mat[3] = 1.0f;
- } else if((strcmp(plane, "XY") == 0) && matSize > 2) {
- mat[0] = 1.0f;
- mat[4] = 1.0f;
- mat[6] = factor;
- mat[7] = factor;
- } else if((strcmp(plane, "XZ") == 0) && matSize > 2) {
- mat[0] = 1.0f;
- mat[3] = factor;
- mat[4] = 1.0f;
- mat[5] = factor;
- mat[8] = 1.0f;
- } else if((strcmp(plane, "YZ") == 0) && matSize > 2) {
- mat[0] = 1.0f;
- mat[1] = factor;
- mat[2] = factor;
- mat[4] = 1.0f;
- mat[8] = 1.0f;
- } else {
- PyErr_SetString(PyExc_AttributeError, "mathutils.ShearMatrix(): expected: x, y, xy, xz, yz or wrong matrix size for shearing plane\n");
- return NULL;
- }
- if(matSize == 4) {
- //resize matrix
- mat[10] = mat[8];
- mat[9] = mat[7];
- mat[8] = mat[6];
- mat[7] = 0.0f;
- mat[6] = mat[5];
- mat[5] = mat[4];
- mat[4] = mat[3];
- mat[3] = 0.0f;
- }
- //pass to matrix creation
- return newMatrixObject(mat, matSize, matSize, Py_NEW, NULL);
-}
/* Utility functions */
@@ -634,7 +147,7 @@ int Mathutils_RegisterCallback(Mathutils_Callback *cb)
/* find the first free slot */
for(i= 0; mathutils_callbacks[i]; i++) {
- if(mathutils_callbacks[i]==cb) /* alredy registered? */
+ if(mathutils_callbacks[i]==cb) /* already registered? */
return i;
}
@@ -696,7 +209,7 @@ PyObject *BaseMathObject_getOwner( BaseMathObject * self, void *type )
return ret;
}
-char BaseMathObject_Wrapped_doc[] = "True when this object wraps external data (readonly). **type** boolean";
+char BaseMathObject_Wrapped_doc[] = "True when this object wraps external data (readonly).\n\n:type: boolean";
PyObject *BaseMathObject_getWrapped( BaseMathObject *self, void *type )
{
return PyBool_FromLong((self->wrapped == Py_WRAP) ? 1:0);
@@ -714,11 +227,6 @@ void BaseMathObject_dealloc(BaseMathObject * self)
/*----------------------------MODULE INIT-------------------------*/
struct PyMethodDef M_Mathutils_methods[] = {
- {"RotationMatrix", (PyCFunction) M_Mathutils_RotationMatrix, METH_VARARGS, M_Mathutils_RotationMatrix_doc},
- {"ScaleMatrix", (PyCFunction) M_Mathutils_ScaleMatrix, METH_VARARGS, M_Mathutils_ScaleMatrix_doc},
- {"ShearMatrix", (PyCFunction) M_Mathutils_ShearMatrix, METH_VARARGS, M_Mathutils_ShearMatrix_doc},
- {"TranslationMatrix", (PyCFunction) M_Mathutils_TranslationMatrix, METH_O, M_Mathutils_TranslationMatrix_doc},
- {"OrthoProjectionMatrix", (PyCFunction) M_Mathutils_OrthoProjectionMatrix, METH_VARARGS, M_Mathutils_OrthoProjectionMatrix_doc},
{NULL, NULL, 0, NULL}
};
@@ -750,7 +258,7 @@ PyObject *Mathutils_Init(void)
return NULL;
submodule = PyModule_Create(&M_Mathutils_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), M_Mathutils_module_def.m_name, submodule);
+ PyDict_SetItemString(PyImport_GetModuleDict(), M_Mathutils_module_def.m_name, submodule);
/* each type has its own new() function */
PyModule_AddObject( submodule, "Vector", (PyObject *)&vector_Type );
diff --git a/source/blender/python/generic/mathutils.h b/source/blender/python/generic/mathutils.h
index b03f15a20b1..85fbe3225ba 100644
--- a/source/blender/python/generic/mathutils.h
+++ b/source/blender/python/generic/mathutils.h
@@ -61,8 +61,7 @@ PyObject *BaseMathObject_getWrapped( BaseMathObject *self, void * );
void BaseMathObject_dealloc(BaseMathObject * self);
PyObject *Mathutils_Init(void);
-
-PyObject *quat_rotation(PyObject *arg1, PyObject *arg2);
+PyObject *Noise_Init(void); /* lazy, saves having own header */
int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
@@ -73,19 +72,6 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
#define Py_NEW 1
#define Py_WRAP 2
-
-/* Mathutils is used by the BGE and Blender so have to define
- * some things here for luddite mac users of py2.3 */
-#ifndef Py_RETURN_NONE
-#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
-#endif
-#ifndef Py_RETURN_FALSE
-#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
-#endif
-#ifndef Py_RETURN_TRUE
-#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
-#endif
-
typedef struct Mathutils_Callback Mathutils_Callback;
typedef int (*BaseMathCheckFunc)(BaseMathObject *); /* checks the user is still valid */
diff --git a/source/blender/python/generic/mathutils_color.c b/source/blender/python/generic/mathutils_color.c
index 5acd03060d4..57d2838238c 100644
--- a/source/blender/python/generic/mathutils_color.c
+++ b/source/blender/python/generic/mathutils_color.c
@@ -434,18 +434,18 @@ static int Color_setHSV(ColorObject * self, PyObject * value, void * type)
/* Python attributes get/set structure: */
/*****************************************************************************/
static PyGetSetDef Color_getseters[] = {
- {"r", (getter)Color_getChannel, (setter)Color_setChannel, "Red color channel. **type** float", (void *)0},
- {"g", (getter)Color_getChannel, (setter)Color_setChannel, "Green color channel. **type** float", (void *)1},
- {"b", (getter)Color_getChannel, (setter)Color_setChannel, "Blue color channel. **type** float", (void *)2},
+ {"r", (getter)Color_getChannel, (setter)Color_setChannel, "Red color channel.\n\n:type: float", (void *)0},
+ {"g", (getter)Color_getChannel, (setter)Color_setChannel, "Green color channel.\n\n:type: float", (void *)1},
+ {"b", (getter)Color_getChannel, (setter)Color_setChannel, "Blue color channel.\n\n:type: float", (void *)2},
- {"h", (getter)Color_getChannelHSV, (setter)Color_setChannelHSV, "HSV Hue component in [0, 1]. **type** float", (void *)0},
- {"s", (getter)Color_getChannelHSV, (setter)Color_setChannelHSV, "HSV Saturation component in [0, 1]. **type** float", (void *)1},
- {"v", (getter)Color_getChannelHSV, (setter)Color_setChannelHSV, "HSV Value component in [0, 1]. **type** float", (void *)2},
+ {"h", (getter)Color_getChannelHSV, (setter)Color_setChannelHSV, "HSV Hue component in [0, 1].\n\n:type: float", (void *)0},
+ {"s", (getter)Color_getChannelHSV, (setter)Color_setChannelHSV, "HSV Saturation component in [0, 1].\n\n:type: float", (void *)1},
+ {"v", (getter)Color_getChannelHSV, (setter)Color_setChannelHSV, "HSV Value component in [0, 1].\n\n:type: float", (void *)2},
- {"hsv", (getter)Color_getHSV, (setter)Color_setHSV, "HSV Values in [0, 1]. **type** float triplet", (void *)0},
+ {"hsv", (getter)Color_getHSV, (setter)Color_setHSV, "HSV Values in [0, 1].\n\n:type: float triplet", (void *)0},
{"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
- {"_owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
+ {"owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
diff --git a/source/blender/python/generic/mathutils_euler.c b/source/blender/python/generic/mathutils_euler.c
index aac65043a0a..b36eb7803f1 100644
--- a/source/blender/python/generic/mathutils_euler.c
+++ b/source/blender/python/generic/mathutils_euler.c
@@ -615,13 +615,13 @@ static int Euler_setOrder( EulerObject * self, PyObject * value, void * type )
/* Python attributes get/set structure: */
/*****************************************************************************/
static PyGetSetDef Euler_getseters[] = {
- {"x", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler X axis in radians. **type** float", (void *)0},
- {"y", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler Y axis in radians. **type** float", (void *)1},
- {"z", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler Z axis in radians. **type** float", (void *)2},
- {"order", (getter)Euler_getOrder, (setter)Euler_setOrder, "Euler rotation order. **type** string in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']", (void *)NULL},
+ {"x", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler X axis in radians.\n\n:type: float", (void *)0},
+ {"y", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler Y axis in radians.\n\n:type: float", (void *)1},
+ {"z", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler Z axis in radians.\n\n:type: float", (void *)2},
+ {"order", (getter)Euler_getOrder, (setter)Euler_setOrder, "Euler rotation order.\n\n:type: string in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']", (void *)NULL},
{"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
- {"_owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
+ {"owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
diff --git a/source/blender/python/generic/mathutils_matrix.c b/source/blender/python/generic/mathutils_matrix.c
index a211386f503..24239e1f541 100644
--- a/source/blender/python/generic/mathutils_matrix.c
+++ b/source/blender/python/generic/mathutils_matrix.c
@@ -181,6 +181,438 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return newMatrixObject(matrix, argSize, seqSize, Py_NEW, NULL);
}
+/*-----------------------CLASS-METHODS----------------------------*/
+
+//----------------------------------mathutils.RotationMatrix() ----------
+//mat is a 1D array of floats - row[0][0],row[0][1], row[1][0], etc.
+static char C_Matrix_Rotation_doc[] =
+".. classmethod:: Rotation(angle, size, axis)\n"
+"\n"
+" Create a matrix representing a rotation.\n"
+"\n"
+" :arg angle: The angle of rotation desired, in radians.\n"
+" :type angle: float\n"
+" :arg size: The size of the rotation matrix to construct [2, 4].\n"
+" :type size: int\n"
+" :arg axis: a string in ['X', 'Y', 'Z'] or a 3D Vector Object (optional when size is 2).\n"
+" :type axis: string or :class:`Vector`\n"
+" :return: A new rotation matrix.\n"
+" :rtype: :class:`Matrix`\n";
+
+static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
+{
+ VectorObject *vec= NULL;
+ char *axis= NULL;
+ int matSize;
+ float angle = 0.0f;
+ 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(!PyArg_ParseTuple(args, "fi|O", &angle, &matSize, &vec)) {
+ PyErr_SetString(PyExc_TypeError, "mathutils.RotationMatrix(angle, size, axis): expected float int and a string or vector\n");
+ return NULL;
+ }
+
+ if(vec && !VectorObject_Check(vec)) {
+ axis= _PyUnicode_AsString((PyObject *)vec);
+ if(axis==NULL || axis[0]=='\0' || axis[1]!='\0' || axis[0] < 'X' || axis[0] > 'Z') {
+ PyErr_SetString(PyExc_TypeError, "mathutils.RotationMatrix(): 3rd argument axis value must be a 3D vector or a string in 'X', 'Y', 'Z'\n");
+ return NULL;
+ }
+ else {
+ /* use the string */
+ vec= NULL;
+ }
+ }
+
+ while (angle<-(Py_PI*2))
+ angle+=(Py_PI*2);
+ while (angle>(Py_PI*2))
+ angle-=(Py_PI*2);
+
+ if(matSize != 2 && matSize != 3 && matSize != 4) {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): can only return a 2x2 3x3 or 4x4 matrix\n");
+ return NULL;
+ }
+ if(matSize == 2 && (vec != NULL)) {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): cannot create a 2x2 rotation matrix around arbitrary axis\n");
+ return NULL;
+ }
+ if((matSize == 3 || matSize == 4) && (axis == NULL) && (vec == NULL)) {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): please choose an axis of rotation for 3d and 4d matrices\n");
+ return NULL;
+ }
+ if(vec) {
+ if(vec->size != 3) {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): the vector axis must be a 3D vector\n");
+ return NULL;
+ }
+
+ if(!BaseMath_ReadCallback(vec))
+ return NULL;
+
+ }
+
+ /* check for valid vector/axis above */
+ if(vec) {
+ axis_angle_to_mat3( (float (*)[3])mat,vec->vec, angle);
+ }
+ else if(matSize == 2) {
+ //2D rotation matrix
+ mat[0] = (float) cos (angle);
+ mat[1] = (float) sin (angle);
+ mat[2] = -((float) sin(angle));
+ mat[3] = (float) cos(angle);
+ } else if(strcmp(axis, "X") == 0) {
+ //rotation around X
+ mat[0] = 1.0f;
+ mat[4] = (float) cos(angle);
+ mat[5] = (float) sin(angle);
+ mat[7] = -((float) sin(angle));
+ mat[8] = (float) cos(angle);
+ } else if(strcmp(axis, "Y") == 0) {
+ //rotation around Y
+ mat[0] = (float) cos(angle);
+ mat[2] = -((float) sin(angle));
+ mat[4] = 1.0f;
+ mat[6] = (float) sin(angle);
+ mat[8] = (float) cos(angle);
+ } else if(strcmp(axis, "Z") == 0) {
+ //rotation around Z
+ mat[0] = (float) cos(angle);
+ mat[1] = (float) sin(angle);
+ mat[3] = -((float) sin(angle));
+ mat[4] = (float) cos(angle);
+ mat[8] = 1.0f;
+ }
+ else {
+ /* should never get here */
+ PyErr_SetString(PyExc_AttributeError, "mathutils.RotationMatrix(): unknown error\n");
+ return NULL;
+ }
+
+ if(matSize == 4) {
+ //resize matrix
+ mat[10] = mat[8];
+ mat[9] = mat[7];
+ mat[8] = mat[6];
+ mat[7] = 0.0f;
+ mat[6] = mat[5];
+ mat[5] = mat[4];
+ mat[4] = mat[3];
+ mat[3] = 0.0f;
+ }
+ //pass to matrix creation
+ return newMatrixObject(mat, matSize, matSize, Py_NEW, (PyTypeObject *)cls);
+}
+
+
+static char C_Matrix_Translation_doc[] =
+".. classmethod:: Translation(vector)\n"
+"\n"
+" Create a matrix representing a translation.\n"
+"\n"
+" :arg vector: The translation vector.\n"
+" :type vector: :class:`Vector`\n"
+" :return: An identity matrix with a translation.\n"
+" :rtype: :class:`Matrix`\n";
+
+static PyObject *C_Matrix_Translation(PyObject *cls, VectorObject * vec)
+{
+ 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(!VectorObject_Check(vec)) {
+ PyErr_SetString(PyExc_TypeError, "mathutils.TranslationMatrix(): expected vector\n");
+ return NULL;
+ }
+ if(vec->size != 3 && vec->size != 4) {
+ PyErr_SetString(PyExc_TypeError, "mathutils.TranslationMatrix(): vector must be 3D or 4D\n");
+ return NULL;
+ }
+
+ if(!BaseMath_ReadCallback(vec))
+ return NULL;
+
+ //create a identity matrix and add translation
+ unit_m4((float(*)[4]) mat);
+ mat[12] = vec->vec[0];
+ mat[13] = vec->vec[1];
+ mat[14] = vec->vec[2];
+
+ return newMatrixObject(mat, 4, 4, Py_NEW, (PyTypeObject *)cls);
+}
+//----------------------------------mathutils.ScaleMatrix() -------------
+//mat is a 1D array of floats - row[0][0],row[0][1], row[1][0], etc.
+static char C_Matrix_Scale_doc[] =
+".. classmethod:: Scale(factor, size, axis)\n"
+"\n"
+" Create a matrix representing a scaling.\n"
+"\n"
+" :arg factor: The factor of scaling to apply.\n"
+" :type factor: float\n"
+" :arg size: The size of the scale matrix to construct [2, 4].\n"
+" :type size: int\n"
+" :arg axis: Direction to influence scale. (optional).\n"
+" :type axis: :class:`Vector`\n"
+" :return: A new scale matrix.\n"
+" :rtype: :class:`Matrix`\n";
+
+static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
+{
+ VectorObject *vec = NULL;
+ float norm = 0.0f, factor;
+ int matSize, x;
+ 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(!PyArg_ParseTuple(args, "fi|O!", &factor, &matSize, &vector_Type, &vec)) {
+ PyErr_SetString(PyExc_TypeError, "mathutils.ScaleMatrix(): expected float int and optional vector\n");
+ return NULL;
+ }
+ if(matSize != 2 && matSize != 3 && matSize != 4) {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.ScaleMatrix(): can only return a 2x2 3x3 or 4x4 matrix\n");
+ return NULL;
+ }
+ if(vec) {
+ if(vec->size > 2 && matSize == 2) {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.ScaleMatrix(): please use 2D vectors when scaling in 2D\n");
+ return NULL;
+ }
+
+ if(!BaseMath_ReadCallback(vec))
+ return NULL;
+
+ }
+ if(vec == NULL) { //scaling along axis
+ if(matSize == 2) {
+ mat[0] = factor;
+ mat[3] = factor;
+ } else {
+ mat[0] = factor;
+ mat[4] = factor;
+ mat[8] = factor;
+ }
+ } else { //scaling in arbitrary direction
+ //normalize arbitrary axis
+ for(x = 0; x < vec->size; x++) {
+ norm += vec->vec[x] * vec->vec[x];
+ }
+ norm = (float) sqrt(norm);
+ for(x = 0; x < vec->size; x++) {
+ vec->vec[x] /= norm;
+ }
+ if(matSize == 2) {
+ mat[0] = 1 +((factor - 1) *(vec->vec[0] * vec->vec[0]));
+ mat[1] =((factor - 1) *(vec->vec[0] * vec->vec[1]));
+ mat[2] =((factor - 1) *(vec->vec[0] * vec->vec[1]));
+ mat[3] = 1 + ((factor - 1) *(vec->vec[1] * vec->vec[1]));
+ } else {
+ mat[0] = 1 + ((factor - 1) *(vec->vec[0] * vec->vec[0]));
+ mat[1] =((factor - 1) *(vec->vec[0] * vec->vec[1]));
+ mat[2] =((factor - 1) *(vec->vec[0] * vec->vec[2]));
+ mat[3] =((factor - 1) *(vec->vec[0] * vec->vec[1]));
+ mat[4] = 1 + ((factor - 1) *(vec->vec[1] * vec->vec[1]));
+ mat[5] =((factor - 1) *(vec->vec[1] * vec->vec[2]));
+ mat[6] =((factor - 1) *(vec->vec[0] * vec->vec[2]));
+ mat[7] =((factor - 1) *(vec->vec[1] * vec->vec[2]));
+ mat[8] = 1 + ((factor - 1) *(vec->vec[2] * vec->vec[2]));
+ }
+ }
+ if(matSize == 4) {
+ //resize matrix
+ mat[10] = mat[8];
+ mat[9] = mat[7];
+ mat[8] = mat[6];
+ mat[7] = 0.0f;
+ mat[6] = mat[5];
+ mat[5] = mat[4];
+ mat[4] = mat[3];
+ mat[3] = 0.0f;
+ }
+ //pass to matrix creation
+ return newMatrixObject(mat, matSize, matSize, Py_NEW, (PyTypeObject *)cls);
+}
+//----------------------------------mathutils.OrthoProjectionMatrix() ---
+//mat is a 1D array of floats - row[0][0],row[0][1], row[1][0], etc.
+static char C_Matrix_OrthoProjection_doc[] =
+".. classmethod:: OrthoProjection(plane, size, axis)\n"
+"\n"
+" Create a matrix to represent an orthographic projection.\n"
+"\n"
+" :arg plane: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ', 'R'], where a single axis is for a 2D matrix and 'R' requires axis is given.\n"
+" :type plane: string\n"
+" :arg size: The size of the projection matrix to construct [2, 4].\n"
+" :type size: int\n"
+" :arg axis: Arbitrary perpendicular plane vector (optional).\n"
+" :type axis: :class:`Vector`\n"
+" :return: A new projection matrix.\n"
+" :rtype: :class:`Matrix`\n";
+static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
+{
+ VectorObject *vec = NULL;
+ char *plane;
+ int matSize, x;
+ float norm = 0.0f;
+ 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(!PyArg_ParseTuple(args, "si|O!", &plane, &matSize, &vector_Type, &vec)) {
+ PyErr_SetString(PyExc_TypeError, "mathutils.OrthoProjectionMatrix(): expected string and int and optional vector\n");
+ return NULL;
+ }
+ if(matSize != 2 && matSize != 3 && matSize != 4) {
+ PyErr_SetString(PyExc_AttributeError,"mathutils.OrthoProjectionMatrix(): can only return a 2x2 3x3 or 4x4 matrix\n");
+ return NULL;
+ }
+ if(vec) {
+ if(vec->size > 2 && matSize == 2) {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.OrthoProjectionMatrix(): please use 2D vectors when scaling in 2D\n");
+ return NULL;
+ }
+
+ if(!BaseMath_ReadCallback(vec))
+ return NULL;
+
+ }
+ if(vec == NULL) { //ortho projection onto cardinal plane
+ if((strcmp(plane, "X") == 0) && matSize == 2) {
+ mat[0] = 1.0f;
+ } else if((strcmp(plane, "Y") == 0) && matSize == 2) {
+ mat[3] = 1.0f;
+ } else if((strcmp(plane, "XY") == 0) && matSize > 2) {
+ mat[0] = 1.0f;
+ mat[4] = 1.0f;
+ } else if((strcmp(plane, "XZ") == 0) && matSize > 2) {
+ mat[0] = 1.0f;
+ mat[8] = 1.0f;
+ } else if((strcmp(plane, "YZ") == 0) && matSize > 2) {
+ mat[4] = 1.0f;
+ mat[8] = 1.0f;
+ } else {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.OrthoProjectionMatrix(): unknown plane - expected: X, Y, XY, XZ, YZ\n");
+ return NULL;
+ }
+ } else { //arbitrary plane
+ //normalize arbitrary axis
+ for(x = 0; x < vec->size; x++) {
+ norm += vec->vec[x] * vec->vec[x];
+ }
+ norm = (float) sqrt(norm);
+ for(x = 0; x < vec->size; x++) {
+ vec->vec[x] /= norm;
+ }
+ if((strcmp(plane, "R") == 0) && matSize == 2) {
+ mat[0] = 1 - (vec->vec[0] * vec->vec[0]);
+ mat[1] = -(vec->vec[0] * vec->vec[1]);
+ mat[2] = -(vec->vec[0] * vec->vec[1]);
+ mat[3] = 1 - (vec->vec[1] * vec->vec[1]);
+ } else if((strcmp(plane, "R") == 0) && matSize > 2) {
+ mat[0] = 1 - (vec->vec[0] * vec->vec[0]);
+ mat[1] = -(vec->vec[0] * vec->vec[1]);
+ mat[2] = -(vec->vec[0] * vec->vec[2]);
+ mat[3] = -(vec->vec[0] * vec->vec[1]);
+ mat[4] = 1 - (vec->vec[1] * vec->vec[1]);
+ mat[5] = -(vec->vec[1] * vec->vec[2]);
+ mat[6] = -(vec->vec[0] * vec->vec[2]);
+ mat[7] = -(vec->vec[1] * vec->vec[2]);
+ mat[8] = 1 - (vec->vec[2] * vec->vec[2]);
+ } else {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.OrthoProjectionMatrix(): unknown plane - expected: 'r' expected for axis designation\n");
+ return NULL;
+ }
+ }
+ if(matSize == 4) {
+ //resize matrix
+ mat[10] = mat[8];
+ mat[9] = mat[7];
+ mat[8] = mat[6];
+ mat[7] = 0.0f;
+ mat[6] = mat[5];
+ mat[5] = mat[4];
+ mat[4] = mat[3];
+ mat[3] = 0.0f;
+ }
+ //pass to matrix creation
+ return newMatrixObject(mat, matSize, matSize, Py_NEW, (PyTypeObject *)cls);
+}
+
+static char C_Matrix_Shear_doc[] =
+".. classmethod:: Shear(plane, factor, size)\n"
+"\n"
+" Create a matrix to represent an shear transformation.\n"
+"\n"
+" :arg plane: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ'], where a single axis is for a 2D matrix.\n"
+" :type plane: string\n"
+" :arg factor: The factor of shear to apply.\n"
+" :type factor: float\n"
+" :arg size: The size of the shear matrix to construct [2, 4].\n"
+" :type size: int\n"
+" :return: A new shear matrix.\n"
+" :rtype: :class:`Matrix`\n";
+
+static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
+{
+ int matSize;
+ char *plane;
+ float factor;
+ 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(!PyArg_ParseTuple(args, "sfi", &plane, &factor, &matSize)) {
+ PyErr_SetString(PyExc_TypeError,"mathutils.ShearMatrix(): expected string float and int\n");
+ return NULL;
+ }
+ if(matSize != 2 && matSize != 3 && matSize != 4) {
+ PyErr_SetString(PyExc_AttributeError,"mathutils.ShearMatrix(): can only return a 2x2 3x3 or 4x4 matrix\n");
+ return NULL;
+ }
+
+ if((strcmp(plane, "X") == 0)
+ && matSize == 2) {
+ mat[0] = 1.0f;
+ mat[2] = factor;
+ mat[3] = 1.0f;
+ } else if((strcmp(plane, "Y") == 0) && matSize == 2) {
+ mat[0] = 1.0f;
+ mat[1] = factor;
+ mat[3] = 1.0f;
+ } else if((strcmp(plane, "XY") == 0) && matSize > 2) {
+ mat[0] = 1.0f;
+ mat[4] = 1.0f;
+ mat[6] = factor;
+ mat[7] = factor;
+ } else if((strcmp(plane, "XZ") == 0) && matSize > 2) {
+ mat[0] = 1.0f;
+ mat[3] = factor;
+ mat[4] = 1.0f;
+ mat[5] = factor;
+ mat[8] = 1.0f;
+ } else if((strcmp(plane, "YZ") == 0) && matSize > 2) {
+ mat[0] = 1.0f;
+ mat[1] = factor;
+ mat[2] = factor;
+ mat[4] = 1.0f;
+ mat[8] = 1.0f;
+ } else {
+ PyErr_SetString(PyExc_AttributeError, "mathutils.ShearMatrix(): expected: x, y, xy, xz, yz or wrong matrix size for shearing plane\n");
+ return NULL;
+ }
+ if(matSize == 4) {
+ //resize matrix
+ mat[10] = mat[8];
+ mat[9] = mat[7];
+ mat[8] = mat[6];
+ mat[7] = 0.0f;
+ mat[6] = mat[5];
+ mat[5] = mat[4];
+ mat[4] = mat[3];
+ mat[3] = 0.0f;
+ }
+ //pass to matrix creation
+ return newMatrixObject(mat, matSize, matSize, Py_NEW, (PyTypeObject *)cls);
+}
+
/* assumes rowsize == colsize is checked and the read callback has run */
static float matrix_determinant(MatrixObject * self)
{
@@ -1300,12 +1732,12 @@ static PyObject *Matrix_getIsNegative( MatrixObject * self, void *type )
/* Python attributes get/set structure: */
/*****************************************************************************/
static PyGetSetDef Matrix_getseters[] = {
- {"row_size", (getter)Matrix_getRowSize, (setter)NULL, "The row size of the matrix (readonly). **type** int", NULL},
- {"col_size", (getter)Matrix_getColSize, (setter)NULL, "The column size of the matrix (readonly). **type** int", NULL},
- {"median_scale", (getter)Matrix_getMedianScale, (setter)NULL, "The average scale applied to each axis (readonly). **type** float", NULL},
- {"is_negative", (getter)Matrix_getIsNegative, (setter)NULL, "True if this matrix results in a negative scale, 3x3 and 4x4 only, (readonly). **type** bool", NULL},
+ {"row_size", (getter)Matrix_getRowSize, (setter)NULL, "The row size of the matrix (readonly).\n\n:type: int", NULL},
+ {"col_size", (getter)Matrix_getColSize, (setter)NULL, "The column size of the matrix (readonly).\n\n:type: int", NULL},
+ {"median_scale", (getter)Matrix_getMedianScale, (setter)NULL, "The average scale applied to each axis (readonly).\n\n:type: float", NULL},
+ {"is_negative", (getter)Matrix_getIsNegative, (setter)NULL, "True if this matrix results in a negative scale, 3x3 and 4x4 only, (readonly).\n\n:type: bool", NULL},
{"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
- {"_owner",(getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
+ {"owner",(getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
@@ -1326,6 +1758,13 @@ static struct PyMethodDef Matrix_methods[] = {
{"to_quat", (PyCFunction) Matrix_toQuat, METH_NOARGS, Matrix_toQuat_doc},
{"copy", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
{"__copy__", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
+
+ /* class methods */
+ {"Rotation", (PyCFunction) C_Matrix_Rotation, METH_VARARGS | METH_CLASS, C_Matrix_Rotation_doc},
+ {"Scale", (PyCFunction) C_Matrix_Scale, METH_VARARGS | METH_CLASS, C_Matrix_Scale_doc},
+ {"Shear", (PyCFunction) C_Matrix_Shear, METH_VARARGS | METH_CLASS, C_Matrix_Shear_doc},
+ {"Translation", (PyCFunction) C_Matrix_Translation, METH_O | METH_CLASS, C_Matrix_Translation_doc},
+ {"OrthoProjection", (PyCFunction) C_Matrix_OrthoProjection, METH_VARARGS | METH_CLASS, C_Matrix_OrthoProjection_doc},
{NULL, NULL, 0, NULL}
};
diff --git a/source/blender/python/generic/mathutils_quat.c b/source/blender/python/generic/mathutils_quat.c
index f94e5e2a03a..553844b6ee5 100644
--- a/source/blender/python/generic/mathutils_quat.c
+++ b/source/blender/python/generic/mathutils_quat.c
@@ -109,7 +109,7 @@ static PyObject *Quaternion_ToEuler(QuaternionObject * self, PyObject *args)
}
//----------------------------Quaternion.toMatrix()------------------
static char Quaternion_ToMatrix_doc[] =
-".. method:: to_matrix(other)\n"
+".. method:: to_matrix()\n"
"\n"
" Return a matrix representation of the quaternion.\n"
"\n"
@@ -190,9 +190,7 @@ static char Quaternion_Difference_doc[] =
static PyObject *Quaternion_Difference(QuaternionObject * self, QuaternionObject * value)
{
- float quat[QUAT_SIZE], tempQuat[QUAT_SIZE];
- double dot = 0.0f;
- int x;
+ float quat[QUAT_SIZE];
if (!QuaternionObject_Check(value)) {
PyErr_SetString( PyExc_TypeError, "quat.difference(value): expected a quaternion argument" );
@@ -202,14 +200,8 @@ static PyObject *Quaternion_Difference(QuaternionObject * self, QuaternionObject
if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value))
return NULL;
- copy_qt_qt(tempQuat, self->quat);
- conjugate_qt(tempQuat);
- dot = sqrt(dot_qtqt(tempQuat, tempQuat));
+ rotation_between_quats_to_quat(quat, self->quat, value->quat);
- for(x = 0; x < QUAT_SIZE; x++) {
- tempQuat[x] /= (float)(dot * dot);
- }
- mul_qt_qtqt(quat, tempQuat, value->quat);
return newQuaternionObject(quat, Py_NEW, NULL);
}
@@ -668,8 +660,9 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2)
return NULL;
}
- if(quat1 && quat2) { /* QUAT*QUAT (dot product) */
- return PyFloat_FromDouble(dot_qtqt(quat1->quat, quat2->quat));
+ if(quat1 && quat2) { /* QUAT*QUAT (cross product) */
+ mul_qt_qtqt(quat, quat1->quat, quat2->quat);
+ return newQuaternionObject(quat, Py_NEW, NULL);
}
/* the only case this can happen (for a supported type is "FLOAT*QUAT" ) */
@@ -685,12 +678,19 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2)
}
else { /* QUAT*SOMETHING */
if(VectorObject_Check(q2)){ /* QUAT*VEC */
+ float tvec[3];
vec = (VectorObject*)q2;
if(vec->size != 3){
PyErr_SetString(PyExc_TypeError, "Quaternion multiplication: only 3D vector rotations currently supported\n");
return NULL;
}
- return quat_rotation((PyObject*)quat1, (PyObject*)vec); /* vector updating done inside the func */
+ if(!BaseMath_ReadCallback(vec)) {
+ return NULL;
+ }
+
+ copy_v3_v3(tvec, vec->vec);
+ mul_qt_v3(quat1->quat, tvec);
+ return newVectorObject(tvec, 3, Py_NEW, NULL);
}
scalar= PyFloat_AsDouble(q2);
@@ -774,27 +774,101 @@ static int Quaternion_setAxis( QuaternionObject * self, PyObject * value, void *
static PyObject *Quaternion_getMagnitude( QuaternionObject * self, void *type )
{
+ if(!BaseMath_ReadCallback(self))
+ return NULL;
+
return PyFloat_FromDouble(sqrt(dot_qtqt(self->quat, self->quat)));
}
static PyObject *Quaternion_getAngle( QuaternionObject * self, void *type )
{
+ if(!BaseMath_ReadCallback(self))
+ return NULL;
+
return PyFloat_FromDouble(2.0 * (saacos(self->quat[0])));
}
-static PyObject *Quaternion_getAxisVec( QuaternionObject * self, void *type )
+static int Quaternion_setAngle(QuaternionObject * self, PyObject * value, void * type)
+{
+ float axis[3];
+ float angle;
+
+ if(!BaseMath_ReadCallback(self))
+ return -1;
+
+ quat_to_axis_angle(axis, &angle, self->quat);
+
+ angle = PyFloat_AsDouble(value);
+
+ if(angle==-1.0f && PyErr_Occurred()) { /* parsed item not a number */
+ PyErr_SetString(PyExc_TypeError, "quaternion.angle = value: float expected");
+ return -1;
+ }
+
+ /* If the axis of rotation is 0,0,0 set it to 1,0,0 - for zero-degree rotations */
+ if( EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
+ EXPP_FloatsAreEqual(axis[1], 0.0f, 10) &&
+ EXPP_FloatsAreEqual(axis[2], 0.0f, 10)
+ ) {
+ axis[0] = 1.0f;
+ }
+
+ axis_angle_to_quat(self->quat, axis, angle);
+
+ if(!BaseMath_WriteCallback(self))
+ return -1;
+
+ return 0;
+}
+
+static PyObject *Quaternion_getAxisVec(QuaternionObject *self, void *type)
{
- float vec[3];
+ float axis[3];
+ float angle;
- normalize_v3_v3(vec, self->quat+1);
+ if(!BaseMath_ReadCallback(self))
+ return NULL;
+
+ quat_to_axis_angle(axis, &angle, self->quat);
/* If the axis of rotation is 0,0,0 set it to 1,0,0 - for zero-degree rotations */
- if( EXPP_FloatsAreEqual(vec[0], 0.0f, 10) &&
- EXPP_FloatsAreEqual(vec[1], 0.0f, 10) &&
- EXPP_FloatsAreEqual(vec[2], 0.0f, 10) ){
- vec[0] = 1.0f;
+ if( EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
+ EXPP_FloatsAreEqual(axis[1], 0.0f, 10) &&
+ EXPP_FloatsAreEqual(axis[2], 0.0f, 10)
+ ) {
+ axis[0] = 1.0f;
}
- return (PyObject *) newVectorObject(vec, 3, Py_NEW, NULL);
+
+ return (PyObject *) newVectorObject(axis, 3, Py_NEW, NULL);
+}
+
+static int Quaternion_setAxisVec(QuaternionObject *self, PyObject *value, void *type)
+{
+ float axis[3];
+ float angle;
+
+ VectorObject *vec;
+
+ if(!BaseMath_ReadCallback(self))
+ return -1;
+
+ quat_to_axis_angle(axis, &angle, self->quat);
+
+ if(!VectorObject_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "quaternion.axis = value: expected a 3D Vector");
+ return -1;
+ }
+
+ vec= (VectorObject *)value;
+ if(!BaseMath_ReadCallback(vec))
+ return -1;
+
+ axis_angle_to_quat(self->quat, vec->vec, angle);
+
+ if(!BaseMath_WriteCallback(self))
+ return -1;
+
+ return 0;
}
//----------------------------------mathutils.Quaternion() --------------
@@ -848,15 +922,15 @@ static struct PyMethodDef Quaternion_methods[] = {
/* Python attributes get/set structure: */
/*****************************************************************************/
static PyGetSetDef Quaternion_getseters[] = {
- {"w", (getter)Quaternion_getAxis, (setter)Quaternion_setAxis, "Quaternion W value. **type** float", (void *)0},
- {"x", (getter)Quaternion_getAxis, (setter)Quaternion_setAxis, "Quaternion X axis. **type** float", (void *)1},
- {"y", (getter)Quaternion_getAxis, (setter)Quaternion_setAxis, "Quaternion Y axis. **type** float", (void *)2},
- {"z", (getter)Quaternion_getAxis, (setter)Quaternion_setAxis, "Quaternion Z axis. **type** float", (void *)3},
- {"magnitude", (getter)Quaternion_getMagnitude, (setter)NULL, "Size of the quaternion (readonly). **type** float", NULL},
- {"angle", (getter)Quaternion_getAngle, (setter)NULL, "angle of the quaternion (readonly). **type** float", NULL},
- {"axis",(getter)Quaternion_getAxisVec, (setter)NULL, "quaternion axis as a vector (readonly). **type** :class:`Vector`", NULL},
+ {"w", (getter)Quaternion_getAxis, (setter)Quaternion_setAxis, "Quaternion W value.\n\n:type: float", (void *)0},
+ {"x", (getter)Quaternion_getAxis, (setter)Quaternion_setAxis, "Quaternion X axis.\n\n:type: float", (void *)1},
+ {"y", (getter)Quaternion_getAxis, (setter)Quaternion_setAxis, "Quaternion Y axis.\n\n:type: float", (void *)2},
+ {"z", (getter)Quaternion_getAxis, (setter)Quaternion_setAxis, "Quaternion Z axis.\n\n:type: float", (void *)3},
+ {"magnitude", (getter)Quaternion_getMagnitude, (setter)NULL, "Size of the quaternion (readonly).\n\n:type: float", NULL},
+ {"angle", (getter)Quaternion_getAngle, (setter)Quaternion_setAngle, "angle of the quaternion.\n\n:type: float", NULL},
+ {"axis",(getter)Quaternion_getAxisVec, (setter)Quaternion_setAxisVec, "quaternion axis as a vector.\n\n:type: :class:`Vector`", NULL},
{"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
- {"_owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
+ {"owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
diff --git a/source/blender/python/generic/mathutils_vector.c b/source/blender/python/generic/mathutils_vector.c
index a9bcdacdb03..75a695526fc 100644
--- a/source/blender/python/generic/mathutils_vector.c
+++ b/source/blender/python/generic/mathutils_vector.c
@@ -508,7 +508,8 @@ static char Vector_angle_doc[] =
" :arg other: another vector to compare the angle with\n"
" :type other: :class:`Vector`\n"
" :arg fallback: return this value when the angle cant be calculated (zero length vector)\n"
-" :return angle: angle in radians or fallback when given\n"
+" :type fallback: any\n"
+" :return: angle in radians or fallback when given\n"
" :rtype: float\n"
"\n"
" .. note:: Zero length vectors raise an :exc:`AttributeError`.\n";
@@ -607,8 +608,9 @@ static char Vector_Project_doc[] =
"\n"
" Return the projection of this vector onto the *other*.\n"
"\n"
+" :arg other: second vector.\n"
" :type other: :class:`Vector`\n"
-" :return projection: the parallel projection vector\n"
+" :return: the parallel projection vector\n"
" :rtype: :class:`Vector`\n";
static PyObject *Vector_Project(VectorObject *self, VectorObject *value)
@@ -1010,13 +1012,20 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
/* VEC * MATRIX */
return row_vector_multiplication(vec1, (MatrixObject*)v2);
} else if (QuaternionObject_Check(v2)) {
- QuaternionObject *quat = (QuaternionObject*)v2; /* quat_rotation validates */
+ /* VEC * QUAT */
+ QuaternionObject *quat2 = (QuaternionObject*)v2;
+ float tvec[4];
if(vec1->size != 3) {
PyErr_SetString(PyExc_TypeError, "Vector multiplication: only 3D vector rotations (with quats) currently supported\n");
return NULL;
}
- return quat_rotation((PyObject*)vec1, (PyObject*)quat);
+ if(!BaseMath_ReadCallback(quat2)) {
+ return NULL;
+ }
+ copy_v3_v3(tvec, vec1->vec);
+ mul_qt_v3(quat2->quat, tvec);
+ return newVectorObject(tvec, 3, Py_NEW, NULL);
}
else if (((scalar= PyFloat_AsDouble(v2)) == -1.0 && PyErr_Occurred())==0) { /* VEC*FLOAT */
int i;
@@ -1468,7 +1477,7 @@ static int Vector_setLength(VectorObject *self, PyObject * value )
self->vec[i]= self->vec[i] / (float)dot;
}
- BaseMath_WriteCallback(self); /* checked alredy */
+ BaseMath_WriteCallback(self); /* checked already */
return 0;
}
@@ -1587,14 +1596,14 @@ static int Vector_setSwizzle(VectorObject *self, PyObject * value, void *closure
/* Python attributes get/set structure: */
/*****************************************************************************/
static PyGetSetDef Vector_getseters[] = {
- {"x", (getter)Vector_getAxis, (setter)Vector_setAxis, "Vector X axis. **type** float", (void *)0},
- {"y", (getter)Vector_getAxis, (setter)Vector_setAxis, "Vector Y axis. **type** float", (void *)1},
- {"z", (getter)Vector_getAxis, (setter)Vector_setAxis, "Vector Z axis (3D Vectors only). **type** float", (void *)2},
- {"w", (getter)Vector_getAxis, (setter)Vector_setAxis, "Vector W axis (4D Vectors only). **type** float", (void *)3},
- {"length", (getter)Vector_getLength, (setter)Vector_setLength, "Vector Length. **type** float", NULL},
- {"magnitude", (getter)Vector_getLength, (setter)Vector_setLength, "Vector Length. **type** float", NULL},
+ {"x", (getter)Vector_getAxis, (setter)Vector_setAxis, "Vector X axis.\n\n:type: float", (void *)0},
+ {"y", (getter)Vector_getAxis, (setter)Vector_setAxis, "Vector Y axis.\n\n:type: float", (void *)1},
+ {"z", (getter)Vector_getAxis, (setter)Vector_setAxis, "Vector Z axis (3D Vectors only).\n\n:type: float", (void *)2},
+ {"w", (getter)Vector_getAxis, (setter)Vector_setAxis, "Vector W axis (4D Vectors only).\n\n:type: float", (void *)3},
+ {"length", (getter)Vector_getLength, (setter)Vector_setLength, "Vector Length.\n\n:type: float", NULL},
+ {"magnitude", (getter)Vector_getLength, (setter)Vector_setLength, "Vector Length.\n\n:type: float", NULL},
{"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
- {"_owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
+ {"owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
/* autogenerated swizzle attrs, see python script below */
{"xx", (getter)Vector_getSwizzle, (setter)NULL, NULL, SET_INT_IN_POINTER(((0|SWIZZLE_VALID_AXIS) | ((0|SWIZZLE_VALID_AXIS)<<SWIZZLE_BITS_PER_AXIS)))}, // 36
@@ -2034,7 +2043,7 @@ static PyObject *Vector_Negate(VectorObject *self)
for(i = 0; i < self->size; i++)
self->vec[i] = -(self->vec[i]);
- BaseMath_WriteCallback(self); // alredy checked for error
+ BaseMath_WriteCallback(self); // already checked for error
Py_INCREF(self);
return (PyObject*)self;
diff --git a/source/blender/python/intern/Makefile b/source/blender/python/intern/Makefile
index 419092cbe21..6c0b7b4d14e 100644
--- a/source/blender/python/intern/Makefile
+++ b/source/blender/python/intern/Makefile
@@ -15,7 +15,7 @@
#
# 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.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
@@ -57,6 +57,7 @@ CPPFLAGS += -I../../imbuf
CPPFLAGS += -I../../blenloader
CPPFLAGS += -I../../windowmanager
CPPFLAGS += -I../../render/extern/include
+CPPFLAGS += -I$(NAN_AUDASPACE)/include
# path to the guarded memory allocator
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index b978e46f6da..87cc0e79509 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -41,33 +41,25 @@
#include "../generic/blf_api.h"
#include "../generic/IDProp.h"
-static char bpy_home_paths_doc[] =
-".. function:: home_paths(subfolder)\n"
+//#include "AUD_PyInit.h"
+
+static char bpy_script_paths_doc[] =
+".. function:: script_paths()\n"
"\n"
-" Return 3 paths to blender home directories.\n"
+" Return 2 paths to blender scripts directories.\n"
"\n"
-" :arg subfolder: The name of a subfolder to find within the blenders home directory.\n"
-" :type subfolder: string\n"
-" :return: (system, local, user) strings will be empty when not found.\n"
+" :return: (system, user) strings will be empty when not found.\n"
" :rtype: tuple of strigs\n";
-PyObject *bpy_home_paths(PyObject *self, PyObject *args)
+PyObject *bpy_script_paths(PyObject *self)
{
- PyObject *ret= PyTuple_New(3);
+ PyObject *ret= PyTuple_New(2);
char *path;
- char *subfolder= "";
- if (!PyArg_ParseTuple(args, "|s:blender_homes", &subfolder))
- return NULL;
-
- path= BLI_gethome_folder(subfolder, BLI_GETHOME_SYSTEM);
+ path= BLI_get_folder(BLENDER_USER_SCRIPTS, NULL);
PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:""));
-
- path= BLI_gethome_folder(subfolder, BLI_GETHOME_LOCAL);
+ path= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL);
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromString(path?path:""));
-
- path= BLI_gethome_folder(subfolder, BLI_GETHOME_USER);
- PyTuple_SET_ITEM(ret, 2, PyUnicode_FromString(path?path:""));
return ret;
}
@@ -75,7 +67,7 @@ PyObject *bpy_home_paths(PyObject *self, PyObject *args)
static char bpy_blend_paths_doc[] =
".. function:: blend_paths(absolute=False)\n"
"\n"
-" Returns a list of paths associated with this blend file.\n"
+" Returns a list of paths to external files referenced by the loaded .blend file.\n"
"\n"
" :arg absolute: When true the paths returned are made absolute.\n"
" :type absolute: boolean\n"
@@ -120,7 +112,7 @@ static PyObject *bpy_blend_paths(PyObject * self, PyObject *args, PyObject *kw)
return list;
}
-static PyMethodDef meth_bpy_home_paths[] = {{ "home_paths", (PyCFunction)bpy_home_paths, METH_VARARGS, bpy_home_paths_doc}};
+static PyMethodDef meth_bpy_script_paths[] = {{ "script_paths", (PyCFunction)bpy_script_paths, METH_NOARGS, bpy_script_paths_doc}};
static PyMethodDef meth_bpy_blend_paths[] = {{ "blend_paths", (PyCFunction)bpy_blend_paths, METH_VARARGS|METH_KEYWORDS, bpy_blend_paths_doc}};
static void bpy_import_test(char *modname)
@@ -159,15 +151,16 @@ void BPy_init_modules( void )
/* stand alone utility modules not related to blender directly */
Geometry_Init();
Mathutils_Init();
+ Noise_Init();
BGL_Init();
BLF_Init();
IDProp_Init_Types();
-
+ //AUD_initPython();
mod = PyModule_New("_bpy");
/* add the module so we can import it */
- PyDict_SetItemString(PySys_GetObject("modules"), "_bpy", mod);
+ PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy", mod);
Py_DECREF(mod);
/* run first, initializes rna types */
@@ -191,7 +184,7 @@ void BPy_init_modules( void )
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
/* utility func's that have nowhere else to go */
- PyModule_AddObject(mod, meth_bpy_home_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_home_paths, NULL));
+ PyModule_AddObject(mod, meth_bpy_script_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_script_paths, NULL));
PyModule_AddObject(mod, meth_bpy_blend_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_blend_paths, NULL));
/* add our own modules dir, this is a python package */
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index 4a2ac0c9252..78658a611a3 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -43,7 +43,6 @@ static PyTypeObject BlenderAppType;
static PyStructSequence_Field app_info_fields[] = {
{"version", "The Blender version as a tuple of 3 numbers. eg. (2, 50, 11)"},
{"version_string", "The Blender version formatted as a string"},
- {"home", "The blender home directory, normally matching $HOME"},
{"binary_path", "The location of blenders executable, useful for utilities that spawn new instances"},
{"debug", "Boolean, set when blender is running in debug mode (started with -d)"},
{"background", "Boolean, True when blender is running without a user interface (started with -b)"},
@@ -85,7 +84,6 @@ static PyObject *make_app_info(void)
SetObjItem(Py_BuildValue("(iii)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
- SetStrItem(BLI_gethome());
SetStrItem(bprogname);
SetObjItem(PyBool_FromLong(G.f & G_DEBUG));
SetObjItem(PyBool_FromLong(G.background));
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index bf91b0498ed..af2b5b41961 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -44,6 +44,7 @@
#include "BKE_context.h"
#include "BKE_text.h"
+#include "BKE_font.h" /* only for utf8towchar */
#include "BKE_main.h"
#include "BKE_global.h" /* only for script checking */
@@ -145,29 +146,6 @@ void BPY_update_modules( void )
bpy_context_module->ptr.data= (void *)BPy_GetContext();
}
-/*****************************************************************************
-* Description: This function creates a new Python dictionary object.
-*****************************************************************************/
-static PyObject *CreateGlobalDictionary( bContext *C, const char *filename )
-{
- PyObject *item;
- PyObject *dict = PyDict_New( );
- PyDict_SetItemString( dict, "__builtins__", PyEval_GetBuiltins( ) );
-
- item = PyUnicode_FromString( "__main__" );
- PyDict_SetItemString( dict, "__name__", item );
- Py_DECREF(item);
-
- /* __file__ only for nice UI'ness */
- if(filename) {
- PyObject *item = PyUnicode_FromString( filename );
- PyDict_SetItemString( dict, "__file__", item );
- Py_DECREF(item);
- }
-
- return dict;
-}
-
/* must be called before Py_Initialize */
void BPY_start_python_path(void)
{
@@ -204,10 +182,15 @@ void BPY_start_python_path(void)
#endif
{
- static wchar_t py_path_bundle_wchar[FILE_MAXDIR];
+ static wchar_t py_path_bundle_wchar[FILE_MAX];
+
+ /* cant use this, on linux gives bug: #23018, TODO: try LANG="en_US.UTF-8" /usr/bin/blender, suggested 22008 */
+ /* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */
+
+ utf8towchar(py_path_bundle_wchar, py_path_bundle);
- mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR);
Py_SetPythonHome(py_path_bundle_wchar);
+ // printf("found python (wchar_t) '%ls'\n", py_path_bundle_wchar);
}
}
@@ -223,9 +206,12 @@ void BPY_start_python( int argc, char **argv )
{
PyThreadState *py_tstate = NULL;
- BPY_start_python_path(); /* allow to use our own included python */
+ /* not essential but nice to set our name */
+ static wchar_t bprogname_wchar[FILE_MAXDIR+FILE_MAXFILE]; /* python holds a reference */
+ utf8towchar(bprogname_wchar, bprogname);
+ Py_SetProgramName(bprogname_wchar);
- // Py_SetProgramName(); // extern char bprogname[FILE_MAXDIR+FILE_MAXFILE];
+ BPY_start_python_path(); /* allow to use our own included python */
Py_Initialize( );
@@ -321,13 +307,13 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
if (fn==NULL && text==NULL) {
return 0;
}
-
+
bpy_context_set(C, &gilstate);
if (text) {
char fn_dummy[FILE_MAXDIR];
bpy_text_filename_get(fn_dummy, text);
- py_dict = CreateGlobalDictionary(C, fn_dummy);
+ py_dict = bpy_namespace_dict_new(fn_dummy);
if( !text->compiled ) { /* if it wasn't already compiled, do it now */
char *buf = txt_to_buf( text );
@@ -348,7 +334,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
else {
FILE *fp= fopen(fn, "r");
- py_dict = CreateGlobalDictionary(C, fn);
+ py_dict = bpy_namespace_dict_new(fn);
if(fp) {
#ifdef _WIN32
@@ -383,7 +369,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
Py_DECREF( py_result );
}
- Py_DECREF(py_dict);
+ PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
bpy_context_clear(C, &gilstate);
@@ -492,7 +478,7 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
gilstate = PyGILState_Ensure();
- py_dict = CreateGlobalDictionary(C);
+ py_dict = bpy_namespace_dict_new("<dummy>");
PyObject *module = PyImport_ImportModule(scpt->script.filename);
if (module==NULL) {
@@ -521,7 +507,7 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
Py_XDECREF(module);
- Py_DECREF(py_dict);
+ PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
PyGILState_Release(gilstate);
return 1;
@@ -532,7 +518,7 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
int BPY_eval_button(bContext *C, const char *expr, double *value)
{
PyGILState_STATE gilstate;
- PyObject *dict, *mod, *retval;
+ PyObject *py_dict, *mod, *retval;
int error_ret = 0;
if (!value || !expr) return -1;
@@ -544,11 +530,11 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
bpy_context_set(C, &gilstate);
- dict= CreateGlobalDictionary(C, NULL);
+ py_dict= bpy_namespace_dict_new("<blender button>");
mod = PyImport_ImportModule("math");
if (mod) {
- PyDict_Merge(dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
+ PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
Py_DECREF(mod);
}
else { /* highly unlikely but possibly */
@@ -556,7 +542,7 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
PyErr_Clear();
}
- retval = PyRun_String(expr, Py_eval_input, dict, dict);
+ retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
if (retval == NULL) {
error_ret= -1;
@@ -593,8 +579,9 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
if(error_ret) {
BPy_errors_to_report(CTX_wm_reports(C));
}
+
+ PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
- Py_DECREF(dict);
bpy_context_clear(C, &gilstate);
return error_ret;
@@ -603,7 +590,7 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
int BPY_eval_string(bContext *C, const char *expr)
{
PyGILState_STATE gilstate;
- PyObject *dict, *retval;
+ PyObject *py_dict, *retval;
int error_ret = 0;
if (!expr) return -1;
@@ -614,9 +601,9 @@ int BPY_eval_string(bContext *C, const char *expr)
bpy_context_set(C, &gilstate);
- dict= CreateGlobalDictionary(C, NULL);
+ py_dict= bpy_namespace_dict_new("<blender string>");
- retval = PyRun_String(expr, Py_eval_input, dict, dict);
+ retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
if (retval == NULL) {
error_ret= -1;
@@ -627,9 +614,10 @@ int BPY_eval_string(bContext *C, const char *expr)
Py_DECREF(retval);
}
- Py_DECREF(dict);
+ PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
+
bpy_context_clear(C, &gilstate);
-
+
return error_ret;
}
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 0e54f158ac4..c6c34fbcaf5 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -63,7 +63,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "sO|O!s:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context_str))
return NULL;
- ot= WM_operatortype_exists(opname);
+ ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format( PyExc_SystemError, "Calling operator \"bpy.ops.%s\" error, could not be found", opname);
@@ -259,7 +259,7 @@ PyObject *BPY_operator_module( void )
static PyMethodDef pyop_macro_def_meth ={"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL};
PyObject *submodule = PyModule_New("_bpy.ops");
- PyDict_SetItemString(PySys_GetObject("modules"), "_bpy.ops", submodule);
+ PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy.ops", submodule);
PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) );
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index 48a2655ecb2..c1698a8d751 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -33,22 +33,15 @@
static void operator_properties_init(wmOperatorType *ot)
{
PyObject *py_class = ot->ext.data;
- PyObject *item= ((PyTypeObject*)py_class)->tp_dict; /* getattr(..., "__dict__") returns a proxy */
-
RNA_struct_blender_type_set(ot->ext.srna, ot);
- if(item) {
- /* only call this so pyrna_deferred_register_props gives a useful error
- * WM_operatortype_append_ptr will call RNA_def_struct_identifier
- * later */
- RNA_def_struct_identifier(ot->srna, ot->idname);
+ /* only call this so pyrna_deferred_register_class gives a useful error
+ * WM_operatortype_append_ptr will call RNA_def_struct_identifier
+ * later */
+ RNA_def_struct_identifier(ot->srna, ot->idname);
- if(pyrna_deferred_register_props(ot->srna, item) != 0) {
- PyErr_Print(); /* failed to register operator props */
- PyErr_Clear();
- }
- }
- else {
+ if(pyrna_deferred_register_class(ot->srna, py_class) != 0) {
+ PyErr_Print(); /* failed to register operator props */
PyErr_Clear();
}
}
@@ -104,7 +97,7 @@ PyObject *PYOP_wrap_macro_define(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", &macro, &opname))
return NULL;
- if (WM_operatortype_exists(opname) == NULL) {
+ if (WM_operatortype_find(opname, TRUE) == NULL) {
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid operator id", opname);
return NULL;
}
@@ -113,7 +106,7 @@ PyObject *PYOP_wrap_macro_define(PyObject *self, PyObject *args)
srna= srna_from_self(macro, "Macro Define:");
macroname = RNA_struct_identifier(srna);
- ot = WM_operatortype_exists(macroname);
+ ot = WM_operatortype_find(macroname, TRUE);
if (!ot) {
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid macro or hasn't been registered yet", macroname);
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index c278ad56ab9..9afe638908c 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -919,7 +919,7 @@ PyObject *BPY_rna_props( void )
{
PyObject *submodule;
submodule= PyModule_Create(&props_module);
- PyDict_SetItemString(PySys_GetObject("modules"), props_module.m_name, submodule);
+ PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule);
/* INCREF since its its assumed that all these functions return the
* module with a new ref like PyDict_New, since they are passed to
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index fbb806f6436..07b237a40f8 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -35,6 +35,7 @@
#include "MEM_guardedalloc.h"
#include "BKE_utildefines.h"
+#include "BKE_idcode.h"
#include "BKE_context.h"
#include "BKE_global.h" /* evil G.* */
#include "BKE_report.h"
@@ -62,11 +63,11 @@ static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_
/* bpyrna vector/euler/quat callbacks */
static int mathutils_rna_array_cb_index= -1; /* index for our callbacks */
-/* not used yet but may want to use the subtype below */
+/* subtype not used much yet */
#define MATHUTILS_CB_SUBTYPE_EUL 0
#define MATHUTILS_CB_SUBTYPE_VEC 1
#define MATHUTILS_CB_SUBTYPE_QUAT 2
-#define MATHUTILS_CB_SUBTYPE_COLOR 0
+#define MATHUTILS_CB_SUBTYPE_COLOR 3
static int mathutils_rna_generic_check(BaseMathObject *bmo)
{
@@ -418,25 +419,50 @@ static PyObject *pyrna_prop_richcmp(PyObject *a, PyObject *b, int op)
}
/*----------------------repr--------------------------------------------*/
-static PyObject *pyrna_struct_repr( BPy_StructRNA *self )
+static PyObject *pyrna_struct_str( BPy_StructRNA *self )
{
- PyObject *pyob;
+ PyObject *ret;
char *name;
/* print name if available */
name= RNA_struct_name_get_alloc(&self->ptr, NULL, FALSE);
if(name) {
- pyob= PyUnicode_FromFormat( "<bpy_struct, %.200s(\"%.200s\")>", RNA_struct_identifier(self->ptr.type), name);
+ ret= PyUnicode_FromFormat( "<bpy_struct, %.200s(\"%.200s\")>", RNA_struct_identifier(self->ptr.type), name);
MEM_freeN(name);
- return pyob;
+ return ret;
}
return PyUnicode_FromFormat( "<bpy_struct, %.200s at %p>", RNA_struct_identifier(self->ptr.type), self->ptr.data);
}
-static PyObject *pyrna_prop_repr( BPy_PropertyRNA *self )
+static PyObject *pyrna_struct_repr(BPy_StructRNA *self)
{
- PyObject *pyob;
+ ID *id= self->ptr.id.data;
+ if(id == NULL)
+ return pyrna_struct_str(self); /* fallback */
+
+ if(RNA_struct_is_ID(self->ptr.type)) {
+ return PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]", BKE_idcode_to_name_plural(GS(id->name)), id->name+2);
+ }
+ else {
+ PyObject *ret;
+ char *path;
+ path= RNA_path_from_ID_to_struct(&self->ptr);
+ if(path) {
+ ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"].%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, path);
+ MEM_freeN(path);
+ }
+ else { /* cant find, print something sane */
+ ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]...%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, RNA_struct_identifier(self->ptr.type));
+ }
+
+ return ret;
+ }
+}
+
+static PyObject *pyrna_prop_str( BPy_PropertyRNA *self )
+{
+ PyObject *ret;
PointerRNA ptr;
char *name;
const char *type_id= NULL;
@@ -470,15 +496,36 @@ static PyObject *pyrna_prop_repr( BPy_PropertyRNA *self )
name= RNA_struct_name_get_alloc(&ptr, NULL, FALSE);
if(name) {
- pyob= PyUnicode_FromFormat( "<bpy_%.200s, %.200s.%.200s(\"%.200s\")>", type_fmt, RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), name);
+ ret= PyUnicode_FromFormat( "<bpy_%.200s, %.200s.%.200s(\"%.200s\")>", type_fmt, RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), name);
MEM_freeN(name);
- return pyob;
+ return ret;
}
}
return PyUnicode_FromFormat( "<bpy_%.200s, %.200s.%.200s>", type_fmt, RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop));
}
+static PyObject *pyrna_prop_repr(BPy_PropertyRNA *self)
+{
+ ID *id= self->ptr.id.data;
+ PyObject *ret;
+ char *path;
+
+ if(id == NULL)
+ return pyrna_prop_str(self); /* fallback */
+
+ path= RNA_path_from_ID_to_property(&self->ptr, self->prop);
+ if(path) {
+ ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"].%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, path);
+ MEM_freeN(path);
+ }
+ else { /* cant find, print something sane */
+ ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]...%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, RNA_property_identifier(self->prop));
+ }
+
+ return ret;
+}
+
static long pyrna_struct_hash( BPy_StructRNA *self )
{
return _Py_HashPointer(self->ptr.data);
@@ -1203,10 +1250,11 @@ static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_s
if(RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum, &newptr)) {
return pyrna_struct_CreatePyObject(&newptr);
}
- PyErr_Format(PyExc_IndexError, "bpy_prop_collection[index]: index %d could not be found", keynum);
- return NULL;
+ else { /* fail's if ptr.data == NULL, valid for mesh.materials */
+ Py_RETURN_NONE;
+ }
}
- PyErr_Format(PyExc_IndexError, "bpy_prop_collection[index]: index %d out of range", keynum);
+ PyErr_Format(PyExc_IndexError, "bpy_prop_collection[index]: index %d out of range, size %d", keynum, len);
return NULL;
}
@@ -1616,12 +1664,12 @@ static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value)
return -1;
}
- if(RNA_struct_idproperties_check(self->ptr.type)==0) {
+ if(RNA_struct_idprops_check(self->ptr.type)==0) {
PyErr_SetString( PyExc_TypeError, "bpy_struct: this type doesnt support IDProperties");
return -1;
}
- group= RNA_struct_idproperties(&self->ptr, 0);
+ group= RNA_struct_idprops(&self->ptr, 0);
if(!group)
return 0;
@@ -1674,7 +1722,7 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key )
IDProperty *group, *idprop;
char *name= _PyUnicode_AsString(key);
- if(RNA_struct_idproperties_check(self->ptr.type)==0) {
+ if(RNA_struct_idprops_check(self->ptr.type)==0) {
PyErr_SetString( PyExc_TypeError, "this type doesn't support IDProperties");
return NULL;
}
@@ -1684,7 +1732,7 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key )
return NULL;
}
- group= RNA_struct_idproperties(&self->ptr, 0);
+ group= RNA_struct_idprops(&self->ptr, 0);
if(group==NULL) {
PyErr_Format( PyExc_KeyError, "bpy_struct[key]: key \"%s\" not found", name);
@@ -1703,7 +1751,7 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key )
static int pyrna_struct_ass_subscript( BPy_StructRNA *self, PyObject *key, PyObject *value )
{
- IDProperty *group= RNA_struct_idproperties(&self->ptr, 1);
+ IDProperty *group= RNA_struct_idprops(&self->ptr, 1);
if(group==NULL) {
PyErr_SetString(PyExc_TypeError, "bpy_struct[key] = val: id properties not supported for this type");
@@ -1733,12 +1781,12 @@ static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self)
{
IDProperty *group;
- if(RNA_struct_idproperties_check(self->ptr.type)==0) {
+ if(RNA_struct_idprops_check(self->ptr.type)==0) {
PyErr_SetString( PyExc_TypeError, "bpy_struct.keys(): this type doesn't support IDProperties");
return NULL;
}
- group= RNA_struct_idproperties(&self->ptr, 0);
+ group= RNA_struct_idprops(&self->ptr, 0);
if(group==NULL)
return PyList_New(0);
@@ -1760,12 +1808,12 @@ static PyObject *pyrna_struct_items(BPy_PropertyRNA *self)
{
IDProperty *group;
- if(RNA_struct_idproperties_check(self->ptr.type)==0) {
+ if(RNA_struct_idprops_check(self->ptr.type)==0) {
PyErr_SetString( PyExc_TypeError, "bpy_struct.items(): this type doesn't support IDProperties");
return NULL;
}
- group= RNA_struct_idproperties(&self->ptr, 0);
+ group= RNA_struct_idprops(&self->ptr, 0);
if(group==NULL)
return PyList_New(0);
@@ -1787,12 +1835,12 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self)
{
IDProperty *group;
- if(RNA_struct_idproperties_check(self->ptr.type)==0) {
+ if(RNA_struct_idprops_check(self->ptr.type)==0) {
PyErr_SetString( PyExc_TypeError, "bpy_struct.values(): this type doesn't support IDProperties");
return NULL;
}
- group= RNA_struct_idproperties(&self->ptr, 0);
+ group= RNA_struct_idprops(&self->ptr, 0);
if(group==NULL)
return PyList_New(0);
@@ -2039,12 +2087,34 @@ static char pyrna_struct_is_property_set_doc[] =
static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *args)
{
+ PropertyRNA *prop;
char *name;
+ int ret;
if (!PyArg_ParseTuple(args, "s:is_property_set", &name))
return NULL;
- return PyBool_FromLong(RNA_property_is_set(&self->ptr, name));
+ if((prop= RNA_struct_find_property(&self->ptr, name)) == NULL) {
+ PyErr_Format(PyExc_TypeError, "%.200s.is_property_set(\"%.200s\") not found", RNA_struct_identifier(self->ptr.type), name);
+ return NULL;
+ }
+
+ /* double property lookup, could speed up */
+ /* return PyBool_FromLong(RNA_property_is_set(&self->ptr, name)); */
+ if(RNA_property_flag(prop) & PROP_IDPROPERTY) {
+ IDProperty *group= RNA_struct_idprops(&self->ptr, 0);
+ if(group) {
+ ret= IDP_GetPropertyFromGroup(group, name) ? 1:0;
+ }
+ else {
+ ret= 0;
+ }
+ }
+ else {
+ ret= 1;
+ }
+
+ return PyBool_FromLong(ret);
}
static char pyrna_struct_is_property_hidden_doc[] =
@@ -2059,15 +2129,16 @@ static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject *
{
PropertyRNA *prop;
char *name;
- int hidden;
if (!PyArg_ParseTuple(args, "s:is_property_hidden", &name))
return NULL;
-
- prop= RNA_struct_find_property(&self->ptr, name);
- hidden= (prop)? (RNA_property_flag(prop) & PROP_HIDDEN): 1;
- return PyBool_FromLong(hidden);
+ if((prop= RNA_struct_find_property(&self->ptr, name)) == NULL) {
+ PyErr_Format(PyExc_TypeError, "%.200s.is_property_hidden(\"%.200s\") not found", RNA_struct_identifier(self->ptr.type), name);
+ return NULL;
+ }
+
+ return PyBool_FromLong(RNA_property_flag(prop) & PROP_HIDDEN);
}
static char pyrna_struct_path_resolve_doc[] =
@@ -2289,7 +2360,7 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname )
if(name[0]=='_') { // rna can't start with a "_", so for __dict__ and similar we can skip using rna lookups
/* annoying exception, maybe we need to have different types for this... */
- if((strcmp(name, "__getitem__")==0 || strcmp(name, "__setitem__")==0) && !RNA_struct_idproperties_check(self->ptr.type)) {
+ if((strcmp(name, "__getitem__")==0 || strcmp(name, "__setitem__")==0) && !RNA_struct_idprops_check(self->ptr.type)) {
PyErr_SetString(PyExc_AttributeError, "bpy_struct: no __getitem__ support for this type");
ret = NULL;
}
@@ -2684,12 +2755,12 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
return NULL;
/* mostly copied from BPy_IDGroup_Map_GetItem */
- if(RNA_struct_idproperties_check(self->ptr.type)==0) {
+ if(RNA_struct_idprops_check(self->ptr.type)==0) {
PyErr_SetString( PyExc_TypeError, "this type doesn't support IDProperties");
return NULL;
}
- group= RNA_struct_idproperties(&self->ptr, 0);
+ group= RNA_struct_idprops(&self->ptr, 0);
if(group) {
idprop= IDP_GetPropertyFromGroup(group, key);
@@ -3060,8 +3131,6 @@ static struct PyMethodDef pyrna_prop_methods[] = {
};
static struct PyMethodDef pyrna_prop_array_methods[] = {
- {"foreach_get", (PyCFunction)pyrna_prop_foreach_get, METH_VARARGS, NULL},
- {"foreach_set", (PyCFunction)pyrna_prop_foreach_set, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
@@ -3086,37 +3155,47 @@ static struct PyMethodDef pyrna_prop_collection_methods[] = {
* todo - also accept useful args */
static PyObject * pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
- BPy_StructRNA *base = NULL;
+ BPy_StructRNA *base;
if (!PyArg_ParseTuple(args, "O!:bpy_struct.__new__", &pyrna_struct_Type, &base))
return NULL;
-
- if (type == &pyrna_struct_Type) {
- return pyrna_struct_CreatePyObject(&base->ptr);
- } else {
+
+ if (type == Py_TYPE(base)) {
+ Py_INCREF(base);
+ return (PyObject *)base;
+ } else if (PyType_IsSubtype(type, &pyrna_struct_Type)) {
BPy_StructRNA *ret = (BPy_StructRNA *) type->tp_alloc(type, 0);
ret->ptr = base->ptr;
return (PyObject *)ret;
}
+ else {
+ PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): type '%.200s' is not a subtype of bpy_struct.", type->tp_name);
+ return NULL;
+ }
}
/* only needed for subtyping, so a new class gets a valid BPy_StructRNA
* todo - also accept useful args */
static PyObject * pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
- BPy_PropertyRNA *base = NULL;
+ BPy_PropertyRNA *base;
- if (!PyArg_ParseTuple(args, "O!:Base BPy_PropertyRNA", &pyrna_prop_Type, &base))
+ if (!PyArg_ParseTuple(args, "O!:bpy_prop.__new__", &pyrna_prop_Type, &base))
return NULL;
- if (ELEM3(type, &pyrna_prop_Type, &pyrna_prop_array_Type, &pyrna_prop_collection_Type)) {
- return pyrna_prop_CreatePyObject(&base->ptr, base->prop);
- } else {
+ if (type == Py_TYPE(base)) {
+ Py_INCREF(base);
+ return (PyObject *)base;
+ } else if (PyType_IsSubtype(type, &pyrna_prop_Type)) {
BPy_PropertyRNA *ret = (BPy_PropertyRNA *) type->tp_alloc(type, 0);
ret->ptr = base->ptr;
ret->prop = base->prop;
return (PyObject *)ret;
}
+ else {
+ PyErr_Format(PyExc_TypeError, "bpy_prop.__new__(type): type '%.200s' is not a subtype of bpy_prop.", type->tp_name);
+ return NULL;
+ }
}
PyObject *pyrna_param_to_py(PointerRNA *ptr, ParameterList *parms, PropertyRNA *prop, void *data)
@@ -3520,7 +3599,7 @@ PyTypeObject pyrna_struct_Type = {
( hashfunc )pyrna_struct_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
- NULL, /* reprfunc tp_str; */
+ (reprfunc) pyrna_struct_str, /* reprfunc tp_str; */
( getattrofunc ) pyrna_struct_getattro, /* getattrofunc tp_getattro; */
( setattrofunc ) pyrna_struct_setattro, /* setattrofunc tp_setattro; */
@@ -3587,7 +3666,7 @@ PyTypeObject pyrna_prop_Type = {
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
- ( reprfunc ) pyrna_prop_repr, /* tp_repr */
+ (reprfunc) pyrna_prop_repr, /* tp_repr */
/* Method suites for standard classes */
@@ -3599,7 +3678,7 @@ PyTypeObject pyrna_prop_Type = {
( hashfunc ) pyrna_prop_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
- NULL, /* reprfunc tp_str; */
+ (reprfunc) pyrna_prop_str, /* reprfunc tp_str; */
/* will only use these if this is a subtype of a py class */
NULL, /* getattrofunc tp_getattro; */
@@ -3970,7 +4049,7 @@ static PyObject* pyrna_srna_Subtype(StructRNA *srna)
- myClass = type(name='myClass', bases=(myBase,), dict={'__module__':'bpy.types'})
*/
- /* Assume RNA_struct_py_type_get(srna) was alredy checked */
+ /* Assume RNA_struct_py_type_get(srna) was already checked */
PyObject *py_base= pyrna_srna_PyBase(srna);
const char *idname= RNA_struct_identifier(srna);
@@ -4163,6 +4242,9 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA *self, PyObject *pynam
}
static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self);
+static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class);
+static PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class);
+
static struct PyMethodDef pyrna_basetype_methods[] = {
{"__dir__", (PyCFunction)pyrna_basetype_dir, METH_NOARGS, ""},
{"register", (PyCFunction)pyrna_basetype_register, METH_O, ""},
@@ -4232,18 +4314,18 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr
}
if(py_srna==NULL) {
- PyErr_Format(PyExc_SystemError, "%.200s internal error, self of type '%.200s' had no bl_rna attribute, should never happen", error_prefix, Py_TYPE(self)->tp_name);
+ PyErr_Format(PyExc_SystemError, "%.200s, missing bl_rna attribute from '%.200s' instance (may not be registered)", error_prefix, Py_TYPE(self)->tp_name);
return NULL;
}
if(!BPy_StructRNA_Check(py_srna)) {
- PyErr_Format(PyExc_SystemError, "%.200s internal error, bl_rna was of type '%.200s', instead of %.200s instance", error_prefix, Py_TYPE(py_srna)->tp_name, pyrna_struct_Type.tp_name);
+ PyErr_Format(PyExc_SystemError, "%.200s, bl_rna attribute wrong type '%.200s' on '%.200s'' instance", error_prefix, Py_TYPE(py_srna)->tp_name, Py_TYPE(self)->tp_name);
Py_DECREF(py_srna);
return NULL;
}
if(py_srna->ptr.type != &RNA_Struct) {
- PyErr_Format(PyExc_SystemError, "%.200s internal error, bl_rna was not a RNA_Struct type of rna struct", error_prefix);
+ PyErr_Format(PyExc_SystemError, "%.200s, bl_rna attribute not a RNA_Struct, on '%.200s'' instance", error_prefix, Py_TYPE(self)->tp_name);
Py_DECREF(py_srna);
return NULL;
}
@@ -4291,7 +4373,6 @@ static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key
if(*_PyUnicode_AsString(key)=='_') {
PyErr_Format(PyExc_ValueError, "bpy_struct \"%.200s\" registration error: %.200s could not register because the property starts with an '_'\n", RNA_struct_identifier(srna), _PyUnicode_AsString(key));
- Py_DECREF(dummy_args);
return -1;
}
pyfunc = PyCapsule_GetPointer(py_func_ptr, NULL);
@@ -4312,8 +4393,6 @@ static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key
// PyLineSpit();
PyErr_Format(PyExc_ValueError, "bpy_struct \"%.200s\" registration error: %.200s could not register\n", RNA_struct_identifier(srna), _PyUnicode_AsString(key));
-
- Py_DECREF(dummy_args);
return -1;
}
}
@@ -4330,7 +4409,7 @@ static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key
return 0;
}
-int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict)
+static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict)
{
PyObject *item, *key;
PyObject *order;
@@ -4340,12 +4419,10 @@ int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict)
dummy_args = PyTuple_New(0);
- order= PyDict_GetItemString(class_dict, "order");
-
- if(order==NULL)
- PyErr_Clear();
-
- if(order && PyList_Check(order)) {
+ if( !PyDict_CheckExact(class_dict) &&
+ (order= PyDict_GetItemString(class_dict, "order")) &&
+ PyList_CheckExact(order)
+ ) {
for(pos= 0; pos<PyList_GET_SIZE(order); pos++) {
key= PyList_GET_ITEM(order, pos);
item= PyDict_GetItem(class_dict, key);
@@ -4368,6 +4445,49 @@ int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict)
return 0;
}
+static int pyrna_deferred_register_class_recursive(StructRNA *srna, PyTypeObject *py_class)
+{
+ const int len= PyTuple_GET_SIZE(py_class->tp_bases);
+ int i, ret;
+
+ /* first scan base classes for registerable properties */
+ for(i=0; i<len; i++) {
+ PyTypeObject *py_superclass= (PyTypeObject *)PyTuple_GET_ITEM(py_class->tp_bases, i);
+
+ /* the rules for using these base classes are not clear,
+ * 'object' is ofcourse not worth looking into and
+ * existing subclasses of RNA would cause a lot more dictionary
+ * looping then is needed (SomeOperator would scan Operator.__dict__)
+ * which is harmless but not at all useful.
+ *
+ * So only scan base classes which are not subclasses if blender types.
+ * This best fits having 'mix-in' classes for operators and render engines.
+ * */
+ if( py_superclass != &PyBaseObject_Type &&
+ !PyObject_IsSubclass((PyObject *)py_superclass, (PyObject *)&pyrna_struct_Type)
+ ) {
+ ret= pyrna_deferred_register_class_recursive(srna, py_superclass);
+
+ if(ret != 0) {
+ return ret;
+ }
+ }
+ }
+
+ /* not register out own properties */
+ return pyrna_deferred_register_props(srna, py_class->tp_dict); /* getattr(..., "__dict__") returns a proxy */
+}
+
+int pyrna_deferred_register_class(StructRNA *srna, PyObject *py_class)
+{
+ /* Panels and Menus dont need this
+ * save some time and skip the checks here */
+ if(!RNA_struct_idprops_register_check(srna))
+ return 0;
+
+ return pyrna_deferred_register_class_recursive(srna, (PyTypeObject *)py_class);
+}
+
/*-------------------- Type Registration ------------------------*/
static int rna_function_arg_count(FunctionRNA *func)
@@ -4375,7 +4495,7 @@ static int rna_function_arg_count(FunctionRNA *func)
const ListBase *lb= RNA_function_defined_parameters(func);
PropertyRNA *parm;
Link *link;
- int count= 1;
+ int count= (RNA_function_flag(func) & FUNC_NO_SELF) ? 0 : 1;
for(link=lb->first; link; link=link->next) {
parm= (PropertyRNA*)link;
@@ -4396,7 +4516,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
const char *class_type= RNA_struct_identifier(srna);
PyObject *py_class= (PyObject*)py_data;
PyObject *base_class= RNA_struct_py_type_get(srna);
- PyObject *item, *fitem;
+ PyObject *item;
PyObject *py_arg_count;
int i, flag, arg_count, func_arg_count;
const char *py_class_name = ((PyTypeObject *)py_class)->tp_name; // __name__
@@ -4433,25 +4553,33 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
PyErr_Clear();
}
else {
- Py_DECREF(item); /* no need to keep a ref, the class owns it */
-
- if (PyMethod_Check(item))
- fitem= PyMethod_Function(item); /* py 2.x */
- else
- fitem= item; /* py 3.x */
-
- if (PyFunction_Check(fitem)==0) {
- PyErr_Format( PyExc_TypeError, "expected %.200s, %.200s class \"%.200s\" attribute to be a function", class_type, py_class_name, RNA_function_identifier(func));
- return -1;
+ Py_DECREF(item); /* no need to keep a ref, the class owns it (technically we should keep a ref but...) */
+ if(flag & FUNC_NO_SELF) {
+ if (PyMethod_Check(item)==0) {
+ PyErr_Format( PyExc_TypeError, "expected %.200s, %.200s class \"%.200s\" attribute to be a method, not a %.200s", class_type, py_class_name, RNA_function_identifier(func), Py_TYPE(item)->tp_name);
+ return -1;
+ }
+ item= ((PyMethodObject *)item)->im_func;
+ }
+ else {
+ if (PyFunction_Check(item)==0) {
+ PyErr_Format( PyExc_TypeError, "expected %.200s, %.200s class \"%.200s\" attribute to be a function, not a %.200s", class_type, py_class_name, RNA_function_identifier(func), Py_TYPE(item)->tp_name);
+ return -1;
+ }
}
func_arg_count= rna_function_arg_count(func);
if (func_arg_count >= 0) { /* -1 if we dont care*/
- py_arg_count = PyObject_GetAttrString(PyFunction_GET_CODE(fitem), "co_argcount");
+ py_arg_count = PyObject_GetAttrString(PyFunction_GET_CODE(item), "co_argcount");
arg_count = PyLong_AsSsize_t(py_arg_count);
Py_DECREF(py_arg_count);
+ /* note, the number of args we check for and the number of args we give to
+ * @classmethods are different (quirk of python), this is why rna_function_arg_count() doesn't return the value -1*/
+ if(flag & FUNC_NO_SELF)
+ func_arg_count++;
+
if (arg_count != func_arg_count) {
PyErr_Format( PyExc_AttributeError, "expected %.200s, %.200s class \"%.200s\" function to have %d args, found %d", class_type, py_class_name, RNA_function_identifier(func), func_arg_count, arg_count);
return -1;
@@ -4524,6 +4652,7 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
ParameterIterator iter;
PointerRNA funcptr;
int err= 0, i, flag, ret_len=0;
+ int is_static = RNA_function_flag(func) & FUNC_NO_SELF;
PropertyRNA *pret_single= NULL;
void *retdata_single= NULL;
@@ -4531,52 +4660,64 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
PyGILState_STATE gilstate;
bContext *C= BPy_GetContext(); // XXX - NEEDS FIXING, QUITE BAD.
+
+ py_class= RNA_struct_py_type_get(ptr->type);
+
+ /* rare case. can happen when registering subclasses */
+ if(py_class==NULL) {
+ fprintf(stderr, "bpy_class_call(): unable to get python class for rna struct '%.200s'\n", RNA_struct_identifier(ptr->type));
+ return -1;
+ }
+
bpy_context_set(C, &gilstate);
- py_class= RNA_struct_py_type_get(ptr->type);
+ if (!is_static) {
+ /* exception, operators store their PyObjects for re-use */
+ if(ptr->data) {
+ if(RNA_struct_is_a(ptr->type, &RNA_Operator)) {
+ wmOperator *op= ptr->data;
+ if(op->py_instance) {
+ py_class_instance= op->py_instance;
+ Py_INCREF(py_class_instance);
+ }
+ else {
+ /* store the instance here once its created */
+ py_class_instance_store= &op->py_instance;
+ }
+ }
+ }
+ /* end exception */
- /* exception, operators store their PyObjects for re-use */
- if(ptr->data) {
- if(RNA_struct_is_a(ptr->type, &RNA_Operator)) {
- wmOperator *op= ptr->data;
- if(op->py_instance) {
- py_class_instance= op->py_instance;
- Py_INCREF(py_class_instance);
+ if(py_class_instance==NULL)
+ py_srna= pyrna_struct_CreatePyObject(ptr);
+
+ if(py_class_instance) {
+ /* special case, instance is cached */
+ }
+ else if(py_srna == NULL) {
+ py_class_instance = NULL;
+ }
+ else if(py_srna == Py_None) { /* probably wont ever happen but possible */
+ Py_DECREF(py_srna);
+ py_class_instance = NULL;
+ }
+ else {
+ args = PyTuple_New(1);
+ PyTuple_SET_ITEM(args, 0, py_srna);
+ py_class_instance= PyObject_Call(py_class, args, NULL);
+ Py_DECREF(args);
+
+ if(py_class_instance == NULL) {
+ err= -1; /* so the error is not overridden below */
}
- else {
- /* store the instance here once its created */
- py_class_instance_store= &op->py_instance;
+ else if(py_class_instance_store) {
+ *py_class_instance_store = py_class_instance;
+ Py_INCREF(py_class_instance);
}
}
}
- /* end exception */
-
- if(py_class_instance==NULL)
- py_srna= pyrna_struct_CreatePyObject(ptr);
-
- if(py_class_instance) {
- /* special case, instance is cached */
- }
- else if(py_srna == NULL) {
- py_class_instance = NULL;
- }
- else if(py_srna == Py_None) { /* probably wont ever happen but possible */
- Py_DECREF(py_srna);
- py_class_instance = NULL;
- }
- else {
- args = PyTuple_New(1);
- PyTuple_SET_ITEM(args, 0, py_srna);
- py_class_instance = PyObject_Call(py_class, args, NULL);
- Py_DECREF(args);
-
- if(py_class_instance_store) {
- *py_class_instance_store = py_class_instance;
- Py_INCREF(py_class_instance);
- }
- }
- if (py_class_instance) { /* Initializing the class worked, now run its invoke function */
+ if (is_static || py_class_instance) { /* Initializing the class worked, now run its invoke function */
PyObject *item= PyObject_GetAttrString(py_class, RNA_function_identifier(func));
// flag= RNA_function_flag(func);
@@ -4584,12 +4725,19 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
args = PyTuple_New(rna_function_arg_count(func)); /* first arg is included in 'item' */
- PyTuple_SET_ITEM(args, 0, py_class_instance);
+
+ if(is_static) {
+ i= 0;
+ }
+ else {
+ PyTuple_SET_ITEM(args, 0, py_class_instance);
+ i= 1;
+ }
RNA_parameter_list_begin(parms, &iter);
/* parse function parameters */
- for (i= 1; iter.valid; RNA_parameter_list_next(&iter)) {
+ for (; iter.valid; RNA_parameter_list_next(&iter)) {
parm= iter.parm;
flag= RNA_property_flag(parm);
@@ -4623,8 +4771,11 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
}
}
else {
- PyErr_Format(PyExc_RuntimeError, "could not create instance of %.200s to call callback function %.200s.", RNA_struct_identifier(ptr->type), RNA_function_identifier(func));
- err= -1;
+ /* the error may be alredy set if the class instance couldnt be created */
+ if(err != -1) {
+ PyErr_Format(PyExc_RuntimeError, "could not create instance of %.200s to call callback function %.200s.", RNA_struct_identifier(ptr->type), RNA_function_identifier(func));
+ err= -1;
+ }
}
if (ret == NULL) { /* covers py_class_instance failing too */
@@ -4717,7 +4868,16 @@ void pyrna_alloc_types(void)
prop = RNA_struct_find_property(&ptr, "structs");
RNA_PROP_BEGIN(&ptr, itemptr, prop) {
- Py_DECREF(pyrna_struct_Subtype(&itemptr));
+ PyObject *item= pyrna_struct_Subtype(&itemptr);
+ if(item == NULL) {
+ if(PyErr_Occurred()) {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+ }
+ else {
+ Py_DECREF(item);
+ }
}
RNA_PROP_END;
@@ -4760,15 +4920,14 @@ void pyrna_free_types(void)
* - Should still be fixed - Campbell
* */
-PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
+static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
{
bContext *C= NULL;
ReportList reports;
StructRegisterFunc reg;
StructRNA *srna;
StructRNA *srna_new;
- PyObject *item;
- const char *identifier= "";
+ const char *identifier;
if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")) {
PyErr_SetString(PyExc_AttributeError, "bpy.types.register(...): already registered as a subclass.");
@@ -4780,11 +4939,19 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
if(srna==NULL)
return NULL;
+ /* fails in cases, cant use this check but would like to :| */
+ /*
+ if(RNA_struct_py_type_get(srna)) {
+ PyErr_Format(PyExc_ValueError, "bpy.types.register(...): %.200s's parent class %.200s is alredy registered, this is not allowed.", ((PyTypeObject*)py_class)->tp_name, RNA_struct_identifier(srna));
+ return NULL;
+ }
+ */
+
/* check that we have a register callback for this type */
reg= RNA_struct_register(srna);
if(!reg) {
- PyErr_SetString(PyExc_ValueError, "bpy.types.register(...): expected a Type subclassed from a registerable rna type (no register supported).");
+ PyErr_Format(PyExc_ValueError, "bpy.types.register(...): expected a subclass of a registerable rna type (%.200s does not support registration).", RNA_struct_identifier(srna));
return NULL;
}
@@ -4794,12 +4961,7 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
/* call the register callback with reports & identifier */
BKE_reports_init(&reports, RPT_STORE);
- item= PyObject_GetAttrString(py_class, "__name__");
-
- if(item) {
- identifier= _PyUnicode_AsString(item);
- Py_DECREF(item); /* no need to keep a ref, the class owns it */
- }
+ identifier= ((PyTypeObject*)py_class)->tp_name;
srna_new= reg(C, &reports, py_class, identifier, bpy_class_validate, bpy_class_call, bpy_class_free);
@@ -4823,27 +4985,47 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
*
* item= PyObject_GetAttrString(py_class, "__dict__");
*/
- item= ((PyTypeObject*)py_class)->tp_dict;
- if(item) {
- if(pyrna_deferred_register_props(srna_new, item)!=0) {
- return NULL;
- }
- }
- else {
- PyErr_Clear();
- }
+ if(pyrna_deferred_register_class(srna_new, py_class)!=0)
+ return NULL;
Py_RETURN_NONE;
}
-PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class)
+
+static int pyrna_srna_contains_pointer_prop_srna(StructRNA *srna_props, StructRNA *srna, const char **prop_identifier)
+{
+ PointerRNA tptr;
+ PropertyRNA *iterprop;
+ RNA_pointer_create(NULL, &RNA_Struct, srna_props, &tptr);
+
+ iterprop= RNA_struct_find_property(&tptr, "properties");
+
+ RNA_PROP_BEGIN(&tptr, itemptr, iterprop) {
+ PropertyRNA *prop= itemptr.data;
+ if(RNA_property_type(prop) == PROP_POINTER) {
+ if (strcmp(RNA_property_identifier(prop), "rna_type") == 0) {
+ /* pass */
+ }
+ else if(RNA_property_pointer_type(&tptr, prop) == srna) {
+ *prop_identifier= RNA_property_identifier(prop);
+ return 1;
+ }
+ }
+ }
+ RNA_PROP_END;
+
+ return 0;
+}
+
+static PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class)
{
bContext *C= NULL;
StructUnregisterFunc unreg;
StructRNA *srna;
/*if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")==NULL) {
- PyErr_SetString(PyExc_ValueError, "bpy.types.unregister(): not a registered as a subclass.");
+ PWM_cursor_wait(0);
+yErr_SetString(PyExc_ValueError, "bpy.types.unregister(): not a registered as a subclass.");
return NULL;
}*/
@@ -4859,6 +5041,34 @@ PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class)
return NULL;
}
+ /* should happen all the time but very slow */
+ if(G.f & G_DEBUG) {
+ /* remove all properties using this class */
+ StructRNA *srna_iter;
+ PointerRNA ptr_rna;
+ PropertyRNA *prop_rna;
+ const char *prop_identifier= NULL;
+
+ RNA_blender_rna_pointer_create(&ptr_rna);
+ prop_rna = RNA_struct_find_property(&ptr_rna, "structs");
+
+
+
+ /* loop over all structs */
+ RNA_PROP_BEGIN(&ptr_rna, itemptr, prop_rna) {
+ srna_iter = itemptr.data;
+ if(pyrna_srna_contains_pointer_prop_srna(srna_iter, srna, &prop_identifier)) {
+ break;
+ }
+ }
+ RNA_PROP_END;
+
+ if(prop_identifier) {
+ PyErr_Format(PyExc_SystemError, "bpy.types.unregister(...): Cant unregister %s because %s.%s pointer property is using this.", RNA_struct_identifier(srna), RNA_struct_identifier(srna_iter), prop_identifier);
+ return NULL;
+ }
+ }
+
/* get the context, so register callback can do necessary refreshes */
C= BPy_GetContext();
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 9892ed6989b..63f6997d82c 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -86,11 +86,7 @@ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_
int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix);
-/* function for registering types */
-PyObject *pyrna_basetype_register(PyObject *self, PyObject *args);
-PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *args);
-
-int pyrna_deferred_register_props(struct StructRNA *srna, PyObject *class_dict);
+int pyrna_deferred_register_class(struct StructRNA *srna, PyObject *py_class);
/* called before stopping python */
void pyrna_alloc_types(void);
diff --git a/source/blender/python/intern/bpy_rna_callback.c b/source/blender/python/intern/bpy_rna_callback.c
index 2404442dc18..b2a7511f998 100644
--- a/source/blender/python/intern/bpy_rna_callback.c
+++ b/source/blender/python/intern/bpy_rna_callback.c
@@ -64,19 +64,28 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args)
char *cb_event_str= NULL;
int cb_event;
- if (!PyArg_ParseTuple(args, "OO|s:bpy_struct.callback_add", &cb_func, &cb_args, &cb_event_str))
+ if (!PyArg_ParseTuple(args, "OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str))
return NULL;
+
+ if(!PyCallable_Check(cb_func)) {
+ PyErr_SetString(PyExc_TypeError, "callback_add(): first argument isn't callable");
+ return NULL;
+ }
if(RNA_struct_is_a(self->ptr.type, &RNA_Region)) {
-
- static EnumPropertyItem region_draw_mode_items[] = {
- {REGION_DRAW_POST_VIEW, "POST_VIEW", 0, "Pose View", ""},
- {REGION_DRAW_POST_PIXEL, "POST_PIXEL", 0, "Post Pixel", ""},
- {REGION_DRAW_PRE_VIEW, "PRE_VIEW", 0, "Pre View", ""},
- {0, NULL, 0, NULL, NULL}};
-
- if(pyrna_enum_value_from_id(region_draw_mode_items, cb_event_str, &cb_event, "bpy_struct.callback_add()") < 0)
- return NULL;
+ if(cb_event_str) {
+ static EnumPropertyItem region_draw_mode_items[] = {
+ {REGION_DRAW_POST_PIXEL, "POST_PIXEL", 0, "Post Pixel", ""},
+ {REGION_DRAW_POST_VIEW, "POST_VIEW", 0, "Post View", ""},
+ {REGION_DRAW_PRE_VIEW, "PRE_VIEW", 0, "Pre View", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+ if(pyrna_enum_value_from_id(region_draw_mode_items, cb_event_str, &cb_event, "bpy_struct.callback_add()") < 0)
+ return NULL;
+ }
+ else {
+ cb_event= REGION_DRAW_POST_PIXEL;
+ }
handle= ED_region_draw_cb_activate(((ARegion *)self->ptr.data)->type, cb_region_draw, (void *)args, cb_event);
Py_INCREF(args);
diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c
index 38462d1b176..1d14ab67510 100644
--- a/source/blender/python/intern/bpy_util.c
+++ b/source/blender/python/intern/bpy_util.c
@@ -54,7 +54,7 @@ void PyObSpit(char *name, PyObject *var) {
}
void PyLineSpit(void) {
- char *filename;
+ const char *filename;
int lineno;
PyErr_Clear();
@@ -63,7 +63,7 @@ void PyLineSpit(void) {
fprintf(stderr, "%s:%d\n", filename, lineno);
}
-void BPY_getFileAndNum(char **filename, int *lineno)
+void BPY_getFileAndNum(const char **filename, int *lineno)
{
PyObject *getframe, *frame;
PyObject *f_lineno= NULL, *co_filename= NULL;
@@ -83,6 +83,7 @@ void BPY_getFileAndNum(char **filename, int *lineno)
return;
}
+ /* when executing a script */
if (filename) {
co_filename= PyObject_GetAttrStringArgs(frame, 1, "f_code", "co_filename");
if (co_filename==NULL) {
@@ -95,6 +96,25 @@ void BPY_getFileAndNum(char **filename, int *lineno)
Py_DECREF(co_filename);
}
+ /* when executing a module */
+ if(filename && *filename == NULL) {
+ /* try an alternative method to get the filename - module based
+ * references below are all borrowed (double checked) */
+ PyObject *mod_name= PyDict_GetItemString(PyEval_GetGlobals(), "__name__");
+ if(mod_name) {
+ PyObject *mod= PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
+ if(mod) {
+ *filename= PyModule_GetFilename(mod);
+ }
+
+ /* unlikely, fallback */
+ if(*filename == NULL) {
+ *filename= _PyUnicode_AsString(mod_name);
+ }
+ }
+ }
+
+
if (lineno) {
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
if (f_lineno==NULL) {
@@ -330,7 +350,7 @@ int BPy_errors_to_report(ReportList *reports)
PyObject *pystring_format= NULL; // workaround, see below
char *cstring;
- char *filename;
+ const char *filename;
int lineno;
if (!PyErr_Occurred())
diff --git a/source/blender/python/intern/bpy_util.h b/source/blender/python/intern/bpy_util.h
index e7e7bb09419..cfe820b53b0 100644
--- a/source/blender/python/intern/bpy_util.h
+++ b/source/blender/python/intern/bpy_util.h
@@ -38,7 +38,7 @@ struct ReportList;
void PyObSpit(char *name, PyObject *var);
void PyLineSpit(void);
-void BPY_getFileAndNum(char **filename, int *lineno);
+void BPY_getFileAndNum(const char **filename, int *lineno);
PyObject *BPY_exception_buffer(void);