ply-loader 0.3 → 0.3.1
raw patch · 4 files changed
+26/−4 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ PLY.Types: instance PLYType CDouble
+ PLY.Types: instance PLYType CFloat
+ PLY.Types: instance PLYType CInt
+ PLY.Types: instance PLYType CUChar
Files
- ply-loader.cabal +1/−1
- src/PLY.hs +1/−0
- src/PLY/Internal/Parsers.hs +3/−3
- src/PLY/Types.hs +21/−0
ply-loader.cabal view
@@ -1,5 +1,5 @@ name: ply-loader-version: 0.3+version: 0.3.1 synopsis: PLY file loader. description: PLY is a lightweight file format for representing 3D
src/PLY.hs view
@@ -34,6 +34,7 @@ import qualified Data.ByteString.Char8 as BC import Data.Either (partitionEithers) import Data.Vector (Vector)+import qualified Data.Vector as VB import qualified Data.Vector.Storable as VS import Linear import System.Directory (canonicalizePath)
src/PLY/Internal/Parsers.hs view
@@ -2,8 +2,8 @@ module PLY.Internal.Parsers where import Control.Applicative import Data.Attoparsec.Char8 hiding (char)-import qualified Data.Attoparsec.ByteString as B import Data.ByteString (ByteString)+import qualified Data.ByteString.Char8 as BC import PLY.Types -- |Skip white space, comments, and obj_info lines.@@ -43,7 +43,7 @@ -- | Take everything up to the end of the line line :: Parser ByteString-line = B.takeTill isEndOfLine+line = BC.pack <$> manyTill anyChar endOfLine scalarProperty :: Parser Property scalarProperty = ScalarProperty <$> ("property " .*> scalarType) <*> line@@ -97,7 +97,7 @@ go acc (ScalarProperty t _:ps) = do !x <- parseScalar t skipSpace go (x:acc) ps- go _ (ListProperty t _:_) = int >>= flip count (parseScalar t)+ go _ (ListProperty t _:_) = int <* skipSpace >>= flip count (parseScalar t) -- FIXME: Support for list properties assumes that an element will not -- have any other properties if it has a list property!
src/PLY/Types.hs view
@@ -4,6 +4,7 @@ import Data.ByteString (ByteString) import Data.Int import Data.Word+import Foreign.C.Types (CFloat, CDouble, CInt, CUChar) import Foreign.Storable (Storable) data Format = ASCII | Binary_LE | Binary_BE deriving Show@@ -38,17 +39,37 @@ unsafeUnwrap (Sfloat x) = x unsafeUnwrap y = error $ "Tried to unwrap "++show y++" as a Float" +instance PLYType CFloat where+ plyType _ = Tfloat+ unsafeUnwrap (Sfloat x) = realToFrac x+ unsafeUnwrap y = error $ "Tried to unwrap "++show y++" as a CFloat"+ instance PLYType Double where plyType _ = Tdouble unsafeUnwrap (Sdouble x) = x unsafeUnwrap y = error $ "Tried to unwrap "++show y++" as a Double" +instance PLYType CDouble where+ plyType _ = Tdouble+ unsafeUnwrap (Sdouble x) = realToFrac x+ unsafeUnwrap y = error $ "Tried to unwrap "++show y++" as a CDouble"+ instance PLYType Int where plyType _ = Tint unsafeUnwrap (Sint x) = x unsafeUnwrap y = error $ "Tried to unwrap "++show y++" as an Int" +instance PLYType CInt where+ plyType _ = Tint+ unsafeUnwrap (Sint x) = fromIntegral x+ unsafeUnwrap y = error $ "Tried to unwrap "++show y++" as an CInt"+ instance PLYType Word8 where plyType _ = Tuchar unsafeUnwrap (Suchar x) = x unsafeUnwrap y = error $ "Tried to unwrap "++show y++" as a Word8"++instance PLYType CUChar where+ plyType _ = Tuchar+ unsafeUnwrap (Suchar x) = fromIntegral x+ unsafeUnwrap y = error $ "Tried to unwrap "++show y++" as a CUChar"