Package pyffi :: Package utils :: Module tristrip
[hide private]
[frames] | no frames]

Module tristrip

source code

A wrapper for TriangleStripifier and some utility functions, for stripification of sets of triangles, stitching and unstitching strips, and triangulation of strips.
Classes [hide private]
  OrientedStrip
An oriented strip, with stitching support.
Functions [hide private]
 
triangulate(strips)
A generator for iterating over the faces in a set of strips.
source code
 
_generate_faces_from_triangles(triangles) source code
 
_sort_triangle_indices(triangles)
Sorts indices of each triangle so lowest index always comes first.
source code
 
_check_strips(triangles, strips)
Checks that triangles and strips describe the same geometry.
source code
 
stripify(triangles, stitchstrips=False)
Converts triangles into a list of strips.
source code
 
stitch_strips(strips)
Stitch strips keeping stitch size minimal.
source code
 
unstitch_strip(strip)
Revert stitched strip back to a set of strips without stitches.
source code
Variables [hide private]
  pytristrip = None
hash(x)
  __package__ = 'pyffi.utils'
Function Details [hide private]

triangulate(strips)

source code 

A generator for iterating over the faces in a set of strips. Degenerate triangles in strips are discarded.

>>> triangulate([[1, 0, 1, 2, 3, 4, 5, 6]])
[(0, 2, 1), (1, 2, 3), (2, 4, 3), (3, 4, 5), (4, 6, 5)]

_sort_triangle_indices(triangles)

source code 

Sorts indices of each triangle so lowest index always comes first. Also removes degenerate triangles.

>>> list(_sort_triangle_indices([(2,1,3),(0,2,6),(9,8,4)]))
[(1, 3, 2), (0, 2, 6), (4, 9, 8)]
>>> list(_sort_triangle_indices([(2,1,1),(0,2,6),(9,8,4)]))
[(0, 2, 6), (4, 9, 8)]

stripify(triangles, stitchstrips=False)

source code 

Converts triangles into a list of strips.

If stitchstrips is True, then everything is wrapped in a single strip using degenerate triangles.

>>> triangles = [(0,1,4),(1,2,4),(2,3,4),(3,0,4)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips)
>>> triangles = [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11), (12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips)
>>> triangles = [(0, 1, 2), (0, 1, 2)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips)
>>> triangles = [(0, 1, 2), (2, 1, 0)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips)
>>> triangles = [(0, 1, 2), (2, 1, 0), (1, 2, 3)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips) # NvTriStrip gives wrong result
>>> triangles = [(0, 1, 2), (0, 1, 3)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips) # NvTriStrip gives wrong result
>>> triangles = [(1, 5, 2), (5, 2, 6), (5, 9, 6), (9, 6, 10), (9, 13, 10), (13, 10, 14), (0, 4, 1), (4, 1, 5), (4, 8, 5), (8, 5, 9), (8, 12, 9), (12, 9, 13), (2, 6, 3), (6, 3, 7), (6, 10, 7), (10, 7, 11), (10, 14, 11), (14, 11, 15)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips) # NvTriStrip gives wrong result
>>> triangles = [(1, 2, 3), (4, 5, 6), (6, 5, 7), (8, 5, 9), (4, 10, 9), (8, 3, 11), (8, 10, 3), (12, 13, 6), (14, 2, 15), (16, 13, 15), (16, 2, 3), (3, 2, 1)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips) # detects bug reported by PacificMorrowind
>>> triangles = [(354, 355, 356), (355, 356, 354), (354, 355, 356), (355, 356, 354), (354, 355, 356), (356, 354, 355), (354, 355, 356), (357, 359, 358),
...              (380, 372, 381), (372, 370, 381), (381, 370, 354), (370, 367, 354), (367, 366, 354), (366, 355, 354), (355, 356, 354), (354, 356, 381),
...              (356, 355, 357), (357, 356, 355), (356, 355, 357), (356, 355, 357), (357, 356, 355)]
>>> strips = stripify(triangles)
>>> _check_strips(triangles, strips) # NvTriStrip gives wrong result