public void Insert(Model9 model, Entity entity, MetaModel metaModel, string metaName, SkinnedMesh skinnedMesh, SlimDX.Direct3D9.Mesh mesh, bool halfSkinned)
 {
     if (skinnedMesh != null)
     {
         RenderSkinnedMesh sm;
         if (!SkinnedMeshes.TryGetValue(skinnedMesh, out sm))
         {
             SkinnedMeshes[skinnedMesh] = sm = new RenderSkinnedMesh();
         }
         sm.Insert(model, entity, metaModel, metaName);
     }
     else if (mesh != null)
     {
         RenderMesh m;
         if (!Meshes.TryGetValue(mesh, out m))
         {
             Meshes[mesh] = m = new RenderMesh(mesh.IndexBuffer, mesh.VertexBuffer);
         }
         m.Insert(model, entity, metaModel, metaName);
     }
 }
    public void OnPostRender()
    {
        // RENDER OPEN SPOTS
        for (int i = TileIndexMin; i <= TileIndexMax; i++)
        {
            for (int j = TileIndexMin; j <= TileIndexMax; j++)
            {
                DrawMeshOnGrid(Meshes["ArenaSquareMesh"], GameAssets.Material.ArenaGrid, new Vector2Int(i, j), Quaternion.identity);
            }
        }

        // RENDER SNAKES
        PlayerSnake.RenderSnake();
        for (int i = 0; i < EnemySnakes.Count; i++)
        {
            EnemySnakes[i].RenderSnake();
        }

        // RENDER THE FOOD
        foreach (Vector2Int FoodPosition in Food)
        {
            DrawMeshOnGrid(Meshes["EngorgedMesh"], GameAssets.Material.Food, FoodPosition, Quaternion.identity);
        }

        // RENDER THE EGGS
        if (Eggs.Count > 0)
        {
            foreach (KeyValuePair <Vector2Int, int> EggKeyPair in Eggs)
            {
                int Tier = EggKeyPair.Value;
                if (!Meshes.TryGetValue("SnakeBodyOutline", out Mesh mesh))
                {
                    Debug.LogError("Missing mesh");
                }
                Material mat = GameAssets.GetTierMaterial(Tier);
                DrawMeshOnGrid(mesh, mat, EggKeyPair.Key, Quaternion.identity);
                DrawMeshOnGrid(mesh, mat, EggKeyPair.Key, Quaternion.Euler(0, 0, 90f));
                DrawMeshOnGrid(mesh, mat, EggKeyPair.Key, Quaternion.Euler(0, 0, 180f));
                DrawMeshOnGrid(mesh, mat, EggKeyPair.Key, Quaternion.Euler(0, 0, 270f));
            }
        }

        // RENDER COLLISSION MAP
        if (RenderCollissionMapFlag)
        {
            for (int i = TileIndexMin; i <= TileIndexMax; i++)
            {
                for (int j = TileIndexMin; j <= TileIndexMax; j++)
                {
                    if (CollisionMap[j, i])
                    {
                        Vector2 GridCenterPosition = new Vector2(GridSize * i, GridSize * j) + RenderOffset;
                        Debug.DrawRay(GridCenterPosition + new Vector2(-GridSize / 2, GridSize / 2), Vector2.right, Color.red);
                        Debug.DrawRay(GridCenterPosition + new Vector2(GridSize / 2, GridSize / 2), Vector2.down, Color.red);
                        Debug.DrawRay(GridCenterPosition + new Vector2(GridSize / 2, -GridSize / 2), Vector2.left, Color.red);
                        Debug.DrawRay(GridCenterPosition + new Vector2(-GridSize / 2, -GridSize / 2), Vector2.up, Color.red);
                    }
                }
            }
        }

        // RENDER WALLS
        // DRAW SNAKE BODY

        foreach (Vector2Int WallPosition in Walls)
        {
            DrawMeshOnGrid(Meshes["EngorgedMesh"], GameAssets.Material.Wall, WallPosition, Quaternion.identity);

            // DRAW WALL OUTLINE
            Material OutlineMaterial = GameAssets.Material.EnemyOutline;
            DrawMeshOnGrid(Meshes["SnakeEngorgedBodyOutline"], OutlineMaterial, WallPosition, Quaternion.Euler(0f, 0f, 0f));
            DrawMeshOnGrid(Meshes["SnakeEngorgedBodyOutline"], OutlineMaterial, WallPosition, Quaternion.Euler(0f, 0f, 90f));
            DrawMeshOnGrid(Meshes["SnakeEngorgedBodyOutline"], OutlineMaterial, WallPosition, Quaternion.Euler(0f, 0f, 180f));
            DrawMeshOnGrid(Meshes["SnakeEngorgedBodyOutline"], OutlineMaterial, WallPosition, Quaternion.Euler(0f, 0f, 270f));
        }
    }