annotate org/integration.org @ 304:2dfebf71053c

Merged Winston cover letter
author Dylan Holmes <ocsenave@gmail.com>
date Sat, 18 Feb 2012 02:07:40 -0600
parents 7e3938f40c52
children 7e7f8d6d9ec5
rev   line source
rlm@281 1 #+title:
rlm@73 2 #+author: Robert McIntyre
rlm@73 3 #+email: rlm@mit.edu
rlm@73 4 #+description:
rlm@73 5 #+keywords: simulation, jMonkeyEngine3, clojure
rlm@73 6 #+SETUPFILE: ../../aurellem/org/setup.org
rlm@73 7 #+INCLUDE: ../../aurellem/org/level-0.org
rlm@73 8
rlm@302 9 * Integration
rlm@129 10
rlm@281 11 This is the ultimate test which features all of the senses that I've
rlm@281 12 made so far. The blender file for the creature serves as an example of
rlm@281 13 a fully equipped creature in terms of senses. You can find it [[../assets/Models/test-creature/hand.blend][here]].
rlm@73 14
rlm@300 15
rlm@300 16 #+begin_html
rlm@300 17 <div class="figure">
rlm@300 18 <video controls="controls" width="755">
rlm@300 19 <source src="../video/hand.ogg" type="video/ogg"
rlm@300 20 preload="none" poster="../images/aurellem-1280x480.png" />
rlm@300 21 </video>
rlm@300 22 <p>Simulated Senses in a Virtual Environment</p>
rlm@300 23 </div>
rlm@300 24 #+end_html
rlm@300 25
rlm@302 26 * Generating the Video
rlm@300 27
rlm@192 28 #+name: integration
rlm@73 29 #+begin_src clojure
rlm@300 30 (ns cortex.test.integration
rlm@73 31 "let's play!"
rlm@192 32 {:author "Robert McIntyre"}
rlm@281 33 (:use (cortex world util body sense
rlm@281 34 hearing touch vision proprioception movement))
rlm@192 35 (:import (com.jme3.math ColorRGBA Vector3f))
rlm@281 36 (:import java.io.File)
rlm@192 37 (:import com.jme3.audio.AudioNode)
rlm@192 38 (:import com.aurellem.capture.RatchetTimer))
rlm@73 39
rlm@281 40 (dorun (cortex.import/mega-import-jme3))
rlm@281 41 (rlm.rlm-commands/help)
rlm@74 42
rlm@281 43 (def hand "Models/test-creature/hand.blend")
rlm@78 44
rlm@281 45 (def output-base (File. "/home/r/proj/cortex/render/hand"))
rlm@300 46 #+end_src
rlm@189 47
rlm@300 48 For this demonstration I have to manually drive the muscles of the
rlm@300 49 hand. I do this by creating a little mini-language to describe
rlm@300 50 simulated muscle contraction.
rlm@297 51
rlm@300 52 #+name: integration-2
rlm@300 53 #+begin_src clojure
rlm@296 54 (defn motor-control-program
rlm@296 55 "Create a function which will execute the motor script"
rlm@296 56 [muscle-positions
rlm@296 57 script]
rlm@296 58 (let [current-frame (atom -1)
rlm@296 59 keyed-script (group-by first script)
rlm@296 60 current-forces (atom {}) ]
rlm@296 61 (fn [effectors]
rlm@296 62 (let [indexed-effectors (vec effectors)]
rlm@296 63 (dorun
rlm@296 64 (for [[_ part force] (keyed-script (swap! current-frame inc))]
rlm@296 65 (swap! current-forces (fn [m] (assoc m part force)))))
rlm@296 66 (doall (map (fn [effector power]
rlm@296 67 (effector (int power)))
rlm@296 68 effectors
rlm@296 69 (map #(@current-forces % 0) muscle-positions)))))))
rlm@296 70
rlm@296 71 (def muscle-positions
rlm@296 72 [:pointer-2-e
rlm@296 73 :pointer-2-f
rlm@296 74 :thumb-1
rlm@296 75 :thumb-1
rlm@296 76 :pointer-1-e
rlm@296 77 :pointer-1-f
rlm@296 78 :thumb-2-e
rlm@296 79 :thumb-2-f
rlm@296 80 :middle-1-e
rlm@296 81 :middle-1-f
rlm@296 82 :pointer-3-f
rlm@296 83 :pointer-3-e
rlm@296 84 :middle-2-e
rlm@296 85 :middle-2-f
rlm@296 86 :middle-3-f
rlm@296 87 :middle-3-e
rlm@296 88 :pinky-2-e
rlm@296 89 :pinky-2-f
rlm@296 90 :pinky-3-f
rlm@296 91 :pinky-3-e
rlm@296 92 :ring-3-e
rlm@296 93 :ring-3-f
rlm@296 94 :ring-2-f
rlm@296 95 :ring-2-e
rlm@296 96 :ring-1-e
rlm@296 97 :ring-1-f
rlm@296 98 :thumb-1-e
rlm@296 99 :thumb-1-f
rlm@296 100 :pinky-1-f
rlm@296 101 :pinky-1-e])
rlm@296 102
rlm@296 103 (def full 9001)
rlm@300 104
rlm@300 105
rlm@300 106 ;; Coreography:
rlm@300 107
rlm@300 108 ;; Let the hand fall palm-up
rlm@300 109
rlm@300 110 ;; it curls its phalanges, starting with the pinky.
rlm@300 111
rlm@300 112 ;; it lets its phalanges fall back down.
rlm@300 113
rlm@300 114 ;; block falls down onto the hand, accompanied by a sound. The block
rlm@300 115 ;; can be seen by the hand's eye.
rlm@300 116
rlm@300 117 ;; hand FORCEFULLY catapults the block so that it hits the camera.
rlm@300 118
rlm@300 119
rlm@296 120 ;; the systax here is [keyframe body-part force]
rlm@300 121 (def move-fingers
rlm@298 122 [[300 :pinky-3-f 50]
rlm@298 123 [320 :pinky-2-f 80]
rlm@298 124 [340 :pinky-1-f 100]
rlm@297 125
rlm@298 126 [310 :ring-3-f 100]
rlm@298 127 [330 :ring-2-f 120]
rlm@298 128 [350 :ring-1-f 140]
rlm@296 129
rlm@298 130 [330 :middle-3-f 120]
rlm@298 131 [340 :middle-2-f 120]
rlm@298 132 [360 :middle-1-f 30]
rlm@296 133
rlm@298 134 [350 :pointer-3-f 120]
rlm@298 135 [360 :pointer-2-f 120]
rlm@298 136 [380 :pointer-1-f 30]
rlm@296 137
rlm@298 138 [800 :pinky-3-f 0]
rlm@298 139 [800 :pinky-2-f 0]
rlm@298 140 [800 :pinky-1-f 0]
rlm@296 141
rlm@298 142 [800 :ring-3-f 0]
rlm@298 143 [800 :ring-2-f 0]
rlm@298 144 [800 :ring-1-f 0]
rlm@296 145
rlm@298 146 [800 :middle-3-f 0]
rlm@298 147 [800 :middle-2-f 0]
rlm@298 148 [800 :middle-1-f 0]
rlm@296 149
rlm@298 150 [800 :pointer-3-f 0]
rlm@298 151 [800 :pointer-2-f 0]
rlm@298 152 [800 :pointer-1-f 0]
rlm@297 153
rlm@297 154
rlm@298 155 [800 :pinky-3-e 50]
rlm@298 156 [800 :pinky-2-e 80]
rlm@298 157 [800 :pinky-1-e 100]
rlm@297 158
rlm@298 159 [800 :ring-3-e 100]
rlm@298 160 [800 :ring-2-e 120]
rlm@298 161 [800 :ring-1-e 140]
rlm@298 162
rlm@298 163 [800 :middle-3-e 120]
rlm@298 164 [800 :middle-2-e 120]
rlm@298 165 [800 :middle-1-e 30]
rlm@298 166
rlm@298 167 [800 :pointer-3-e 120]
rlm@298 168 [800 :pointer-2-e 120]
rlm@298 169 [800 :pointer-1-e 30]
rlm@298 170
rlm@298 171 [870 :pinky-3-e 0]
rlm@298 172 [870 :pinky-2-e 0]
rlm@298 173 [870 :pinky-1-e 0]
rlm@298 174
rlm@298 175 [870 :ring-3-e 0]
rlm@298 176 [870 :ring-2-e 0]
rlm@298 177 [870 :ring-1-e 0]
rlm@298 178
rlm@298 179 [870 :middle-3-e 0]
rlm@298 180 [870 :middle-2-e 0]
rlm@298 181 [870 :middle-1-e 0]
rlm@298 182
rlm@298 183 [870 :pointer-3-e 0]
rlm@298 184 [870 :pointer-2-e 0]
rlm@298 185 [870 :pointer-1-e 0]
rlm@298 186
rlm@298 187 [1500 :pointer-1-f full]
rlm@298 188 [1500 :pointer-2-f full]
rlm@298 189 [1500 :pointer-3-f full]
rlm@298 190
rlm@298 191 [1500 :middle-1-f full]
rlm@298 192 [1500 :middle-2-f full]
rlm@298 193 [1500 :middle-3-f full]
rlm@298 194
rlm@298 195 [1510 :pointer-1-f 0]
rlm@298 196 [1510 :pointer-2-f 0]
rlm@298 197 [1510 :pointer-3-f 0]
rlm@298 198
rlm@298 199 [1510 :middle-1-f 0]
rlm@298 200 [1510 :middle-2-f 0]
rlm@298 201 [1510 :middle-3-f 0]
rlm@297 202 ])
rlm@297 203
rlm@298 204 (defn gen-summon-ball [debug?]
rlm@298 205 (let [wait (atom 1100)]
rlm@297 206 (fn [world]
rlm@297 207 (if (= 0 (swap! wait dec))
rlm@297 208 (let [brick
rlm@297 209 (box 0.8 0.8 0.8 :mass 0.05
rlm@298 210 :position (Vector3f. -0.5 0 0.5)
rlm@298 211 :color (ColorRGBA/Red))
rlm@298 212 bell (AudioNode. (asset-manager)
rlm@298 213 "Sounds/pure.wav" false)]
rlm@298 214 (.play bell)
rlm@298 215 (if debug?
rlm@298 216 (.addControl
rlm@298 217 brick
rlm@298 218 (proxy [AbstractControl] []
rlm@298 219 (controlUpdate [tpf]
rlm@298 220 (println-repl (.getWorldTranslation brick)))
rlm@298 221 (controlRender [_ _]))))
rlm@297 222 (add-element world brick))))))
rlm@295 223
rlm@298 224 (import com.aurellem.capture.Capture)
rlm@298 225
rlm@281 226 (defn test-everything!
rlm@281 227 ([] (test-everything! false))
rlm@281 228 ([record?]
rlm@281 229 (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
rlm@281 230
rlm@298 231 base (File. "/home/r/proj/cortex/render/hand")
rlm@298 232
rlm@298 233
rlm@281 234 creature (doto (load-blender-model hand)
rlm@281 235 (body!))
rlm@297 236
rlm@298 237 summon-ball (gen-summon-ball false)
rlm@192 238 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
rlm@298 239 touch (touch! creature)
rlm@298 240 touch-display (view-touch)
rlm@189 241
rlm@298 242 vision (vision! creature)
rlm@298 243 vision-display (view-vision)
rlm@189 244
rlm@298 245 hearing (hearing! creature)
rlm@298 246 hearing-display (view-hearing)
rlm@189 247
rlm@173 248 prop (proprioception! creature)
rlm@190 249 prop-display (view-proprioception)
rlm@148 250
rlm@296 251 control-script (motor-control-program
rlm@300 252 muscle-positions move-fingers)
rlm@191 253 muscles (movement! creature)
rlm@281 254 muscle-display (view-movement)
rlm@281 255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
rlm@189 256
rlm@281 257 fix-display (gen-fix-display)]
rlm@285 258 (world
rlm@285 259 (nodify [creature
rlm@285 260 (box 10 2 10 :position (Vector3f. 0 -9 0)
rlm@285 261 :color ColorRGBA/Gray :mass 0)
rlm@285 262 me])
rlm@298 263 standard-debug-controls
rlm@298 264
rlm@285 265 (fn [world]
rlm@285 266 (.setTimer world (RatchetTimer. 60))
rlm@297 267 (position-camera
rlm@298 268 world (Vector3f. -0.13217318, 5.816415, -5.3089414)
rlm@298 269 (Quaternion. 0.55685693, 0.0042774677, -0.0028673497, 0.83059245))
rlm@298 270
rlm@285 271 (light-up-everything world)
rlm@285 272 (enable-debug world)
rlm@285 273 (add-camera! world
rlm@285 274 (add-eye! creature
rlm@285 275 (.getChild
rlm@285 276 (.getChild creature "eyes") "eye"))
rlm@285 277 (comp (view-image) BufferedImage!))
rlm@298 278
rlm@298 279 (if record?
rlm@298 280 (Capture/captureVideo
rlm@298 281 world (File. base "main")))
rlm@298 282 (if record?
rlm@298 283 (Capture/captureAudio
rlm@298 284 world (File. base "main.wav"))))
rlm@285 285 (fn [world tpf]
rlm@298 286 (prop-display
rlm@298 287 (prop)
rlm@298 288 (if record? (File. base "proprio")))
rlm@298 289 (touch-display
rlm@298 290 (map #(% (.getRootNode world)) touch)
rlm@298 291 (if record? (File. base "touch")))
rlm@298 292 (vision-display
rlm@298 293 (map #(% world) vision)
rlm@298 294 (if record? (File. base "vision")))
rlm@298 295 (hearing-display
rlm@298 296 (map #(% world) hearing)
rlm@298 297 (if record? (File. base "hearing")))
rlm@298 298 (muscle-display
rlm@298 299 (control-script muscles)
rlm@298 300 (if record? (File. base "muscle")))
rlm@298 301
rlm@297 302 (summon-ball world)
rlm@298 303
rlm@285 304 (.setLocalTranslation me (.getLocation (.getCamera world)))
rlm@285 305 (fix-display world))))))
rlm@300 306 #+end_src
rlm@298 307
rlm@302 308 ** ImageMagick / ffmpeg
rlm@300 309
rlm@300 310 Just a bunch of calls to imagemagick to arrange the data that
rlm@300 311 =test-everything!= produces.
rlm@300 312
rlm@300 313 #+name: magick-8
rlm@300 314 #+begin_src clojure
rlm@300 315 (ns cortex.video.magick8
rlm@300 316 (:import java.io.File)
rlm@300 317 (:use clojure.contrib.shell-out))
rlm@298 318
rlm@298 319 (comment
rlm@298 320 ;; list of touch targets
rlm@298 321 0 middle-11
rlm@298 322 1 middle-21
rlm@298 323 2 middle-31
rlm@298 324 3 pinky-11
rlm@298 325 4 pinky-21
rlm@298 326 5 pinky-31
rlm@298 327 6 pointer-11
rlm@298 328 7 pointer-21
rlm@298 329 8 pointer-31
rlm@298 330 9 ring-11
rlm@298 331 10 ring-21
rlm@298 332 11 ring-31
rlm@298 333 12 thumb-11
rlm@298 334 13 thumb-2.0011
rlm@298 335
rlm@298 336
rlm@298 337 ;; list of vision targets
rlm@298 338 0 :all
rlm@298 339 1 :green
rlm@298 340 2 :blue
rlm@298 341 3 :red
rlm@298 342
rlm@298 343 ;; list of proprio targets
rlm@298 344 0 middle-11 -> middle-21
rlm@298 345 1 middle-21 -> middle-31
rlm@298 346 2 thumb-11 -> thumb-2.0011
rlm@298 347 3 pointer-11 -> pointer-21
rlm@298 348 4 pointer-21 -> pointer-31
rlm@298 349 5 ring-21 -> ring-31
rlm@298 350 6 ring-11 -> ring-21
rlm@298 351 7 pinky-21 -> pinky-31
rlm@298 352 8 pinky-11 -> pinky-21
rlm@298 353 9 middle-11 -> palm1
rlm@298 354 10 pinky-11 -> palm1
rlm@298 355 11 palm1 -> pointer-11
rlm@298 356 12 palm1 -> ring-11
rlm@298 357 13 palm1 -> thumb-11
rlm@298 358
rlm@298 359
rlm@298 360 ;; list of muscle targets
rlm@298 361 0 :pointer-2-e
rlm@298 362 1 :pointer-2-f
rlm@298 363 2 :thumb-1
rlm@298 364 3 :thumb-1
rlm@298 365 4 :pointer-1-e
rlm@298 366 5 :pointer-1-f
rlm@298 367 6 :thumb-2-e
rlm@298 368 7 :thumb-2-f
rlm@298 369 8 :middle-1-e
rlm@298 370 9 :middle-1-f
rlm@298 371 10 :pointer-3-f
rlm@298 372 11 :pointer-3-e
rlm@298 373 12 :middle-2-e
rlm@298 374 13 :middle-2-f
rlm@298 375 14 :middle-3-f
rlm@298 376 15 :middle-3-e
rlm@298 377 16 :pinky-2-e
rlm@298 378 17 :pinky-2-f
rlm@298 379 18 :pinky-3-f
rlm@298 380 19 :pinky-3-e
rlm@298 381 20 :ring-3-e
rlm@298 382 21 :ring-3-f
rlm@298 383 22 :ring-2-f
rlm@298 384 23 :ring-2-e
rlm@298 385 24 :ring-1-e
rlm@298 386 25 :ring-1-f
rlm@298 387 26 :thumb-1-e
rlm@298 388 27 :thumb-1-f
rlm@298 389 28 :pinky-1-f
rlm@298 390 29 :pinky-1-e
rlm@298 391 )
rlm@298 392
rlm@298 393 (def base (File. "/home/r/proj/cortex/render/hand"))
rlm@298 394
rlm@298 395 (defn prepare-muscle [muscle]
rlm@298 396 ["(" muscle "-rotate" "90" "-scale" "15x60!" ")"])
rlm@298 397
rlm@298 398 (defn prepare-touch [touch]
rlm@298 399 ["(" touch "-rotate" "180" ")"])
rlm@298 400
rlm@298 401 (defn generate-top-finger [tip-flexor tip-extensor tip
rlm@298 402 joint-2-3
rlm@298 403 mid-flexor mid-extensor mid
rlm@298 404 joint-1-2]
rlm@298 405 ["("
rlm@298 406 "-size" "113x357" "xc:transparent"
rlm@298 407 (prepare-muscle tip-flexor) "-geometry" "+0+7" "-composite"
rlm@298 408 (prepare-muscle tip-extensor) "-geometry" "+98+7" "-composite"
rlm@298 409 (prepare-touch tip) "-geometry" "+18+0" "-composite"
rlm@298 410
rlm@298 411 joint-2-3 "-geometry" "+32+79" "-composite"
rlm@298 412
rlm@298 413 (prepare-muscle mid-flexor) "-geometry" "+19+131" "-composite"
rlm@298 414 (prepare-muscle mid-extensor) "-geometry" "+80+131" "-composite"
rlm@298 415 (prepare-touch mid) "-geometry" "+39+133" "-composite"
rlm@298 416
rlm@298 417 joint-1-2 "-geometry" "+32+193" "-composite"
rlm@298 418 ")"])
rlm@298 419
rlm@299 420 (defn file-names [#^File dir]
rlm@299 421 (map #(.getCanonicalPath %) (next (sort (file-seq dir)))))
rlm@299 422
rlm@299 423 (defn file-groups [& paths]
rlm@299 424 (apply (partial map list )
rlm@299 425 (map (comp file-names #(File. base %))
rlm@299 426 paths)))
rlm@299 427
rlm@299 428 (defn pinky []
rlm@299 429 (file-groups
rlm@299 430 "muscle/18"
rlm@299 431 "muscle/19"
rlm@299 432 "touch/5"
rlm@299 433 "proprio/7"
rlm@299 434
rlm@299 435 "muscle/17"
rlm@299 436 "muscle/16"
rlm@299 437 "touch/4"
rlm@299 438 "proprio/8"
rlm@299 439
rlm@299 440 "muscle/28"
rlm@299 441 "muscle/29"
rlm@299 442 "touch/3"
rlm@299 443 "proprio/10"))
rlm@299 444
rlm@299 445 (defn ring []
rlm@299 446 (file-groups
rlm@299 447 "muscle/21"
rlm@299 448 "muscle/20"
rlm@299 449 "touch/11"
rlm@299 450 "proprio/5"
rlm@299 451
rlm@299 452 "muscle/22"
rlm@299 453 "muscle/23"
rlm@299 454 "touch/10"
rlm@299 455 "proprio/6"
rlm@299 456
rlm@299 457 "muscle/25"
rlm@299 458 "muscle/24"
rlm@299 459 "touch/9"
rlm@299 460 "proprio/12"))
rlm@299 461
rlm@299 462 (defn middle []
rlm@299 463 (file-groups
rlm@299 464 "muscle/14"
rlm@299 465 "muscle/15"
rlm@299 466 "touch/2"
rlm@299 467 "proprio/1"
rlm@299 468
rlm@300 469 "muscle/13"
rlm@299 470 "muscle/12"
rlm@299 471 "touch/1"
rlm@299 472 "proprio/0"
rlm@299 473
rlm@300 474 "muscle/9"
rlm@299 475 "muscle/8"
rlm@299 476 "touch/0"
rlm@299 477 "proprio/9"))
rlm@299 478
rlm@299 479 (defn pointer []
rlm@299 480 (file-groups
rlm@299 481 "muscle/10"
rlm@299 482 "muscle/11"
rlm@299 483 "touch/8"
rlm@299 484 "proprio/4"
rlm@299 485
rlm@299 486 "muscle/1"
rlm@299 487 "muscle/0"
rlm@299 488 "touch/7"
rlm@299 489 "proprio/3"
rlm@299 490
rlm@299 491 "muscle/5"
rlm@299 492 "muscle/4"
rlm@299 493 "touch/6"
rlm@299 494 "proprio/11"))
rlm@299 495
rlm@299 496 (defn thumb []
rlm@299 497 (file-groups
rlm@299 498 "muscle/7"
rlm@299 499 "muscle/6"
rlm@299 500 "touch/13"
rlm@299 501 "proprio/2"
rlm@299 502
rlm@299 503 "muscle/27"
rlm@299 504 "muscle/26"
rlm@299 505 "muscle/3"
rlm@299 506 "muscle/2"
rlm@299 507 "touch/12"
rlm@299 508 "proprio/13"))
rlm@299 509
rlm@298 510 (defn generate-finger
rlm@298 511 [tip-flexor tip-extensor tip
rlm@298 512 joint-2-3
rlm@298 513 mid-flexor mid-extensor mid
rlm@298 514 joint-1-2
rlm@298 515 base-flexor base-extensor base
rlm@298 516 joint-palm-1]
rlm@298 517 ["("
rlm@298 518 "-size" "113x357" "xc:transparent"
rlm@298 519 (generate-top-finger
rlm@298 520 tip-flexor tip-extensor tip
rlm@298 521 joint-2-3
rlm@298 522 mid-flexor mid-extensor mid
rlm@298 523 joint-1-2) "-geometry" "+0+0" "-composite"
rlm@298 524 (prepare-muscle base-flexor) "-geometry" "+19+245" "-composite"
rlm@298 525 (prepare-muscle base-extensor) "-geometry" "+80+245" "-composite"
rlm@298 526 (prepare-touch base) "-geometry" "+39+247" "-composite"
rlm@298 527 joint-palm-1 "-geometry" "+32+307" "-composite"
rlm@298 528 ")"])
rlm@298 529
rlm@298 530 (defn generate-thumb
rlm@298 531 [tip-flexor tip-extensor tip
rlm@298 532 joint-1-2
rlm@298 533 mid-flexor mid-extensor mid-flexor-2 mid-extensor-2 mid
rlm@298 534 joint-palm-1]
rlm@298 535 ["("
rlm@298 536 "-size" "113x357" "xc:transparent"
rlm@298 537 (generate-top-finger
rlm@298 538 tip-flexor tip-extensor tip
rlm@298 539 joint-1-2
rlm@298 540 mid-flexor mid-extensor mid
rlm@298 541 joint-palm-1) "-geometry" "+0+0" "-composite"
rlm@298 542 (prepare-muscle mid-flexor-2) "-geometry" "+2+131" "-composite"
rlm@298 543 (prepare-muscle mid-extensor-2) "-geometry" "+100+131" "-composite"
rlm@298 544 ")"])
rlm@298 545
rlm@298 546 (defn generate-hand
rlm@298 547 [pinky-pieces
rlm@298 548 ring-pieces
rlm@298 549 middle-pieces
rlm@298 550 pointer-pieces
rlm@298 551 thumb-pieces]
rlm@298 552 ["("
rlm@298 553 "-size" "688x769" "xc:transparent"
rlm@298 554 (apply generate-finger pinky-pieces)
rlm@298 555 "-geometry" "+0+195" "-composite"
rlm@298 556 (apply generate-finger ring-pieces)
rlm@298 557 "-geometry" "+111+100" "-composite"
rlm@298 558 (apply generate-finger middle-pieces)
rlm@298 559 "-geometry" "+228+0" "-composite"
rlm@298 560 "(" (apply generate-thumb thumb-pieces) "-background" "#00000000"
rlm@298 561 "-rotate" "45" ")"
rlm@298 562 "-geometry" "+300+420" "-composite"
rlm@298 563 (apply generate-finger pointer-pieces)
rlm@298 564 "-geometry" "+350+96" "-composite"
rlm@298 565 ")"])
rlm@298 566
rlm@298 567 (defn generate-vision
rlm@298 568 [all green blue red]
rlm@298 569 ["("
rlm@298 570 "-size" "204x192" "xc:transparent"
rlm@298 571 all "-geometry" "+0+0" "-composite"
rlm@298 572 green "-geometry" "+113+0" "-composite"
rlm@298 573 blue "-geometry" "+0+105" "-composite"
rlm@298 574 red "-geometry" "+113+105" "-composite"
rlm@298 575 ")"])
rlm@298 576
rlm@298 577 (def test-muscle (File. base "muscle/0/0000000.png"))
rlm@298 578 (def test-proprio (File. base "proprio/0/0000000.png"))
rlm@298 579 (def test-tip (File. base "touch/2/0000000.png"))
rlm@298 580 (def test-mid (File. base "touch/0/0000000.png"))
rlm@298 581 (def test-vision (File. base "vision/0/0000000.png"))
rlm@298 582 (def test-hearing (File. base "hearing/0/0000000.png"))
rlm@298 583 (def test-main (File. base "main/0000000.png"))
rlm@298 584
rlm@298 585 (def test-target (File. base "output.png"))
rlm@298 586
rlm@298 587 (def background (File. base "background.png"))
rlm@298 588
rlm@298 589 (use 'clojure.contrib.shell-out)
rlm@299 590
rlm@299 591 (defn vision []
rlm@299 592 (file-groups
rlm@299 593 "vision/0"
rlm@299 594 "vision/1"
rlm@299 595 "vision/2"
rlm@299 596 "vision/3"))
rlm@299 597
rlm@299 598 (defn hearing []
rlm@299 599 (file-names (File. base "hearing/0")))
rlm@299 600
rlm@299 601 (defn main []
rlm@299 602 (file-names (File. base "main")))
rlm@299 603
rlm@300 604 (defn targets [dest max]
rlm@299 605 (map
rlm@299 606 (comp #(.getCanonicalPath %)
rlm@300 607 #(File. (str base dest (format "%07d.png" %))))
rlm@300 608 (range max)))
rlm@299 609
rlm@299 610
rlm@299 611 (defn final-image [main [all red green blue] hearing
rlm@299 612 pinky ring middle pointer thumb target]
rlm@299 613 (println target)
rlm@299 614 (apply
rlm@298 615 sh
rlm@298 616 (flatten
rlm@298 617 ["convert"
rlm@298 618 (.getCanonicalPath background)
rlm@299 619
rlm@299 620 (generate-hand pinky ring middle pointer thumb)
rlm@298 621 "-geometry" "+809+22" "-composite"
rlm@298 622
rlm@299 623 (generate-vision all red green blue)
rlm@298 624 "-geometry" "+974+599" "-composite"
rlm@298 625
rlm@298 626 hearing
rlm@298 627 "-geometry" "+784+819" "-composite"
rlm@298 628
rlm@298 629 main
rlm@298 630 "-geometry" "+78+202" "-composite"
rlm@298 631
rlm@299 632 target])))
rlm@298 633
rlm@300 634 (defn combine-files []
rlm@299 635 (dorun
rlm@299 636 (pmap final-image
rlm@299 637 (main)
rlm@299 638 (vision)
rlm@299 639 (hearing)
rlm@299 640 (pinky)
rlm@299 641 (ring)
rlm@299 642 (middle)
rlm@299 643 (pointer)
rlm@299 644 (thumb)
rlm@300 645 (targets "/out/" (count (main))))))
rlm@300 646
rlm@300 647 (defn subtitles []
rlm@300 648 (file-names (File. base "subs")))
rlm@300 649
rlm@300 650 (defn outs []
rlm@300 651 (file-names (File. base "out")))
rlm@300 652
rlm@300 653
rlm@300 654 (defn mix-subtitles []
rlm@300 655 (let [subs (subtitles)
rlm@300 656 targets (targets "/out-subs/" (count subs))
rlm@300 657 overlay (.getCanonicalPath (File. base "output.png"))]
rlm@300 658 (dorun
rlm@300 659 (pmap
rlm@300 660 (fn [sub target]
rlm@300 661 (sh
rlm@300 662 "convert"
rlm@300 663 overlay
rlm@300 664 sub "-geometry" "+0+0" "-composite"
rlm@300 665 target))
rlm@300 666 subs targets))))
rlm@300 667
rlm@300 668 (defn out-subtitles []
rlm@300 669 (file-names (File. base "out-subs")))
rlm@300 670
rlm@300 671
rlm@300 672 (defn insert-subtitles []
rlm@300 673 (let [subtitles (out-subtitles)
rlm@300 674 outs (outs)
rlm@300 675 targets (targets
rlm@300 676 "/final/"
rlm@300 677 (+ (count outs) (count subtitles)))]
rlm@300 678 (dorun
rlm@300 679 (pmap
rlm@300 680 #(sh "cp" %1 %2)
rlm@300 681 (concat subtitles outs) targets))))
rlm@300 682
rlm@300 683 (defn generate-final []
rlm@300 684 (combine-files)
rlm@300 685 (mix-subtitles)
rlm@300 686 (insert-subtitles))
rlm@299 687 #+end_src
rlm@298 688
rlm@300 689 #+begin_src sh :results silent
rlm@299 690 cd /home/r/proj/cortex/render/hand
rlm@298 691
rlm@300 692 sox --ignore-length main.wav main-delayed.wav delay 24
rlm@300 693
rlm@300 694 mogrify -resize 755x final/*
rlm@300 695
rlm@300 696 ffmpeg -r 60 -i final/%07d.png -i main-delayed.wav -b:a 128k \
rlm@299 697 -b:v 9000k -c:a libvorbis -c:v libtheora hand.ogg
rlm@87 698 #+end_src
rlm@83 699
rlm@301 700
rlm@301 701 * Source Listing
rlm@301 702 - [[../src/cortex/test/integration.clj][cortex.test.integration]]
rlm@302 703 - [[../src/cortex/video/magick8.clj][cortex.video.magick8]]
rlm@301 704 - [[../assets/Models/subtitles/hand.blend][subtitles/hand.blend]]
rlm@301 705 #+html: <ul> <li> <a href="../org/integration.org">This org file</a> </li> </ul>
rlm@301 706 - [[http://hg.bortreb.com ][source-repository]]
rlm@301 707
rlm@301 708
rlm@78 709 * COMMENT purgatory
rlm@78 710 #+begin_src clojure
rlm@77 711 (defn bullet-trans* []
rlm@77 712 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
rlm@77 713 :position (Vector3f. 5 0 0)
rlm@77 714 :mass 90)
rlm@77 715 obj-b (sphere 0.5 :color ColorRGBA/Blue
rlm@77 716 :position (Vector3f. -5 0 0)
rlm@77 717 :mass 0)
rlm@77 718 control-a (.getControl obj-a RigidBodyControl)
rlm@77 719 control-b (.getControl obj-b RigidBodyControl)
rlm@77 720 move-up? (atom nil)
rlm@77 721 move-down? (atom nil)
rlm@77 722 move-left? (atom nil)
rlm@77 723 move-right? (atom nil)
rlm@77 724 roll-left? (atom nil)
rlm@77 725 roll-right? (atom nil)
rlm@77 726 force 100
rlm@77 727 swivel
rlm@77 728 (.toRotationMatrix
rlm@77 729 (doto (Quaternion.)
rlm@77 730 (.fromAngleAxis (/ Math/PI 2)
rlm@77 731 Vector3f/UNIT_X)))
rlm@77 732 x-move
rlm@77 733 (doto (Matrix3f.)
rlm@77 734 (.fromStartEndVectors Vector3f/UNIT_X
rlm@77 735 (.normalize (Vector3f. 1 1 0))))
rlm@77 736
rlm@77 737 timer (atom 0)]
rlm@77 738 (doto
rlm@77 739 (ConeJoint.
rlm@77 740 control-a control-b
rlm@77 741 (Vector3f. -8 0 0)
rlm@77 742 (Vector3f. 2 0 0)
rlm@77 743 ;;swivel swivel
rlm@77 744 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
rlm@77 745 x-move Matrix3f/IDENTITY
rlm@77 746 )
rlm@77 747 (.setCollisionBetweenLinkedBodys false)
rlm@77 748 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
rlm@77 749 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
rlm@77 750 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
rlm@77 751 (world (nodify
rlm@77 752 [obj-a obj-b])
rlm@77 753 (merge standard-debug-controls
rlm@77 754 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@77 755 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@77 756 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@77 757 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@77 758 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@77 759 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@77 760
rlm@77 761 (fn [world]
rlm@77 762 (enable-debug world)
rlm@77 763 (set-gravity world Vector3f/ZERO)
rlm@77 764 )
rlm@77 765
rlm@77 766 (fn [world _]
rlm@77 767
rlm@77 768 (if @move-up?
rlm@77 769 (.applyForce control-a
rlm@77 770 (Vector3f. force 0 0)
rlm@77 771 (Vector3f. 0 0 0)))
rlm@77 772 (if @move-down?
rlm@77 773 (.applyForce control-a
rlm@77 774 (Vector3f. (- force) 0 0)
rlm@77 775 (Vector3f. 0 0 0)))
rlm@77 776 (if @move-left?
rlm@77 777 (.applyForce control-a
rlm@77 778 (Vector3f. 0 force 0)
rlm@77 779 (Vector3f. 0 0 0)))
rlm@77 780 (if @move-right?
rlm@77 781 (.applyForce control-a
rlm@77 782 (Vector3f. 0 (- force) 0)
rlm@77 783 (Vector3f. 0 0 0)))
rlm@77 784
rlm@77 785 (if @roll-left?
rlm@77 786 (.applyForce control-a
rlm@77 787 (Vector3f. 0 0 force)
rlm@77 788 (Vector3f. 0 0 0)))
rlm@77 789 (if @roll-right?
rlm@77 790 (.applyForce control-a
rlm@77 791 (Vector3f. 0 0 (- force))
rlm@77 792 (Vector3f. 0 0 0)))
rlm@77 793
rlm@77 794 (if (zero? (rem (swap! timer inc) 100))
rlm@77 795 (.attachChild
rlm@77 796 (.getRootNode world)
rlm@77 797 (sphere 0.05 :color ColorRGBA/Yellow
rlm@77 798 :physical? false :position
rlm@77 799 (.getWorldTranslation obj-a)))))
rlm@77 800 )
rlm@77 801 ))
rlm@77 802
rlm@106 803 (defn test-joint [joint]
rlm@106 804 (let [[origin top bottom floor] (world-setup joint)
rlm@106 805 control (.getControl top RigidBodyControl)
rlm@106 806 move-up? (atom false)
rlm@106 807 move-down? (atom false)
rlm@106 808 move-left? (atom false)
rlm@106 809 move-right? (atom false)
rlm@106 810 roll-left? (atom false)
rlm@106 811 roll-right? (atom false)
rlm@106 812 timer (atom 0)]
rlm@106 813
rlm@106 814 (world
rlm@106 815 (nodify [top bottom floor origin])
rlm@106 816 (merge standard-debug-controls
rlm@106 817 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@106 818 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@106 819 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@106 820 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@106 821 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@106 822 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@106 823
rlm@106 824 (fn [world]
rlm@106 825 (light-up-everything world)
rlm@106 826 (enable-debug world)
rlm@106 827 (set-gravity world (Vector3f. 0 0 0))
rlm@106 828 )
rlm@106 829
rlm@106 830 (fn [world _]
rlm@106 831 (if (zero? (rem (swap! timer inc) 100))
rlm@106 832 (do
rlm@106 833 ;; (println-repl @timer)
rlm@106 834 (.attachChild (.getRootNode world)
rlm@106 835 (sphere 0.05 :color ColorRGBA/Yellow
rlm@106 836 :position (.getWorldTranslation top)
rlm@106 837 :physical? false))
rlm@106 838 (.attachChild (.getRootNode world)
rlm@106 839 (sphere 0.05 :color ColorRGBA/LightGray
rlm@106 840 :position (.getWorldTranslation bottom)
rlm@106 841 :physical? false))))
rlm@106 842
rlm@106 843 (if @move-up?
rlm@106 844 (.applyTorque control
rlm@106 845 (.mult (.getPhysicsRotation control)
rlm@106 846 (Vector3f. 0 0 10))))
rlm@106 847 (if @move-down?
rlm@106 848 (.applyTorque control
rlm@106 849 (.mult (.getPhysicsRotation control)
rlm@106 850 (Vector3f. 0 0 -10))))
rlm@106 851 (if @move-left?
rlm@106 852 (.applyTorque control
rlm@106 853 (.mult (.getPhysicsRotation control)
rlm@106 854 (Vector3f. 0 10 0))))
rlm@106 855 (if @move-right?
rlm@106 856 (.applyTorque control
rlm@106 857 (.mult (.getPhysicsRotation control)
rlm@106 858 (Vector3f. 0 -10 0))))
rlm@106 859 (if @roll-left?
rlm@106 860 (.applyTorque control
rlm@106 861 (.mult (.getPhysicsRotation control)
rlm@106 862 (Vector3f. -1 0 0))))
rlm@106 863 (if @roll-right?
rlm@106 864 (.applyTorque control
rlm@106 865 (.mult (.getPhysicsRotation control)
rlm@106 866 (Vector3f. 1 0 0))))))))
rlm@99 867 #+end_src
rlm@192 868
rlm@99 869
rlm@99 870 * COMMENT generate source
rlm@300 871 #+begin_src clojure :tangle ../src/cortex/test/integration.clj
rlm@192 872 <<integration>>
rlm@300 873 <<integration-2>>
rlm@300 874 #+end_src
rlm@300 875
rlm@300 876 #+begin_src clojure :tangle ../src/cortex/video/magick8.clj
rlm@300 877 <<magick-8>>
rlm@99 878 #+end_src