# HG changeset patch # User Robert McIntyre # Date 1327133315 25200 # Node ID 1261444da2c73ed9548e37bec691a23cfd9fbe99 # Parent 94c005f7f9ddcfe5375e92633629e1d9ce9fd3da got rough vision pipeline working diff -r 94c005f7f9dd -r 1261444da2c7 assets/Models/creature1/retina-UV-small.png Binary file assets/Models/creature1/retina-UV-small.png has changed diff -r 94c005f7f9dd -r 1261444da2c7 assets/Models/creature1/retina-small.png Binary file assets/Models/creature1/retina-small.png has changed diff -r 94c005f7f9dd -r 1261444da2c7 assets/Models/creature1/retina-small.xcf Binary file assets/Models/creature1/retina-small.xcf has changed diff -r 94c005f7f9dd -r 1261444da2c7 assets/Models/creature1/try-again.blend Binary file assets/Models/creature1/try-again.blend has changed diff -r 94c005f7f9dd -r 1261444da2c7 org/test-creature.org --- a/org/test-creature.org Fri Jan 20 05:47:56 2012 -0700 +++ b/org/test-creature.org Sat Jan 21 01:08:35 2012 -0700 @@ -83,7 +83,11 @@ width (- (apply max xs) x0) height (- (apply max ys) y0) image (BufferedImage. (inc width) (inc height) - BufferedImage/TYPE_BYTE_BINARY)] + BufferedImage/TYPE_4BYTE_ABGR)] + (dorun + (for [x (range (.getWidth image)) + y (range (.getHeight image))] + (.setRGB image x y 0xFFFF0000))) (dorun (for [index (range (count points))] (.setRGB image (- (xs index) x0) (- (ys index) y0) -1))) @@ -736,25 +740,50 @@ (controlRender [_ _]))))) -(defn attach-eyes - "For each eye in the creature, attach a Camera to the appropiate - area and return the Camera." - [#^Node creature] - (for [eye (creature-eyes creature)] - (let [target (eye-target creature eye) - [cam-width cam-height] (eye-dimensions eye) - cam (Camera. cam-width cam-height)] - (.setLocation cam (.getWorldTranslation eye)) - (.setRotation cam (.getWorldRotation eye)) - - ) - - -)) - +(defn attach-eye + "Attach a Camera to the appropiate area and return the Camera." + [#^Node creature #^Spatial eye] + + (let [target (eye-target creature eye) + [cam-width cam-height] (eye-dimensions eye) + cam (Camera. cam-width cam-height)] + (.setLocation cam (.getWorldTranslation eye)) + (.setRotation cam (.getWorldRotation eye)) + (bind-camera target cam) + cam)) + + +(def presets + {:gray identity}) + +(defn enable-vision + "return [init-function sensor-functions] for a particular eye" + [#^Node creature #^Spatial eye & {skip :skip :or {skip 0}}] + (let [retinal-map (retina-sensor-image eye) + vision-image (atom nil) + camera (attach-eye creature eye)] + [ + (fn [world] + (add-eye + world camera + (let [counter (atom 0)] + (fn [r fb bb bi] + (if (zero? (rem (swap! counter inc) (inc skip))) + (reset! vision-image (BufferedImage! r fb bb bi))))))) + (vector + (let [whites (white-coordinates (:gray retinal-map)) + topology (vec (collapse whites))] + (fn [] + (vector + topology + (vec + (for [[x y] whites] + (.getRGB @vision-image x y))))))) + ])) + (defn vision - ;; need to create a camera based on uv image, + ;; need to create a camera based on UV image, ;; update this camera every frame based on the position of this ;; geometry. (maybe can get cam to follow the object) @@ -798,6 +827,20 @@ 1 -1} (sensor-data i))))) (vi image))))) +(defn debug-vision-window + "creates function that offers a debug view of sensor data" + [] + (let [vi (view-image)] + (fn + [[coords sensor-data]] + (let [image (points->image coords)] + (dorun + (for [i (range (count coords))] + (.setRGB image ((coords i) 0) ((coords i) 1) + (sensor-data i)))) + (vi image))))) + + ;;(defn test-touch [world creature] @@ -812,17 +855,30 @@ creature (blender-creature thing) touch-nerves (touch creature) touch-debug-windows (map (fn [_] (debug-window)) touch-nerves) + [init-vision [vision-data]] + (enable-vision creature (test-eye)) + vision-debug (debug-vision-window) + me (sphere 0.5 :color ColorRGBA/Blue :physical? false) ] (world (nodify [creature (box 10 2 10 :position (Vector3f. 0 -9 0) :color ColorRGBA/Gray :mass 0) x-axis y-axis z-axis + me ]) standard-debug-controls (fn [world] (light-up-everything world) (enable-debug world) + (init-vision world) + + (add-eye world + (attach-eye creature (test-eye)) + (comp (view-image) BufferedImage!)) + + (add-eye world (.getCamera world) no-op) + ;;(com.aurellem.capture.Capture/captureVideo ;; world (file-str "/home/r/proj/ai-videos/hand")) ;;(.setTimer world (RatchetTimer. 60)) @@ -837,7 +893,10 @@ (map #(%1 (%2 (.getRootNode world))) touch-debug-windows touch-nerves) ) - + ;;(println-repl (vision-data)) + (.setLocalTranslation me (.getLocation (.getCamera world))) + + (vision-debug (vision-data)) ) ;;(let [timer (atom 0)] ;; (fn [_ _] @@ -918,6 +977,7 @@ :position (Vector3f. 0 10 0) :mass 30 ) + rot (.getWorldRotation rock) table (box 3 1 10 :color ColorRGBA/Gray :mass 0 :position (Vector3f. 0 -3 0))] @@ -937,8 +997,9 @@ (add-eye world cam (comp (view-image) BufferedImage!)) (add-eye world (.getCamera world) no-op)) ) - no-op))) + (fn [_ _] (println-repl rot))))) + #+end_src #+results: body-1