parser works. intersection with triangle is next step
This commit is contained in:
parent
7bdeb03558
commit
46ae09671b
@ -65,7 +65,6 @@ filterObjects (a:as) = case a of
|
|||||||
validateAndParseScene :: B8.ByteString -> FilePath -> EitherT String IO Scene
|
validateAndParseScene :: B8.ByteString -> FilePath -> EitherT String IO Scene
|
||||||
validateAndParseScene f p = do
|
validateAndParseScene f p = do
|
||||||
obs <- hoistEither $ parseScene f
|
obs <- hoistEither $ parseScene f
|
||||||
lift $ print obs
|
|
||||||
obs' <- initializeMeshes p obs
|
obs' <- initializeMeshes p obs
|
||||||
cam <- hoistEither $ findCamera obs'
|
cam <- hoistEither $ findCamera obs'
|
||||||
depth <- hoistEither $ findDepth obs'
|
depth <- hoistEither $ findDepth obs'
|
||||||
@ -108,7 +107,6 @@ main = do
|
|||||||
putStrLn $ "reading and parsing "++ show a
|
putStrLn $ "reading and parsing "++ show a
|
||||||
!f <- B.readFile a
|
!f <- B.readFile a
|
||||||
r <- runEitherT $ validateAndParseScene f (dropFileName a)
|
r <- runEitherT $ validateAndParseScene f (dropFileName a)
|
||||||
print r
|
|
||||||
case r of
|
case r of
|
||||||
Left error -> putStrLn $ "Error: " ++ error
|
Left error -> putStrLn $ "Error: " ++ error
|
||||||
Right s -> do
|
Right s -> do
|
||||||
|
@ -195,25 +195,25 @@ parseMesh' :: Shading -> Material -> Parser ObjectParser
|
|||||||
parseMesh' s m = do
|
parseMesh' s m = do
|
||||||
string "OFF"
|
string "OFF"
|
||||||
skipSpace
|
skipSpace
|
||||||
D.trace "first Line" endOfLine
|
--D.trace "first Line" endOfLine
|
||||||
v <- decimal
|
v <- decimal
|
||||||
skipSpace
|
skipSpace
|
||||||
f <- decimal
|
f <- decimal
|
||||||
skipSpace
|
skipSpace
|
||||||
_ <- decimal --ignored in our OFF-Files
|
_ <- decimal --ignored in our OFF-Files
|
||||||
D.trace "second Line" endOfLine
|
D.trace "second Line" endOfLine
|
||||||
verts <- D.trace "verts" $ A8.count v parseVector
|
verts <- D.trace (show v ++ " verts") $ A8.count v parseVector
|
||||||
faces <- D.trace "faces" $ A8.count f parseTriangle
|
faces <- D.trace (show f ++ " faces") $ A8.count f parseTriangle
|
||||||
-- whatever should be parsed afterwards in OFF..
|
-- whatever should be parsed afterwards in OFF..
|
||||||
let
|
let
|
||||||
mv = IM.fromList $ P.zip [1..] verts
|
mv = IM.fromList $ P.zip [0..] verts
|
||||||
mf = IM.fromList $ P.zip [1..] faces
|
mf = IM.fromList $ P.zip [0..] faces
|
||||||
mfn = normal mv <$> mf
|
mfn = normal mv <$> mf
|
||||||
normal :: IntMap (V3 Float) -> V3 Int -> V3 Float
|
normal :: IntMap (V3 Float) -> V3 Int -> V3 Float
|
||||||
normal verts (V3 v1 v2 v3) = normalize $ cross (verts ! v1 - verts ! v2)
|
normal verts (V3 v1 v2 v3) = normalize $ cross (verts ! v1 - verts ! v2)
|
||||||
(verts ! v3 - verts ! v2)
|
(verts ! v3 - verts ! v2)
|
||||||
-- maybe * (-1)
|
-- 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 :: IntMap (V3 Float) -> IntMap (V3 Int) -> Int -> V3 Float
|
||||||
vnormal norms faces i = normalize $ F.foldl' (+) (V3 0 0 0) $ (!) norms <$> fs
|
vnormal norms faces i = normalize $ F.foldl' (+) (V3 0 0 0) $ (!) norms <$> fs
|
||||||
--TODO: weight sum with opening-angle!
|
--TODO: weight sum with opening-angle!
|
||||||
@ -242,13 +242,13 @@ parseMesh' s m = do
|
|||||||
|
|
||||||
parseTriangle :: Parser (V3 Int)
|
parseTriangle :: Parser (V3 Int)
|
||||||
parseTriangle = do
|
parseTriangle = do
|
||||||
|
skipSpace
|
||||||
_ <- string "3"
|
_ <- string "3"
|
||||||
|
skipSpace
|
||||||
a <- decimal
|
a <- decimal
|
||||||
skipSpace
|
skipSpace
|
||||||
b <- decimal
|
b <- decimal
|
||||||
skipSpace
|
skipSpace
|
||||||
c <- decimal
|
c <- decimal
|
||||||
skipSpace
|
|
||||||
endOfLine
|
|
||||||
return $ V3 a b c
|
return $ V3 a b c
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ intersect (Ray ro rd) p@(P (Plane pc pn _)) = if det == 0 || t < epsilon
|
|||||||
! det = dot rd' pn
|
! det = dot rd' pn
|
||||||
t = (dot (pc - ro) pn)/det
|
t = (dot (pc - ro) pn)/det
|
||||||
rd' = normalize rd
|
rd' = normalize rd
|
||||||
intersect _ _ = undefined
|
intersect _ _ = error "intersection with unknown object"
|
||||||
|
|
||||||
|
|
||||||
-- deprecated - wrong calculation of rays.
|
-- deprecated - wrong calculation of rays.
|
||||||
|
Loading…
Reference in New Issue
Block a user