         e = $(".salvus-3d-templates .salvus-3d-viewer").clone()
         elt.empty().append(e)
         opts.element = e
-        elt.data('salvus-threejs', new SalvusThreeJS(opts))
-
-
-
+        f = () -> elt.data('salvus-threejs', new SalvusThreeJS(opts))
+        if not THREE?
+            load_threejs (err) =>
+                if not err
+                    f()
+                else
+                    # TODO -- not sure what to do at this point...
+                    console.log("Error loading THREE.js")
+        else
+            f()
+
+
+


rgb_to_hex = (r, g, b) -> "#" + component_to_hex(r) + component_to_hex(g) + component_to_hex(b)

class SalvusThreeJS
    constructor: (opts) ->
        @opts = defaults opts,

            foreground      : undefined
            camera_distance : 10

        @init()

    init: () =>
        @scene = new THREE.Scene()
