This is a python question. What I want is a function that takes a mesh M and a bounding box B (This bounding box can be axis aligned or on an arbitrary angle. This detail isn't important, which ever is easier to implement, so it's okay to restrict B to be an axis aligned box if it helps) I want a new mesh M' that is subdivided so that M' fits perfectly into the bounding box B. To make it more clear, if a polygon P in mesh M is partially inside B and outside B, then that polygon needs to be split into P1 to Pn, and only the polygons inside B are returned; the rest are discarded.
I want this to be non-destructive, so M' shouldn't be added to the scene, nor should M be changed in anyway. I just want a new mesh that's not a part of the scene, so that I can export it. I already know how to split polygons by planes and implement this from scratch, however, I want to know how much of this is already implemented/not implemented for me within blender's libraries. It seems non-trivial to do this from scratch, and just using my linear algebra knowledge.