 (ns geometer.lsystem
   (:require [thi.ng.geom.core        :as g]
             [thi.ng.geom.core.vector :refer [vec3]]
-            [thi.ng.geom.cuboid      :refer [cuboid]]
-            [thi.ng.geom.gmesh       :as gm]
+            [thi.ng.geom.core.matrix :refer [M44]]
+            [thi.ng.geom.aabb        :refer [aabb]]
+            [thi.ng.geom.basicmesh   :as bm]
             [thi.ng.geom.types.utils :as tu]
             [thi.ng.math.core        :as m]))
 

  "Add a cuboid branch of `length` to `mesh` from `position` with `rotation`. (Produces somewhat organic-looking segments)."
  [length mesh position rotation]
  (let [[x y z] (last rotation)
        corners (map #(-> % (g/rotate-x x) (g/rotate-y y) (g/rotate-z z) (g/+ (last position)))
                     [(vec3 0 0 0) (vec3 -1 0 0) (vec3 0 -1 0) (vec3 0 1 0)
                      (vec3 -1 0 length) (vec3 0 -1 length) (vec3 0 1 length) (vec3 0 0 length)])]
    [(conj (pop position) (last corners))
     rotation
     (tu/into-mesh mesh gm/add-face (apply cuboid corners))]))

(defn- execute-op
  "Execute a single L-System operation and return the new state of the system. The `angle-fn` is used to determine angle changes and the `grow-fn` to extend a branch."

    \[ [(conj pos (last pos)) (conj rot (last rot)) mesh]
    \] (if (or (= 1 (count pos)) (= 1 (count rot))) ; guard against popping empties
         [pos rot mesh]
         [(pop pos) (pop rot) mesh])
    [pos rot mesh]))                                ; default to no-op

(defn execute-ops
