# HG changeset patch # User Robert McIntyre # Date 1328989998 25200 # Node ID e5db1d2ff9a85a4e57f158153a8eba1da2e5ad5d # Parent 5cea47455b43f05baad065d707c13ef79950cc12 removed outdated test from touch.org diff -r 5cea47455b43 -r e5db1d2ff9a8 assets/Models/test-creature/worm.blend Binary file assets/Models/test-creature/worm.blend has changed diff -r 5cea47455b43 -r e5db1d2ff9a8 org/touch.org --- a/org/touch.org Sat Feb 11 12:32:31 2012 -0700 +++ b/org/touch.org Sat Feb 11 12:53:18 2012 -0700 @@ -8,29 +8,13 @@ * Touch -My creatures need to be able to feel their environments. The idea here -is to create thousands of small /touch receptors/ along the geometries -which make up the creature's body. The number of touch receptors in a -given area is determined by how complicated that area is, as -determined by the total number of triangles in that region. This way, -complicated regions like the hands/face, etc. get more touch receptors -than simpler areas of the body. +Touch is critical to navigation and spatial reasoning and as such I +need a simulated version of it to give to my AI creatures. #+name: skin-main #+begin_src clojure -(ns cortex.touch - "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry - to be outfitted with touch sensors with density proportional to the - density of triangles along the surface of the Geometry. Enables a - Geometry to know what parts of itself are touching nearby objects." - {:author "Robert McIntyre"} - (:use (cortex world util sense)) - (:use clojure.contrib.def) - (:import (com.jme3.scene Geometry Node Mesh)) - (:import com.jme3.collision.CollisionResults) - (:import com.jme3.scene.VertexBuffer$Type) - (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f))) - +(in-ns 'cortex.touch) + (defn triangles "Return a sequence of all the Triangles which compose a given Geometry." @@ -313,184 +297,31 @@ (.setRGB image ((coords i) 0) ((coords i) 1) (gray (sensor-data i))))) image)))) - - #+end_src +* Headers +#+begin_src clojure +(ns cortex.touch + "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry + to be outfitted with touch sensors with density determined by a UV + image. In this way a Geometry can know what parts of itself are + touching nearby objects. Reads specially prepared blender files to + construct this sense automatically." + {:author "Robert McIntyre"} + (:use (cortex world util sense)) + (:use clojure.contrib.def) + (:import (com.jme3.scene Geometry Node Mesh)) + (:import com.jme3.collision.CollisionResults) + (:import com.jme3.scene.VertexBuffer$Type) + (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f))) +#+end_src -* Example - -#+name: touch-test -#+begin_src clojure -(ns cortex.test.touch - (:use (cortex world util touch)) - (:import - com.jme3.scene.shape.Sphere - com.jme3.math.ColorRGBA - com.jme3.math.Vector3f - com.jme3.material.RenderState$BlendMode - com.jme3.renderer.queue.RenderQueue$Bucket - com.jme3.scene.shape.Box - com.jme3.scene.Node)) - -(defn ray-origin-debug - [ray color] - (make-shape - (assoc base-shape - :shape (Sphere. 5 5 0.05) - :name "arrow" - :color color - :texture false - :physical? false - :position - (.getOrigin ray)))) - -(defn ray-debug [ray color] - (make-shape - (assoc - base-shape - :name "debug-ray" - :physical? false - :shape (com.jme3.scene.shape.Line. - (.getOrigin ray) - (.add - (.getOrigin ray) - (.mult (.getDirection ray) - (float (.getLimit ray)))))))) - - -(defn contact-color [contacts] - (case contacts - 0 ColorRGBA/Gray - 1 ColorRGBA/Red - 2 ColorRGBA/Green - 3 ColorRGBA/Yellow - 4 ColorRGBA/Orange - 5 ColorRGBA/Red - 6 ColorRGBA/Magenta - 7 ColorRGBA/Pink - 8 ColorRGBA/White)) - -(defn update-ray-debug [node ray contacts] - (let [origin (.getChild node 0)] - (.setLocalTranslation origin (.getOrigin ray)) - (.setColor (.getMaterial origin) "Color" (contact-color contacts)))) - -(defn init-node - [debug-node rays] - (.detachAllChildren debug-node) - (dorun - (for [ray rays] - (do - (.attachChild - debug-node - (doto (Node.) - (.attachChild (ray-origin-debug ray ColorRGBA/Gray)) - (.attachChild (ray-debug ray ColorRGBA/Gray)) - )))))) - -(defn manage-ray-debug-node [debug-node geom touch-data limit] - (let [rays (normal-rays limit geom)] - (if (not= (count (.getChildren debug-node)) (count touch-data)) - (init-node debug-node rays)) - (dorun - (for [n (range (count touch-data))] - (update-ray-debug - (.getChild debug-node n) (nth rays n) (nth touch-data n)))))) - -(defn transparent-sphere [] - (doto - (make-shape - (merge base-shape - {:position (Vector3f. 0 2 0) - :name "the blob." - :material "Common/MatDefs/Misc/Unshaded.j3md" - :texture "Textures/purpleWisp.png" - :physical? true - :mass 70 - :color ColorRGBA/Blue - :shape (Sphere. 10 10 1)})) - (-> (.getMaterial) - (.getAdditionalRenderState) - (.setBlendMode RenderState$BlendMode/Alpha)) - (.setQueueBucket RenderQueue$Bucket/Transparent))) - -(defn transparent-box [] - (doto - (make-shape - (merge base-shape - {:position (Vector3f. 0 2 0) - :name "box" - :material "Common/MatDefs/Misc/Unshaded.j3md" - :texture "Textures/purpleWisp.png" - :physical? true - :mass 70 - :color ColorRGBA/Blue - :shape (Box. 1 1 1)})) - (-> (.getMaterial) - (.getAdditionalRenderState) - (.setBlendMode RenderState$BlendMode/Alpha)) - (.setQueueBucket RenderQueue$Bucket/Transparent))) - -(defn transparent-floor [] - (doto - (box 5 0.2 5 :mass 0 :position (Vector3f. 0 -2 0) - :material "Common/MatDefs/Misc/Unshaded.j3md" - :texture "Textures/redWisp.png" - :name "floor") - (-> (.getMaterial) - (.getAdditionalRenderState) - (.setBlendMode RenderState$BlendMode/Alpha)) - (.setQueueBucket RenderQueue$Bucket/Transparent))) - -(defn test-skin - "Testing touch: - you should see a ball which responds to the table - and whatever balls hit it." - [] - (let [b - ;;(transparent-box) - (transparent-sphere) - ;;(sphere) - f (transparent-floor) - debug-node (Node.) - node (doto (Node.) (.attachChild b) (.attachChild f)) - root-node (doto (Node.) (.attachChild node) - (.attachChild debug-node)) - ] - - (world - root-node - {"key-return" (fire-cannon-ball node)} - (fn [world] - ;; (Capture/SimpleCaptureVideo - ;; world - ;; (file-str "/home/r/proj/cortex/tmp/blob.avi")) - ;; (no-logging) - ;;(enable-debug world) - ;; (set-accuracy world (/ 1 60)) - ) - - (fn [& _] - (let [sensitivity 0.2 - touch-data (touch-percieve sensitivity b node)] - (manage-ray-debug-node debug-node b touch-data sensitivity)) - )))) - - -#+end_src - - - - - -* COMMENT code generation +* COMMENT Code Generation #+begin_src clojure :tangle ../src/cortex/touch.clj <> #+end_src #+begin_src clojure :tangle ../src/cortex/test/touch.clj -<> #+end_src @@ -498,3 +329,4 @@ +