3d data mangling in Javascript