In my 3D game, when a player runs behind a tree I want to hide the tree, so the player can continue to see themselves. However, this tree is an obstacle in a GridMap, which makes this difficult.
Raycasting from the camera can tell you "the GridMap is in the way" but it cannot tell you which cell. You can use local_to_map for small objects which only span a single cell, but for large objects like this tree the cell could be far away from ray collision.
Instead of raycasts, I considered checking the GridMap cells in front the player and setting a shader parameter for those meshes. However, GridMap doesn't expose any kind of "get_mesh_at(cell)" method, so I wouldn't have an object to set the shader parameter on. ...However, GridMap does expose a get_meshes() method which exposes all the meshes and their transforms.
So the best idea I can think of is, "call get_meshes(), reverse-engineer a lookup table based on the transforms, and use that to get the mesh at a specific cell and turn it invisible."
Is this weird "reverse lookup table to get the mesh at a specific cell" really the best approach here? Or is there a simpler approach, or is this a case where GridMaps are the wrong tool for the job?