         geometry = new THREE.TextGeometry opts.text,
             size        : opts.size
             height      : opts.depth
-            font        : "helvetiker"
+            font        : opts.fontface
 
         material =  new THREE.MeshBasicMaterial
             opacity     : opts.material.opacity


rgb_to_hex = (rgb) -> '#'+rgb.map(rescale_to_hex).join('')

remove_element = (element) ->
    if element? and (parent = element.parentElement)?
        parent.removeChild element

loadScript = (script_src, callback) ->
    run_callback = true

    script = document.createElement 'script'

    script.onload = ->
            remove_element script
            if run_callback
                run_callback = false
                callback()
    script.onerror = ->
            remove_element script
            if run_callback
                run_callback = false
                callback "error loading script #{script.src}"

    script.type = 'text/javascript'
    script.async = true
    script.src = script_src

    document.head.appendChild script

_loading_threejs_callbacks = []
_orbitcontrols_setup = false

math3d.threejs_src = "//cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"

math3d.load_threejs = (callback) ->
    if THREE? and _orbitcontrols_setup
        return callback()

    _loading_threejs_callbacks.push callback
    if _loading_threejs_callbacks.length > 1
        return

    run_callbacks = (error) ->
        while callback = _loading_threejs_callbacks.shift()
            callback error

    setup_orbitcontrols = ->
        _orbitcontrols_setup = true
        OrbitControls.prototype = Object.create THREE.EventDispatcher.prototype
        run_callbacks()

    if THREE?
        return setup_orbitcontrols()

    loadScript math3d.threejs_src, (error) ->
        if (error)
            run_callbacks error
        else
            setup_orbitcontrols()

_scene_using_renderer = undefined
_renderer = {}

        @renderer_type = 'dynamic'

        # remove the current renderer (if it exists)
        removeElement @element.lastChild

        # place renderer in correct place in the DOM
        @element.appendChild @renderer.domElement
