annotate org/integration.org @ 385:aea7ebf61cde

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