module Graphics.Implicit.Export.NormedTriangleMeshFormats where
import Graphics.Implicit.Definitions
import Graphics.Implicit.Export.TextBuilderUtils
obj normedtriangles = toLazyText $ vertcode <> normcode <> trianglecode
where
v :: ℝ3 -> Builder
v (x,y,z) = "v " <> bf x <> " " <> bf y <> " " <> bf z <> "\n"
n :: ℝ3 -> Builder
n (x,y,z) = "vn " <> bf x <> " " <> bf y <> " " <> bf z <> "\n"
verts = do
((a,_),(b,_),(c,_)) <- normedtriangles
[a,b,c]
norms = do
((_,a),(_,b),(_,c)) <- normedtriangles
[a,b,c]
vertcode = mconcat $ map v verts
normcode = mconcat $ map n norms
trianglecode = mconcat $ do
n <- map ((+1).(*3)) [0,1 .. length normedtriangles 1]
let
vta = buildInt n
vtb = buildInt (n+1)
vtc = buildInt (n+2)
return $ "f " <> vta <> " " <> vtb <> " " <> vtc <> " " <> "\n"