Mercurial > cortex
changeset 147:72801a20b8e5
First stab at blender muscles. (gee that sounds a little violent...)
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 03 Feb 2012 00:48:34 -0700 |
parents | 68226790d1fa |
children | 511112c44b16 |
files | assets/Models/creature1/basic-muscle.png assets/Models/creature1/try-again.blend org/test-creature.org |
diffstat | 3 files changed, 50 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
1.1 Binary file assets/Models/creature1/basic-muscle.png has changed
2.1 Binary file assets/Models/creature1/try-again.blend has changed
3.1 --- a/org/test-creature.org Thu Feb 02 13:22:14 2012 -0700 3.2 +++ b/org/test-creature.org Fri Feb 03 00:48:34 2012 -0700 3.3 @@ -80,7 +80,8 @@ 3.4 - [X] proprioception sensor map in the style of the other senses -- day 3.5 - [ ] refactor integration code to distribute to each of the senses 3.6 -- day 3.7 - - [ ] create video showing all the senses for Winston -- 2 days 3.8 + - [ ] create video showing all the senses for Winston -- 2 days 3.9 + - [ ] send package to friends for critiques -- 2 days 3.10 - [ ] write summary of project for Winston \ 3.11 - [ ] project proposals for Winston \ 3.12 - [ ] additional senses to be implemented for Winston | -- 2 days 3.13 @@ -1077,14 +1078,55 @@ 3.14 ;; represent relative roll, pitch, and yaw. Write display code for 3.15 ;; this though. 3.16 3.17 -(defn muscle-fibre-values 3.18 - "Take the first row of the image and return the low-order bytes." 3.19 +(defn muscle-fiber-values 3.20 + "get motor pool strengths" 3.21 [#^BufferedImage image] 3.22 - (let [width (.getWidth image)] 3.23 - (for [x (range width)] 3.24 - (bit-and 3.25 - 0xFF 3.26 - (.getRGB image x 0))))) 3.27 + (vec 3.28 + (let [width (.getWidth image)] 3.29 + (for [x (range width)] 3.30 + (- 255 3.31 + (bit-and 3.32 + 0x0000FF 3.33 + (.getRGB image x 0))))))) 3.34 + 3.35 + 3.36 +(defn creature-muscles 3.37 + "Return the children of the creature's \"muscles\" node." 3.38 + [#^Node creature] 3.39 + (if-let [muscle-node (.getChild creature "muscles")] 3.40 + (seq (.getChildren muscle-node)) 3.41 + (do (println-repl "could not find muscles node") []))) 3.42 + 3.43 +(defn single-muscle [#^Node parts #^Node muscle] 3.44 + (let [target (closest-node parts muscle) 3.45 + axis 3.46 + (.mult (.getWorldRotation muscle) Vector3f/UNIT_Y) 3.47 + strength (meta-data muscle "strength") 3.48 + image-name (read-string (meta-data muscle "muscle")) 3.49 + image 3.50 + (ImageToAwt/convert 3.51 + (.getImage (.loadTexture (asset-manager) image-name)) 3.52 + false false 0) 3.53 + fibers (muscle-fiber-values image) 3.54 + fiber-integral (reductions + fibers) 3.55 + force-index (vec 3.56 + (map 3.57 + #(float (* strength (/ % (last 3.58 + fiber-integral)))) 3.59 + fiber-integral)) 3.60 + control (.getControl target RigidBodyControl)] 3.61 + (fn [n] 3.62 + (let [pool-index (min n (count fibers))] 3.63 + (.applyTorque control (force-index n)))))) 3.64 + 3.65 + 3.66 +(defn enable-muscles 3.67 + "Must be called on a creature after RigidBodyControls have been 3.68 + created." 3.69 + [#^Node creature] 3.70 + (let [muscles (creature-muscles creature)] 3.71 + (for [muscle muscles] 3.72 + (single-muscle creature muscle)))) 3.73 3.74 (defn test-creature [thing] 3.75 (let [x-axis