Merged changes in the trunk up to revision 30781.
This commit is contained in:
@@ -74,19 +74,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 */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -774,27 +766,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 vec[3];
|
||||
float axis[3];
|
||||
float angle;
|
||||
|
||||
normalize_v3_v3(vec, self->quat+1);
|
||||
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(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);
|
||||
|
||||
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 axis[3];
|
||||
float angle;
|
||||
|
||||
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(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(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() --------------
|
||||
@@ -853,8 +919,8 @@ static PyGetSetDef Quaternion_getseters[] = {
|
||||
{"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},
|
||||
{"angle", (getter)Quaternion_getAngle, (setter)Quaternion_setAngle, "angle of the quaternion. **type** float", NULL},
|
||||
{"axis",(getter)Quaternion_getAxisVec, (setter)Quaternion_setAxisVec, "quaternion axis as a vector. **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},
|
||||
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -204,10 +205,13 @@ 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];
|
||||
|
||||
/* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */ /* cant use this, on linux gives bug: #23018 */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4163,6 +4163,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 +4235,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;
|
||||
}
|
||||
@@ -4760,7 +4763,7 @@ 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;
|
||||
@@ -4836,14 +4839,41 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
|
||||
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 +4889,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();
|
||||
|
||||
|
||||
@@ -86,10 +86,6 @@ 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);
|
||||
|
||||
/* called before stopping python */
|
||||
|
||||
Reference in New Issue
Block a user