Browse files

weekend hacking... not much progress

  • Loading branch information...
1 parent e05d92e commit 27f2daa2b5b04a8ab2f9cbbd0e0ac185d7c59c69 @metadave committed Apr 1, 2012
Showing with 71 additions and 0 deletions.
  1. +20 −0 cube.obj
  2. +51 −0 obj2json.hs
View
20 cube.obj
@@ -0,0 +1,20 @@
+# Blender v2.59 (sub 0) OBJ File: 'cube.blend'
+# www.blender.org
+mtllib cube.mtl
+o Cube
+v 1.000000 -1.000000 -1.000000
+v 1.000000 -1.000000 1.000000
+v -1.000000 -1.000000 1.000000
+v -1.000000 -1.000000 -1.000000
+v 1.000000 1.000000 -0.999999
+v 0.999999 1.000000 1.000001
+v -1.000000 1.000000 1.000000
+v -1.000000 1.000000 -1.000000
+usemtl Material
+s off
+f 1 2 3 4
+f 5 8 7 6
+f 1 5 6 2
+f 2 6 7 3
+f 3 7 8 4
+f 5 1 4 8
View
51 obj2json.hs
@@ -0,0 +1,51 @@
+module ObjParser where
+
+import Data.Char
+import Data.Maybe
+
+-- raw types
+data RawType =
+ O String |
+ V Float Float Float |
+ VN Float Float Float |
+ F [Integer] |
+ USEMATL String |
+ S String |
+ MTLLIB String
+ deriving (Show,Read)
+
+firstToken :: String -> Maybe String
+firstToken [] = Nothing
+firstToken l = Just h
+ where h = head $ words l
+
+isCommentLine :: Maybe String -> Bool
+isCommentLine Nothing = True
+isCommentLine (Just l) = c == '#'
+ where c = head l
+
+getDataLines :: String -> [String]
+getDataLines contents = filter (not . isCommentLine . firstToken) $ lines contents
+
+
+_processLine :: String -> String -> RawType
+_processLine _ line = read line :: RawType
+
+processLine :: String -> RawType
+processLine l =
+ _processLine ft l
+ where
+ ft = map toUpper $ (fromJust $ firstToken l)
+
+processData :: String -> IO ()
+processData contents =
+ return ()
+ where
+ ls = getDataLines contents
+ mapped = map processLine ls
+
+main :: IO ()
+main = do
+ contents <- readFile "/Users/dparfitt/src/cube.obj"
+ processData contents
+ return ()

0 comments on commit 27f2daa

Please sign in to comment.