-----------------------------------------------------------------------------
-- |
-- Copyright   : (C) 2015 Dimitri Sabadie
-- License     : BSD3
--
-- Maintainer  : Dimitri Sabadie <dimitri.sabadie@gmail.com>
-- Stability   : experimental
-- Portability : portable
--
-----------------------------------------------------------------------------

module Codec.Wavefront.Object where

import Codec.Wavefront.Element
import Codec.Wavefront.Face
import Codec.Wavefront.Lexer ( Ctxt(..) )
import Codec.Wavefront.Line
import Codec.Wavefront.Location
import Codec.Wavefront.Normal
import Codec.Wavefront.Point
import Codec.Wavefront.TexCoord
import Data.DList ( DList, toList )
import Data.Text ( Text )
import Data.Vector ( Vector, fromList )

data WavefrontOBJ = WavefrontOBJ {
    -- |Locations.
    WavefrontOBJ -> Vector Location
objLocations :: Vector Location
    -- |Texture coordinates.
  , WavefrontOBJ -> Vector TexCoord
objTexCoords :: Vector TexCoord
    -- |Normals.
  , WavefrontOBJ -> Vector Normal
objNormals :: Vector Normal
    -- |Points.
  , WavefrontOBJ -> Vector (Element Point)
objPoints :: Vector (Element Point)
    -- |Lines.
  , WavefrontOBJ -> Vector (Element Line)
objLines :: Vector (Element Line)
    -- |Faces.
  , WavefrontOBJ -> Vector (Element Face)
objFaces :: Vector (Element Face)
    -- |Material libraries.
  , WavefrontOBJ -> Vector Text
objMtlLibs :: Vector Text
  } deriving (WavefrontOBJ -> WavefrontOBJ -> Bool
(WavefrontOBJ -> WavefrontOBJ -> Bool)
-> (WavefrontOBJ -> WavefrontOBJ -> Bool) -> Eq WavefrontOBJ
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WavefrontOBJ -> WavefrontOBJ -> Bool
$c/= :: WavefrontOBJ -> WavefrontOBJ -> Bool
== :: WavefrontOBJ -> WavefrontOBJ -> Bool
$c== :: WavefrontOBJ -> WavefrontOBJ -> Bool
Eq,Int -> WavefrontOBJ -> ShowS
[WavefrontOBJ] -> ShowS
WavefrontOBJ -> String
(Int -> WavefrontOBJ -> ShowS)
-> (WavefrontOBJ -> String)
-> ([WavefrontOBJ] -> ShowS)
-> Show WavefrontOBJ
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WavefrontOBJ] -> ShowS
$cshowList :: [WavefrontOBJ] -> ShowS
show :: WavefrontOBJ -> String
$cshow :: WavefrontOBJ -> String
showsPrec :: Int -> WavefrontOBJ -> ShowS
$cshowsPrec :: Int -> WavefrontOBJ -> ShowS
Show)

ctxtToWavefrontOBJ :: Ctxt -> WavefrontOBJ
ctxtToWavefrontOBJ :: Ctxt -> WavefrontOBJ
ctxtToWavefrontOBJ ctxt :: Ctxt
ctxt = WavefrontOBJ :: Vector Location
-> Vector TexCoord
-> Vector Normal
-> Vector (Element Point)
-> Vector (Element Line)
-> Vector (Element Face)
-> Vector Text
-> WavefrontOBJ
WavefrontOBJ {
    objLocations :: Vector Location
objLocations = DList Location -> Vector Location
forall a. DList a -> Vector a
fromDList (Ctxt -> DList Location
ctxtLocations Ctxt
ctxt)
  , objTexCoords :: Vector TexCoord
objTexCoords = DList TexCoord -> Vector TexCoord
forall a. DList a -> Vector a
fromDList (Ctxt -> DList TexCoord
ctxtTexCoords Ctxt
ctxt)
  , objNormals :: Vector Normal
objNormals = DList Normal -> Vector Normal
forall a. DList a -> Vector a
fromDList (Ctxt -> DList Normal
ctxtNormals Ctxt
ctxt)
  , objPoints :: Vector (Element Point)
objPoints = DList (Element Point) -> Vector (Element Point)
forall a. DList a -> Vector a
fromDList (Ctxt -> DList (Element Point)
ctxtPoints Ctxt
ctxt)
  , objLines :: Vector (Element Line)
objLines = DList (Element Line) -> Vector (Element Line)
forall a. DList a -> Vector a
fromDList (Ctxt -> DList (Element Line)
ctxtLines Ctxt
ctxt)
  , objFaces :: Vector (Element Face)
objFaces = DList (Element Face) -> Vector (Element Face)
forall a. DList a -> Vector a
fromDList (Ctxt -> DList (Element Face)
ctxtFaces Ctxt
ctxt)
  , objMtlLibs :: Vector Text
objMtlLibs = DList Text -> Vector Text
forall a. DList a -> Vector a
fromDList (Ctxt -> DList Text
ctxtMtlLibs Ctxt
ctxt)
  }

fromDList :: DList a -> Vector a
fromDList :: DList a -> Vector a
fromDList = [a] -> Vector a
forall a. [a] -> Vector a
fromList ([a] -> Vector a) -> (DList a -> [a]) -> DList a -> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList a -> [a]
forall a. DList a -> [a]
toList