summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/Obj3D.hs9
-rw-r--r--src/Data/Obj3D/Parser.hs20
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