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 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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user