diff org/test-creature.org @ 90:6d7c17c847a3

saving progress
author Robert McIntyre <rlm@mit.edu>
date Sun, 08 Jan 2012 06:11:58 -0700
parents cd5151b5e7c3
children 2bcc7636cfea
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Sat Jan 07 10:49:49 2012 -0700
     1.2 +++ b/org/test-creature.org	Sun Jan 08 06:11:58 2012 -0700
     1.3 @@ -264,6 +264,10 @@
     1.4  
     1.5  (def worm "Models/creature1/try-again.blend")
     1.6  
     1.7 +(def touch "Models/creature1/touch.blend")
     1.8 +
     1.9 +(defn worm-model [] (load-blender-model worm))
    1.10 +
    1.11  (defn x-ray [#^ColorRGBA color]
    1.12    (doto (Material. (asset-manager)
    1.13                     "Common/MatDefs/Misc/Unshaded.j3md")
    1.14 @@ -285,19 +289,105 @@
    1.15              x-axis y-axis z-axis
    1.16              ])
    1.17     standard-debug-controls
    1.18 -   (comp light-up-everything enable-debug
    1.19 -         (fn [world]
    1.20 -           (.setTimer world (NanoTimer.))
    1.21 -           ;;(set-gravity world (Vector3f. 0 0 0))
    1.22 -           (speed-up world)
    1.23 -           world
    1.24 -           ))
    1.25 -   no-op)))
    1.26 +   (fn [world]
    1.27 +     (light-up-everything world)
    1.28 +     (enable-debug world)
    1.29 +     ;;(com.aurellem.capture.Capture/captureVideo
    1.30 +     ;; world (file-str "/home/r/proj/ai-videos/hand"))
    1.31 +     (.setTimer world (NanoTimer.))
    1.32 +     ;;(set-gravity world (Vector3f. 0 0 0))
    1.33 +     (speed-up world)
    1.34 +     )
    1.35 +   no-op
    1.36 +   ;;(let [timer (atom 0)]
    1.37 +   ;;  (fn [_ _]
    1.38 +   ;;    (swap! timer inc)
    1.39 +   ;;    (if (= (rem @timer 60) 0)
    1.40 +   ;;      (println-repl (float (/ @timer 60))))))
    1.41 +   )))
    1.42 +
    1.43 +
    1.44 +(def colorful (.getChild (worm-model) "worm-21"))
    1.45 +
    1.46 +(def im-data
    1.47 +  (let [sink (byte-array 3145727)
    1.48 +        data (.getData (.getImage texture) 0)]
    1.49 +    (.rewind data)
    1.50 +    (.get data sink)
    1.51 +    (vec (seq sink))))
    1.52 +
    1.53 +
    1.54 +(import jme3tools.converters.ImageToAwt)
    1.55 +
    1.56 +(import ij.ImagePlus)
    1.57 +
    1.58 +
    1.59 +
    1.60 +(defn triangle-indices
    1.61 +  "Get the triangle vertex indices of a given triangle from a given
    1.62 +   mesh."
    1.63 +  [#^Mesh mesh triangle-index]
    1.64 +  (let [indices (int-array 3)]
    1.65 +    (.getTriangle mesh triangle-index indices)
    1.66 +    (vec indices)))
    1.67 +
    1.68 +(defn uv-coord
    1.69 +  "Get the uv-coordinates of the vertex named by vertex-index"
    1.70 +  [#^Mesh mesh vertex-index]
    1.71 +  (let [UV-buffer
    1.72 +        (.getData
    1.73 +         (.getBuffer
    1.74 +          mesh
    1.75 +          VertexBuffer$Type/TexCoord))]
    1.76 +    [(.get UV-buffer (* vertex-index 2))
    1.77 +     (.get UV-buffer (+ 1 (* vertex-index 2)))]))
    1.78 +
    1.79 +(defn touch-receptor-image [#^Geometry obj]
    1.80 +  
    1.81 +
    1.82 +
    1.83 +;; yay there's a converter!
    1.84 +
    1.85 +(defn uv-image []
    1.86 +  (let
    1.87 +      [colorful (.getChild (worm-model) "worm-21")
    1.88 +       mat (.getMaterial colorful)
    1.89 +       texture
    1.90 +       (.getTextureValue
    1.91 +        (.getTextureParam
    1.92 +         mat
    1.93 +         MaterialHelper/TEXTURE_TYPE_DIFFUSE))
    1.94 +       im (.getImage texture)]
    1.95 +       (ImagePlus.
    1.96 +        "UV-map"
    1.97 +        (ImageToAwt/convert im false false 0))))
    1.98 +
    1.99 +;; for each triangle in the mesh,
   1.100 +;; get the normal to the triangle,
   1.101 +;; look at the UV touch map, restricted to that triangle,
   1.102 +;; get the positions of those touch sensors in geometry-relative
   1.103 +;; coordinates.
   1.104 +
   1.105 +
   1.106 +
   1.107 +
   1.108 +
   1.109 +
   1.110 +
   1.111 +
   1.112 +       
   1.113 +(defrecord LulzLoader [])
   1.114 +(defprotocol Lulzable (load-lulz [this]))
   1.115 +(extend-type LulzLoader
   1.116 +  Lulzable
   1.117 +  (load-lulz [this] (println "the lulz have arrived!")))
   1.118 +
   1.119 +(defn 
   1.120 +
   1.121 +
   1.122  
   1.123  (defn world-setup [joint]
   1.124 -  (let [
   1.125 -
   1.126 -        joint-position (Vector3f. 0 0 0)
   1.127 +  (let [joint-position (Vector3f. 0 0 0)
   1.128          joint-rotation
   1.129          (.toRotationMatrix
   1.130           (.mult