diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2010-04-12 02:17:42 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2010-04-12 02:17:42 +0200 |
commit | 68d71025f47fd3d4d2c1e4d4dcda2180f2565ddd (patch) | |
tree | 87ccf62c566bc5a23561f4ee1d64638d148b3487 | |
parent | 67e1d2569baa712c40be26998dd3661ad8f3caa4 (diff) | |
download | obj-model-master.tar obj-model-master.zip |
-rw-r--r-- | src/Data/Obj3D.hs | 9 | ||||
-rw-r--r-- | src/Data/Obj3D/Parser.hs | 20 |
2 files changed, 15 insertions, 14 deletions
diff --git a/src/Data/Obj3D.hs b/src/Data/Obj3D.hs index c25deb8..4ef8151 100644 --- a/src/Data/Obj3D.hs +++ b/src/Data/Obj3D.hs @@ -1,9 +1,10 @@ -module Data.Obj3D ( processObj +module Data.Obj3D ( ObjModel(..) + , processObj , loadObj , loadObjFile , Vertex , VertexNormal - , TexCoords + , TexCoord , FaceVertex , Face , SourceName @@ -18,7 +19,7 @@ import Data.Obj3D.Parser data ObjModel = ObjModel { objVertices :: [Vertex] - , objTexCoords :: [TexCoords] + , objTexCoords :: [TexCoord] , objNormals :: [VertexNormal] , objFaces :: [[Face]] } deriving Show @@ -36,7 +37,7 @@ processObj objlines = ObjModel vertex _ = Nothing texcoords = catMaybes $ map texcoord objlines - texcoord (TexCoordsLine v) = Just v + texcoord (TexCoordLine v) = Just v texcoord _ = Nothing diff --git a/src/Data/Obj3D/Parser.hs b/src/Data/Obj3D/Parser.hs index 2d3dbce..408eab5 100644 --- a/src/Data/Obj3D/Parser.hs +++ b/src/Data/Obj3D/Parser.hs @@ -1,6 +1,6 @@ module Data.Obj3D.Parser ( Vertex , VertexNormal - , TexCoords + , TexCoord , FaceVertex , Face , ObjLine(..) @@ -15,16 +15,16 @@ import Text.ParserCombinators.Parsec hiding (space, spaces, Parser) type Vertex = (Float, Float, Float) type VertexNormal = (Float, Float, Float) -type TexCoords = (Float, Float) +type TexCoord = (Float, Float) type FaceVertex = (Integer, Maybe Integer, Maybe Integer) type Face = (FaceVertex, FaceVertex, FaceVertex) -data ObjLine = VertexLine Vertex | TexCoordsLine TexCoords | VertexNormalLine VertexNormal | FaceLine Face | ObjectLine String | UnknownLine String | EmptyLine +data ObjLine = VertexLine Vertex | TexCoordLine TexCoord | VertexNormalLine VertexNormal | FaceLine Face | ObjectLine String | UnknownLine String | EmptyLine deriving Show data ParserState = ParserState { vertexCount :: Integer - , texCoordsCount :: Integer + , texCoordCount :: Integer , vertexNormalCount :: Integer } @@ -73,7 +73,7 @@ faceVertex = do v <- liftM (subtract 1) $ relativeInteger $ vertexCount state (t, n) <- option (Nothing, Nothing) $ do char '/' - t <- option Nothing $ liftM (Just . subtract 1) $ relativeInteger $ texCoordsCount state + t <- option Nothing $ liftM (Just . subtract 1) $ relativeInteger $ texCoordCount state n <- option Nothing $ do char '/' option Nothing $ liftM (Just . subtract 1) $ relativeInteger $ vertexNormalCount state @@ -101,8 +101,8 @@ vertexLine = do updateState $ \state -> state {vertexCount = 1 + vertexCount state} return $ VertexLine (x, y, z) -texCoordsLine :: Parser ObjLine -texCoordsLine = do +texCoordLine :: Parser ObjLine +texCoordLine = do try $ do string "vt" spaces @@ -112,8 +112,8 @@ texCoordsLine = do optional $ do spaces float - updateState $ \state -> state {texCoordsCount = 1 + texCoordsCount state} - return $ TexCoordsLine (u, v) + updateState $ \state -> state {texCoordCount = 1 + texCoordCount state} + return $ TexCoordLine (u, v) vertexNormalLine :: Parser ObjLine vertexNormalLine = do @@ -157,7 +157,7 @@ emptyLine = return EmptyLine line :: Parser ObjLine line = do optional spaces - l <- vertexLine <|> texCoordsLine <|> vertexNormalLine <|> faceLine <|> objectLine <|> anyLine <|> emptyLine + l <- vertexLine <|> texCoordLine <|> vertexNormalLine <|> faceLine <|> objectLine <|> anyLine <|> emptyLine optional spaces optional comment newline |