diff options
author | Joe Crayne <joe@jerkface.net> | 2019-06-19 17:38:34 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-06-19 17:38:34 -0400 |
commit | 797f800ab38505f0866a59f0e4ea38ce90d85c32 (patch) | |
tree | f374094e8deaf33e962ce143b62aadf2b710a874 | |
parent | 5024860293943ad598d4d89331bdc1615a862d25 (diff) |
Moved addOBJToObjectArray to module LoadMesh.
-rw-r--r-- | LoadMesh.hs | 26 | ||||
-rw-r--r-- | MeshSketch.hs | 22 |
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 | ||
6 | import LambdaCube.GL as LC -- renderer | 6 | import LambdaCube.GL as LC -- renderer |
7 | import LambdaCube.GL.Mesh as LambdaCubeGL | 7 | import LambdaCube.GL.Mesh as LambdaCubeGL |
8 | import LambdaCube.GL.Type as LC | ||
8 | import MtlParser | 9 | import MtlParser |
9 | 10 | ||
10 | import Control.Monad | 11 | import Control.Monad |
@@ -24,6 +25,7 @@ import Codec.Picture as Juicy | |||
24 | import Wavefront | 25 | import Wavefront |
25 | import Wavefront.Types | 26 | import Wavefront.Types |
26 | import Data.Aeson | 27 | import Data.Aeson |
28 | import Mask | ||
27 | 29 | ||
28 | type MeshData = ( [(Mesh,Maybe Text)] -- List of uniform-material meshes (and the name of the material). | 30 | type 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 | |||
157 | data MaskableObject = MaskableObject | ||
158 | { maskableObject :: LC.Object | ||
159 | , groupMasks :: Map Text Mask | ||
160 | } | ||
161 | |||
162 | objSpan :: LC.Object -> Mask | ||
163 | objSpan obj = case Map.elems (objAttributes obj) of | ||
164 | Stream { streamLength = x }:_ -> Mask [(0,fromIntegral x)] | ||
165 | _ -> Mask [(0,1)] | ||
166 | |||
167 | |||
168 | |||
169 | addOBJToObjectArray :: GLStorage -> String -> [(GPUMesh, Maybe Text)] -> Map Text (ObjMaterial,TextureData) | ||
170 | -> IO [MaskableObject] | ||
171 | addOBJToObjectArray 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 |
142 | realToFracVector v = Math.fromList $ map realToFrac $ Math.toList v | 142 | realToFracVector v = Math.fromList $ map realToFrac $ Math.toList v |
143 | 143 | ||
144 | data MaskableObject = MaskableObject | ||
145 | { maskableObject :: LC.Object | ||
146 | , groupMasks :: Map Text Mask | ||
147 | } | ||
148 | |||
149 | objSpan :: LC.Object -> Mask | ||
150 | objSpan obj = case Map.elems (objAttributes obj) of | ||
151 | Stream { streamLength = x }:_ -> Mask [(0,fromIntegral x)] | ||
152 | _ -> Mask [(0,1)] | ||
153 | |||
154 | addOBJToObjectArray :: GLStorage -> String -> [(GPUMesh, Maybe Text)] -> Map Text (ObjMaterial,TextureData) | ||
155 | -> IO [MaskableObject] | ||
156 | addOBJToObjectArray 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 | |||
166 | mkFullscreenToggle :: IsWindow a => a -> IO (IO ()) | 144 | mkFullscreenToggle :: IsWindow a => a -> IO (IO ()) |
167 | mkFullscreenToggle w = do | 145 | mkFullscreenToggle w = do |
168 | full <- newIORef False | 146 | full <- newIORef False |