diff org/body.org @ 56:8b571c137f81

bone influence appears to be wrong! Investigating...
author Robert McIntyre <rlm@mit.edu>
date Tue, 15 Nov 2011 23:18:37 -0700
parents 8b95180f5c69
children 37a3256e1ed3
line wrap: on
line diff
     1.1 --- a/org/body.org	Tue Nov 15 17:48:10 2011 -0700
     1.2 +++ b/org/body.org	Tue Nov 15 23:18:37 2011 -0700
     1.3 @@ -56,7 +56,7 @@
     1.4  (defn worm-blender
     1.5    []
     1.6    (first (seq (.getChildren (load-blender-model
     1.7 -                             "Models/anim2/worm3.blend")))))
     1.8 +                             "Models/anim2/simple-worm.blend")))))
     1.9  
    1.10  (defn skel [node]
    1.11    (doto
    1.12 @@ -178,7 +178,7 @@
    1.13          (range (.getBoneCount skeleton))))
    1.14  
    1.15  
    1.16 -      (let [b (.getBone skeleton 6)]
    1.17 +      (let [b (.getBone skeleton 2)]
    1.18          (println-repl "moving " (.getName b))
    1.19          (println-repl (.getLocalPosition b))
    1.20          (.setUserTransforms b
    1.21 @@ -233,13 +233,9 @@
    1.22       
    1.23       )))
    1.24      
    1.25 -
    1.26 -
    1.27 -
    1.28  (defn joint-control
    1.29    [joint]
    1.30 -  (let [physics-space (ref nil)
    1.31 -        enabled? (ref true)]
    1.32 +  (let [physics-space (ref nil)]
    1.33      (reify PhysicsControl
    1.34        (setPhysicsSpace [this space]
    1.35          (dosync
    1.36 @@ -249,9 +245,8 @@
    1.37        (setSpatial [this spatial])
    1.38        (render [this rm vp])
    1.39        (getPhysicsSpace [this] (deref physics-space))
    1.40 -      (isEnabled [this] (deref enabled?))
    1.41 -      (setEnabled [this state]
    1.42 -        (dosync (ref-set enabled? state))))))
    1.43 +      (isEnabled [this] true)
    1.44 +      (setEnabled [this state]))))
    1.45  
    1.46  (defn add-joint
    1.47    "Add a joint to a particular object. When the object is added to the
    1.48 @@ -273,18 +268,86 @@
    1.49      (doto (Node. "hinge-world")
    1.50        (.attachChild sphere1)
    1.51        (.attachChild sphere2))))
    1.52 -        
    1.53  
    1.54 -(defn test-joint 
    1.55 -  []
    1.56 -  (.start
    1.57 -   (world
    1.58 -    (doto (Node.)
    1.59 -      (.attachChild
    1.60 +(defn test-joint []
    1.61 +  (view (hinge-world)))
    1.62         
    1.63  
    1.64  
    1.65  
    1.66 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    1.67 +;;; here is the ragdoll stuff
    1.68 +
    1.69 +(def worm-mesh (.getMesh (.getChild (worm-blender) 0)))
    1.70 +(def mesh worm-mesh)
    1.71 +
    1.72 +(.getFloatBuffer mesh VertexBuffer$Type/Position)
    1.73 +(.getFloatBuffer mesh VertexBuffer$Type/BoneWeight)
    1.74 +(.getData  (.getBuffer mesh VertexBuffer$Type/BoneIndex))
    1.75 +
    1.76 +
    1.77 +(defn position [index]
    1.78 +  (.get
    1.79 +   (.getFloatBuffer worm-mesh VertexBuffer$Type/Position)
    1.80 +     index))
    1.81 +
    1.82 +(defn vec-pos [index]
    1.83 +  (let [offset (* index 3)]
    1.84 +    (Vector3f. (position offset)
    1.85 +               (position (inc offset))
    1.86 +               (position (inc(inc offset))))))
    1.87 +
    1.88 +(defn bones [index]
    1.89 +  (.get
    1.90 +   (.getData  (.getBuffer mesh VertexBuffer$Type/BoneIndex))
    1.91 +   index))
    1.92 +
    1.93 +(defn bone-control-color [index]
    1.94 +  (get {[1 0 0 0] ColorRGBA/Red
    1.95 +        [1 2 0 0] ColorRGBA/Magenta
    1.96 +        [2 0 0 0] ColorRGBA/Blue}
    1.97 +       (vec (map (comp int bones) (range (* index 4) (+ (* index 4) 4))))
    1.98 +       ColorRGBA/White))
    1.99 +
   1.100 +(defn bone-weights [index]
   1.101 +  (.get
   1.102 +   (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight)
   1.103 +   index))
   1.104 +
   1.105 +(defn influence-color [index bone-num]
   1.106 +  (get
   1.107 +   {(float 0)   ColorRGBA/Blue
   1.108 +    (float 0.5) ColorRGBA/Green
   1.109 +    (float 1)   ColorRGBA/Red}
   1.110 +   (bone-weights (+ (* 4 index) bone-num))))
   1.111 +
   1.112 +(defn test-info []
   1.113 +  (let [points (Node.)]
   1.114 +    (dorun
   1.115 +     (map #(.attachChild points %)
   1.116 +          (map #(sphere 0.01
   1.117 +                        :position (vec-pos %)
   1.118 +                        :color (influence-color % 0)
   1.119 +                        :physical? false)
   1.120 +               (range 12))))
   1.121 +    (view points)))
   1.122 +  
   1.123 +
   1.124 +
   1.125 +
   1.126 +
   1.127 +
   1.128 +
   1.129 +
   1.130 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   1.131 +
   1.132 +
   1.133 +
   1.134 +
   1.135 +
   1.136 +
   1.137 +
   1.138 +
   1.139  #+end_src
   1.140  
   1.141