changeset 300:c78917fb0615

created first version of the video which demonstrates all the senses
author Robert McIntyre <rlm@mit.edu>
date Fri, 17 Feb 2012 11:06:27 -0700
parents 47fe4f7b74b3
children 4203c2140b95
files assets/Models/subtitles/hand.blend org/integration.org
diffstat 2 files changed, 109 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
     1.1 Binary file assets/Models/subtitles/hand.blend has changed
     2.1 --- a/org/integration.org	Thu Feb 16 21:14:28 2012 -0700
     2.2 +++ b/org/integration.org	Fri Feb 17 11:06:27 2012 -0700
     2.3 @@ -12,9 +12,22 @@
     2.4  made so far. The blender file for the creature serves as an example of
     2.5  a fully equipped creature in terms of senses. You can find it [[../assets/Models/test-creature/hand.blend][here]].
     2.6  
     2.7 +
     2.8 +#+begin_html
     2.9 +<div class="figure">
    2.10 +<video controls="controls" width="755">
    2.11 +  <source src="../video/hand.ogg" type="video/ogg"
    2.12 +	  preload="none" poster="../images/aurellem-1280x480.png" />
    2.13 +</video>
    2.14 +<p>Simulated Senses in a Virtual Environment</p>
    2.15 +</div>
    2.16 +#+end_html
    2.17 +
    2.18 +
    2.19 +
    2.20  #+name: integration
    2.21  #+begin_src clojure 
    2.22 -(ns cortex.integration
    2.23 +(ns cortex.test.integration
    2.24    "let's play!"
    2.25    {:author "Robert McIntyre"}
    2.26    (:use (cortex world util body sense
    2.27 @@ -30,20 +43,14 @@
    2.28  (def hand "Models/test-creature/hand.blend")
    2.29  
    2.30  (def output-base (File. "/home/r/proj/cortex/render/hand"))
    2.31 +#+end_src
    2.32  
    2.33 +For this demonstration I have to manually drive the muscles of the
    2.34 +hand. I do this by creating a little mini-language to describe
    2.35 +simulated muscle contraction.
    2.36  
    2.37 -;; Let the hand fall palm-up
    2.38 -
    2.39 -;; it curls its phalanges, starting with the pinky.
    2.40 -
    2.41 -;; it lets these fall back down?
    2.42 -
    2.43 -;; block falls down onto the hand, accompanied by a sound. The block
    2.44 -;; can be seen by the hand's eye.
    2.45 -
    2.46 -;; hand FORCEFULLY catapults the  block so that it hits the camera.
    2.47 -
    2.48 -
    2.49 +#+name: integration-2
    2.50 +#+begin_src clojure
    2.51  (defn motor-control-program
    2.52    "Create a function which will execute the motor script"
    2.53    [muscle-positions
    2.54 @@ -94,8 +101,24 @@
    2.55     :pinky-1-e])
    2.56  
    2.57  (def full 9001)
    2.58 +
    2.59 +
    2.60 +;; Coreography:
    2.61 +
    2.62 +;; Let the hand fall palm-up
    2.63 +
    2.64 +;; it curls its phalanges, starting with the pinky.
    2.65 +
    2.66 +;; it lets its phalanges fall back down.
    2.67 +
    2.68 +;; block falls down onto the hand, accompanied by a sound. The block
    2.69 +;; can be seen by the hand's eye.
    2.70 +
    2.71 +;; hand FORCEFULLY catapults the  block so that it hits the camera.
    2.72 +
    2.73 +
    2.74  ;; the systax here is [keyframe body-part force]
    2.75 -(def wiggle-each-finger-tip
    2.76 +(def move-fingers
    2.77    [[300 :pinky-3-f 50]
    2.78     [320 :pinky-2-f 80]
    2.79     [340 :pinky-1-f 100]
    2.80 @@ -197,41 +220,6 @@
    2.81                   (println-repl (.getWorldTranslation brick)))
    2.82                 (controlRender [_ _]))))
    2.83            (add-element world brick))))))
    2.84 -          
    2.85 -
    2.86 -(def control-list
    2.87 - [
    2.88 -  0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.89 -  0 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.90 -  0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)>
    2.91 -  0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)>
    2.92 -  0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.93 -  0 ;;pointer-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.94 -  0 ;;thumb-2.0011 #<Vector3f (-0.71705645, -0.44753736, -0.5343599)>
    2.95 -  0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)>
    2.96 -  0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)>
    2.97 -  0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.98 -  0 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
    2.99 -  0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)>
   2.100 -  0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)>
   2.101 -  0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.102 -  0 ;;middle-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.103 -  0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)>
   2.104 -  0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)>
   2.105 -  0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.106 -  0 ;;pinky-31 #<Vector3f (-1, 0.0, 0.0)>
   2.107 -  0 ;;pinky-31 #<Vector3f (1.0, 0.0, 0.0)>
   2.108 -  0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)>
   2.109 -  0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.110 -  0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.111 -  0 ;;ring-21 #<Vector3f (0.99999994, 0.0, 0.0)>
   2.112 -  0 ;;ring-11 #<Vector3f (0.99999994, 0.0, 0.0)>
   2.113 -  0 ;;ring-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.114 -  0 ;;thumb-11 #<Vector3f (-0.43154645, 0.7302033, 0.5296894)>
   2.115 -  0 ;;thumb-11 #<Vector3f (-0.8032993, -0.2722854, -0.5296895)>
   2.116 -  0 ;;pinky-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
   2.117 -  0 ;;pinky-11 #<Vector3f (0.99999994, 0.0, 0.0)>
   2.118 -  ])
   2.119  
   2.120  (import com.aurellem.capture.Capture)
   2.121  
   2.122 @@ -261,7 +249,7 @@
   2.123          prop-display (view-proprioception)
   2.124  
   2.125          control-script (motor-control-program
   2.126 -                        muscle-positions wiggle-each-finger-tip)
   2.127 +                        muscle-positions move-fingers)
   2.128          muscles (movement! creature)
   2.129          muscle-display (view-movement)
   2.130          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   2.131 @@ -315,7 +303,18 @@
   2.132         
   2.133         (.setLocalTranslation me (.getLocation (.getCamera world)))
   2.134         (fix-display world))))))
   2.135 +#+end_src
   2.136  
   2.137 +* Generating the Video
   2.138 +
   2.139 +Just a bunch of calls to imagemagick to arrange the data that
   2.140 +=test-everything!= produces.
   2.141 +
   2.142 +#+name: magick-8
   2.143 +#+begin_src clojure
   2.144 +(ns cortex.video.magick8
   2.145 +  (:import java.io.File)
   2.146 +  (:use clojure.contrib.shell-out))
   2.147  
   2.148  (comment
   2.149  ;; list of touch targets
   2.150 @@ -426,7 +425,6 @@
   2.151           (map (comp file-names #(File. base %))
   2.152                paths)))
   2.153    
   2.154 -
   2.155  (defn pinky []
   2.156    (file-groups
   2.157     "muscle/18"
   2.158 @@ -468,13 +466,13 @@
   2.159     "touch/2"
   2.160     "proprio/1"
   2.161  
   2.162 +   "muscle/13"
   2.163     "muscle/12"
   2.164 -   "muscle/13"
   2.165     "touch/1"
   2.166     "proprio/0"
   2.167  
   2.168 +   "muscle/9"
   2.169     "muscle/8"
   2.170 -   "muscle/9"
   2.171     "touch/0"
   2.172     "proprio/9"))
   2.173  
   2.174 @@ -603,11 +601,11 @@
   2.175  (defn main []
   2.176    (file-names (File. base "main")))
   2.177  
   2.178 -(defn targets []
   2.179 +(defn targets [dest max]
   2.180    (map
   2.181     (comp #(.getCanonicalPath %)
   2.182 -         #(File. (str base "/out/" (format "%07d.png" %))))
   2.183 -   (range 0 (count (main)))))
   2.184 +         #(File. (str base dest (format "%07d.png" %))))
   2.185 +   (range max)))
   2.186  
   2.187  
   2.188  (defn final-image [main [all red green blue] hearing
   2.189 @@ -633,7 +631,7 @@
   2.190                
   2.191         target])))
   2.192    
   2.193 -(defn convert-files []
   2.194 +(defn combine-files []
   2.195    (dorun
   2.196     (pmap final-image
   2.197           (main)
   2.198 @@ -644,20 +642,61 @@
   2.199           (middle)
   2.200           (pointer)
   2.201           (thumb)
   2.202 -         (targets))))
   2.203 +         (targets "/out/" (count (main))))))
   2.204 +
   2.205 +(defn subtitles [] 
   2.206 +  (file-names (File. base "subs")))
   2.207 +
   2.208 +(defn outs []
   2.209 +  (file-names (File. base "out")))
   2.210 +
   2.211 +
   2.212 +(defn mix-subtitles []
   2.213 +  (let [subs (subtitles)
   2.214 +        targets (targets "/out-subs/" (count subs))
   2.215 +        overlay (.getCanonicalPath (File. base "output.png"))]
   2.216 +    (dorun 
   2.217 +     (pmap
   2.218 +      (fn [sub target]
   2.219 +        (sh
   2.220 +         "convert"
   2.221 +         overlay
   2.222 +         sub "-geometry" "+0+0" "-composite"
   2.223 +         target))
   2.224 +      subs targets))))
   2.225 +
   2.226 +(defn out-subtitles []
   2.227 +  (file-names (File. base "out-subs")))
   2.228 +                    
   2.229 +
   2.230 +(defn insert-subtitles []
   2.231 +  (let [subtitles (out-subtitles)
   2.232 +        outs (outs)
   2.233 +        targets (targets
   2.234 +                 "/final/"
   2.235 +                 (+ (count outs) (count subtitles)))]
   2.236 +    (dorun
   2.237 +     (pmap
   2.238 +      #(sh "cp" %1 %2)
   2.239 +      (concat subtitles outs) targets))))
   2.240 +
   2.241 +(defn generate-final []
   2.242 +  (combine-files)
   2.243 +   (mix-subtitles)
   2.244 +   (insert-subtitles))
   2.245  #+end_src
   2.246  
   2.247 -
   2.248 -#+begin_src sh
   2.249 +#+begin_src sh :results silent
   2.250  cd /home/r/proj/cortex/render/hand
   2.251  
   2.252 -ffmpeg -r 60 -i out/%07d.png -i main.wav -b:a 128k \
   2.253 +sox --ignore-length main.wav main-delayed.wav delay 24 
   2.254 +
   2.255 +mogrify -resize 755x final/*
   2.256 +
   2.257 +ffmpeg -r 60 -i final/%07d.png -i main-delayed.wav -b:a 128k \
   2.258           -b:v 9000k -c:a libvorbis -c:v libtheora hand.ogg 
   2.259  #+end_src
   2.260  
   2.261 -#+results: integration
   2.262 -: #'cortex.integration/convert-files
   2.263 -
   2.264  * COMMENT purgatory
   2.265  #+begin_src clojure
   2.266  (defn bullet-trans* []
   2.267 @@ -820,8 +859,13 @@
   2.268    
   2.269  
   2.270  * COMMENT generate source
   2.271 -#+begin_src clojure :tangle ../src/cortex/integration.clj
   2.272 +#+begin_src clojure :tangle ../src/cortex/test/integration.clj
   2.273  <<integration>>
   2.274 +<<integration-2>>
   2.275 +#+end_src
   2.276 +
   2.277 +#+begin_src clojure :tangle ../src/cortex/video/magick8.clj
   2.278 +<<magick-8>>
   2.279  #+end_src
   2.280  
   2.281