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

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