Blender's subdividing code

almost documentation :-)
Hmm.. just sat down and worked my way through the mountians of subdivision code, because we were running in trouble with the seam information used by LSCM in tuhopuu. Though edge / seam information may be stored in a new edge data block, which may prevent seam scrambeling, pinned UVs will not be preserved by this. UVs and thus their pinning is stored in tface structure and have to be remapped to the new faces. To know the right mapping, the fate of faces while subdividing needs to be known.

All this happens in the function subdivideflag( ... ) in "editmesh.c". This code runs when a mesh is subdivided in edit-mode.
  1. Edges are subdevided
  2. 'test' bit-flags are set .. 1 edge1 was divided, 2 .. edge 2, 4 ..edge 3, 8 .. edge 4,so 'test' ranges 0..15
  3. New faces get created (the old face's data stucture including edges /* sigh !! this is where the new 'tuhopuu'-seam information gets scrambled */ gets recycled by one of the faces)
  4. New UVs are calculated on the fly. The function 'set_wuv( ... )' does it. It seems to be the right place to do remapping here.
  5. Old, unused edges get deleted

The following drafts show the different cases of new face generation.
  • All edges,verts number counter clock wise (maths positive)
  • Capital letters A,B,C denote order of face creation in code /* in all but generic 4 edge C is the recycled face */
  • 1,A1,C1, marks vertex #1 in new face
case 4 edges less than 4 get cut; 1
case 4 edges less than 4 get cut; 2
case 4 edges generic
case 3 edges; 1
NOTE the 'funny' cases 3,5,6. They occur on knive-subdivide (i did test it in blender!). I think they are not optimal. The triangle should be cut into one 3 egde and one 4 edge. (hm .. i think i'll give it a try some day)
case 3 edges; 2