                         @camera.position.x = x(t)
                         @camera.position.y = y(t)
                 .each "end", resolve
+
+    panCameraToBBox: (object, duration) =>
+        bbox = new THREE.BoundingBoxHelper( object, 0xff0000 )
+        do bbox.update
+        @panCameraToPosition bbox.box.center(), 1000
 
     zoomCameraToPosition: (target, duration) =>
         new Promise (resolve) =>


        traverse root

        # root._text_object ?= @getLineObject(root.line)
        # root._text_object.children.forEach (mesh) ->
        #     mesh.material.uniforms.opacity.value = 1
        # lines_object.add root._text_object
        #
        # bbox = new THREE.BoundingBoxHelper( root._text_object, 0xff0000 )
        # do bbox.update
        #
        # @scene.add bbox
        #
        # @panCameraToPosition bbox.box.center(), 1000
        #     .then => @zoomToBoundingBoxWidth(bbox.box, 1000)


    animate: =>
        requestAnimationFrame @animate
        @renderer.render( @scene, @camera )

module.exports = Main

# app = createOrbitViewer({
#     clearColor: 'rgb(255, 255, 255)',

                    idx = _.line.search regex
                    _._text_object.children[idx].position.x
                .reduce (a, b) -> a - b
            child._text_object.position.x = parent_x + offset

    addObjects: (lines_object) =>
        (root) =>
            traverse = (node) =>
                debugger if ! node.line?
                node._text_object = @getLineObject(node.line)
                node._text_object.children.forEach (mesh) ->
                    mesh.material.uniforms.opacity.value = 0.2
                lines_object.add node._text_object

                node.children.forEach traverse if node.children

            traverse(root)

    # transitionTargetWord: (word, transition) =>
    #     (child) =>
    #

    animateLines: (root) =>
        traverse = (node) =>
            @panCameraToBBox node._text_object
                .then -> fade(0.2, 1, 1000) node._text_object
                .then ->
                    if node.children?
                        promises = node.children.map (child) ->
                             fade(0.2, 1, 1000) child._text_object

        traverse root

    addLines: (lines) =>
        lines_object = new THREE.Object3D()
