WaveFront 0.1.0.0 → 0.1.0.1
raw patch · 5 files changed
+11/−177 lines, 5 files
Files
- WaveFront.cabal +1/−1
- src/Graphics/WaveFront/Foreign.hs +2/−28
- src/Graphics/WaveFront/Load.hs +2/−1
- src/Graphics/WaveFront/Parsers.hs +3/−146
- src/Graphics/WaveFront/Utilities.hs +3/−1
WaveFront.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.1.0.0 +version: 0.1.0.1 -- A short (one-line) description of the package. synopsis: Parsers and utilities for the OBJ WaveFront 3D model format
src/Graphics/WaveFront/Foreign.hs view
@@ -36,41 +36,15 @@ import Foreign.Storable import qualified Foreign.C as C +import Graphics.WaveFront.Types import qualified Graphics.WaveFront.Parsers as Parsers -------------------------------------------------------------------------------------------------------------------------------------------- --- Types --------------------------------------------------------------------------------------------------------------------------------------------- --- | -newtype COBJ = COBJ Parsers.OBJ - - --- | -newtype CMTL = CMTL Parsers.MTL - - --- | We -instance Storable COBJ where - sizeOf = const 0 - alignment = const 0 - peek _ = error "Work in progress" - poke _ = error "Work in progress" - - --- | We -instance Storable CMTL where - sizeOf = const 0 - alignment = const 0 - peek _ = error "Work in progress" - poke _ = error "Work in progress" - - - --------------------------------------------------------------------------------------------------------------------------------------------- -- Functions -------------------------------------------------------------------------------------------------------------------------------------------- + -- | -- I feel dirty... parseOBJ :: C.CString -> COBJ
src/Graphics/WaveFront/Load.hs view
@@ -38,7 +38,8 @@ import Data.Either (rights, isLeft) -import Graphics.WaveFront.Parsers (parseOBJ, parseMTL, createMTLTable, createModel, OBJ(), MTL(), MTLTable(), OBJToken(LibMTL), Model()) +import Graphics.WaveFront.Types +import Graphics.WaveFront.Parsers (parseOBJ, parseMTL, createMTLTable, createModel) import Graphics.WaveFront.Utilities
src/Graphics/WaveFront/Parsers.hs view
@@ -86,141 +86,15 @@ -- import Southpaw.Utilities.Utilities (pairwise, cuts) +import Graphics.WaveFront.Types import Graphics.WaveFront.Utilities - -------------------------------------------------------------------------------------------------------------------------------------------- --- Types --------------------------------------------------------------------------------------------------------------------------------------------- --- OBJ parser types ------------------------------------------------------------------------------------------------------------------------ --- | Represents a single (valid) OBJ token --- --- TODO: Polymorphic numerical types (?) --- TODO: Add context, metadata (eg. line numbers, filename) (?) --- TODO: Naming scheme (added OBJ prefix to prevent name clashes; cf. Face type) --- TODO: Comment token (preserve comments in parser output or remove them) (?) -data OBJToken = OBJVertex Float Float Float | - OBJNormal Float Float Float | - OBJTexture Float Float | - OBJFace [(Int, Maybe Int, Maybe Int)] | -- TODO: Associate material with each face, handle absent indices - - UseMTL String | -- - LibMTL String | -- TODO: Use actual MTL type - - Group [String] | -- TODO: Do grouped faces have to be consecutive? - Object [String] -- TODO: What is the difference between group and object? - deriving (Eq, Show) -- TODO: Derive Read (?) - - --- | --- TODO: Rename (?) -data OBJNoParse = OBJComment String | OBJEmpty | OBJNoSuchAttribute String | OBJNoParse String deriving (Show) - - --- | --- TODO: Use error type instead of String, allowing us to distinguish invalid data --- from eg. comments and blank lines (?) -type OBJRow = (Int, Either OBJNoParse OBJToken, String) - - --- | Output type of the OBJ parser. Currently a list of line number and token (or error string) pairs --- --- TODO: Rename (?) --- TODO: Use Integral for line number (?) --- -type OBJ = [OBJRow] - - --- MTL parser types ------------------------------------------------------------------------------------------------------------------------ --- | Represents a single (valid) MTL token --- --- TODO: Is the alpha channel optional, ignored, disallowed? --- TODO: Include support for ('Ns', 'Ni', 'd', 'Tr', 'illum') --- -data MTLToken = Ambient Float Float Float (Maybe Float) | -- Ka - Diffuse Float Float Float (Maybe Float) | -- Kd - Specular Float Float Float (Maybe Float) | -- Ks - - MapDiffuse String | -- map_Kd - NewMaterial String -- newmtl - deriving (Eq, Show) - - --- | --- TODO: Rename (?) -data MTLNoParse = MTLComment String | MTLEmpty | MTLNoSuchAttribute String | MTLNoParse String deriving (Show) - - --- | Output type of the single-row MTL parser. -type MTLRow = (Int, Either MTLNoParse MTLToken, String) - - --- | Output type of the MTL parser. Currently a list of line number and token (or error string) pairs --- --- TODO: Add type for processed MTL (eg. a map between names and materials) --- -type MTL = [MTLRow] -- (line number, MTL token, comment) - - --- | -type MTLTable = Map.Map String (Map.Map String Material) - - --- General types --------------------------------------------------------------------------------------------------------------------------- - -type Vector num = (num, num, num) -- Queen Vectoria -type Point num = (num, num) -- Haskell is no longer Point-free - --- API types ------------------------------------------------------------------------------------------------------------------------------- - --- | --- TODO: Validation (eg. length ivertices == length == ivertices == length itextures if length isn't 0) --- TOOD: Pack indices in a tuple (eg. indices :: [(Int, Int, Int)]) (?) --- TOOD: Use (String, String) for the names of the mtl file and material instead of Material (?) --- TODO: Use types so as not to confuse the indices (eg. newtype INormal, newtype ITexcoord) -data Face = Face { indices :: [(Int, Maybe Int, Maybe Int)], material :: Material } deriving (Show) - - --- | -type Colour = (Float, Float, Float, Float) - - --- | --- TODO: Do all materials have an ambient, a diffuse and a specular colour (?) --- TODO: Support more attributes (entire spec) (?) --- TODO: Lenses (?) -data Material = Material { ambient :: Colour, diffuse :: Colour, specular :: Colour, texture :: Maybe String } deriving (Show) - - --- | Abstract representation of an OBJ model with associated MTL definitions. --- --- TODO: Rename (?) --- TODO: Include metadata, comments, rejected data (?) --- TODO: Separate type for processed OBJTokens (ie. token + context) --- TODO: Perform index lookups (?) --- TODO: Reconsider the types (especially of the materials) --- TODO: Rename accessor functions (eg. texcoords instead of textures) (?) --- -data Model = Model { vertices :: [Vector Float], - normals :: [Vector Float], - texcoords :: [Point Float], - faces :: [Face], - materials :: MTLTable, -- TODO: Type synonym (?) - groups :: Map.Map [String] (Int, Int), -- TODO: Type synonym - objects :: Map.Map [String] (Int, Int) -- TODO: Type synonym - } deriving (Show) - - --- | -data BoundingBox n = BoundingBox { left :: n, right :: n, top :: n, bottom :: n, front :: n, back :: n } - - - --------------------------------------------------------------------------------------------------------------------------------------------- -- Functions (pure) -------------------------------------------------------------------------------------------------------------------------------------------- + -- OBJ parsing ----------------------------------------------------------------------------------------------------------------------------- -- | This function creates an OBJToken or error for each line in the input data @@ -405,7 +279,7 @@ -- | -- TODO: Use map for materials (?) -- TODO: How to retrieve MTL data --- TODO: How to deal with errors, including no-parse, index errors, etc. +-- TODO: How to deal with errors, including no-parse, index errors, etc. (use applicative?) -- TODO: Performance, how are 'copies' of coordinates handled (?) -- TODO: Performance, one pass (with a fold perhaps) -- TODO: Use a more efficient data structure (especially w.r.t indexing; cf. Vector) @@ -426,23 +300,6 @@ groups = groupsOf modeldata, objects = objectsOf modeldata, materials = thematerials } - - --- | --- data Attributes = Attributes { - -- vertexdata :: Vertices - -- texcoorddata :: TexCoords --- } - --- newtype Vertices = Vertices [Vector Float] --- newtype TexCoords = TexCoords [Maybe (Point Float)] --- newtype Normals = Normals [Maybe (Vector Float)] --- newtype Materials = Materials [Material] - -type Vertices = [Vector Float] -type TexCoords = [Maybe (Point Float)] -type Normals = [Maybe (Vector Float)] -type Materials = [Material] -- | Extracts vertex, normal, texture and material data from a model
src/Graphics/WaveFront/Utilities.hs view
@@ -37,7 +37,9 @@ -------------------------------------------------------------------------------------------------------------------------------------------- -- Functions -------------------------------------------------------------------------------------------------------------------------------------------- + -- Parsing utilities ----------------------------------------------------------------------------------------------------------------------- + -- | This strikes me as overly convoluted. Should probably be refactored or removed entirely. parseTokenWith :: String -> (String -> Either e token) -> Int -> (Int, Either e token, String) parseTokenWith line parse = withoutComment line parse @@ -78,7 +80,7 @@ -- TODO: Higher order function for composing predicates rows :: String -> [String] rows = filter (not . satisfiesAny [null, isComment]) . lines - where satisfiesAny predicates x = any ($ x) predicates + where satisfiesAny ps x = any ($ x) ps -- |