# HG changeset patch # User Robert McIntyre # Date 1328255314 25200 # Node ID 72801a20b8e5d2b994b538e2a4e868b6db0750ad # Parent 68226790d1fa46e56f19c575509c8365562d6a8d First stab at blender muscles. (gee that sounds a little violent...) diff -r 68226790d1fa -r 72801a20b8e5 assets/Models/creature1/basic-muscle.png Binary file assets/Models/creature1/basic-muscle.png has changed diff -r 68226790d1fa -r 72801a20b8e5 assets/Models/creature1/try-again.blend Binary file assets/Models/creature1/try-again.blend has changed diff -r 68226790d1fa -r 72801a20b8e5 org/test-creature.org --- a/org/test-creature.org Thu Feb 02 13:22:14 2012 -0700 +++ b/org/test-creature.org Fri Feb 03 00:48:34 2012 -0700 @@ -80,7 +80,8 @@ - [X] proprioception sensor map in the style of the other senses -- day - [ ] refactor integration code to distribute to each of the senses -- day - - [ ] create video showing all the senses for Winston -- 2 days + - [ ] create video showing all the senses for Winston -- 2 days + - [ ] send package to friends for critiques -- 2 days - [ ] write summary of project for Winston \ - [ ] project proposals for Winston \ - [ ] additional senses to be implemented for Winston | -- 2 days @@ -1077,14 +1078,55 @@ ;; represent relative roll, pitch, and yaw. Write display code for ;; this though. -(defn muscle-fibre-values - "Take the first row of the image and return the low-order bytes." +(defn muscle-fiber-values + "get motor pool strengths" [#^BufferedImage image] - (let [width (.getWidth image)] - (for [x (range width)] - (bit-and - 0xFF - (.getRGB image x 0))))) + (vec + (let [width (.getWidth image)] + (for [x (range width)] + (- 255 + (bit-and + 0x0000FF + (.getRGB image x 0))))))) + + +(defn creature-muscles + "Return the children of the creature's \"muscles\" node." + [#^Node creature] + (if-let [muscle-node (.getChild creature "muscles")] + (seq (.getChildren muscle-node)) + (do (println-repl "could not find muscles node") []))) + +(defn single-muscle [#^Node parts #^Node muscle] + (let [target (closest-node parts muscle) + axis + (.mult (.getWorldRotation muscle) Vector3f/UNIT_Y) + strength (meta-data muscle "strength") + image-name (read-string (meta-data muscle "muscle")) + image + (ImageToAwt/convert + (.getImage (.loadTexture (asset-manager) image-name)) + false false 0) + fibers (muscle-fiber-values image) + fiber-integral (reductions + fibers) + force-index (vec + (map + #(float (* strength (/ % (last + fiber-integral)))) + fiber-integral)) + control (.getControl target RigidBodyControl)] + (fn [n] + (let [pool-index (min n (count fibers))] + (.applyTorque control (force-index n)))))) + + +(defn enable-muscles + "Must be called on a creature after RigidBodyControls have been + created." + [#^Node creature] + (let [muscles (creature-muscles creature)] + (for [muscle muscles] + (single-muscle creature muscle)))) (defn test-creature [thing] (let [x-axis