diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-11-02 20:17:05 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-11-02 20:17:05 +0400 |
commit | 2f453773f6b4cd0a03f5e2d9876ee250b87871f0 (patch) | |
tree | 08c4bb2c1c3ee3fe5131e46a4e39b9224ba5c251 /source/blender/python | |
parent | 02fae3440c8b4b89aa0f9412bc4e0db60a787c13 (diff) | |
parent | e1594ebb3c52f573a8a6c90f3d30acfb3de6e8a5 (diff) |
Cycles: svn merge -r41266:41467 ^/trunk/blender
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/BPY_extern.h | 18 | ||||
-rw-r--r-- | source/blender/python/generic/IDProp.c | 18 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 2 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.h | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy.c | 67 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_library.c | 5 | ||||
-rw-r--r-- | source/blender/python/intern/gpu.c | 2 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_Quaternion.c | 96 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_geometry.c | 12 | ||||
-rw-r--r-- | source/blender/python/simple_enum_gen.py | 6 |
10 files changed, 139 insertions, 89 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index c43a2520bb8..d8ddcd593a8 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -20,7 +20,10 @@ * * The Original Code was in: source/blender/bpython/include/BPY_extern.h * - * Contributor(s): Michel Selten, Willian P. Germano, Chris Keith + * Contributor(s): Michel Selten, + * Willian P. Germano, + * Chris Keith, + * Campbell Barton * * ***** END GPL LICENSE BLOCK ***** */ @@ -39,14 +42,10 @@ struct ID; /* DNA_ID.h */ struct Object; /* DNA_object_types.h */ struct ChannelDriver; /* DNA_anim_types.h */ struct ListBase; /* DNA_listBase.h */ -struct SpaceText; /* DNA_space_types.h */ -struct ScrArea; /* DNA_screen_types.h */ -struct bScreen; /* DNA_screen_types.h */ struct bConstraint; /* DNA_constraint_types.h */ struct bPythonConstraint; /* DNA_constraint_types.h */ struct bConstraintOb; /* DNA_constraint_types.h */ struct bConstraintTarget; /* DNA_constraint_types.h*/ -struct BPyMenu; struct bContext; struct bContextDataResult; struct ReportList; @@ -61,16 +60,9 @@ void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTa void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con); int BPY_is_pyconstraint(struct Text *text); // void BPY_free_pyconstraint_links(struct Text *text); -// + void BPY_python_start(int argc, const char **argv); void BPY_python_end(void); -// void init_syspath(int first_time); -// void syspath_append(char *dir); -// void BPY_rebuild_syspath(void); -// int BPY_path_update(void); -// -// int BPY_Err_getLinenumber(void); -// const char *BPY_Err_getFilename(void); /* 2.5 UI Scripts */ int BPY_filepath_exec(struct bContext *C, const char *filepath, struct ReportList *reports); diff --git a/source/blender/python/generic/IDProp.c b/source/blender/python/generic/IDProp.c index 7aa5ed61203..076b4811d07 100644 --- a/source/blender/python/generic/IDProp.c +++ b/source/blender/python/generic/IDProp.c @@ -65,9 +65,9 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop ) switch ( prop->type ) { case IDP_STRING: #ifdef USE_STRING_COERCE - return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len); + return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1); #else - return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len); + return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len - 1); #endif case IDP_INT: return PyLong_FromLong( (long)prop->data.val ); @@ -483,9 +483,9 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop) switch (prop->type) { case IDP_STRING: #ifdef USE_STRING_COERCE - return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len); + return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1); #else - return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len); + return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len - 1); #endif break; case IDP_FLOAT: @@ -625,11 +625,11 @@ static PyObject *BPy_IDGroup_IterItems(BPy_IDProperty *self) } /* utility function */ -static void BPy_IDGroup_CorrectListLen(IDProperty *prop, PyObject *seq, int len) +static void BPy_IDGroup_CorrectListLen(IDProperty *prop, PyObject *seq, int len, const char *func) { int j; - printf("ID Property Error found and corrected in BPy_IDGroup_GetKeys/Values/Items!\n"); + printf("%s: ID Property Error found and corrected!\n", func); /*fill rest of list with valid references to None*/ for (j=len; j<prop->len; j++) { @@ -654,7 +654,7 @@ PyObject *BPy_Wrap_GetKeys(IDProperty *prop) for (; loop; loop=loop->next, i++) {} if (i != prop->len) { /* if the loop didnt finish, we know the length is wrong */ - BPy_IDGroup_CorrectListLen(prop, seq, i); + BPy_IDGroup_CorrectListLen(prop, seq, i, __func__); Py_DECREF(seq); /*free the list*/ /*call self again*/ return BPy_Wrap_GetKeys(prop); @@ -674,7 +674,7 @@ PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop) } if (i != prop->len) { - BPy_IDGroup_CorrectListLen(prop, seq, i); + BPy_IDGroup_CorrectListLen(prop, seq, i, __func__); Py_DECREF(seq); /*free the list*/ /*call self again*/ return BPy_Wrap_GetValues(id, prop); @@ -697,7 +697,7 @@ PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop) } if (i != prop->len) { - BPy_IDGroup_CorrectListLen(prop, seq, i); + BPy_IDGroup_CorrectListLen(prop, seq, i, __func__); Py_DECREF(seq); /*free the list*/ /*call self again*/ return BPy_Wrap_GetItems(id, prop); diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index ac54cef7d4d..293ade35584 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -124,7 +124,7 @@ PyObject *bpy_text_import(Text *text) return PyImport_ExecCodeModule(modulename, text->compiled); } -PyObject *bpy_text_import_name(char *name, int *found) +PyObject *bpy_text_import_name(const char *name, int *found) { Text *text; char txtname[MAX_ID_NAME-2]; diff --git a/source/blender/python/generic/bpy_internal_import.h b/source/blender/python/generic/bpy_internal_import.h index 8bc10234a9b..2ce644715e9 100644 --- a/source/blender/python/generic/bpy_internal_import.h +++ b/source/blender/python/generic/bpy_internal_import.h @@ -49,7 +49,7 @@ struct Text; void bpy_import_init(PyObject *builtins); PyObject* bpy_text_import(struct Text *text); -PyObject* bpy_text_import_name(char *name, int *found); +PyObject* bpy_text_import_name(const char *name, int *found); PyObject* bpy_text_reimport(PyObject *module, int *found); /* void bpy_text_clear_modules(int clear_all);*/ /* Clear user modules */ diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index d9d1c16e11f..dfb7a1e8f75 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -81,53 +81,52 @@ static PyObject *bpy_script_paths(PyObject *UNUSED(self)) return ret; } +static int bpy_blend_paths_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src) +{ + PyObject *list= (PyObject *)userdata; + PyObject *item= PyUnicode_DecodeFSDefault(path_src); + PyList_Append(list, item); + Py_DECREF(item); + return FALSE; /* never edits the path */ +} + PyDoc_STRVAR(bpy_blend_paths_doc, -".. function:: blend_paths(absolute=False)\n" +".. function:: blend_paths(absolute=False, packed=False, local=False)\n" "\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" +" :arg packed: When true skip file paths for packed data.\n" +" :type packed: boolean\n" +" :arg local: When true skip linked library paths.\n" +" :type local: boolean\n" " :return: path list.\n" " :rtype: list of strings\n" ); static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObject *kw) { - struct BPathIterator *bpi; - PyObject *list, *st; /* stupidly big string to be safe */ - /* be sure there is low chance of the path being too short */ - char filepath_expanded[1024]; - const char *lib; + int flag= 0; + PyObject *list; - int absolute= 0; - static const char *kwlist[]= {"absolute", NULL}; + int absolute= FALSE; + int packed= FALSE; + int local= FALSE; + static const char *kwlist[]= {"absolute", "packed", "local", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kw, "|i:blend_paths", (char **)kwlist, &absolute)) + if (!PyArg_ParseTupleAndKeywords(args, kw, "|ii:blend_paths", + (char **)kwlist, &absolute, &packed)) + { return NULL; + } - list= PyList_New(0); + if (absolute) flag |= BPATH_TRAVERSE_ABS; + if (!packed) flag |= BPATH_TRAVERSE_SKIP_PACKED; + if (local) flag |= BPATH_TRAVERSE_SKIP_LIBRARY; - for (BLI_bpathIterator_init(&bpi, G.main, G.main->name, 0); !BLI_bpathIterator_isDone(bpi); BLI_bpathIterator_step(bpi)) { - /* build the list */ - if (absolute) { - BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded); - } - else { - lib= BLI_bpathIterator_getLib(bpi); - if (lib && (BLI_path_cmp(lib, BLI_bpathIterator_getBasePath(bpi)))) { /* relative path to the library is NOT the same as our blendfile path, return an absolute path */ - BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded); - } - else { - BLI_bpathIterator_getPath(bpi, filepath_expanded); - } - } - st= PyUnicode_DecodeFSDefault(filepath_expanded); - - PyList_Append(list, st); - Py_DECREF(st); - } + list= PyList_New(0); - BLI_bpathIterator_free(bpi); + bpath_traverse_main(G.main, bpy_blend_paths_visit_cb, flag, (void *)list); return list; } @@ -147,10 +146,10 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj return NULL; /* stupid string compare */ - if (!strcmp(type, "DATAFILES")) folder_id= BLENDER_USER_DATAFILES; - else if (!strcmp(type, "CONFIG")) folder_id= BLENDER_USER_CONFIG; - else if (!strcmp(type, "SCRIPTS")) folder_id= BLENDER_USER_SCRIPTS; - else if (!strcmp(type, "AUTOSAVE")) folder_id= BLENDER_USER_AUTOSAVE; + if (!strcmp(type, "DATAFILES")) folder_id= BLENDER_USER_DATAFILES; + else if (!strcmp(type, "CONFIG")) folder_id= BLENDER_USER_CONFIG; + else if (!strcmp(type, "SCRIPTS")) folder_id= BLENDER_USER_SCRIPTS; + else if (!strcmp(type, "AUTOSAVE")) folder_id= BLENDER_USER_AUTOSAVE; else { PyErr_SetString(PyExc_ValueError, "invalid resource argument"); return NULL; diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c index 651a626244f..382a513f40a 100644 --- a/source/blender/python/intern/bpy_library.c +++ b/source/blender/python/intern/bpy_library.c @@ -310,13 +310,14 @@ static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item) static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) { + Main *bmain= CTX_data_main(BPy_GetContext()); Main *mainl= NULL; int err= 0; flag_all_listbases_ids(LIB_PRE_EXISTING, 1); /* here appending/linking starts */ - mainl= BLO_library_append_begin(CTX_data_main(BPy_GetContext()), &(self->blo_handle), self->relpath); + mainl= BLO_library_append_begin(bmain, &(self->blo_handle), self->relpath); { int i= 0, code; @@ -399,7 +400,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) /* append, rather than linking */ if ((self->flag & FILE_LINK)==0) { Library *lib= BLI_findstring(&G.main->library, self->abspath, offsetof(Library, name)); - if (lib) all_local(lib, 1); + if (lib) BKE_library_make_local(bmain, lib, 1); else BLI_assert(!"cant find name of just added library!"); } } diff --git a/source/blender/python/intern/gpu.c b/source/blender/python/intern/gpu.c index 238558b7ad7..1162491ee26 100644 --- a/source/blender/python/intern/gpu.c +++ b/source/blender/python/intern/gpu.c @@ -236,7 +236,7 @@ static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObj PY_DICT_ADD_LONG(dict,uniform,texnumber); } if (uniform->texpixels) { - val = PyByteArray_FromStringAndSize((const char *)uniform->texpixels, uniform->texsize); + val = PyByteArray_FromStringAndSize((const char *)uniform->texpixels, uniform->texsize * 4); PyDict_SetItemString(dict, "texpixels", val); Py_DECREF(val); PY_DICT_ADD_LONG(dict,uniform,texsize); diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 554d4ba132d..f892c25f67e 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -39,6 +39,7 @@ #define QUAT_SIZE 4 static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObject *self); +static void quat__axis_angle_sanitize(float axis[3], float *angle); static PyObject *Quaternion_copy(QuaternionObject *self); //-----------------------------METHODS------------------------------ @@ -141,6 +142,39 @@ static PyObject *Quaternion_to_matrix(QuaternionObject *self) return newMatrixObject(mat, 3, 3, Py_NEW, NULL); } +//----------------------------Quaternion.toMatrix()------------------ +PyDoc_STRVAR(Quaternion_to_axis_angle_doc, +".. method:: to_axis_angle()\n" +"\n" +" Return the axis, angle representation of the quaternion.\n" +"\n" +" :return: axis, angle.\n" +" :rtype: (:class:`Vector`, float) pair\n" +); +static PyObject *Quaternion_to_axis_angle(QuaternionObject *self) +{ + PyObject *ret; + + float tquat[4]; + + float axis[3]; + float angle; + + if (BaseMath_ReadCallback(self) == -1) + return NULL; + + normalize_qt_qt(tquat, self->quat); + quat_to_axis_angle(axis, &angle, tquat); + + quat__axis_angle_sanitize(axis, &angle); + + ret= PyTuple_New(2); + PyTuple_SET_ITEM(ret, 0, newVectorObject(axis, 3, Py_NEW, NULL)); + PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(angle)); + return ret; +} + + //----------------------------Quaternion.cross(other)------------------ PyDoc_STRVAR(Quaternion_cross_doc, ".. method:: cross(other)\n" @@ -881,12 +915,18 @@ static PyObject *Quaternion_getMagnitude(QuaternionObject *self, void *UNUSED(cl static PyObject *Quaternion_getAngle(QuaternionObject *self, void *UNUSED(closure)) { float tquat[4]; + float angle; if (BaseMath_ReadCallback(self) == -1) return NULL; normalize_qt_qt(tquat, self->quat); - return PyFloat_FromDouble(2.0f * (saacos(tquat[0]))); + + angle= 2.0f * saacos(tquat[0]); + + quat__axis_angle_sanitize(NULL, &angle); + + return PyFloat_FromDouble(angle); } static int Quaternion_setAngle(QuaternionObject *self, PyObject *value, void *UNUSED(closure)) @@ -895,7 +935,7 @@ static int Quaternion_setAngle(QuaternionObject *self, PyObject *value, void *UN float len; float axis[3], angle_dummy; - double angle; + float angle; if (BaseMath_ReadCallback(self) == -1) return -1; @@ -913,13 +953,7 @@ static int Quaternion_setAngle(QuaternionObject *self, PyObject *value, void *UN angle= angle_wrap_rad(angle); - /* 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; - } + quat__axis_angle_sanitize(axis, &angle); axis_angle_to_quat(self->quat, axis, angle); mul_qt_fl(self->quat, len); @@ -935,21 +969,15 @@ static PyObject *Quaternion_getAxisVec(QuaternionObject *self, void *UNUSED(clos float tquat[4]; float axis[3]; - float angle; + float angle_dummy; if (BaseMath_ReadCallback(self) == -1) return NULL; normalize_qt_qt(tquat, self->quat); - quat_to_axis_angle(axis, &angle, tquat); + quat_to_axis_angle(axis, &angle_dummy, tquat); - /* 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; - } + quat__axis_angle_sanitize(axis, NULL); return (PyObject *) newVectorObject(axis, 3, Py_NEW, NULL); } @@ -971,6 +999,8 @@ static int Quaternion_setAxisVec(QuaternionObject *self, PyObject *value, void * if (mathutils_array_parse(axis, 3, 3, value, "quat.axis = other") == -1) return -1; + quat__axis_angle_sanitize(axis, &angle); + axis_angle_to_quat(self->quat, axis, angle); mul_qt_fl(self->quat, len); @@ -1029,6 +1059,33 @@ static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObjec } } +/* axis vector suffers from precission errors, use this function to ensure */ +static void quat__axis_angle_sanitize(float axis[3], float *angle) +{ + if (axis) { + if ( !finite(axis[0]) || + !finite(axis[1]) || + !finite(axis[2])) + { + axis[0]= 1.0f; + axis[1]= 0.0f; + axis[2]= 0.0f; + } + else 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; + } + } + + if (angle) { + if (!finite(*angle)) { + *angle= 0.0f; + } + } +} + //-----------------------METHOD DEFINITIONS ---------------------- static struct PyMethodDef Quaternion_methods[] = { /* in place only */ @@ -1048,6 +1105,7 @@ static struct PyMethodDef Quaternion_methods[] = { /* return converted representation */ {"to_euler", (PyCFunction) Quaternion_to_euler, METH_VARARGS, Quaternion_to_euler_doc}, {"to_matrix", (PyCFunction) Quaternion_to_matrix, METH_NOARGS, Quaternion_to_matrix_doc}, + {"to_axis_angle", (PyCFunction) Quaternion_to_axis_angle, METH_NOARGS, Quaternion_to_axis_angle_doc}, /* operation between 2 or more types */ {"cross", (PyCFunction) Quaternion_cross, METH_O, Quaternion_cross_doc}, @@ -1157,7 +1215,7 @@ PyObject *newQuaternionObject(float *quat, int type, PyTypeObject *base_type) unit_qt(self->quat); } else { - QUATCOPY(self->quat, quat); + copy_qt_qt(self->quat, quat); } self->wrapped = Py_NEW; } diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index 44bb2ed51aa..6e8624721b7 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -628,14 +628,14 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec return NULL; /* accept 2d verts */ - if (pt->size==3) { VECCOPY(pt_in, pt->vec);} - else { pt_in[2]=0.0; VECCOPY2D(pt_in, pt->vec) } + if (pt->size==3) { copy_v3_v3(pt_in, pt->vec);} + else { pt_in[2]=0.0; copy_v2_v2(pt_in, pt->vec); } - if (line_1->size==3) { VECCOPY(l1, line_1->vec);} - else { l1[2]=0.0; VECCOPY2D(l1, line_1->vec) } + if (line_1->size==3) { copy_v3_v3(l1, line_1->vec);} + else { l1[2]=0.0; copy_v2_v2(l1, line_1->vec); } - if (line_2->size==3) { VECCOPY(l2, line_2->vec);} - else { l2[2]=0.0; VECCOPY2D(l2, line_2->vec) } + if (line_2->size==3) { copy_v3_v3(l2, line_2->vec);} + else { l2[2]=0.0; copy_v2_v2(l2, line_2->vec); } /* do the calculation */ lambda= closest_to_line_v3(pt_out, pt_in, l1, l2); diff --git a/source/blender/python/simple_enum_gen.py b/source/blender/python/simple_enum_gen.py index bc7a2df9fb6..ec2eead522c 100644 --- a/source/blender/python/simple_enum_gen.py +++ b/source/blender/python/simple_enum_gen.py @@ -29,11 +29,11 @@ defs = """ SPACE_INFO, SPACE_SEQ, SPACE_TEXT, - SPACE_IMASEL, - SPACE_SOUND, + SPACE_IMASEL, #Deprecated + SPACE_SOUND, #Deprecated SPACE_ACTION, SPACE_NLA, - SPACE_SCRIPT, + SPACE_SCRIPT, #Deprecated SPACE_TIME, SPACE_NODE, SPACEICONMAX |