# HG changeset patch # User Robert McIntyre # Date 1321771341 25200 # Node ID 25142dad240a10fe1ad7d4582f82b48d43babe0a # Parent 37a3256e1ed3999bcb7c0854de80c4a4705bd0be created test suite diff -r 37a3256e1ed3 -r 25142dad240a assets/Models/anim2/joint-worm.blend Binary file assets/Models/anim2/joint-worm.blend has changed diff -r 37a3256e1ed3 -r 25142dad240a org/body.org --- a/org/body.org Wed Nov 16 02:42:50 2011 -0700 +++ b/org/body.org Sat Nov 19 23:42:21 2011 -0700 @@ -5,7 +5,7 @@ #+SETUPFILE: ../../aurellem/org/setup.org #+INCLUDE: ../../aurellem/org/level-0.org -* COMMENT Body +* Body #+srcname: body-main #+begin_src clojure @@ -233,6 +233,91 @@ ))) + + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; here is the ragdoll stuff + +(def worm-mesh (.getMesh (.getChild (worm-blender) 0))) +(def mesh worm-mesh) + +(.getFloatBuffer mesh VertexBuffer$Type/Position) +(.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) +(.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) + + +(defn position [index] + (.get + (.getFloatBuffer worm-mesh VertexBuffer$Type/Position) + index)) + +(defn bones [index] + (.get + (.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) + index)) + +(defn bone-weights [index] + (.get + (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) + index)) + + + +(defn vertex-bones [vertex] + (vec (map (comp int bones) (range (* vertex 4) (+ (* vertex 4) 4))))) + +(defn vertex-weights [vertex] + (vec (map (comp float bone-weights) (range (* vertex 4) (+ (* vertex 4) 4))))) + +(defn vertex-position [index] + (let [offset (* index 3)] + (Vector3f. (position offset) + (position (inc offset)) + (position (inc(inc offset)))))) + +(def vertex-info (juxt vertex-position vertex-bones vertex-weights)) + +(defn bone-control-color [index] + (get {[1 0 0 0] ColorRGBA/Red + [1 2 0 0] ColorRGBA/Magenta + [2 0 0 0] ColorRGBA/Blue} + (vertex-bones index) + ColorRGBA/White)) + +(defn influence-color [index bone-num] + (get + {(float 0) ColorRGBA/Blue + (float 0.5) ColorRGBA/Green + (float 1) ColorRGBA/Red} + ;; find the weight of the desired bone + ((zipmap (vertex-bones index)(vertex-weights index)) + bone-num) + ColorRGBA/Blue)) + +(def worm-vertices (set (map vertex-info (range 60)))) + + +(defn test-info [] + (let [points (Node.)] + (dorun + (map #(.attachChild points %) + (map #(sphere 0.01 + :position (vertex-position %) + :color (influence-color % 1) + :physical? false) + (range 60)))) + (view points))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + + + + + +;;;;;;;;;;;; eve-style bodies ;;;;;;;; (defn joint-control [joint] (let [physics-space (ref nil)] @@ -271,94 +356,80 @@ (defn test-joint [] (view (hinge-world))) - +(defn worm [segment-length num-segments interstitial-space radius] + (letfn [(nth-segment + [n] + (box segment-length radius radius :mass 0.1 + :position + (Vector3f. + (* 2 n (+ interstitial-space segment-length)) 0 0) + :name (str "worm-segment" n) + :color (ColorRGBA/randomColor)))] + (map nth-segment (range num-segments)))) + +(defn nodify + "take a sequence of things that can be attached to a node and return + a node with all of the attached" + ([name children] + (let [node (Node. name)] + (dorun (map #(.attachChild node %) children)) + node)) + ([children] (nodify "" children))) + + +(defn connect-at-midpoint + [segmentA segmentB] + (let [centerA (.getWorldTranslation segmentA) + centerB (.getWorldTranslation segmentB) + midpoint (.mult (.add centerA centerB) (float 0.5)) + pivotA (.subtract midpoint centerA) + pivotB (.subtract midpoint centerB) + + joint (Point2PointJoint. + (.getControl segmentA RigidBodyControl) + (.getControl segmentB RigidBodyControl) + pivotA + pivotB)] + (add-joint segmentA joint) + segmentB)) + + +(defn point-worm [] + (let [segments (worm 0.2 5 0.1 0.1)] + (dorun (map (partial apply connect-at-midpoint) + (partition 2 1 segments))) + (nodify "worm" segments))) + + +(defn test-worm [] + (.start + (world + (doto (Node.) + ;;(.attachChild (point-worm)) + (.attachChild (load-blender-model + "Models/anim2/joint-worm.blend")) + + (.attachChild (box 10 1 10 + :position (Vector3f. 0 -2 0) :mass 0 + :color (ColorRGBA/Gray)))) + { + "key-space" (fire-cannon-ball) + } + (fn [world] + (enable-debug world) + (light-up-everything world) + ;;(.setTimer world (NanoTimer.)) + ) + no-op))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; here is the ragdoll stuff -(def worm-mesh (.getMesh (.getChild (worm-blender) 0))) -(def mesh worm-mesh) -(.getFloatBuffer mesh VertexBuffer$Type/Position) -(.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) -(.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) -(defn position [index] - (.get - (.getFloatBuffer worm-mesh VertexBuffer$Type/Position) - index)) -(defn bones [index] - (.get - (.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) - index)) - -(defn bone-weights [index] - (.get - (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) - index)) - - - -(defn vertex-bones [vertex] - (vec (map (comp int bones) (range (* vertex 4) (+ (* vertex 4) 4))))) - -(defn vertex-weights [vertex] - (vec (map (comp float bone-weights) (range (* vertex 4) (+ (* vertex 4) 4))))) - -(defn vertex-position [index] - (let [offset (* index 3)] - (Vector3f. (position offset) - (position (inc offset)) - (position (inc(inc offset)))))) - -(def vertex-info (juxt vertex-position vertex-bones vertex-weights)) - -(defn bone-control-color [index] - (get {[1 0 0 0] ColorRGBA/Red - [1 2 0 0] ColorRGBA/Magenta - [2 0 0 0] ColorRGBA/Blue} - (vertex-bones index) - ColorRGBA/White)) - -(defn influence-color [index bone-num] - (get - {(float 0) ColorRGBA/Blue - (float 0.5) ColorRGBA/Green - (float 1) ColorRGBA/Red} - ;; find the weight of the desired bone - ((zipmap (vertex-bones index)(vertex-weights index)) - bone-num) - ColorRGBA/Blue)) - - - - -(def worm-vertices (set (map vertex-info (range 60)))) - - -(defn test-info [] - (let [points (Node.)] - (dorun - (map #(.attachChild points %) - (map #(sphere 0.01 - :position (vertex-position %) - :color (influence-color % 1) - :physical? false) - (range 60)))) - (view points))) - - - - - - - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff -r 37a3256e1ed3 -r 25142dad240a org/eyes.org --- a/org/eyes.org Wed Nov 16 02:42:50 2011 -0700 +++ b/org/eyes.org Sat Nov 19 23:42:21 2011 -0700 @@ -130,27 +130,26 @@ object from different angles and displaying both of those views in JFrames." [] - (.start - (let [candy - (box 1 1 1 :physical? false :color ColorRGBA/Blue)] - (world (doto (Node.) - (.attachChild candy)) - {} - (fn [world] - (let [cam (.clone (.getCamera world)) - width (.getWidth cam) - height (.getHeight cam)] - (add-eye world cam (view-image width height)) - (add-eye world - (doto (.clone cam) - (.setLocation (Vector3f. -10 0 0)) - (.lookAt Vector3f/ZERO Vector3f/UNIT_Y)) - (view-image width height)) + (let [candy + (box 1 1 1 :physical? false :color ColorRGBA/Blue)] + (world (doto (Node.) + (.attachChild candy)) + {} + (fn [world] + (let [cam (.clone (.getCamera world)) + width (.getWidth cam) + height (.getHeight cam)] + (add-eye world cam (view-image width height)) + (add-eye world + (doto (.clone cam) + (.setLocation (Vector3f. -10 0 0)) + (.lookAt Vector3f/ZERO Vector3f/UNIT_Y)) + (view-image width height)) ;; This is here to restore the main view - ;; after the other views have completed processing - (add-eye world (.getCamera world) no-op))) - (fn [world tpf] - (.rotate candy (* tpf 0.2) 0 0)))))) + ;; after the other views have completed processing + (add-eye world (.getCamera world) no-op))) + (fn [world tpf] + (.rotate candy (* tpf 0.2) 0 0))))) #+end_src The example code will create two videos of the same rotating object diff -r 37a3256e1ed3 -r 25142dad240a org/skin.org --- a/org/skin.org Wed Nov 16 02:42:50 2011 -0700 +++ b/org/skin.org Sat Nov 19 23:42:21 2011 -0700 @@ -227,10 +227,10 @@ (defn test-skin [] (let [b - ;;(transparent-box) - (transparent-sphere) + ;;(transparent-box) + (transparent-sphere) ;;(sphere) - f (transparent-floor) + f (transparent-floor) debug-node (Node.) node (doto (Node.) (.attachChild b) (.attachChild f)) root-node (doto (Node.) (.attachChild node) @@ -247,8 +247,8 @@ ;; (no-logging) ;;(enable-debug world) ;; (set-accuracy world (/ 1 60)) - ) - + ) + (fn [& _] (let [sensitivity 0.2 touch-data (touch-percieve sensitivity b node)] diff -r 37a3256e1ed3 -r 25142dad240a org/test.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/test.org Sat Nov 19 23:42:21 2011 -0700 @@ -0,0 +1,78 @@ +#+title: The BODY!!! +#+author: Robert McIntyre +#+email: rlm@mit.edu +#+description: Simulating a body (movement, touch, propioception) in jMonkeyEngine3. +#+SETUPFILE: ../../aurellem/org/setup.org +#+INCLUDE: ../../aurellem/org/level-0.org + +* Body + +#+srcname: body-main +#+begin_src clojure +(ns test.all + (:require [test touch vision]) + (:import com.jme3.app.state.AppState + com.jme3.system.AppSettings)) + +(defn run-world + "run the simulation and wait until it closes proprely" + [world] + (let [lock (promise)] + (.enqueue + world + (partial + (fn [world] + (.attach + (.getStateManager world) + (proxy [AppState] [] + (cleanup [] (deliver lock nil)) + (initialize [_ _]) + (isEnabled [] true) + (setEnabled [_] ) + (stateAttached [_]) + (stateDetached [_]) + (update [_]) + (render [_]) + (isInitialized [] true) + (postRender [])))) + world)) + (.start world) + (deref lock))) + +(defn test-all [] + (println + "***************\n" + "Testing touch:\n" + "you should see a ball which responds to the table\n" + "and whatever balls hit it.\n") + (run-world (test.touch/test-skin)) + (println + "***************\n" + "Testing vision:\n" + "You should see a rotating cube, and two windows,\n" + "each displaying a different view of the cube.\n") + (run-world (test.vision/test-two-eyes)) + (println + "***************\n" + "Testing hearing:\n" + "You should see a blue sphere flying around several\n" + "cubes. As the sphere approaches each cube, it turns\n" + "green.\n") + (run-world + (doto (com.aurellem.capture.examples.Advanced.) + (.setSettings + (doto (AppSettings. true) + (.setAudioRenderer "Send"))) + (.setShowSettings false) + (.setPauseOnLostFocus false)))) +#+end_src + + + + +* COMMENT generate Source. +#+begin_src clojure :tangle ../src/test/all.clj +<> +#+end_src + +