(ns cortex.test.integration "let's play!" {:author "Robert McIntyre"} (:use (cortex world util import body sense hearing touch vision proprioception movement)) (:import (com.jme3.math ColorRGBA Vector3f)) (:import java.io.File) (:import com.jme3.audio.AudioNode) (:import com.aurellem.capture.RatchetTimer)) (dorun (cortex.import/mega-import-jme3)) ;;(rlm.rlm-commands/help) (def hand "Models/test-creature/hand.blend") (def output-base (File. "/home/r/proj/cortex/render/hand")) (defn motor-control-program "Create a function which will execute the motor script" [muscle-positions script] (let [current-frame (atom -1) keyed-script (group-by first script) current-forces (atom {}) ] (fn [effectors] (let [indexed-effectors (vec effectors)] (dorun (for [[_ part force] (keyed-script (swap! current-frame inc))] (swap! current-forces (fn [m] (assoc m part force))))) (doall (map (fn [effector power] (effector (int power))) effectors (map #(@current-forces % 0) muscle-positions))))))) (def muscle-positions [:pointer-2-e :pointer-2-f :thumb-1 :thumb-1 :pointer-1-e :pointer-1-f :thumb-2-e :thumb-2-f :middle-1-e :middle-1-f :pointer-3-f :pointer-3-e :middle-2-e :middle-2-f :middle-3-f :middle-3-e :pinky-2-e :pinky-2-f :pinky-3-f :pinky-3-e :ring-3-e :ring-3-f :ring-2-f :ring-2-e :ring-1-e :ring-1-f :thumb-1-e :thumb-1-f :pinky-1-f :pinky-1-e]) (def full 9001) ;; Choreography: ;; Let the hand fall palm-up ;; it curls its phalanges, starting with the pinky. ;; it lets its phalanges fall back down. ;; block falls down onto the hand, accompanied by a sound. The block ;; can be seen by the hand's eye. ;; hand FORCEFULLY catapults the block so that it hits the camera. ;; the syntax here is [keyframe body-part force] (def move-fingers [[300 :pinky-3-f 50] [320 :pinky-2-f 80] [340 :pinky-1-f 100] [310 :ring-3-f 100] [330 :ring-2-f 120] [350 :ring-1-f 140] [330 :middle-3-f 120] [340 :middle-2-f 120] [360 :middle-1-f 30] [350 :pointer-3-f 120] [360 :pointer-2-f 120] [380 :pointer-1-f 30] [800 :pinky-3-f 0] [800 :pinky-2-f 0] [800 :pinky-1-f 0] [800 :ring-3-f 0] [800 :ring-2-f 0] [800 :ring-1-f 0] [800 :middle-3-f 0] [800 :middle-2-f 0] [800 :middle-1-f 0] [800 :pointer-3-f 0] [800 :pointer-2-f 0] [800 :pointer-1-f 0] [800 :pinky-3-e 50] [800 :pinky-2-e 80] [800 :pinky-1-e 100] [800 :ring-3-e 100] [800 :ring-2-e 120] [800 :ring-1-e 140] [800 :middle-3-e 120] [800 :middle-2-e 120] [800 :middle-1-e 30] [800 :pointer-3-e 120] [800 :pointer-2-e 120] [800 :pointer-1-e 30] [870 :pinky-3-e 0] [870 :pinky-2-e 0] [870 :pinky-1-e 0] [870 :ring-3-e 0] [870 :ring-2-e 0] [870 :ring-1-e 0] [870 :middle-3-e 0] [870 :middle-2-e 0] [870 :middle-1-e 0] [870 :pointer-3-e 0] [870 :pointer-2-e 0] [870 :pointer-1-e 0] [1500 :pointer-1-f full] [1500 :pointer-2-f full] [1500 :pointer-3-f full] [1500 :middle-1-f full] [1500 :middle-2-f full] [1500 :middle-3-f full] [1510 :pointer-1-f 0] [1510 :pointer-2-f 0] [1510 :pointer-3-f 0] [1510 :middle-1-f 0] [1510 :middle-2-f 0] [1510 :middle-3-f 0] ]) (defn gen-summon-ball [debug?] (let [wait (atom 1100)] (fn [world] (if (= 0 (swap! wait dec)) (let [brick (box 0.8 0.8 0.8 :mass 0.05 :position (Vector3f. -0.5 0 0.5) :color (ColorRGBA/Red)) bell (AudioNode. (asset-manager) "Sounds/pure.wav" false)] (.play bell) (if debug? (.addControl brick (proxy [AbstractControl] [] (controlUpdate [tpf] (println-repl (.getWorldTranslation brick))) (controlRender [_ _])))) (add-element world brick)))))) (import com.aurellem.capture.Capture) (defn test-integration "Testing Everything! You will see an articulated hand fall onto the table. It has all senses including: - Vision, 4 channels - Hearing - Touch - Proprioceptoin - Muscle Tension Keys: : fire ball" ([] (test-integration false)) ([record?] (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false) base (File. "/home/r/proj/cortex/render/hand") creature (doto (load-blender-model hand) (body!)) summon-ball (gen-summon-ball false) ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;; touch (touch! creature) touch-display (view-touch) vision (vision! creature) vision-display (view-vision) hearing (hearing! creature) hearing-display (view-hearing) prop (proprioception! creature) prop-display (view-proprioception) control-script (motor-control-program muscle-positions move-fingers) muscles (movement! creature) muscle-display (view-movement) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fix-display (gen-fix-display)] (world (nodify [creature (box 10 2 10 :position (Vector3f. 0 -9 0) :color ColorRGBA/Gray :mass 0) me]) standard-debug-controls (fn [world] (.setTimer world (RatchetTimer. 60)) (position-camera world (Vector3f. -0.13217318, 5.816415, -5.3089414) (Quaternion. 0.55685693, 0.0042774677, -0.0028673497, 0.83059245)) (light-up-everything world) (enable-debug world) (add-camera! world (add-eye! creature (.getChild (.getChild creature "eyes") "eye")) (comp (view-image) BufferedImage!)) (if record? (Capture/captureVideo world (File. base "main"))) (if record? (Capture/captureAudio world (File. base "main.wav")))) (fn [world tpf] (prop-display (prop) (if record? (File. base "proprio"))) (touch-display (map #(% (.getRootNode world)) touch) (if record? (File. base "touch"))) (vision-display (map #(% world) vision) (if record? (File. base "vision"))) (hearing-display (map #(% world) hearing) (if record? (File. base "hearing"))) (muscle-display (control-script muscles) (if record? (File. base "muscle"))) (summon-ball world) (.setLocalTranslation me (.getLocation (.getCamera world))) (fix-display world))))))