refactoring and organisation of 3d javascript