groupToIndexedModel :: Group -> IM.IndexedModel
groupToIndexedModel g
    | M.isNothing norm0 && M.isNothing tex0 = IM.IndexedModel (V.convert vert0) VS.empty VS.empty (V.convert index0)
    | M.isJust norm0 && M.isNothing tex0 = runST $ do
      (newVert,newNorms,newIndex) <- rearrangeCaller defaultNormal vert0 index0 (V.fromList . toList . M.fromJust $ norm0) normIndex0
      return $ IM.IndexedModel (V.convert newVert) (V.convert newNorms) VS.empty (V.convert newIndex)
    | M.isNothing norm0 && M.isJust tex0 = runST $ do
      (newVert,newText,newIndex) <- rearrangeCaller defaultTexture vert0 index0 (V.fromList . toList . M.fromJust $ tex0) textIndex0
      return $ IM.IndexedModel (V.convert newVert) VS.empty (V.convert . V.map easyGLVector2Correction $ newText) (V.convert newIndex)
    | M.isJust norm0 && M.isJust tex0 = runST $ do
      (newVert,newNorms,newIndex) <- rearrangeCaller defaultNormal vert0 index0 (V.fromList . toList . M.fromJust $ norm0) normIndex0
      let newThing = V.zip newVert newNorms
      (newThing,newText,newIndex) <- rearrangeCaller defaultTexture newThing newIndex (V.fromList . toList . M.fromJust $ tex0) textIndex0
      let (newVert,newNorms) = V.unzip newThing
      return $ IM.IndexedModel (V.convert newVert) (V.convert newNorms) (V.convert . V.map easyGLVector2Correction $ newText) (V.convert newIndex)
    | otherwise = IM.emptyIndexedModel
  where
    vert0 = V.fromList . toList $ groupVertices g
    norm0 = groupNormals g
    tex0 = groupTextureCoord g
    (index0,textIndex0,normIndex0) = allIndexesV g
groupToIndexedModel :: Group -> IM.IndexedModel
groupToIndexedModel g
    | M.isNothing norm0 && M.isNothing tex0 = IM.IndexedModel (V.convert vert0) VS.empty VS.empty (V.convert index0)
    | M.isJust norm0 && M.isNothing tex0 = runST $ do
      (newVert,newNorms,newIndex) <- rearrangeCaller defaultNormal vert0 index0 (V.fromList . toList . M.fromJust $ norm0) normIndex0
      return $ IM.IndexedModel (V.convert newVert) (V.convert newNorms) VS.empty (V.convert newIndex)
    | M.isNothing norm0 && M.isJust tex0 = runST $ do
      (newVert,newText,newIndex) <- rearrangeCaller defaultTexture vert0 index0 (V.fromList . toList . M.fromJust $ tex0) textIndex0
      return $ IM.IndexedModel (V.convert newVert) VS.empty (V.convert . V.map easyGLVector2Correction $ newText) (V.convert newIndex)
    | M.isJust norm0 && M.isJust tex0 = runST $ do
      (newVert,newNorms,newIndex) <- rearrangeCaller defaultNormal vert0 index0 (V.fromList . toList . M.fromJust $ norm0) normIndex0
      let newThing = V.zip newVert newNorms
      (newThing,newText,newIndex) <- rearrangeCaller defaultTexture newThing newIndex (V.fromList . toList . M.fromJust $ tex0) textIndex0
      let (newVert,newNorms) = V.unzip newThing
      return $ IM.IndexedModel (V.convert newVert) (V.convert newNorms) (V.convert . V.map easyGLVector2Correction $ newText) (V.convert newIndex)
    | otherwise = IM.emptyIndexedModel
  where
    vert0 = V.fromList . toList $ groupVertices g
    norm0 = groupNormals g
    tex0 = groupTextureCoord g
    (index0,textIndex0,normIndex0) = allIndexesV g
groupToIndexedModel g
    | M.isNothing norm0 && M.isNothing tex0 = IM.IndexedModel (V.convert vert0) VS.empty VS.empty (V.convert index0)
    | M.isJust norm0 && M.isNothing tex0 = runST $ do
      (newVert,newNorms,newIndex) <- rearrangeCaller defaultNormal vert0 index0 (V.fromList . toList . M.fromJust $ norm0) normIndex0
      return $ IM.IndexedModel (V.convert newVert) (V.convert newNorms) VS.empty (V.convert newIndex)
    | M.isNothing norm0 && M.isJust tex0 = runST $ do
      (newVert,newText,newIndex) <- rearrangeCaller defaultTexture vert0 index0 (V.fromList . toList . M.fromJust $ tex0) textIndex0
      return $ IM.IndexedModel (V.convert newVert) VS.empty (V.convert . V.map easyGLVector2Correction $ newText) (V.convert newIndex)
    | M.isJust norm0 && M.isJust tex0 = runST $ do
      (newVert,newNorms,newIndex) <- rearrangeCaller defaultNormal vert0 index0 (V.fromList . toList . M.fromJust $ norm0) normIndex0
      let newThing = V.zip newVert newNorms
      (newThing,newText,newIndex) <- rearrangeCaller defaultTexture newThing newIndex (V.fromList . toList . M.fromJust $ tex0) textIndex0
      let (newVert,newNorms) = V.unzip newThing
      return $ IM.IndexedModel (V.convert newVert) (V.convert newNorms) (V.convert . V.map easyGLVector2Correction $ newText) (V.convert newIndex)
    | otherwise = IM.emptyIndexedModel
  where
    vert0 = V.fromList . toList $ groupVertices g
    norm0 = groupNormals g
    tex0 = groupTextureCoord g
    (index0,textIndex0,normIndex0) = allIndexesV g