Some minor changes
This commit is contained in:
parent
67e1d2569b
commit
68d71025f4
2 changed files with 15 additions and 14 deletions
|
@ -1,9 +1,10 @@
|
||||||
module Data.Obj3D ( processObj
|
module Data.Obj3D ( ObjModel(..)
|
||||||
|
, processObj
|
||||||
, loadObj
|
, loadObj
|
||||||
, loadObjFile
|
, loadObjFile
|
||||||
, Vertex
|
, Vertex
|
||||||
, VertexNormal
|
, VertexNormal
|
||||||
, TexCoords
|
, TexCoord
|
||||||
, FaceVertex
|
, FaceVertex
|
||||||
, Face
|
, Face
|
||||||
, SourceName
|
, SourceName
|
||||||
|
@ -18,7 +19,7 @@ import Data.Obj3D.Parser
|
||||||
|
|
||||||
data ObjModel = ObjModel
|
data ObjModel = ObjModel
|
||||||
{ objVertices :: [Vertex]
|
{ objVertices :: [Vertex]
|
||||||
, objTexCoords :: [TexCoords]
|
, objTexCoords :: [TexCoord]
|
||||||
, objNormals :: [VertexNormal]
|
, objNormals :: [VertexNormal]
|
||||||
, objFaces :: [[Face]]
|
, objFaces :: [[Face]]
|
||||||
} deriving Show
|
} deriving Show
|
||||||
|
@ -36,7 +37,7 @@ processObj objlines = ObjModel
|
||||||
vertex _ = Nothing
|
vertex _ = Nothing
|
||||||
|
|
||||||
texcoords = catMaybes $ map texcoord objlines
|
texcoords = catMaybes $ map texcoord objlines
|
||||||
texcoord (TexCoordsLine v) = Just v
|
texcoord (TexCoordLine v) = Just v
|
||||||
texcoord _ = Nothing
|
texcoord _ = Nothing
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Data.Obj3D.Parser ( Vertex
|
module Data.Obj3D.Parser ( Vertex
|
||||||
, VertexNormal
|
, VertexNormal
|
||||||
, TexCoords
|
, TexCoord
|
||||||
, FaceVertex
|
, FaceVertex
|
||||||
, Face
|
, Face
|
||||||
, ObjLine(..)
|
, ObjLine(..)
|
||||||
|
@ -15,16 +15,16 @@ import Text.ParserCombinators.Parsec hiding (space, spaces, Parser)
|
||||||
|
|
||||||
type Vertex = (Float, Float, Float)
|
type Vertex = (Float, Float, Float)
|
||||||
type VertexNormal = (Float, Float, Float)
|
type VertexNormal = (Float, Float, Float)
|
||||||
type TexCoords = (Float, Float)
|
type TexCoord = (Float, Float)
|
||||||
type FaceVertex = (Integer, Maybe Integer, Maybe Integer)
|
type FaceVertex = (Integer, Maybe Integer, Maybe Integer)
|
||||||
type Face = (FaceVertex, FaceVertex, FaceVertex)
|
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
|
deriving Show
|
||||||
|
|
||||||
data ParserState = ParserState
|
data ParserState = ParserState
|
||||||
{ vertexCount :: Integer
|
{ vertexCount :: Integer
|
||||||
, texCoordsCount :: Integer
|
, texCoordCount :: Integer
|
||||||
, vertexNormalCount :: Integer
|
, vertexNormalCount :: Integer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ faceVertex = do
|
||||||
v <- liftM (subtract 1) $ relativeInteger $ vertexCount state
|
v <- liftM (subtract 1) $ relativeInteger $ vertexCount state
|
||||||
(t, n) <- option (Nothing, Nothing) $ do
|
(t, n) <- option (Nothing, Nothing) $ do
|
||||||
char '/'
|
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
|
n <- option Nothing $ do
|
||||||
char '/'
|
char '/'
|
||||||
option Nothing $ liftM (Just . subtract 1) $ relativeInteger $ vertexNormalCount state
|
option Nothing $ liftM (Just . subtract 1) $ relativeInteger $ vertexNormalCount state
|
||||||
|
@ -101,8 +101,8 @@ vertexLine = do
|
||||||
updateState $ \state -> state {vertexCount = 1 + vertexCount state}
|
updateState $ \state -> state {vertexCount = 1 + vertexCount state}
|
||||||
return $ VertexLine (x, y, z)
|
return $ VertexLine (x, y, z)
|
||||||
|
|
||||||
texCoordsLine :: Parser ObjLine
|
texCoordLine :: Parser ObjLine
|
||||||
texCoordsLine = do
|
texCoordLine = do
|
||||||
try $ do
|
try $ do
|
||||||
string "vt"
|
string "vt"
|
||||||
spaces
|
spaces
|
||||||
|
@ -112,8 +112,8 @@ texCoordsLine = do
|
||||||
optional $ do
|
optional $ do
|
||||||
spaces
|
spaces
|
||||||
float
|
float
|
||||||
updateState $ \state -> state {texCoordsCount = 1 + texCoordsCount state}
|
updateState $ \state -> state {texCoordCount = 1 + texCoordCount state}
|
||||||
return $ TexCoordsLine (u, v)
|
return $ TexCoordLine (u, v)
|
||||||
|
|
||||||
vertexNormalLine :: Parser ObjLine
|
vertexNormalLine :: Parser ObjLine
|
||||||
vertexNormalLine = do
|
vertexNormalLine = do
|
||||||
|
@ -157,7 +157,7 @@ emptyLine = return EmptyLine
|
||||||
line :: Parser ObjLine
|
line :: Parser ObjLine
|
||||||
line = do
|
line = do
|
||||||
optional spaces
|
optional spaces
|
||||||
l <- vertexLine <|> texCoordsLine <|> vertexNormalLine <|> faceLine <|> objectLine <|> anyLine <|> emptyLine
|
l <- vertexLine <|> texCoordLine <|> vertexNormalLine <|> faceLine <|> objectLine <|> anyLine <|> emptyLine
|
||||||
optional spaces
|
optional spaces
|
||||||
optional comment
|
optional comment
|
||||||
newline
|
newline
|
||||||
|
|
Reference in a new issue