rewritten to use prototype inheritance for three.js issue #3117