This paper introduces three dimensional (3D) topology optimization specifically tailored for designing spatially-varying primitive-cubic (CP) type lattice structures. The developed design process consists of three steps: pre-processing, main processing, and post-processing. In the pre-processing step, a surrogate model between lattice geometry variables and effective elasticity tensor is constructed using an artificial neural network. This surrogate model is essential because it enables the quick calculation of the effective elasticity tensor of lattice microstructure. In the subsequent main processing step, multiscale topology optimization is performed. During this step, lattice microstructure size and rotation design variables are optimized together with the macrostructure density design variables. Macrostructures are designed using a well-established three-field density scheme with a SIMP formulation. Formulations for spatially-varying 3D lattice microstructure are newly developed based on a unit quaternion rotation representation scheme. In the final post-processing step, a spatially-varying microstructure is restored using a de-homogenization scheme, newly developed particularly for the primitive-cubic (CP) type 3D lattice structures. The effectiveness and robustness of the proposed formulations are validated through three design examples for the compliance minimization problem. Moreover, a designed lattice structure is fabricated using an additive manufacturing machine.