Generalized $J$-integral and three-dimensional fracture mechanics. I