# HG changeset patch # User Robert McIntyre # Date 1328353645 25200 # Node ID 9e6a30b8c99a1eb2d36f8af6fa061936155dc8fb # Parent e4c2cc79a17155c79abc64def4feabe5eb45d896 renamed some functions in eyes.org diff -r e4c2cc79a171 -r 9e6a30b8c99a org/eyes.org --- a/org/eyes.org Sat Feb 04 03:38:05 2012 -0700 +++ b/org/eyes.org Sat Feb 04 04:07:25 2012 -0700 @@ -48,10 +48,6 @@ the eye's camera are equal to the dimensions of the eye's "UV" map. - - - - #+name: eyes #+begin_src clojure (ns cortex.vision @@ -60,6 +56,7 @@ the observed data to any arbitray function." {:author "Robert McIntyre"} (:use (cortex world sense util)) + (:use clojure.contrib.def) (:import com.jme3.post.SceneProcessor) (:import (com.jme3.util BufferUtils Screenshots)) (:import java.nio.ByteBuffer) @@ -67,7 +64,6 @@ (:import com.jme3.renderer.ViewPort) (:import com.jme3.math.ColorRGBA) (:import com.jme3.renderer.Renderer) - (:import jme3tools.converters.ImageToAwt) (:import com.jme3.scene.Node)) (cortex.import/mega-import-jme3) @@ -124,10 +120,10 @@ (byteBuffer->bufferedImage! (frameBuffer->byteBuffer! r fb bb) bi)) -(defn add-eye +(defn add-eye! "Add an eye to the world, calling continuation on every frame produced." - [world camera continuation] + [#^Application world camera continuation] (let [width (.getWidth camera) height (.getHeight camera) render-manager (.getRenderManager world) @@ -148,9 +144,7 @@ [#^Spatial eye] (if-let [eye-map (meta-data eye "eye")] (map-vals - #(ImageToAwt/convert - (.getImage (.loadTexture (asset-manager) %)) - false false 0) + load-image (eval (read-string eye-map))))) (defn eye-dimensions @@ -162,16 +156,11 @@ [(apply max (map first dimensions)) (apply max (map second dimensions))])) -(defn creature-eyes - ;;dylan - "Return the children of the creature's \"eyes\" node." - ;;"The eye nodes which are children of the \"eyes\" node in the - ;;creature." - [#^Node creature] - (if-let [eye-node (.getChild creature "eyes")] - (seq (.getChildren eye-node)) - (do (println-repl "could not find eyes node") []))) - +(defvar + ^{:arglists '([creature])} + eyes + (sense-nodes "eyes") + "Return the children of the creature's \"eyes\" node.") (defn attach-eye "Attach a Camera to the appropiate area and return the Camera." @@ -204,7 +193,7 @@ (.getHeight camera) BufferedImage/TYPE_BYTE_BINARY))] [(fn [world] - (add-eye + (add-eye! world camera (let [counter (atom 0)] (fn [r fb bb bi] @@ -233,7 +222,7 @@ [(conj init-a init-b) (into senses-a senses-b)]) [[][]] - (for [eye (creature-eyes creature)] + (for [eye (eyes creature)] (enable-vision creature eye)))) @@ -281,11 +270,11 @@ (let [cam (.clone (.getCamera world)) width (.getWidth cam) height (.getHeight cam)] - (add-eye world cam + (add-eye! world cam ;;no-op (comp (view-image) BufferedImage!) ) - (add-eye world + (add-eye! world (doto (.clone cam) (.setLocation (Vector3f. -10 0 0)) (.lookAt Vector3f/ZERO Vector3f/UNIT_Y)) @@ -293,7 +282,7 @@ (comp (view-image) BufferedImage!)) ;; This is here to restore the main view ;; after the other views have completed processing - (add-eye world (.getCamera world) no-op))) + (add-eye! world (.getCamera world) no-op))) (fn [world tpf] (.rotate candy (* tpf 0.2) 0 0))))) #+end_src diff -r e4c2cc79a171 -r 9e6a30b8c99a org/hearing.org --- a/org/hearing.org Sat Feb 04 03:38:05 2012 -0700 +++ b/org/hearing.org Sat Feb 04 04:07:25 2012 -0700 @@ -741,22 +741,13 @@ * Finally, Ears in clojure! -Now that the infrastructure is complete (modulo a few patches to -jMonkeyEngine3 to support accessing this modified version of =OpenAL= -that are not worth discussing), the clojure ear abstraction is rather -simple. Just as there were =SceneProcessors= for vision, there are +Now that the infrastructure is complete the clojure ear abstraction is +simple. Just as there were =SceneProcessors= for vision, there are now =SoundProcessors= for hearing. #+include "../../jmeCapture/src/com/aurellem/capture/audio/SoundProcessor.java" src java -Ears work the same way as vision. - -(hearing creature) will return [init-functions sensor-functions]. The -init functions each take the world and register a SoundProcessor that -does foureier transforms on the incommong sound data, making it -available to each sensor function. - #+name: ears #+begin_src clojure @@ -866,7 +857,6 @@ (for [ear (ears creature)] (hearing-fn creature ear))) - #+end_src * Example diff -r e4c2cc79a171 -r 9e6a30b8c99a org/sense-util.org --- a/org/sense-util.org Sat Feb 04 03:38:05 2012 -0700 +++ b/org/sense-util.org Sat Feb 04 04:07:25 2012 -0700 @@ -13,7 +13,8 @@ (cortex.import/mega-import-jme3) (import ij.process.ImageProcessor) (import java.awt.image.BufferedImage) - +(use 'cortex.util) +(import jme3tools.converters.ImageToAwt) (defn meta-data [blender-node key] (if-let [data (.getUserData blender-node "properties")] @@ -181,6 +182,13 @@ (seq (.getChildren sense-node)) (do (println-repl "could not find" parent-name "node") [])))) +(defn load-image + "Load an image as a BufferedImage using the asset-manager system." + [asset-relative-path] + (ImageToAwt/convert + (.getImage (.loadTexture (asset-manager) asset-relative-path)) + false false 0)) + #+end_src diff -r e4c2cc79a171 -r 9e6a30b8c99a org/test-creature.org --- a/org/test-creature.org Sat Feb 04 03:38:05 2012 -0700 +++ b/org/test-creature.org Sat Feb 04 04:07:25 2012 -0700 @@ -233,11 +233,11 @@ (dorun (map #(% world) init-vision-fns)) ;;(dorun (map #(% world) init-hearing-fns)) - (add-eye world + (add-eye! world (attach-eye creature (test-eye)) (comp (view-image) BufferedImage!)) - (add-eye world (.getCamera world) no-op) + (add-eye! world (.getCamera world) no-op) ;;(set-gravity world (Vector3f. 0 0 0)) ;;(com.aurellem.capture.Capture/captureVideo ;; world (file-str "/home/r/proj/ai-videos/hand")) @@ -308,8 +308,8 @@ (bind-sense rock cam) (.setTimer world (RatchetTimer. 60)) - (add-eye world cam (comp (view-image) BufferedImage!)) - (add-eye world (.getCamera world) no-op)) + (add-eye! world cam (comp (view-image) BufferedImage!)) + (add-eye! world (.getCamera world) no-op)) ) (fn [_ _] (println-repl rot)))))