summaryrefslogtreecommitdiff
path: root/src/Graphics/WaveFront/Model.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Graphics/WaveFront/Model.hs')
-rw-r--r--src/Graphics/WaveFront/Model.hs12
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)
60import Data.List (groupBy) 60import Data.List (groupBy)
61import Data.Maybe (listToMaybe, catMaybes) 61import Data.Maybe (listToMaybe, catMaybes)
62 62
63import Linear (V2(..), V3(..)) 63import Linear (V2(..), V3(..), V4(..))
64 64
65import Control.Lens ((^.), (.~), (%~), (&), _1, _2, _3) 65import 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
274bounds :: (Num f, Ord f, Foldable m, HasVertices (Model f s i m) (m (V3 f))) => Model f s i m -> BoundingBox (V3 f) 274bounds :: (Num f, Ord f, Foldable m, HasVertices (Model f s i m) (m (V4 f))) => Model f s i m -> BoundingBox (V3 f)
275bounds model = fromExtents $ axisBounds (model^.vertices) <$> V3 x y z 275bounds 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-- |
319unindexedVertices :: Model f Text Int Vector -> Maybe (Vector (V3 f)) 321unindexedVertices :: Model f Text Int Vector -> Maybe (Vector (V4 f))
320unindexedVertices model = sequence $ fromFaceIndices (model^.vertices) (index) (^.ivertex) (model^.faces) 322unindexedVertices 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
329unindexedTexcoords :: Model f Text Int Vector -> Maybe (Vector (V2 f)) 331unindexedTexcoords :: Model f Text Int Vector -> Maybe (Vector (V3 f))
330unindexedTexcoords model = sequence $ fromFaceIndices (model^.texcoords) (index) (^.itexcoord) (model^.faces) 332unindexedTexcoords 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)