cleanup & debug-output
This commit is contained in:
parent
fc72fd8095
commit
eaeae7d4e2
@ -75,7 +75,7 @@ readHeader = do
|
|||||||
_ <- lift $ string (pack "INTERQUAKEMODEL\0")
|
_ <- lift $ string (pack "INTERQUAKEMODEL\0")
|
||||||
modify (+16)
|
modify (+16)
|
||||||
v <- w32leCParser
|
v <- w32leCParser
|
||||||
lift $ when (v /= 2) $ fail "Version /= 2.\nThis Parser only supports Version 2 of the InterQuake-Model IQM"
|
lift $ when (v /= 2) $ fail "Version /= 2.\nThis Parser only supports Version 2 of the InterQuake-Model IQM"
|
||||||
-- when v /= 2 then fail parsing.
|
-- when v /= 2 then fail parsing.
|
||||||
size' <- w32leCParser
|
size' <- w32leCParser
|
||||||
flags' <- w32leCParser
|
flags' <- w32leCParser
|
||||||
@ -207,24 +207,25 @@ skipToCounter a = do
|
|||||||
-- fills the Structure in a 2nd Pass from Offsets (O(memcpy'd bytes)).
|
-- fills the Structure in a 2nd Pass from Offsets (O(memcpy'd bytes)).
|
||||||
parseIQM :: String -> IO IQM
|
parseIQM :: String -> IO IQM
|
||||||
parseIQM a =
|
parseIQM a =
|
||||||
do
|
do
|
||||||
f <- B.readFile a
|
f <- B.readFile a
|
||||||
vao <- makeVAO (return ())
|
vao <- makeVAO (return ())
|
||||||
-- Parse Headers/Offsets
|
-- Parse Headers/Offsets
|
||||||
let result = parse (doIQMparse vao) f
|
let result = parse (doIQMparse vao) f
|
||||||
raw <- case result of
|
raw <- case result of
|
||||||
Done _ x -> return x
|
Done _ x -> return x
|
||||||
y -> error $ show y
|
y -> error $ show y
|
||||||
-- Fill Vertex-Arrays with data of Offsets
|
-- Fill Vertex-Arrays with data of Offsets
|
||||||
let va = vertexArrays raw
|
let va = vertexArrays raw
|
||||||
va' <- mapM (readInVAO f) va
|
va' <- mapM (readInVAO f) va
|
||||||
vbo <- sequence $ map toVBOfromVAO va
|
vbo <- mapM toVBOfromVAO va
|
||||||
withVAO vao $ createVAO (zip va' vbo)
|
withVAO vao $ createVAO (zip va' vbo)
|
||||||
return $ raw
|
print raw
|
||||||
{ vertexArrays = va'
|
return $ raw
|
||||||
|
{ vertexArrays = va'
|
||||||
, vertexBufferObjects = vbo
|
, vertexBufferObjects = vbo
|
||||||
, vertexArrayObject = vao
|
, vertexArrayObject = vao
|
||||||
}
|
}
|
||||||
|
|
||||||
createVAO :: [(IQMVertexArray, BufferObject)] -> IO ()
|
createVAO :: [(IQMVertexArray, BufferObject)] -> IO ()
|
||||||
createVAO bo = do
|
createVAO bo = do
|
||||||
@ -286,24 +287,24 @@ readInVAO d (IQMVertexArray type' a format num offset ptr) =
|
|||||||
-- not allocated and copied. readInVAO has to be called on each one.
|
-- not allocated and copied. readInVAO has to be called on each one.
|
||||||
doIQMparse :: VertexArrayObject -> Parser IQM
|
doIQMparse :: VertexArrayObject -> Parser IQM
|
||||||
doIQMparse vao =
|
doIQMparse vao =
|
||||||
flip evalStateT 0 $ --evaluate parser with state starting at 0
|
flip evalStateT 0 $ --evaluate parser with state starting at 0
|
||||||
do
|
do
|
||||||
h <- readHeader --read header
|
h <- readHeader --read header
|
||||||
skipToCounter $ ofs_text h --skip 0-n bytes to get to text
|
skipToCounter $ ofs_text h --skip 0-n bytes to get to text
|
||||||
text <- lift . take . fromIntegral $ num_text h --read texts
|
text <- lift . take . fromIntegral $ num_text h --read texts
|
||||||
modify . (+) . fromIntegral $ num_text h --put offset forward
|
modify . (+) . fromIntegral $ num_text h --put offset forward
|
||||||
skipToCounter $ ofs_meshes h --skip 0-n bytes to get to meshes
|
skipToCounter $ ofs_meshes h --skip 0-n bytes to get to meshes
|
||||||
meshes' <- readMeshes $ fromIntegral $ num_meshes h --read meshes
|
meshes' <- readMeshes $ fromIntegral $ num_meshes h --read meshes
|
||||||
skipToCounter $ ofs_vertexarrays h --skip 0-n bytes to get to Vertex-Arrays
|
skipToCounter $ ofs_vertexarrays h --skip 0-n bytes to get to Vertex-Arrays
|
||||||
vaf <- readVAFs $ fromIntegral $ num_vertexarrays h --read Vertex-Arrays
|
vaf <- readVAFs $ fromIntegral $ num_vertexarrays h --read Vertex-Arrays
|
||||||
return IQM
|
return IQM
|
||||||
{ header = h
|
{ header = h
|
||||||
, texts = filter (not.null) (split (unsafeCoerce '\0') text)
|
, texts = filter (not.null) (split (unsafeCoerce '\0') text)
|
||||||
, meshes = meshes'
|
, meshes = meshes'
|
||||||
, vertexArrays = vaf
|
, vertexArrays = vaf
|
||||||
, vertexBufferObjects = [] --initialized later, after vaf get allocated.
|
, vertexBufferObjects = [] --initialized later, after vaf get allocated.
|
||||||
, vertexArrayObject = vao
|
, vertexArrayObject = vao
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Helper-Function for Extracting a random substring out of a Bytestring
|
-- | Helper-Function for Extracting a random substring out of a Bytestring
|
||||||
-- by the Offsets provided.
|
-- by the Offsets provided.
|
||||||
|
Loading…
Reference in New Issue
Block a user