summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-06-19 17:38:34 -0400
committerJoe Crayne <joe@jerkface.net>2019-06-19 17:38:34 -0400
commit797f800ab38505f0866a59f0e4ea38ce90d85c32 (patch)
treef374094e8deaf33e962ce143b62aadf2b710a874
parent5024860293943ad598d4d89331bdc1615a862d25 (diff)
Moved addOBJToObjectArray to module LoadMesh.
-rw-r--r--LoadMesh.hs26
-rw-r--r--MeshSketch.hs22
2 files changed, 26 insertions, 22 deletions
diff --git a/LoadMesh.hs b/LoadMesh.hs
index ee93344..7cc61bc 100644
--- a/LoadMesh.hs
+++ b/LoadMesh.hs
@@ -5,6 +5,7 @@ module LoadMesh where
5 5
6import LambdaCube.GL as LC -- renderer 6import LambdaCube.GL as LC -- renderer
7import LambdaCube.GL.Mesh as LambdaCubeGL 7import LambdaCube.GL.Mesh as LambdaCubeGL
8import LambdaCube.GL.Type as LC
8import MtlParser 9import MtlParser
9 10
10import Control.Monad 11import Control.Monad
@@ -24,6 +25,7 @@ import Codec.Picture as Juicy
24import Wavefront 25import Wavefront
25import Wavefront.Types 26import Wavefront.Types
26import Data.Aeson 27import Data.Aeson
28import Mask
27 29
28type MeshData = ( [(Mesh,Maybe Text)] -- List of uniform-material meshes (and the name of the material). 30type MeshData = ( [(Mesh,Maybe Text)] -- List of uniform-material meshes (and the name of the material).
29 , ( MtlLib -- Material definitions. 31 , ( MtlLib -- Material definitions.
@@ -151,3 +153,27 @@ objToMesh OBJ{..} = [(toMesh faceGroup, elMtl . head $ faceGroup) | faceGroup <-
151 , let TexCoord x y z = fromMaybe defaultTexCoord ((objTexCoords !-) =<< faceTexCoordIndex) in V3 x y z 153 , let TexCoord x y z = fromMaybe defaultTexCoord ((objTexCoords !-) =<< faceTexCoordIndex) in V3 x y z
152 ) 154 )
153 (position,normal,texcoord) = V.unzip3 . V.concat . map (V.fromList . map toVertex . triangulate . elValue) $ l 155 (position,normal,texcoord) = V.unzip3 . V.concat . map (V.fromList . map toVertex . triangulate . elValue) $ l
156
157data MaskableObject = MaskableObject
158 { maskableObject :: LC.Object
159 , groupMasks :: Map Text Mask
160 }
161
162objSpan :: LC.Object -> Mask
163objSpan obj = case Map.elems (objAttributes obj) of
164 Stream { streamLength = x }:_ -> Mask [(0,fromIntegral x)]
165 _ -> Mask [(0,1)]
166
167
168
169addOBJToObjectArray :: GLStorage -> String -> [(GPUMesh, Maybe Text)] -> Map Text (ObjMaterial,TextureData)
170 -> IO [MaskableObject]
171addOBJToObjectArray storage slotName objMesh mtlLib = forM objMesh $ \(mesh,mat) -> do
172 obj <- LambdaCubeGL.addMeshToObjectArray storage slotName ["diffuseTexture","diffuseColor"] mesh
173 -- diffuseTexture and diffuseColor values can change on each model
174 case mat >>= flip Map.lookup mtlLib of
175 Nothing -> return ()
176 Just (ObjMaterial{..},t) -> LC.updateObjectUniforms obj $ do
177 "diffuseTexture" @= return t -- set model's diffuse texture
178 "diffuseColor" @= let (r,g,b) = mtl_Kd in return (V4 r g b mtl_Tr)
179 return $ MaskableObject obj $ maybe Map.empty (`Map.singleton` objSpan obj) mat
diff --git a/MeshSketch.hs b/MeshSketch.hs
index 87d9763..d9290fd 100644
--- a/MeshSketch.hs
+++ b/MeshSketch.hs
@@ -141,28 +141,6 @@ realToFracVector :: ( Real a
141 ) => Vector a -> Vector b 141 ) => Vector a -> Vector b
142realToFracVector v = Math.fromList $ map realToFrac $ Math.toList v 142realToFracVector v = Math.fromList $ map realToFrac $ Math.toList v
143 143
144data MaskableObject = MaskableObject
145 { maskableObject :: LC.Object
146 , groupMasks :: Map Text Mask
147 }
148
149objSpan :: LC.Object -> Mask
150objSpan obj = case Map.elems (objAttributes obj) of
151 Stream { streamLength = x }:_ -> Mask [(0,fromIntegral x)]
152 _ -> Mask [(0,1)]
153
154addOBJToObjectArray :: GLStorage -> String -> [(GPUMesh, Maybe Text)] -> Map Text (ObjMaterial,TextureData)
155 -> IO [MaskableObject]
156addOBJToObjectArray storage slotName objMesh mtlLib = forM objMesh $ \(mesh,mat) -> do
157 obj <- LC.addMeshToObjectArray storage slotName ["diffuseTexture","diffuseColor"] mesh
158 -- diffuseTexture and diffuseColor values can change on each model
159 case mat >>= flip Map.lookup mtlLib of
160 Nothing -> return ()
161 Just (ObjMaterial{..},t) -> LC.updateObjectUniforms obj $ do
162 "diffuseTexture" @= return t -- set model's diffuse texture
163 "diffuseColor" @= let (r,g,b) = mtl_Kd in return (V4 r g b mtl_Tr)
164 return $ MaskableObject obj $ maybe Map.empty (`Map.singleton` objSpan obj) mat
165
166mkFullscreenToggle :: IsWindow a => a -> IO (IO ()) 144mkFullscreenToggle :: IsWindow a => a -> IO (IO ())
167mkFullscreenToggle w = do 145mkFullscreenToggle w = do
168 full <- newIORef False 146 full <- newIORef False