We obtain exact spatiotemporal periodic traveling wave solutions to the generalized (3+1)-dimensional cubic-quintic nonlinear Schrödinger equation with spatial distributed coefficients. For restrictive parameters, these periodic wave solutions acquire the form of localized spatial solitons. Such solutions exist under certain conditions, and impose constraints on the functions describing dispersion, nonlinearity, and gain (or loss). We then demonstrate the nonlinear tunneling effects and controllable compression technique of three-dimensional bright and dark solitons when they pass unchanged through the potential barriers and wells affected by special choices of the diffraction and/or the nonlinearity parameters. Direct numerical simulation has been performed to show the stable propagation of bright soliton with 5% white noise perturbation.