diff options
Diffstat (limited to 'src/Graphics/WaveFront/Model.hs')
-rw-r--r-- | src/Graphics/WaveFront/Model.hs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Graphics/WaveFront/Model.hs b/src/Graphics/WaveFront/Model.hs index 96172a8..dfd90ef 100644 --- a/src/Graphics/WaveFront/Model.hs +++ b/src/Graphics/WaveFront/Model.hs | |||
@@ -60,7 +60,7 @@ import Data.Set (Set) | |||
60 | import Data.List (groupBy) | 60 | import Data.List (groupBy) |
61 | import Data.Maybe (listToMaybe, catMaybes) | 61 | import Data.Maybe (listToMaybe, catMaybes) |
62 | 62 | ||
63 | import Linear (V2(..), V3(..)) | 63 | import Linear (V2(..), V3(..), V4(..)) |
64 | 64 | ||
65 | import Control.Lens ((^.), (.~), (%~), (&), _1, _2, _3) | 65 | import Control.Lens ((^.), (.~), (%~), (&), _1, _2, _3) |
66 | 66 | ||
@@ -271,14 +271,16 @@ tessellate = indices %~ triangles | |||
271 | -- - Refactor | 271 | -- - Refactor |
272 | -- - Folding over applicative (fold in parallel) | 272 | -- - Folding over applicative (fold in parallel) |
273 | -- - Make sure the order is right | 273 | -- - Make sure the order is right |
274 | bounds :: (Num f, Ord f, Foldable m, HasVertices (Model f s i m) (m (V3 f))) => Model f s i m -> BoundingBox (V3 f) | 274 | bounds :: (Num f, Ord f, Foldable m, HasVertices (Model f s i m) (m (V4 f))) => Model f s i m -> BoundingBox (V3 f) |
275 | bounds model = fromExtents $ axisBounds (model^.vertices) <$> V3 x y z | 275 | bounds model = fromExtents $ axisBounds (model^.vertices) <$> V3 x y z |
276 | where | 276 | where |
277 | -- TODO | - Factor out 'minmax' | 277 | -- TODO | - Factor out 'minmax' |
278 | minmaxBy :: (Ord o, Num o, Foldable m) => (a -> o) -> m a -> (o, o) | 278 | minmaxBy :: (Ord o, Num o, Foldable m) => (a -> o) -> m a -> (o, o) |
279 | minmaxBy f values = foldr (\val' acc -> let val = f val' in (min val (fst acc), max val (snd acc))) (0, 0) values -- TODO: Factor out | 279 | minmaxBy f values = foldr (\val' acc -> let val = f val' in (min val (fst acc), max val (snd acc))) (0, 0) values -- TODO: Factor out |
280 | 280 | ||
281 | axisBounds vs axis = minmaxBy (^.axis) vs | 281 | axisBounds vs axis = minmaxBy ((^.axis) . proj) vs |
282 | |||
283 | proj (V4 x y z _) = V3 x y z | ||
282 | 284 | ||
283 | -- Orphaned TODOs? | 285 | -- Orphaned TODOs? |
284 | 286 | ||
@@ -316,7 +318,7 @@ diffuseColours faces' = V.concatMap (\f -> V.replicate (V.length $ f^.indices) ( | |||
316 | -- - Add docstrings | 318 | -- - Add docstrings |
317 | 319 | ||
318 | -- | | 320 | -- | |
319 | unindexedVertices :: Model f Text Int Vector -> Maybe (Vector (V3 f)) | 321 | unindexedVertices :: Model f Text Int Vector -> Maybe (Vector (V4 f)) |
320 | unindexedVertices model = sequence $ fromFaceIndices (model^.vertices) (index) (^.ivertex) (model^.faces) | 322 | unindexedVertices model = sequence $ fromFaceIndices (model^.vertices) (index) (^.ivertex) (model^.faces) |
321 | where | 323 | where |
322 | index coords i = coords !? (i-1) | 324 | index coords i = coords !? (i-1) |
@@ -326,7 +328,7 @@ unindexedNormals model = sequence $ fromFaceIndices (model^.normals) (index) (^. | |||
326 | where | 328 | where |
327 | index coords mi = mi >>= \i -> coords !? (i-1) | 329 | index coords mi = mi >>= \i -> coords !? (i-1) |
328 | 330 | ||
329 | unindexedTexcoords :: Model f Text Int Vector -> Maybe (Vector (V2 f)) | 331 | unindexedTexcoords :: Model f Text Int Vector -> Maybe (Vector (V3 f)) |
330 | unindexedTexcoords model = sequence $ fromFaceIndices (model^.texcoords) (index) (^.itexcoord) (model^.faces) | 332 | unindexedTexcoords model = sequence $ fromFaceIndices (model^.texcoords) (index) (^.itexcoord) (model^.faces) |
331 | where | 333 | where |
332 | index coords mi = mi >>= \i -> coords !? (i-1) | 334 | index coords mi = mi >>= \i -> coords !? (i-1) |