summaryrefslogtreecommitdiff
path: root/LoadMesh.hs
diff options
context:
space:
mode:
Diffstat (limited to 'LoadMesh.hs')
-rw-r--r--LoadMesh.hs43
1 files changed, 30 insertions, 13 deletions
diff --git a/LoadMesh.hs b/LoadMesh.hs
index cda6349..d8ce42b 100644
--- a/LoadMesh.hs
+++ b/LoadMesh.hs
@@ -126,8 +126,6 @@ uploadOBJToGPU :: Maybe BoundingBox -> MeshData -> IO ([MaterialMesh GPUMesh],Ma
126uploadOBJToGPU scalebb (subModels,(mtlLib,objpath)) = do 126uploadOBJToGPU scalebb (subModels,(mtlLib,objpath)) = do
127 let meshbb = foldMap (attribBoundingBox . mAttributes . materialMesh) subModels :: BoundingBox 127 let meshbb = foldMap (attribBoundingBox . mAttributes . materialMesh) subModels :: BoundingBox
128 m = maybe (ident 4) (scaleWithin meshbb) scalebb 128 m = maybe (ident 4) (scaleWithin meshbb) scalebb
129 -- BoundingBox {minX = -6.44698, maxX = 6.44698, minY = 0.0, maxY = 1.0e9, minZ = -0.768655, maxZ = 1.0e8}
130 -- BoundingBox {minX = -6.44698, maxX = 6.44698, minY = 0.0, maxY = 18.2027, minZ = -0.768655, maxZ = 2.238049}
131 putStrLn $ show meshbb 129 putStrLn $ show meshbb
132 gpuSubModels <- forM subModels $ \matmesh -> do 130 gpuSubModels <- forM subModels $ \matmesh -> do
133 a <- LambdaCubeGL.uploadMeshToGPU (transformMesh m (materialMesh matmesh)) 131 a <- LambdaCubeGL.uploadMeshToGPU (transformMesh m (materialMesh matmesh))
@@ -204,25 +202,44 @@ objSpan obj = case Map.elems (objAttributes obj) of
204 _ -> Mask [(0,1)] 202 _ -> Mask [(0,1)]
205 203
206 204
207searchMaterial :: V.Vector (Map Text (ObjMaterial, TextureData)) 205searchMaterial
208 -> (Int, Text) 206 :: V.Vector (Map Text (ObjMaterial, TextureData)) -- ^ Some tail end of this vector will be searched.
209 -> Maybe (ObjMaterial, TextureData) 207 -> (Int, Text) -- ^ Size of tail and material name to search for.
208 -> Maybe (ObjMaterial, TextureData)
210searchMaterial mtlLib (count,name) = foldr go id (V.drop (V.length mtlLib - count) mtlLib) Nothing 209searchMaterial mtlLib (count,name) = foldr go id (V.drop (V.length mtlLib - count) mtlLib) Nothing
211 where 210 where
212 go m f r = case Map.lookup name m of 211 go m f r = case Map.lookup name m of
213 Nothing -> f r 212 Nothing -> f r
214 x -> x :: Maybe (ObjMaterial,TextureData) 213 x -> x :: Maybe (ObjMaterial,TextureData)
215 214
216addOBJToObjectArray :: GLStorage -> String -> [MaterialMesh GPUMesh] -> V.Vector (Map Text (ObjMaterial,TextureData)) 215addOBJToObjectArray :: GLStorage -> String
216 -> [MaterialMesh GPUMesh]
217 -> V.Vector (Map Text (ObjMaterial,TextureData))
217 -> IO [MaskableObject] 218 -> IO [MaskableObject]
218addOBJToObjectArray storage slotName objMesh mtlLib = forM objMesh $ \matmesh -> do 219addOBJToObjectArray storage slotName objMesh mtlLib = forM objMesh $ \matmesh -> do
219 obj <- LambdaCubeGL.addMeshToObjectArray storage slotName ["diffuseTexture","diffuseColor"] (materialMesh matmesh) 220 obj <- case materialName matmesh >>= searchMaterial mtlLib of
220 -- diffuseTexture and diffuseColor values can change on each model 221 Nothing -> do
221 case materialName matmesh >>= searchMaterial mtlLib of 222 let slotnm = slotName ++ "0"
222 Nothing -> return () 223 obj <- LambdaCubeGL.addMeshToObjectArray storage
223 Just (ObjMaterial{..},t) -> LC.updateObjectUniforms obj $ do 224 slotnm
224 "diffuseTexture" @= return t -- set model's diffuse texture 225 [ "diffuseTexture"
225 "diffuseColor" @= let (r,g,b) = mtl_Kd in return (V4 r g b mtl_Tr) 226 , "diffuseColor"
227 , "specularReflectivity"]
228 (materialMesh matmesh)
229 return obj
230 Just (ObjMaterial{..},t) -> do
231 let slotnm = slotName ++ show (if 0 <= mtl_illum && mtl_illum <= 2 then mtl_illum else 2)
232 obj <- LambdaCubeGL.addMeshToObjectArray storage
233 slotnm
234 [ "diffuseTexture"
235 , "diffuseColor"
236 , "specularReflectivity"]
237 (materialMesh matmesh)
238 LC.updateObjectUniforms obj $ do
239 "diffuseTexture" @= return t -- set model's diffuse texture
240 "diffuseColor" @= let (r,g,b) = mtl_Kd in return (V4 r g b mtl_Tr)
241 "specularReflectivity" @= let (r,g,b) = mtl_Ks in return (V4 r g b mtl_Ns)
242 return obj
226 let matmask = maybe Map.empty (`Map.singleton` objSpan obj) 243 let matmask = maybe Map.empty (`Map.singleton` objSpan obj)
227 (fmap (\(c,n) -> "m:" <> pack (show c) <> ":" <> n) $ materialName matmesh) 244 (fmap (\(c,n) -> "m:" <> pack (show c) <> ":" <> n) $ materialName matmesh)
228 return $ MaskableObject obj (matmask `Map.union` materialMasks matmesh) 245 return $ MaskableObject obj (matmask `Map.union` materialMasks matmesh)