Logo Search packages:      
Sourcecode: blender version File versions  Download package

Mesh::MFace Class Reference

List of all members.


Detailed Description

The MFace object
================
This object holds mesh face data.

Example::
      import Blender
      from Blender import Mesh, Window

      in_emode = Window.EditMode()
      if in_emode: Window.EditMode(0)

      me = Mesh.Get("Mesh")
      faces = me.faces

      ## Example for editmode faces selection:
      selected_faces = []
      for f in faces:
            if f.sel:
                  selected_faces.append(f)
      # ... unselect selected and select all the others:
      for f in faces:
            f.sel = not f.sel # 1 becomes 0, 0 becomes 1

      ## Example for UV textured faces selection:
      selected_faces = []
      SEL = Mesh.FaceFlags['SELECT']
      # get selected faces:
      for f in faces:
            if f.flag & SEL:
                  selected_faces.append(f)
      # ... unselect selected and select all the others:
      for f in faces:
            if f.flag & SEL:
                  f.flag &= ~SEL # unselect these
            else:
                  f.flag |= SEL # and select these

      if in_emode: Window.EditMode(1)
      Blender.Redraw()

@ivar verts: The face's vertices.  Each face has 3 or 4 vertices.
@type verts: list of MVerts
@ivar v: Same as L{verts}.  This attribute is only for compatibility with
      NMesh scripts and will probably be deprecated in the future.
@ivar sel: The face's B{edit mode} selection state (selected=1).
      This is not the same as the selection state of the textured faces
      (see L{flag}). B{Note}: changing the select state of a face changes
      the select state of the face's vertices.
@type sel: int
@ivar hide: The face's B{edit mode} visibility state (hidden=1).
      This is not the same as the visibility state of
      the textured faces (see L{flag}).
@type hide: int
@ivar smooth: If set, the vertex normals are averaged to make this
      face look smooth.  (This is the same as choosing "Set Smooth" in the 
      Editing Panel (F9) under "Link and Material" properties).
@type smooth: int
@ivar col: The face's vertex colors, if defined.  Each vertex has its own
      color.
      Will throw an exception if L{Mesh.vertexColors} is False.

      Example::
            # This example uses vertex normals to apply normal colors to each face.
            import bpy
            from Blender import Window
            scn= bpy.scenes.active	# Current scene, important to be scene aware
            ob= scn.objects.active	# last selected object
            me= ob.getData(mesh=1)	# thin wrapper doesn't copy mesh data like nmesh
            me.vertexColors= True	# Enable face, vertex colors
            for f in me.faces:
                  for i, v in enumerate(f):
                        no= v.no
                        col= f.col[i]
                        col.r= int((no.x+1)*128)
                        col.g= int((no.y+1)*128)
                        col.b= int((no.z+1)*128)
            Window.RedrawAll()
@type col: tuple of MCols
@ivar mat: The face's index into the mesh's materials
            list.  It is in the range [0,15].
@type mat: int
@ivar image: The Image used as a texture for this face.
            Setting this attribute will create UV faces if they do not exist.
            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.  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
            L{Mesh.faceUV} to test.
@type mode: int
@ivar index: The face's index within the mesh.  Read-only.
@type index: int

@ivar flag: The face's B{texture mode} flags; indicates the selection, 
            active , and visibility states of a textured face (see
            L{FaceFlags} for values).
            This is not the same as the selection or visibility states of
            the faces in edit mode (see L{sel} and L{hide}).
            To set the active face, use
            the L{Mesh.activeFace} attribute instead.
            Will throw an exception if the mesh does not have UV faces; use
            L{Mesh.faceUV} to test.

@ivar transp: Transparency mode.  It is one of the values in 
            L{FaceTranspModes}).
            Will throw an exception if the mesh does not have UV faces; use
            L{Mesh.faceUV} to test.
@type transp: int

@ivar uv: The face's UV coordinates.  Each vertex has its own UV coordinate.
            Setting this attribute will create UV faces if they do not exist.
            Getting this attribute throw an exception if the mesh does not have 
            UV faces; use L{Mesh.faceUV} to test.  
@type uv: tuple of vectors (WRAPPED DATA)
@ivar uvSel: The face's UV coordinates selection state; a 1 indicates the
            vertex is selected.  Each vertex has its own UV coordinate select state
            (this is not the same as the vertex's edit mode selection state).
            Setting this attribute will create UV faces if they do not exist.
            Getting this attribute throw an exception if the mesh does not have 
            UV faces; use L{Mesh.faceUV} to test.  
@type uvSel: tuple of ints
@ivar no: The face's normal vector (x, y, z).  Read-only.
@type no: vector
@ivar cent: The center of the face. Read-only.
@type cent: vector
@ivar area: The area of the face. Read-only.
@type area: float
@ivar edge_keys: A tuple, each item a key that can reference an edge by its
ordered indices. Read-only.  This is useful for building connectivity data.
Example::
            from Blender import Mesh
            me = Mesh.Get('Cube')
            # a dictionary where the edge is the key, and a list of faces that use it are the value
            edge_faces = dict([(ed.key, []) for ed in me.edges])

            # Add the faces to the dict
            for f in me.faces:
                  for key in f.edge_keys:
                        edge_faces[key].append(f) # add this face to the edge as a user

            # Print the edges and the number of face users
            for key, face_users in edge_faces.iteritems():
                  print 'Edge:', key, 'uses:', len(face_users),'faces'

@type edge_keys: tuple
@note: there are regular faces and textured faces in Blender, both currently
      with their own selection and visibility states, due to a mix of old and new
      code.  To (un)select or (un)hide regular faces (visible in EditMode), use
      L{MFace.sel} and L{MFace.hide} attributes.  For textured faces (UV Face 
      Select and Paint modes in Blender) use the L{MFace.flag} attribute.
      Check the example above and note L{Window.EditMode}.
@note: Assigning UV textures to mesh faces in Blender works like this:
      1. Select your mesh.
      2. Enter face select mode (press f) and select at least some face(s).
      3. In the UV/Image Editor window, load / select an image.
      4. Play in both windows (better split the screen to see both at the same
            time) until the UV coordinates are where you want them.  Hint: in the
            3D window, the 'u' key opens a menu of default UV choices and the 'r'
            key lets you rotate the UV coords.
      5. Leave face select mode (press f).

Definition at line 450 of file Mesh.py.


Public Member Functions

def __iter__
def __len__

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index