10x meshing speedup.

Used lookup tables rather than code, + moved lookup table definition outside function.