diff --git a/src/Importer/IQM/Parser.hs b/src/Importer/IQM/Parser.hs index b3cafb1..be0351e 100644 --- a/src/Importer/IQM/Parser.hs +++ b/src/Importer/IQM/Parser.hs @@ -31,6 +31,8 @@ import Foreign.Marshal.Utils import Prelude as P hiding (take, null) +import Render.Misc (printPtrAsFloatArray, printPtrAsUByteArray) + -- | helper-function for creating an integral out of [8-Bit Ints] _w8ToInt :: Integral a => a -> a -> a _w8ToInt i add = 256*i + add @@ -271,14 +273,19 @@ readInVAO :: ByteString -> Word32 -> IQMVertexArray -> IO IQMVertexArray readInVAO d vcount (IQMVertexArray type' a format num offset ptr) = do let - byteLen = fromIntegral vcount * fromIntegral num * vaSize format + numElems = fromIntegral vcount * fromIntegral num + byteLen = numElems * vaSize format data' = skipDrop (fromIntegral offset) byteLen d unless (ptr == nullPtr) $ error $ "Error reading Vertex-Array: Double Read of " ++ show type' p <- mallocBytes byteLen putStrLn $ concat ["Allocating ", show vcount ,"x", show num,"x",show (vaSize format)," = ", show byteLen, " Bytes at ", show p, " for ", show type'] - putStrLn $ concat ["Filling with: ", show data', " starting at ", show offset] + putStrLn $ concat ["Filling starting at ", show offset, " with: "] unsafeUseAsCString data' (\s -> copyBytes p s byteLen) + case type' of + IQMBlendIndexes -> printPtrAsUByteArray p numElems + IQMBlendWeights -> printPtrAsUByteArray p numElems + _ -> printPtrAsFloatArray p numElems return $ IQMVertexArray type' a format num offset $ castPtr p -- | Real internal Parser. diff --git a/src/Render/Misc.hs b/src/Render/Misc.hs index 4d302d1..7478bf1 100644 --- a/src/Render/Misc.hs +++ b/src/Render/Misc.hs @@ -10,7 +10,9 @@ import Graphics.Rendering.OpenGL.GLU.Errors import Graphics.UI.SDL.Types (Texture) import System.IO (hPutStrLn, stderr) import Linear -import Foreign.C (CFloat) +import Foreign.C (CFloat, CUChar) +import Foreign.Marshal.Array (peekArray) +import Foreign.Ptr (Ptr, castPtr) up :: V3 CFloat up = V3 0 1 0 @@ -124,7 +126,13 @@ getCam (x',z') dist' xa' ya' = lookAt (cpos ^+^ at') at' up -- | Prints any Pointer as Float-Array with given number of elements. printPtrAsFloatArray :: Ptr a -> Int -> IO () printPtrAsFloatArray pointer num = do - a <- peekArray num (castPtr pointer :: Ptr Float) + a <- peekArray num (castPtr pointer :: Ptr CFloat) + print a + +-- | Prints any Pointer as UByte-Array with given number of elements. +printPtrAsUByteArray :: Ptr a -> Int -> IO () +printPtrAsUByteArray pointer num = do + a <- peekArray num (castPtr pointer :: Ptr CUChar) print a curb :: Ord a => a -> a -> a -> a