changeset 226:e5db1d2ff9a8

removed outdated test from touch.org
author Robert McIntyre <rlm@mit.edu>
date Sat, 11 Feb 2012 12:53:18 -0700
parents 5cea47455b43
children 2a7f57e7efdb
files assets/Models/test-creature/worm.blend org/touch.org
diffstat 2 files changed, 22 insertions(+), 190 deletions(-) [+]
line wrap: on
line diff
     1.1 Binary file assets/Models/test-creature/worm.blend has changed
     2.1 --- a/org/touch.org	Sat Feb 11 12:32:31 2012 -0700
     2.2 +++ b/org/touch.org	Sat Feb 11 12:53:18 2012 -0700
     2.3 @@ -8,29 +8,13 @@
     2.4  
     2.5  * Touch
     2.6  
     2.7 -My creatures need to be able to feel their environments. The idea here
     2.8 -is to create thousands of small /touch receptors/ along the geometries
     2.9 -which make up the creature's body. The number of touch receptors in a
    2.10 -given area is determined by how complicated that area is, as
    2.11 -determined by the total number of triangles in that region. This way,
    2.12 -complicated regions like the hands/face, etc. get more touch receptors
    2.13 -than simpler areas of the body.
    2.14 +Touch is critical to navigation and spatial reasoning and as such I
    2.15 +need a simulated version of it to give to my AI creatures.
    2.16  
    2.17  #+name: skin-main
    2.18  #+begin_src clojure
    2.19 -(ns cortex.touch
    2.20 -  "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry
    2.21 -  to be outfitted with touch sensors with density proportional to the
    2.22 -  density of triangles along the surface of the Geometry. Enables a
    2.23 -  Geometry to know what parts of itself are touching nearby objects."
    2.24 -  {:author "Robert McIntyre"}
    2.25 -  (:use (cortex world util sense))
    2.26 -  (:use clojure.contrib.def)
    2.27 -  (:import (com.jme3.scene Geometry Node Mesh))
    2.28 -  (:import com.jme3.collision.CollisionResults)
    2.29 -  (:import com.jme3.scene.VertexBuffer$Type)
    2.30 -  (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))
    2.31 -   
    2.32 +(in-ns 'cortex.touch)
    2.33 +
    2.34  (defn triangles
    2.35    "Return a sequence of all the Triangles which compose a given
    2.36    Geometry." 
    2.37 @@ -313,184 +297,31 @@
    2.38            (.setRGB image ((coords i) 0) ((coords i) 1)
    2.39                     (gray (sensor-data i)))))
    2.40         image))))
    2.41 - 
    2.42 -
    2.43  #+end_src
    2.44  
    2.45 +* Headers 
    2.46 +#+begin_src clojure
    2.47 +(ns cortex.touch
    2.48 +  "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry
    2.49 +  to be outfitted with touch sensors with density determined by a UV
    2.50 +  image. In this way a Geometry can know what parts of itself are
    2.51 +  touching nearby objects. Reads specially prepared blender files to
    2.52 +  construct this sense automatically."
    2.53 +  {:author "Robert McIntyre"}
    2.54 +  (:use (cortex world util sense))
    2.55 +  (:use clojure.contrib.def)
    2.56 +  (:import (com.jme3.scene Geometry Node Mesh))
    2.57 +  (:import com.jme3.collision.CollisionResults)
    2.58 +  (:import com.jme3.scene.VertexBuffer$Type)
    2.59 +  (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))
    2.60 +#+end_src   
    2.61  
    2.62 -* Example
    2.63 -
    2.64 -#+name: touch-test
    2.65 -#+begin_src clojure 
    2.66 -(ns cortex.test.touch
    2.67 -  (:use (cortex world util touch))
    2.68 -  (:import
    2.69 -   com.jme3.scene.shape.Sphere
    2.70 -   com.jme3.math.ColorRGBA
    2.71 -   com.jme3.math.Vector3f
    2.72 -   com.jme3.material.RenderState$BlendMode
    2.73 -   com.jme3.renderer.queue.RenderQueue$Bucket
    2.74 -   com.jme3.scene.shape.Box
    2.75 -   com.jme3.scene.Node))
    2.76 -
    2.77 -(defn ray-origin-debug
    2.78 -  [ray color]
    2.79 -  (make-shape
    2.80 -   (assoc base-shape
    2.81 -     :shape (Sphere. 5 5 0.05)
    2.82 -     :name "arrow"
    2.83 -     :color color
    2.84 -     :texture false
    2.85 -     :physical? false
    2.86 -     :position
    2.87 -     (.getOrigin ray))))
    2.88 -
    2.89 -(defn ray-debug [ray color]
    2.90 -  (make-shape
    2.91 -   (assoc
    2.92 -       base-shape
    2.93 -     :name "debug-ray"
    2.94 -     :physical? false
    2.95 -     :shape (com.jme3.scene.shape.Line.
    2.96 -             (.getOrigin ray)
    2.97 -             (.add
    2.98 -              (.getOrigin ray)
    2.99 -              (.mult (.getDirection ray)
   2.100 -                     (float (.getLimit ray))))))))
   2.101 -             
   2.102 -
   2.103 -(defn contact-color [contacts]
   2.104 -  (case contacts
   2.105 -    0 ColorRGBA/Gray
   2.106 -    1  ColorRGBA/Red 
   2.107 -    2  ColorRGBA/Green 
   2.108 -    3  ColorRGBA/Yellow 
   2.109 -    4  ColorRGBA/Orange 
   2.110 -    5  ColorRGBA/Red 
   2.111 -    6  ColorRGBA/Magenta 
   2.112 -    7  ColorRGBA/Pink 
   2.113 -    8  ColorRGBA/White))
   2.114 -
   2.115 -(defn update-ray-debug [node ray contacts]
   2.116 -  (let [origin (.getChild node 0)]
   2.117 -    (.setLocalTranslation origin (.getOrigin ray))
   2.118 -    (.setColor (.getMaterial origin) "Color" (contact-color contacts))))
   2.119 -
   2.120 -(defn init-node
   2.121 -  [debug-node rays]
   2.122 -    (.detachAllChildren debug-node)
   2.123 -    (dorun 
   2.124 -     (for [ray rays]
   2.125 -       (do
   2.126 -         (.attachChild
   2.127 -          debug-node 
   2.128 -          (doto (Node.)
   2.129 -            (.attachChild (ray-origin-debug ray ColorRGBA/Gray))
   2.130 -            (.attachChild (ray-debug ray ColorRGBA/Gray))
   2.131 -            ))))))
   2.132 -
   2.133 -(defn manage-ray-debug-node [debug-node geom touch-data limit]
   2.134 -  (let [rays (normal-rays limit geom)]
   2.135 -    (if (not= (count (.getChildren debug-node)) (count touch-data))
   2.136 -      (init-node debug-node rays))
   2.137 -    (dorun 
   2.138 -     (for [n (range (count touch-data))]
   2.139 -       (update-ray-debug
   2.140 -        (.getChild debug-node n) (nth rays n) (nth touch-data n))))))
   2.141 -
   2.142 -(defn transparent-sphere []
   2.143 -  (doto
   2.144 -      (make-shape
   2.145 -       (merge base-shape
   2.146 -	      {:position (Vector3f. 0 2 0)
   2.147 -	       :name "the blob."
   2.148 -	       :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.149 -	       :texture "Textures/purpleWisp.png"
   2.150 -	       :physical? true
   2.151 -	       :mass 70
   2.152 -	       :color ColorRGBA/Blue
   2.153 -	       :shape (Sphere. 10 10 1)}))
   2.154 -    (-> (.getMaterial)
   2.155 -	(.getAdditionalRenderState)
   2.156 -	(.setBlendMode RenderState$BlendMode/Alpha))
   2.157 -    (.setQueueBucket RenderQueue$Bucket/Transparent)))
   2.158 -
   2.159 -(defn transparent-box []
   2.160 -    (doto
   2.161 -      (make-shape
   2.162 -       (merge base-shape
   2.163 -	      {:position (Vector3f. 0 2 0)
   2.164 -	       :name "box"
   2.165 -	       :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.166 -	       :texture "Textures/purpleWisp.png"
   2.167 -	       :physical? true
   2.168 -	       :mass 70
   2.169 -	       :color ColorRGBA/Blue
   2.170 -	       :shape (Box. 1 1 1)}))
   2.171 -    (-> (.getMaterial)
   2.172 -	(.getAdditionalRenderState)
   2.173 -	(.setBlendMode RenderState$BlendMode/Alpha))
   2.174 -    (.setQueueBucket RenderQueue$Bucket/Transparent)))
   2.175 -
   2.176 -(defn transparent-floor []
   2.177 -  (doto
   2.178 -      (box 5 0.2 5  :mass 0 :position (Vector3f. 0 -2 0)
   2.179 -           :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.180 -           :texture "Textures/redWisp.png"
   2.181 -           :name "floor")
   2.182 -    (-> (.getMaterial)
   2.183 -        (.getAdditionalRenderState)
   2.184 -        (.setBlendMode RenderState$BlendMode/Alpha))
   2.185 -    (.setQueueBucket RenderQueue$Bucket/Transparent)))
   2.186 -
   2.187 -(defn test-skin 
   2.188 -  "Testing touch:
   2.189 -   you should see a ball which responds to the table
   2.190 -   and whatever balls hit it."
   2.191 -  []
   2.192 -  (let [b
   2.193 -        ;;(transparent-box)
   2.194 -        (transparent-sphere)
   2.195 -        ;;(sphere)
   2.196 -        f (transparent-floor)
   2.197 -        debug-node (Node.)
   2.198 -        node      (doto (Node.) (.attachChild b) (.attachChild f))
   2.199 -        root-node (doto (Node.) (.attachChild node)
   2.200 -                        (.attachChild debug-node))
   2.201 -        ]
   2.202 -    
   2.203 -    (world
   2.204 -     root-node
   2.205 -     {"key-return" (fire-cannon-ball node)}
   2.206 -     (fn [world]
   2.207 -       ;;  (Capture/SimpleCaptureVideo
   2.208 -       ;;   world 
   2.209 -       ;;   (file-str "/home/r/proj/cortex/tmp/blob.avi"))
   2.210 -       ;;  (no-logging)
   2.211 -       ;;(enable-debug world)
   2.212 -       ;;  (set-accuracy world (/ 1 60))
   2.213 -       )
   2.214 -     
   2.215 -     (fn [& _]
   2.216 -       (let [sensitivity 0.2
   2.217 -             touch-data (touch-percieve sensitivity b node)]
   2.218 -         (manage-ray-debug-node debug-node b touch-data sensitivity))
   2.219 -       ))))
   2.220 -
   2.221 -
   2.222 -#+end_src
   2.223 -
   2.224 -
   2.225 -
   2.226 -
   2.227 -  
   2.228 -* COMMENT code generation
   2.229 +* COMMENT Code Generation
   2.230  #+begin_src clojure :tangle ../src/cortex/touch.clj
   2.231  <<skin-main>>
   2.232  #+end_src
   2.233  
   2.234  #+begin_src clojure :tangle ../src/cortex/test/touch.clj 
   2.235 -<<touch-test>>
   2.236  #+end_src
   2.237  
   2.238  
   2.239 @@ -498,3 +329,4 @@
   2.240    
   2.241  
   2.242  
   2.243 +