Please find the source code at
JSBIN
.
See the:
Sphere version
.
Cube version
.
See my blog:
Code and Copy
.