changeset 181:0f1c7921d967

removed blender.org; got rid of magic constant in sense-utils.
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 07:31:08 -0700
parents f1b078375484
children f2552d61e8df
files org/blender.org org/movement.org org/sense-util.org
diffstat 3 files changed, 32 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/blender.org	Sat Feb 04 07:20:12 2012 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,19 +0,0 @@
     1.4 -#+title: Blender Clojure utilities
     1.5 -#+author: Robert McIntyre
     1.6 -#+email: rlm@mit.edu
     1.7 -#+description: blender utilities
     1.8 -#+keywords: simulation, jMonkeyEngine3, clojure, blender
     1.9 -#+SETUPFILE: ../../aurellem/org/setup.org
    1.10 -#+INCLUDE: ../../aurellem/org/level-0.org
    1.11 -
    1.12 -
    1.13 -#+name: blender
    1.14 -#+begin_src clojure 
    1.15 -
    1.16 -#+end_src
    1.17 -
    1.18 -
    1.19 -* COMMENT generate source
    1.20 -#+begin_src clojure :tangle ../src/cortex/blender.clj
    1.21 -<<blender>>
    1.22 -#+end_src
     2.1 --- a/org/movement.org	Sat Feb 04 07:20:12 2012 -0700
     2.2 +++ b/org/movement.org	Sat Feb 04 07:31:08 2012 -0700
     2.3 @@ -87,7 +87,6 @@
     2.4      (for [muscle (muscles creature)]
     2.5        (movement-fn creature muscle)))
     2.6  
     2.7 -
     2.8  #+end_src
     2.9  
    2.10  
     3.1 --- a/org/sense-util.org	Sat Feb 04 07:20:12 2012 -0700
     3.2 +++ b/org/sense-util.org	Sat Feb 04 07:31:08 2012 -0700
     3.3 @@ -14,9 +14,12 @@
     3.4  (import ij.process.ImageProcessor)
     3.5  (import java.awt.image.BufferedImage)
     3.6  (use 'cortex.util)
     3.7 +(use 'cortex.world)
     3.8  (import jme3tools.converters.ImageToAwt)
     3.9  
    3.10 -(defn meta-data [blender-node key]
    3.11 +(defn meta-data
    3.12 +  "Get the meta-data for a node created with blender."
    3.13 +  [blender-node key]
    3.14    (if-let [data (.getUserData blender-node "properties")]
    3.15      (.findValue data key)
    3.16      nil))
    3.17 @@ -51,16 +54,21 @@
    3.18         (controlUpdate [tpf]
    3.19           (let [total-rotation
    3.20                 (.mult base-anti-rotation (.getWorldRotation obj))]
    3.21 -           (.setLocation sense
    3.22 -                         (.add
    3.23 -                          (.mult total-rotation sense-offset)
    3.24 -                          (.getWorldTranslation obj)))
    3.25 -           (.setRotation sense
    3.26 -                         (.mult total-rotation initial-sense-rotation))))
    3.27 +           (.setLocation
    3.28 +            sense
    3.29 +            (.add
    3.30 +             (.mult total-rotation sense-offset)
    3.31 +             (.getWorldTranslation obj)))
    3.32 +           (.setRotation
    3.33 +            sense
    3.34 +            (.mult total-rotation initial-sense-rotation))))
    3.35         (controlRender [_ _])))))
    3.36  
    3.37 -(def white -1)
    3.38 -  
    3.39 +(def white 0xFFFFFF)
    3.40 +
    3.41 +(defn white? [rgb]
    3.42 +  (= (bit-and white rgb) white))
    3.43 +
    3.44  (defn filter-pixels
    3.45    "List the coordinates of all pixels matching pred, within the bounds
    3.46     provided. Bounds -> [x0 y0 width height]"
    3.47 @@ -80,16 +88,13 @@
    3.48  (defn white-coordinates
    3.49    "Coordinates of all the white pixels in a subset of the image."
    3.50    ([#^BufferedImage image bounds]
    3.51 -     (filter-pixels #(= % white) image bounds))
    3.52 +     (filter-pixels white? image bounds))
    3.53    ([#^BufferedImage image]
    3.54 -     (filter-pixels #(= % white) image)))
    3.55 +     (filter-pixels white? image)))
    3.56  
    3.57  (defn points->image
    3.58    "Take a sparse collection of points and visuliaze it as a
    3.59     BufferedImage."
    3.60 -
    3.61 -  ;; TODO maybe parallelize this since it's easy
    3.62 -
    3.63    [points]
    3.64    (if (empty? points)
    3.65      (BufferedImage. 1 1 BufferedImage/TYPE_BYTE_BINARY)
    3.66 @@ -108,7 +113,6 @@
    3.67        (dorun 
    3.68         (for [index (range (count points))]
    3.69           (.setRGB image (- (xs index) x0) (- (ys index) y0) -1)))
    3.70 -      
    3.71        image)))
    3.72  
    3.73  (defn average [coll]
    3.74 @@ -188,8 +192,20 @@
    3.75    (ImageToAwt/convert
    3.76     (.getImage (.loadTexture (asset-manager) asset-relative-path))
    3.77     false false 0))
    3.78 -  
    3.79  
    3.80 +(defn jme-to-blender
    3.81 +  "Convert from JME coordinates to Blender coordinates"
    3.82 +  [#^Vector3f in]
    3.83 +  (Vector3f. (.getX in)
    3.84 +             (- (.getZ in))
    3.85 +             (.getY in)))
    3.86 +
    3.87 +(defn blender-to-jme
    3.88 +  "Convert from Blender coordinates to JME coordinates"
    3.89 +  [#^Vector3f in]
    3.90 +  (Vector3f. (.getX in)
    3.91 +             (.getZ in)
    3.92 +             (- (.getY in))))
    3.93  #+end_src
    3.94  
    3.95  #+results: sense-util