diff options
Diffstat (limited to 'src/Wavefront.hs')
-rw-r--r-- | src/Wavefront.hs | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/Wavefront.hs b/src/Wavefront.hs index 51a0e6b..2131d96 100644 --- a/src/Wavefront.hs +++ b/src/Wavefront.hs | |||
@@ -48,12 +48,15 @@ objBookKeeping builder = (lift Rank2.<$> builder) | |||
48 | , points = \xs -> do | 48 | , points = \xs -> do |
49 | n <- gets objLocations | 49 | n <- gets objLocations |
50 | lift $ points builder $ fixupRef n <$> xs | 50 | lift $ points builder $ fixupRef n <$> xs |
51 | incrementCount objPoints $ \x o -> o { objPoints = x } | ||
51 | , line = \ts -> do | 52 | , line = \ts -> do |
52 | o <- get | 53 | o <- get |
53 | lift $ line builder $ fixupTriple o <$> ts | 54 | lift $ line builder $ fixupTriple o <$> ts |
55 | incrementCount objLines $ \x o -> o { objLines = x } | ||
54 | , face = \ts -> do | 56 | , face = \ts -> do |
55 | o <- get | 57 | o <- get |
56 | lift $ face builder $ fixupTriple o <$> ts | 58 | lift $ face builder $ fixupTriple o <$> ts |
59 | incrementCount objFaces $ \x o -> o { objFaces = x } | ||
57 | } | 60 | } |
58 | 61 | ||
59 | mkv :: [Double] -> Location | 62 | mkv :: [Double] -> Location |
@@ -115,26 +118,40 @@ buildOBJ = nullBuilder | |||
115 | modify $ second $ \e -> e { elSmoothingGroup = fromIntegral x } | 118 | modify $ second $ \e -> e { elSmoothingGroup = fromIntegral x } |
116 | } | 119 | } |
117 | 120 | ||
118 | parse :: L.ByteString -> OBJ Vector | 121 | blankElement :: Element () |
119 | parse bs = Rank2.fmap (Vector.fromList . DList.toList) obj | 122 | blankElement = Element |
120 | where | ||
121 | b = objBookKeeping buildOBJ | ||
122 | ls = OBJ | ||
123 | { objLocations = DList.empty | ||
124 | , objTexCoords = DList.empty | ||
125 | , objNormals = DList.empty | ||
126 | , objPoints = DList.empty | ||
127 | , objLines = DList.empty | ||
128 | , objFaces = DList.empty | ||
129 | , objMtlLibs = DList.empty | ||
130 | } | ||
131 | c = Rank2.fmap (const $ Count 0) ls :: OBJ Count | ||
132 | el = Element | ||
133 | { elObject = Nothing | 123 | { elObject = Nothing |
134 | , elGroups = [] | 124 | , elGroups = [] |
135 | , elMtl = Nothing | 125 | , elMtl = Nothing |
136 | , elSmoothingGroup = 0 | 126 | , elSmoothingGroup = 0 |
137 | , elValue = () | 127 | , elValue = () |
138 | } | 128 | } |
129 | |||
130 | emptyCounts :: OBJ Count | ||
131 | emptyCounts = OBJ | ||
132 | { objLocations = Count 0 | ||
133 | , objTexCoords = Count 0 | ||
134 | , objNormals = Count 0 | ||
135 | , objPoints = Count 0 | ||
136 | , objLines = Count 0 | ||
137 | , objFaces = Count 0 | ||
138 | , objMtlLibs = Count 0 | ||
139 | } | ||
140 | |||
141 | mzeroOBJ :: MonadPlus m => OBJ m | ||
142 | mzeroOBJ = OBJ | ||
143 | { objLocations = mzero | ||
144 | , objTexCoords = mzero | ||
145 | , objNormals = mzero | ||
146 | , objPoints = mzero | ||
147 | , objLines = mzero | ||
148 | , objFaces = mzero | ||
149 | , objMtlLibs = mzero | ||
150 | } | ||
151 | |||
152 | parse :: L.ByteString -> OBJ Vector | ||
153 | parse bs = Rank2.fmap (Vector.fromList . DList.toList) obj | ||
154 | where | ||
155 | b = objBookKeeping buildOBJ | ||
139 | substvars = ObjConfig IntMap.empty | 156 | substvars = ObjConfig IntMap.empty |
140 | (obj,_) = execState (runStateT (parseOBJ b substvars bs) c) (ls,el) | 157 | (obj,_) = execState (runStateT (parseOBJ b substvars bs) emptyCounts) (mzeroOBJ,blankElement) |