From 46ae09671b18953c6e5ab90966db1d3fb56da470 Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Sun, 30 Nov 2014 23:44:20 +0100 Subject: [PATCH] parser works. intersection with triangle is next step --- src/Main.hs | 2 -- src/Scene/Parser.hs | 18 +++++++++--------- src/Scene/Renderer.hs | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index bb562e3..e8c58e6 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -65,7 +65,6 @@ filterObjects (a:as) = case a of validateAndParseScene :: B8.ByteString -> FilePath -> EitherT String IO Scene validateAndParseScene f p = do obs <- hoistEither $ parseScene f - lift $ print obs obs' <- initializeMeshes p obs cam <- hoistEither $ findCamera obs' depth <- hoistEither $ findDepth obs' @@ -108,7 +107,6 @@ main = do putStrLn $ "reading and parsing "++ show a !f <- B.readFile a r <- runEitherT $ validateAndParseScene f (dropFileName a) - print r case r of Left error -> putStrLn $ "Error: " ++ error Right s -> do diff --git a/src/Scene/Parser.hs b/src/Scene/Parser.hs index f153944..be9f9af 100644 --- a/src/Scene/Parser.hs +++ b/src/Scene/Parser.hs @@ -195,25 +195,25 @@ parseMesh' :: Shading -> Material -> Parser ObjectParser parseMesh' s m = do string "OFF" skipSpace - D.trace "first Line" endOfLine + --D.trace "first Line" endOfLine v <- decimal skipSpace f <- decimal skipSpace _ <- decimal --ignored in our OFF-Files D.trace "second Line" endOfLine - verts <- D.trace "verts" $ A8.count v parseVector - faces <- D.trace "faces" $ A8.count f parseTriangle + verts <- D.trace (show v ++ " verts") $ A8.count v parseVector + faces <- D.trace (show f ++ " faces") $ A8.count f parseTriangle -- whatever should be parsed afterwards in OFF.. let - mv = IM.fromList $ P.zip [1..] verts - mf = IM.fromList $ P.zip [1..] faces + mv = IM.fromList $ P.zip [0..] verts + mf = IM.fromList $ P.zip [0..] faces mfn = normal mv <$> mf normal :: IntMap (V3 Float) -> V3 Int -> V3 Float normal verts (V3 v1 v2 v3) = normalize $ cross (verts ! v1 - verts ! v2) (verts ! v3 - verts ! v2) -- maybe * (-1) - mn = IM.fromList $ P.zip [1..] $ vnormal mfn mf <$> [1..v] + mn = IM.fromList $ P.zip [0..] $ vnormal mfn mf <$> [0..v] vnormal :: IntMap (V3 Float) -> IntMap (V3 Int) -> Int -> V3 Float vnormal norms faces i = normalize $ F.foldl' (+) (V3 0 0 0) $ (!) norms <$> fs --TODO: weight sum with opening-angle! @@ -242,13 +242,13 @@ parseMesh' s m = do parseTriangle :: Parser (V3 Int) parseTriangle = do - _ <- string "3 " + skipSpace + _ <- string "3" + skipSpace a <- decimal skipSpace b <- decimal skipSpace c <- decimal - skipSpace - endOfLine return $ V3 a b c diff --git a/src/Scene/Renderer.hs b/src/Scene/Renderer.hs index 4255f44..445de6c 100644 --- a/src/Scene/Renderer.hs +++ b/src/Scene/Renderer.hs @@ -136,7 +136,7 @@ intersect (Ray ro rd) p@(P (Plane pc pn _)) = if det == 0 || t < epsilon ! det = dot rd' pn t = (dot (pc - ro) pn)/det rd' = normalize rd -intersect _ _ = undefined +intersect _ _ = error "intersection with unknown object" -- deprecated - wrong calculation of rays.