# HG changeset patch # User Robert McIntyre # Date 1321424317 25200 # Node ID 8b571c137f81ff57236c28ffcacb8d3099027d79 # Parent 8b95180f5c691cbc880f8d999c743917aa02bc5d bone influence appears to be wrong! Investigating... diff -r 8b95180f5c69 -r 8b571c137f81 assets/Models/anim2/simple-worm.blend Binary file assets/Models/anim2/simple-worm.blend has changed diff -r 8b95180f5c69 -r 8b571c137f81 org/body.org --- a/org/body.org Tue Nov 15 17:48:10 2011 -0700 +++ b/org/body.org Tue Nov 15 23:18:37 2011 -0700 @@ -56,7 +56,7 @@ (defn worm-blender [] (first (seq (.getChildren (load-blender-model - "Models/anim2/worm3.blend"))))) + "Models/anim2/simple-worm.blend"))))) (defn skel [node] (doto @@ -178,7 +178,7 @@ (range (.getBoneCount skeleton)))) - (let [b (.getBone skeleton 6)] + (let [b (.getBone skeleton 2)] (println-repl "moving " (.getName b)) (println-repl (.getLocalPosition b)) (.setUserTransforms b @@ -233,13 +233,9 @@ ))) - - - (defn joint-control [joint] - (let [physics-space (ref nil) - enabled? (ref true)] + (let [physics-space (ref nil)] (reify PhysicsControl (setPhysicsSpace [this space] (dosync @@ -249,9 +245,8 @@ (setSpatial [this spatial]) (render [this rm vp]) (getPhysicsSpace [this] (deref physics-space)) - (isEnabled [this] (deref enabled?)) - (setEnabled [this state] - (dosync (ref-set enabled? state)))))) + (isEnabled [this] true) + (setEnabled [this state])))) (defn add-joint "Add a joint to a particular object. When the object is added to the @@ -273,18 +268,86 @@ (doto (Node. "hinge-world") (.attachChild sphere1) (.attachChild sphere2)))) - -(defn test-joint - [] - (.start - (world - (doto (Node.) - (.attachChild +(defn test-joint [] + (view (hinge-world))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; 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 vec-pos [index] + (let [offset (* index 3)] + (Vector3f. (position offset) + (position (inc offset)) + (position (inc(inc offset)))))) + +(defn bones [index] + (.get + (.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) + index)) + +(defn bone-control-color [index] + (get {[1 0 0 0] ColorRGBA/Red + [1 2 0 0] ColorRGBA/Magenta + [2 0 0 0] ColorRGBA/Blue} + (vec (map (comp int bones) (range (* index 4) (+ (* index 4) 4)))) + ColorRGBA/White)) + +(defn bone-weights [index] + (.get + (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) + index)) + +(defn influence-color [index bone-num] + (get + {(float 0) ColorRGBA/Blue + (float 0.5) ColorRGBA/Green + (float 1) ColorRGBA/Red} + (bone-weights (+ (* 4 index) bone-num)))) + +(defn test-info [] + (let [points (Node.)] + (dorun + (map #(.attachChild points %) + (map #(sphere 0.01 + :position (vec-pos %) + :color (influence-color % 0) + :physical? false) + (range 12)))) + (view points))) + + + + + + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + + + + + + + #+end_src