Python API
authorKen Hughes <khughes@pacific.edu>
Wed, 20 Dec 2006 22:56:58 +0000 (22:56 +0000)
committerKen Hughes <khughes@pacific.edu>
Wed, 20 Dec 2006 22:56:58 +0000 (22:56 +0000)
----------
Bugfix/enhancement: allow image of mesh's UV faces to be removed/cleared by
"del f.image" or "f.image = None", and handle image user counts correctly
when assigning/clearing images.

source/blender/python/api2_2x/Mesh.c
source/blender/python/api2_2x/doc/Mesh.py

index 45c599872f04e7de2661e933bd92008c79b6da01..12de447e60ce7a243816694d6d95bbbf7c94daaf 100644 (file)
@@ -3729,6 +3729,10 @@ static int MFace_setImage( BPy_MFace *self, PyObject *value )
        if( !MFace_get_pointer( self ) )
                return -1;
 
+       if( value && value != Py_None && !BPy_Image_Check( value ) )
+           return EXPP_ReturnIntError( PyExc_TypeError,
+                   "expected image object or None" );
+
        if( !self->mesh->mtface )
 #if 0
                return EXPP_ReturnIntError( PyExc_ValueError,
@@ -3738,17 +3742,19 @@ static int MFace_setImage( BPy_MFace *self, PyObject *value )
 #endif
 
        face = &self->mesh->mtface[self->index];
-    if( value == Py_None )
-        face->tpage = NULL;            /* should memory be freed? */
-    else {
-        if( !BPy_Image_Check( value ) )
-            return EXPP_ReturnIntError( PyExc_TypeError,
-                                       "expected image object" );
-        face->tpage = ( ( BPy_Image * ) value )->image;
+
+       if( face->tpage )
+               face->tpage->id.us--;
+
+       if( value == NULL || value == Py_None )
+               face->tpage = NULL;             /* should memory be freed? */
+       else {
+               face->tpage = ( ( BPy_Image * ) value )->image;
+               face->tpage->id.us++;
                face->mode |= TF_TEX;
-    }
+       }
 
-    return 0;
+       return 0;
 }
 
 #define MFACE_FLAG_BITMASK ( TF_SELECT | TF_ACTIVE | TF_SEL1 | \
index f013480872f22a48526ebff5b4d72d9d7b184023..b981f4f5119a5bff9f78718b166b299933c0841c 100644 (file)
@@ -537,7 +537,8 @@ class MFace:
       Getting this attribute throw an exception if the mesh does not have 
       UV faces; use L{Mesh.faceUV} to test.  
       Assigning an image will automatically set the TEX attribute of the
-      L{mode} bitfield.
+      L{mode} bitfield.  Use "del f.image" or "f.image = None" to clear the
+      image assigned to the face.
   @type image: Image
   @ivar mode: The texture mode bitfield (see L{FaceModes}).
       Will throw an exception if the mesh does not have UV faces; use