==Python API==
authorKen Hughes <khughes@pacific.edu>
Sun, 5 Feb 2006 07:19:37 +0000 (07:19 +0000)
committerKen Hughes <khughes@pacific.edu>
Sun, 5 Feb 2006 07:19:37 +0000 (07:19 +0000)
A couple of bug fixes and enhancements:
(1) Setting the UV attributes of a mesh face will create texture faces if
    they are not already defined.  Previously this threw an exception.
(2) Setting the image attribute of a mesh face will also set the TEX bit
    of the face.mode flag
(3) When "sticky" vertices are created with mesh.vertexUV, the color is
    set to white instead of black.
(4) Bugfix #3872: copying the mode attribute of one mesh to another would
    sometimes result in an exception due to unexpected bits being set. I
    still don't know how these other bits are being set, but this patch will
    stop the complaint if they are set.

source/blender/python/api2_2x/Mesh.c

index 91b86947a83ef0f020ee45a007f17dd123ba25f8..a089863ddcf4330ddb39840d79cfee6b4f370b7c 100644 (file)
@@ -2461,7 +2461,7 @@ static PyObject *MEdgeSeq_extend( BPy_MEdgeSeq * self, PyObject *args )
        case 1:
                /* if a sequence... */
                tmp = PyTuple_GET_ITEM( args, 0 );
-               if( PySequence_Check( tmp ) ) {
+               if( PySequence_Check( tmp ) && PySequence_Size( tmp ) == 1 ) {
                        /* if another sequence, use it */
                        PyObject *tmp2 = PySequence_ITEM( tmp, 0 );
                        if( PySequence_Check( tmp2 ) )
@@ -3204,13 +3204,18 @@ static PyObject *MFace_getImage( BPy_MFace *self )
 static int MFace_setImage( BPy_MFace *self, PyObject *value )
 {
        TFace *face;
-       if( !self->mesh->tface )
-               return EXPP_ReturnIntError( PyExc_ValueError,
-                               "face has no texture values" );
 
        if( !MFace_get_pointer( self ) )
                return -1;
 
+       if( !self->mesh->tface )
+#if 0
+               return EXPP_ReturnIntError( PyExc_ValueError,
+                               "face has no texture values" );
+#else
+               make_tfaces( self->mesh );
+#endif
+
        face = &self->mesh->tface[self->index];
     if( value == Py_None )
         face->tpage = NULL;            /* should memory be freed? */
@@ -3219,6 +3224,7 @@ static int MFace_setImage( BPy_MFace *self, PyObject *value )
             return EXPP_ReturnIntError( PyExc_TypeError,
                                        "expected image object" );
         face->tpage = ( ( BPy_Image * ) value )->image;
+               face->mode |= TF_TEX;
     }
 
     return 0;
@@ -3449,10 +3455,6 @@ static int MFace_setUV( BPy_MFace * self, PyObject * value )
        TFace *face;
        int length, i;
 
-       if( !self->mesh->tface )
-               return EXPP_ReturnIntError( PyExc_ValueError,
-                               "face has no texture values" );
-
        if( !MFace_get_pointer( self ) )
                return -1;
 
@@ -3466,6 +3468,14 @@ static int MFace_setUV( BPy_MFace * self, PyObject * value )
                return EXPP_ReturnIntError( PyExc_TypeError,
                                            "size of vertex and UV sequences differ" );
 
+       if( !self->mesh->tface )
+#if 0
+               return EXPP_ReturnIntError( PyExc_ValueError,
+                               "face has no texture values" );
+#else
+               make_tfaces( self->mesh );
+#endif
+
        face = &self->mesh->tface[self->index];
        for( i=0; i<length; ++i ) {
                VectorObject *vector = (VectorObject *)PySequence_ITEM( value, i );
@@ -3525,10 +3535,6 @@ static int MFace_setUVSel( BPy_MFace * self, PyObject * value )
        TFace *face;
        int length, i, mask;
 
-       if( !self->mesh->tface )
-               return EXPP_ReturnIntError( PyExc_ValueError,
-                               "face has no texture values" );
-
        if( !MFace_get_pointer( self ) )
                return -1;
 
@@ -3541,6 +3547,14 @@ static int MFace_setUVSel( BPy_MFace * self, PyObject * value )
                return EXPP_ReturnIntError( PyExc_TypeError,
                                            "size of vertex and UV lists differ" );
 
+       if( !self->mesh->tface )
+#if 0
+               return EXPP_ReturnIntError( PyExc_ValueError,
+                               "face has no texture values" );
+#else
+               make_tfaces( self->mesh );
+#endif
+
        /* set coord select state, one bit at a time */
        face = &self->mesh->tface[self->index];
        mask = TF_SEL1;
@@ -4014,7 +4028,7 @@ static PyObject *MFaceSeq_extend( BPy_MEdgeSeq * self, PyObject *args )
        case 1:         /* better be a sequence or a tuple */
                /* if a sequence... */
                tmp = PyTuple_GET_ITEM( args, 0 );
-               if( PySequence_Check( tmp ) ) {
+               if( PySequence_Check( tmp ) && PySequence_Size( tmp ) == 1 ) {
                        /* if another sequence, use it */
                        PyObject *tmp2 = PySequence_ITEM( tmp, 0 );
                        if( PySequence_Check( tmp2 ) )
@@ -6118,8 +6132,9 @@ static int Mesh_setFlag( BPy_Mesh * self, PyObject *value, void *type )
                        }
                } else {
                        if( !mesh->msticky ) {
-                               mesh->msticky= MEM_callocN( mesh->totvert*sizeof( MSticky ),
+                               mesh->msticky= MEM_mallocN( mesh->totvert*sizeof( MSticky ),
                                                "sticky" );
+                               memset( mesh->msticky, 255, mesh->totvert*sizeof( MSticky ) );
                                /* TODO: rework RE_make_sticky() so we can calculate */
                        }
                }
@@ -6144,7 +6159,9 @@ static PyObject *Mesh_getMode( BPy_Mesh * self )
 static int Mesh_setMode( BPy_Mesh *self, PyObject *value )
 {
        short param;
-       static short bitmask = ME_NOPUNOFLIP | ME_TWOSIDED | ME_AUTOSMOOTH;
+       static short bitmask = ME_ISDONE | ME_NOPUNOFLIP | ME_TWOSIDED |
+               ME_UVEFFECT | ME_VCOLEFFECT | ME_AUTOSMOOTH | ME_SMESH |
+               ME_SUBSURF | ME_OPT_EDGES;
 
        if( !PyInt_CheckExact ( value ) ) {
                char errstr[128];