changeset 58:25142dad240a

created test suite
author Robert McIntyre <rlm@mit.edu>
date Sat, 19 Nov 2011 23:42:21 -0700
parents 37a3256e1ed3
children 63951929fe44
files assets/Models/anim2/joint-worm.blend org/body.org org/eyes.org org/skin.org org/test.org
diffstat 5 files changed, 253 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
     1.1 Binary file assets/Models/anim2/joint-worm.blend has changed
     2.1 --- a/org/body.org	Wed Nov 16 02:42:50 2011 -0700
     2.2 +++ b/org/body.org	Sat Nov 19 23:42:21 2011 -0700
     2.3 @@ -5,7 +5,7 @@
     2.4  #+SETUPFILE: ../../aurellem/org/setup.org
     2.5  #+INCLUDE: ../../aurellem/org/level-0.org
     2.6  
     2.7 -* COMMENT Body  
     2.8 +* Body  
     2.9  
    2.10  #+srcname: body-main
    2.11  #+begin_src clojure 
    2.12 @@ -233,6 +233,91 @@
    2.13       
    2.14       )))
    2.15      
    2.16 +       
    2.17 +
    2.18 +
    2.19 +
    2.20 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    2.21 +;;; here is the ragdoll stuff
    2.22 +
    2.23 +(def worm-mesh (.getMesh (.getChild (worm-blender) 0)))
    2.24 +(def mesh worm-mesh)
    2.25 +
    2.26 +(.getFloatBuffer mesh VertexBuffer$Type/Position)
    2.27 +(.getFloatBuffer mesh VertexBuffer$Type/BoneWeight)
    2.28 +(.getData  (.getBuffer mesh VertexBuffer$Type/BoneIndex))
    2.29 +
    2.30 +
    2.31 +(defn position [index]
    2.32 +  (.get
    2.33 +   (.getFloatBuffer worm-mesh VertexBuffer$Type/Position)
    2.34 +     index))
    2.35 +
    2.36 +(defn bones [index]
    2.37 +  (.get
    2.38 +   (.getData  (.getBuffer mesh VertexBuffer$Type/BoneIndex))
    2.39 +   index))
    2.40 +
    2.41 +(defn bone-weights [index]
    2.42 +  (.get
    2.43 +   (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight)
    2.44 +   index))
    2.45 +
    2.46 +
    2.47 +
    2.48 +(defn vertex-bones [vertex]
    2.49 +  (vec (map (comp int bones) (range (* vertex 4) (+ (* vertex 4) 4)))))
    2.50 +
    2.51 +(defn vertex-weights [vertex]
    2.52 +  (vec (map (comp float bone-weights) (range (* vertex 4) (+ (* vertex 4) 4)))))
    2.53 +
    2.54 +(defn vertex-position [index]
    2.55 +  (let [offset (* index 3)]
    2.56 +    (Vector3f. (position offset)
    2.57 +               (position (inc offset))
    2.58 +               (position (inc(inc offset))))))
    2.59 +
    2.60 +(def vertex-info (juxt vertex-position vertex-bones vertex-weights))
    2.61 +
    2.62 +(defn bone-control-color [index]
    2.63 +  (get {[1 0 0 0] ColorRGBA/Red
    2.64 +        [1 2 0 0] ColorRGBA/Magenta
    2.65 +        [2 0 0 0] ColorRGBA/Blue}
    2.66 +       (vertex-bones index)
    2.67 +       ColorRGBA/White))
    2.68 +
    2.69 +(defn influence-color [index bone-num]
    2.70 +  (get
    2.71 +   {(float 0)   ColorRGBA/Blue
    2.72 +    (float 0.5) ColorRGBA/Green
    2.73 +    (float 1)   ColorRGBA/Red}
    2.74 +     ;; find the weight of the desired bone
    2.75 +   ((zipmap (vertex-bones index)(vertex-weights index))
    2.76 +    bone-num)
    2.77 +   ColorRGBA/Blue))
    2.78 +         
    2.79 +(def worm-vertices (set (map vertex-info (range 60))))
    2.80 +
    2.81 +
    2.82 +(defn test-info []
    2.83 +  (let [points (Node.)]
    2.84 +    (dorun
    2.85 +     (map #(.attachChild points %)
    2.86 +          (map #(sphere 0.01
    2.87 +                        :position (vertex-position %)
    2.88 +                        :color (influence-color % 1)
    2.89 +                        :physical? false)
    2.90 +               (range 60))))
    2.91 +    (view points)))
    2.92 +  
    2.93 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    2.94 +
    2.95 +
    2.96 +
    2.97 +
    2.98 +
    2.99 +
   2.100 +;;;;;;;;;;;;  eve-style bodies  ;;;;;;;;
   2.101  (defn joint-control
   2.102    [joint]
   2.103    (let [physics-space (ref nil)]
   2.104 @@ -271,94 +356,80 @@
   2.105  
   2.106  (defn test-joint []
   2.107    (view (hinge-world)))
   2.108 -       
   2.109  
   2.110  
   2.111 +(defn worm [segment-length num-segments interstitial-space radius]
   2.112 +  (letfn [(nth-segment
   2.113 +            [n]
   2.114 +            (box segment-length radius radius :mass 0.1
   2.115 +                 :position
   2.116 +                 (Vector3f.
   2.117 +                  (* 2 n (+ interstitial-space segment-length)) 0 0)
   2.118 +                 :name (str "worm-segment" n)
   2.119 +                 :color (ColorRGBA/randomColor)))]
   2.120 +    (map nth-segment (range num-segments))))
   2.121 +
   2.122 +(defn nodify
   2.123 +  "take a sequence of things that can be attached to a node and return
   2.124 +  a node with all of the attached"
   2.125 +  ([name children]
   2.126 +     (let [node (Node. name)]
   2.127 +       (dorun (map #(.attachChild node %) children))
   2.128 +       node))
   2.129 +  ([children] (nodify "" children)))
   2.130 +
   2.131 +
   2.132 +(defn connect-at-midpoint
   2.133 +  [segmentA segmentB]
   2.134 +  (let [centerA (.getWorldTranslation segmentA)
   2.135 +        centerB (.getWorldTranslation segmentB)
   2.136 +        midpoint (.mult (.add centerA centerB) (float 0.5))
   2.137 +        pivotA (.subtract midpoint centerA)
   2.138 +        pivotB (.subtract midpoint centerB)
   2.139 +
   2.140 +        joint (Point2PointJoint.
   2.141 +               (.getControl segmentA RigidBodyControl)
   2.142 +               (.getControl segmentB RigidBodyControl)
   2.143 +               pivotA
   2.144 +               pivotB)]
   2.145 +    (add-joint segmentA joint)
   2.146 +  segmentB))
   2.147 +
   2.148 +
   2.149 +(defn point-worm []
   2.150 +  (let [segments (worm 0.2 5 0.1 0.1)]
   2.151 +    (dorun (map (partial apply connect-at-midpoint)
   2.152 +                (partition 2 1 segments)))
   2.153 +    (nodify "worm"  segments)))
   2.154 +
   2.155 +
   2.156 +(defn test-worm []
   2.157 +  (.start
   2.158 +   (world
   2.159 +    (doto (Node.)
   2.160 +      ;;(.attachChild (point-worm))
   2.161 +      (.attachChild (load-blender-model
   2.162 +                     "Models/anim2/joint-worm.blend"))
   2.163 +                      
   2.164 +      (.attachChild (box 10 1 10
   2.165 +                         :position (Vector3f. 0 -2 0) :mass 0
   2.166 +                         :color (ColorRGBA/Gray))))
   2.167 +    {
   2.168 +     "key-space" (fire-cannon-ball)
   2.169 +     }
   2.170 +    (fn [world]
   2.171 +      (enable-debug world)
   2.172 +      (light-up-everything world)
   2.173 +      ;;(.setTimer world (NanoTimer.))
   2.174 +      )
   2.175 +    no-op)))
   2.176  
   2.177  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   2.178 -;;; here is the ragdoll stuff
   2.179  
   2.180 -(def worm-mesh (.getMesh (.getChild (worm-blender) 0)))
   2.181 -(def mesh worm-mesh)
   2.182  
   2.183 -(.getFloatBuffer mesh VertexBuffer$Type/Position)
   2.184 -(.getFloatBuffer mesh VertexBuffer$Type/BoneWeight)
   2.185 -(.getData  (.getBuffer mesh VertexBuffer$Type/BoneIndex))
   2.186  
   2.187  
   2.188 -(defn position [index]
   2.189 -  (.get
   2.190 -   (.getFloatBuffer worm-mesh VertexBuffer$Type/Position)
   2.191 -     index))
   2.192  
   2.193 -(defn bones [index]
   2.194 -  (.get
   2.195 -   (.getData  (.getBuffer mesh VertexBuffer$Type/BoneIndex))
   2.196 -   index))
   2.197 -
   2.198 -(defn bone-weights [index]
   2.199 -  (.get
   2.200 -   (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight)
   2.201 -   index))
   2.202 -
   2.203 -
   2.204 -
   2.205 -(defn vertex-bones [vertex]
   2.206 -  (vec (map (comp int bones) (range (* vertex 4) (+ (* vertex 4) 4)))))
   2.207 -
   2.208 -(defn vertex-weights [vertex]
   2.209 -  (vec (map (comp float bone-weights) (range (* vertex 4) (+ (* vertex 4) 4)))))
   2.210 -
   2.211 -(defn vertex-position [index]
   2.212 -  (let [offset (* index 3)]
   2.213 -    (Vector3f. (position offset)
   2.214 -               (position (inc offset))
   2.215 -               (position (inc(inc offset))))))
   2.216 -
   2.217 -(def vertex-info (juxt vertex-position vertex-bones vertex-weights))
   2.218 -
   2.219 -(defn bone-control-color [index]
   2.220 -  (get {[1 0 0 0] ColorRGBA/Red
   2.221 -        [1 2 0 0] ColorRGBA/Magenta
   2.222 -        [2 0 0 0] ColorRGBA/Blue}
   2.223 -       (vertex-bones index)
   2.224 -       ColorRGBA/White))
   2.225 -
   2.226 -(defn influence-color [index bone-num]
   2.227 -  (get
   2.228 -   {(float 0)   ColorRGBA/Blue
   2.229 -    (float 0.5) ColorRGBA/Green
   2.230 -    (float 1)   ColorRGBA/Red}
   2.231 -     ;; find the weight of the desired bone
   2.232 -   ((zipmap (vertex-bones index)(vertex-weights index))
   2.233 -    bone-num)
   2.234 -   ColorRGBA/Blue))
   2.235 -         
   2.236 -   
   2.237 -   
   2.238 -
   2.239 -(def worm-vertices (set (map vertex-info (range 60))))
   2.240 -
   2.241 -
   2.242 -(defn test-info []
   2.243 -  (let [points (Node.)]
   2.244 -    (dorun
   2.245 -     (map #(.attachChild points %)
   2.246 -          (map #(sphere 0.01
   2.247 -                        :position (vertex-position %)
   2.248 -                        :color (influence-color % 1)
   2.249 -                        :physical? false)
   2.250 -               (range 60))))
   2.251 -    (view points)))
   2.252 -  
   2.253 -
   2.254 -
   2.255 -
   2.256 -
   2.257 -
   2.258 -
   2.259 -
   2.260 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   2.261  
   2.262  
   2.263  
     3.1 --- a/org/eyes.org	Wed Nov 16 02:42:50 2011 -0700
     3.2 +++ b/org/eyes.org	Sat Nov 19 23:42:21 2011 -0700
     3.3 @@ -130,27 +130,26 @@
     3.4    object from different angles and displaying both of those views in
     3.5    JFrames."  
     3.6    []
     3.7 -  (.start
     3.8 -   (let [candy
     3.9 -         (box 1 1 1 :physical? false :color ColorRGBA/Blue)]
    3.10 -     (world (doto (Node.)
    3.11 -              (.attachChild candy))
    3.12 -            {}
    3.13 -            (fn [world]
    3.14 -              (let [cam (.clone (.getCamera world))
    3.15 -                    width (.getWidth cam)
    3.16 -                    height (.getHeight cam)]
    3.17 -                (add-eye world cam (view-image width height))
    3.18 -                (add-eye world
    3.19 -                         (doto (.clone cam)
    3.20 -                           (.setLocation (Vector3f. -10 0 0))
    3.21 -                           (.lookAt Vector3f/ZERO Vector3f/UNIT_Y))
    3.22 -                         (view-image width height))
    3.23 +  (let [candy
    3.24 +        (box 1 1 1 :physical? false :color ColorRGBA/Blue)]
    3.25 +    (world (doto (Node.)
    3.26 +             (.attachChild candy))
    3.27 +           {}
    3.28 +           (fn [world]
    3.29 +             (let [cam (.clone (.getCamera world))
    3.30 +                   width (.getWidth cam)
    3.31 +                   height (.getHeight cam)]
    3.32 +               (add-eye world cam (view-image width height))
    3.33 +               (add-eye world
    3.34 +                        (doto (.clone cam)
    3.35 +                          (.setLocation (Vector3f. -10 0 0))
    3.36 +                          (.lookAt Vector3f/ZERO Vector3f/UNIT_Y))
    3.37 +                        (view-image width height))
    3.38                  ;; This is here to restore the main view
    3.39 -                ;; after the other views have completed processing
    3.40 -                (add-eye world (.getCamera world) no-op)))
    3.41 -            (fn [world tpf]
    3.42 -              (.rotate candy (* tpf 0.2) 0 0))))))
    3.43 +               ;; after the other views have completed processing
    3.44 +               (add-eye world (.getCamera world) no-op)))
    3.45 +           (fn [world tpf]
    3.46 +             (.rotate candy (* tpf 0.2) 0 0)))))
    3.47  #+end_src
    3.48  
    3.49  The example code will create two videos of the same rotating object
     4.1 --- a/org/skin.org	Wed Nov 16 02:42:50 2011 -0700
     4.2 +++ b/org/skin.org	Sat Nov 19 23:42:21 2011 -0700
     4.3 @@ -227,10 +227,10 @@
     4.4  
     4.5  (defn test-skin []
     4.6    (let [b
     4.7 -	;;(transparent-box)
     4.8 -	(transparent-sphere)
     4.9 +        ;;(transparent-box)
    4.10 +        (transparent-sphere)
    4.11          ;;(sphere)
    4.12 -	f (transparent-floor)
    4.13 +        f (transparent-floor)
    4.14          debug-node (Node.)
    4.15          node      (doto (Node.) (.attachChild b) (.attachChild f))
    4.16          root-node (doto (Node.) (.attachChild node)
    4.17 @@ -247,8 +247,8 @@
    4.18         ;;  (no-logging)
    4.19         ;;(enable-debug world)
    4.20         ;;  (set-accuracy world (/ 1 60))
    4.21 -     )
    4.22 -
    4.23 +       )
    4.24 +     
    4.25       (fn [& _]
    4.26         (let [sensitivity 0.2
    4.27               touch-data (touch-percieve sensitivity b node)]
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/org/test.org	Sat Nov 19 23:42:21 2011 -0700
     5.3 @@ -0,0 +1,78 @@
     5.4 +#+title: The BODY!!!
     5.5 +#+author: Robert McIntyre
     5.6 +#+email: rlm@mit.edu
     5.7 +#+description: Simulating a body (movement, touch, propioception) in jMonkeyEngine3.
     5.8 +#+SETUPFILE: ../../aurellem/org/setup.org
     5.9 +#+INCLUDE: ../../aurellem/org/level-0.org
    5.10 +
    5.11 +* Body  
    5.12 +
    5.13 +#+srcname: body-main
    5.14 +#+begin_src clojure 
    5.15 +(ns test.all
    5.16 +  (:require [test touch vision])
    5.17 +  (:import com.jme3.app.state.AppState
    5.18 +           com.jme3.system.AppSettings))
    5.19 +
    5.20 +(defn run-world
    5.21 +  "run the simulation and wait until it closes proprely"
    5.22 +  [world]
    5.23 +  (let [lock (promise)]
    5.24 +    (.enqueue
    5.25 +     world 
    5.26 +     (partial
    5.27 +      (fn [world]
    5.28 +        (.attach
    5.29 +         (.getStateManager world)
    5.30 +         (proxy [AppState] []
    5.31 +           (cleanup [] (deliver lock nil))
    5.32 +           (initialize [_ _])
    5.33 +           (isEnabled [] true)
    5.34 +           (setEnabled [_] )
    5.35 +           (stateAttached [_])
    5.36 +           (stateDetached [_])
    5.37 +           (update [_])
    5.38 +           (render [_])
    5.39 +           (isInitialized [] true)
    5.40 +           (postRender []))))
    5.41 +      world))
    5.42 +    (.start world)
    5.43 +    (deref lock)))
    5.44 +
    5.45 +(defn test-all []
    5.46 +  (println
    5.47 +   "***************\n"
    5.48 +   "Testing touch:\n"
    5.49 +   "you should see a ball which responds to the table\n"
    5.50 +   "and whatever balls hit it.\n")
    5.51 +  (run-world (test.touch/test-skin))
    5.52 +  (println
    5.53 +   "***************\n"
    5.54 +   "Testing vision:\n"
    5.55 +   "You should see a rotating cube, and two windows,\n"
    5.56 +   "each displaying a different view of the cube.\n")
    5.57 +  (run-world (test.vision/test-two-eyes))
    5.58 +  (println
    5.59 +   "***************\n"
    5.60 +   "Testing hearing:\n"
    5.61 +   "You should see a blue sphere flying around several\n"
    5.62 +   "cubes.  As the sphere approaches each cube, it turns\n"
    5.63 +   "green.\n")
    5.64 +  (run-world
    5.65 +   (doto (com.aurellem.capture.examples.Advanced.)
    5.66 +     (.setSettings
    5.67 +      (doto (AppSettings. true)
    5.68 +        (.setAudioRenderer "Send")))
    5.69 +     (.setShowSettings false)
    5.70 +     (.setPauseOnLostFocus false))))
    5.71 +#+end_src
    5.72 +
    5.73 +
    5.74 +
    5.75 +
    5.76 +* COMMENT generate Source.
    5.77 +#+begin_src clojure :tangle ../src/test/all.clj
    5.78 +<<body-main>>
    5.79 +#+end_src
    5.80 +
    5.81 +