utility functions is_negative_m3 & is_negative_m4, added python Mathutils access...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 30 Jan 2010 13:15:39 +0000 (13:15 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 30 Jan 2010 13:15:39 +0000 (13:15 +0000)
renamed Mathutils attribute wrapped -> is_wrapped

release/scripts/modules/bpy/app.py
source/blender/blenkernel/intern/object.c
source/blender/blenlib/BLI_math_matrix.h
source/blender/blenlib/intern/math_matrix.c
source/blender/python/generic/euler.c
source/blender/python/generic/matrix.c
source/blender/python/generic/quat.c
source/blender/python/generic/vector.c
source/blender/python/intern/bpy_interface.c
source/blender/python/intern/bpy_rna.c

index 7b4b5e03ab718628057f620149dc86f001bd63ef..26011ca5c2eb47efc06b65d1728e47175f647116 100644 (file)
@@ -45,9 +45,8 @@ This module contains application values that remain unchanged during runtime.
 """
 # constants
 import _bpy
-import sys as _sys
 version = _bpy._VERSION
 version_string = _bpy._VERSION_STR
 home = _bpy._HOME
 binary_path = _bpy._BINPATH
-debug = ("-d" in _sys.argv)
+debug = _bpy._DEBUG
index 0ea2925705ec4cc10797d311f8566903c8a3c08c..42fe565f1bb2f7fb555936e24367da935332ec04 100644 (file)
@@ -1980,7 +1980,7 @@ void set_no_parent_ipo(int val)
 void where_is_object_time(Scene *scene, Object *ob, float ctime)
 {
        float *fp1, *fp2, slowmat[4][4] = MAT4_UNITY;
-       float stime=ctime, fac1, fac2, vec[3];
+       float stime=ctime, fac1, fac2;
        int a;
        
        /* new version: correct parent+vertexparent and track+parent */
@@ -2050,9 +2050,8 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime)
        }
        
        /* set negative scale flag in object */
-       cross_v3_v3v3(vec, ob->obmat[0], ob->obmat[1]);
-       if( dot_v3v3(vec, ob->obmat[2]) < 0.0 ) ob->transflag |= OB_NEG_SCALE;
-       else ob->transflag &= ~OB_NEG_SCALE;
+       if(is_negative_m4(ob->obmat))   ob->transflag |= OB_NEG_SCALE;
+       else                                                    ob->transflag &= ~OB_NEG_SCALE;
 }
 
 static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul)
index 5667fb793324715fc5c27f66b443e8c96b82ed04..0a442687ffc207650333f20f9ffca8d46640e20d 100644 (file)
@@ -148,6 +148,9 @@ void loc_quat_size_to_mat4(float R[4][4],
 void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], float t);
 void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], float t);
 
+int is_negative_m3(float mat[3][3]);
+int is_negative_m4(float mat[4][4]);
+
 /*********************************** Other ***********************************/
 
 void print_m3(char *str, float M[3][3]);
index 47b99bce8abf1c13aff5d48b83000607f079c897..4765a1f4728d2eda8ebf55b3fc020e60cc20b735 100644 (file)
@@ -1037,6 +1037,21 @@ void blend_m4_m4m4(float out[][4], float dst[][4], float src[][4], float srcweig
        loc_quat_size_to_mat4(out, floc, fquat, fsize);
 }
 
+
+int is_negative_m3(float mat[][3])
+{
+       float vec[3];
+       cross_v3_v3v3(vec, mat[0], mat[1]);
+       return (dot_v3v3(vec, mat[2]) < 0.0f);
+}
+
+int is_negative_m4(float mat[][4])
+{
+       float vec[3];
+       cross_v3_v3v3(vec, mat[0], mat[1]);
+       return (dot_v3v3(vec, mat[2]) < 0.0f);
+}
+
 /* make a 4x4 matrix out of 3 transform components */
 /* matrices are made in the order: scale * rot * loc */
 // TODO: need to have a version that allows for rotation order...
@@ -1128,4 +1143,3 @@ void print_m4(char *str, float m[][4])
        printf("%f %f %f %f\n",m[0][3],m[1][3],m[2][3],m[3][3]);
        printf("\n");
 }
-
index 82bd2ebe70a888bf19b29ffb8284516f9abd4838..c41107286e0fd1d9e06255197a0dfb8bd1c3b6c9 100644 (file)
@@ -571,7 +571,7 @@ static PyGetSetDef Euler_getseters[] = {
        {"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},
 
-       {"wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, 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 */
 };
index a61cf4a2d415ebc652b2d2c122fbc5487712ce87..0928a93f13dc118a791759dfe429e7de10aacddb 100644 (file)
@@ -1231,14 +1231,34 @@ static PyObject *Matrix_getMedianScale( MatrixObject * self, void *type )
        return PyFloat_FromDouble(mat3_to_scale(mat));
 }
 
+static PyObject *Matrix_getIsNegative( MatrixObject * self, void *type )
+{
+       float vec[3];
+
+       if(!BaseMath_ReadCallback(self))
+               return NULL;
+
+       /*must be 3-4 cols, 3-4 rows, square matrix*/
+       if(self->colSize == 4 && self->rowSize == 4)
+               return PyBool_FromLong(is_negative_m4((float (*)[4])*self->matrix));
+       else if(self->colSize == 3 && self->rowSize == 3)
+               return PyBool_FromLong(is_negative_m3((float (*)[3])*self->matrix));
+       else {
+               PyErr_SetString(PyExc_AttributeError, "Matrix.is_negative: inappropriate matrix size - expects 3x3 or 4x4 matrix\n");
+               return NULL;
+       }
+}
+
+
 /*****************************************************************************/
 /* 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},
-       {"wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, 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, 4x4 only) (readonly). **type** bool", 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 */
 };
index 9b5016b91d740909e1f13ab6d9b992585706ee86..33d35da5175eff175846430c5a79673b438d96f1 100644 (file)
@@ -854,7 +854,7 @@ static PyGetSetDef Quaternion_getseters[] = {
        {"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},
-       {"wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, 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 */
 };
index 784ea1a153fdc86eb18ba5af61f5d62a5ce42cad..4efd168eb8798b446d9f86ef96ff230b66a297f0 100644 (file)
@@ -1635,7 +1635,7 @@ static PyGetSetDef Vector_getseters[] = {
        {"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},
-       {"wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
+       {"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
        {"_owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
        
        /* autogenerated swizzle attrs, see python script below */
index 58f271a5e77027c835a82972d7ae1a1e81fe20ff..e5204c0b8b5b75f9278d7146dceb2093a73cf1b9 100644 (file)
@@ -235,6 +235,7 @@ static void bpy_init_modules( void )
                sprintf(tmpstr, "%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
                PyModule_AddStringConstant(mod, "_VERSION_STR",  tmpstr);
                PyModule_AddStringConstant(mod, "_BINPATH",  bprogname);
+               PyModule_AddIntConstant(mod, "_DEBUG",  G.f & G_DEBUG ? 1:0);
        }
 
        /* add our own modules dir, this is a python package */
index 49dfa95109c6d9cf9bf4ee8dfbafd305edce5109..4cda17902cbbc8d33c1994fe2fd9f3d5140995dc 100644 (file)
@@ -3575,11 +3575,12 @@ PyObject *BPY_rna_types(void)
        }
        
        self= (BPy_BaseTypeRNA *)PyObject_NEW( BPy_BaseTypeRNA, &pyrna_basetype_Type );
-       
+       self->arraydim = self->arrayoffset = 0; /* unused but better set */
+
        /* avoid doing this lookup for every getattr */
        RNA_blender_rna_pointer_create(&self->ptr);
        self->prop = RNA_struct_find_property(&self->ptr, "structs");
-       
+
        return (PyObject *)self;
 }