I guess. On the top of my head, the steps could be
1) get the bbox
2) get the largest length dimension of the three (Depth, Width ,Height) by subtracting the biggest, and smallest value. The largest will determine the direction
4) after you get the the largest dimension, get its biggest and smallest value (already available in #2). Use that as you actual direction values.
That said can only be sustainable if your obejcts are predictable. For example if the object is rotated by 60% and its baked on the mesh, then the DWH will be skewed.
Need to normalized it and that's the probably the most tricky one.