module Graphics.Triangulation.Triangulation where
import Graphics.Formats.Collada.ColladaTypes
import Data.Array (Array(..),listArray)
type Points = Array Int (Float,Float)
type TriangulationFunction = Points -> [Int] -> [(Int,Int,Int)]
triangulate :: TriangulationFunction -> Geometry -> Geometry
triangulate f (Geometry name prims (Vertices vname ps ns)) =
Geometry name (map triPoly prims) (Vertices vname ps ns)
where
triPoly (LP (LinePrimitive pIndices nIndices tex col)) = PL (LinePrimitive (tri pIndices) (normals pIndices nIndices) tex col)
tri pIndices = map (\(x,y,z) -> [x,y,z]) (concat (map (f arr) pIndices) )
normals pIndices nIndices = replicate (length (concat pIndices)) (head nIndices)
arr = listArray (0,l1) $ map (\(x,y,z) -> (x,z)) ps
l = length ps