Accurate and efficient computation of traveltimes and their spatial derivatives for 3D heterogeneous media is essential in many areas of seismology, such as traveltime/slope tomography and quantitative migration. A popular method of obtaining this information is to solve the eikonal equation using a finite-difference (FD) scheme. However, the complex surface of the earth causes numerical complications when applying FD methods based on rectangular grids. To overcome the challenge of taking into account topographic effects, we make use of the 3D topography-dependent eikonal equation (TDEE) which is a 3D surface-flattening scheme that uses curvilinear grids to transform irregular surfaces in the physical domain into regular surfaces in the computational domain. Unfortunately, solving the TDEE in three dimensions starting from the initial point-source condition needs to get around the point-source singularity. Therefore, we formulate the 3D factored TDEE (FTDEE) according to a factorization principle. Furthermore, to numerically solve the 3D original TDEE, as well as the FTDEE, we apply a lock sweeping method, which avoids the problem of repetitive computation when using the fast sweeping method. Several numerical examples demonstrate the efficiency of the new lock scheme in terms of computation time and accuracy of the 3D FTDEE solver for the calculation of traveltimes and their derivatives. This scheme provides a good choice for the calculation of traveltimes and their spatial derivatives using models with irregular surfaces, which means greater potential for seismic data processing under conditions of complex topography.