diff org/body.org @ 52:00d0e1639d4b

simplified world, got buggy physics ragdoll working
author Robert McIntyre <rlm@mit.edu>
date Mon, 14 Nov 2011 21:30:23 -0700
parents 2a6ede6d8ad8
children bb24106cbd6a
line wrap: on
line diff
     1.1 --- a/org/body.org	Mon Nov 14 19:44:30 2011 -0700
     1.2 +++ b/org/body.org	Mon Nov 14 21:30:23 2011 -0700
     1.3 @@ -58,6 +58,14 @@
     1.4    (first (seq (.getChildren (load-blender-model
     1.5                               "Models/anim2/worm3.blend")))))
     1.6  
     1.7 +(defn skel [node]
     1.8 +  (doto
     1.9 +      (.getSkeleton
    1.10 +       (.getControl node SkeletonControl))
    1.11 +    ;; this is necessary to force the skeleton to have accurate world
    1.12 +    ;; transforms before it is rendered to the screen. 
    1.13 +    (.resetAndUpdate)))
    1.14 +
    1.15  (defprotocol Textual
    1.16    (text [something]
    1.17      "Display a detailed textual analysis of the given object."))
    1.18 @@ -76,7 +84,7 @@
    1.19    Textual
    1.20    (text [control]
    1.21      (let [animations (.getAnimationNames control)]
    1.22 -      (println "Animation Control with " (count animations) " animations:")
    1.23 +      (println "Animation Control with " (count animations) " animation(s):")
    1.24        (dorun (map println animations)))))
    1.25  
    1.26  (extend-type com.jme3.animation.SkeletonControl
    1.27 @@ -85,6 +93,12 @@
    1.28      (println "Skeleton Control with the following skeleton:")
    1.29      (println (.getSkeleton control))))
    1.30  
    1.31 +(extend-type com.jme3.bullet.control.KinematicRagdollControl
    1.32 +  Textual
    1.33 +  (text [control]
    1.34 +    (println "Ragdoll Control")))
    1.35 +                 
    1.36 +
    1.37  (extend-type com.jme3.scene.Geometry
    1.38    Textual
    1.39    (text [control]
    1.40 @@ -94,26 +108,49 @@
    1.41  
    1.42  
    1.43  (defn body
    1.44 -  "given a node with a skeleton, will produce a body sutiable for AI
    1.45 -  control with movement and proprioception."
    1.46 +  "given a node with a SkeletonControl, will produce a body sutiable
    1.47 +  for AI control with movement and proprioception."
    1.48    [node]
    1.49    (let [skeleton-control (.getControl node SkeletonControl)
    1.50          krc (KinematicRagdollControl. (float 0.5))]
    1.51      (dorun
    1.52       (map #(.addBoneName krc %)
    1.53 -          ["mid1" "mid2" "mid3" "tail" "head"]))
    1.54 +          ["mid1" "mid2" "mid3" "tail" "head"]
    1.55 +        ;; ["Ulna.L"
    1.56 +        ;;  "Ulna.R"
    1.57 +        ;;  "Chest"
    1.58 +        ;;  "Foot.L"
    1.59 +        ;;  "Foot.R"
    1.60 +        ;;  "Hand.R"
    1.61 +        ;;  "Hand.L"
    1.62 +        ;;  "Neck"
    1.63 +        ;;  "Root"
    1.64 +        ;;  "Stomach"
    1.65 +        ;;  "Waist"
    1.66 +        ;;  "Humerus.L"
    1.67 +        ;;  "Humerus.R"
    1.68 +        ;;  "Thigh.L"
    1.69 +        ;;  "Thigh.R"
    1.70 +        ;;  "Calf.L"
    1.71 +        ;;  "Calf.R"
    1.72 +        ;;  "Clavicle.L"
    1.73 +        ;;  "Clavicle.R"]
    1.74 +        ))
    1.75 +
    1.76 +
    1.77 +    
    1.78      (.addControl node krc)
    1.79 -    (.setRagdollMode krc))
    1.80 +    (.setRagdollMode krc)
    1.81 +    )
    1.82    node
    1.83    )
    1.84  
    1.85 -(defn
    1.86 -  green-x-ray []
    1.87 +(defn green-x-ray []
    1.88    (doto (Material. (asset-manager)
    1.89                     "Common/MatDefs/Misc/Unshaded.j3md")
    1.90      (.setColor "Color" ColorRGBA/Green)
    1.91 -    (-> (.getAdditionalRenderState) (.setDepthTest
    1.92 -                                     false))))
    1.93 +    (-> (.getAdditionalRenderState)
    1.94 +        (.setDepthTest false))))
    1.95  
    1.96  (defn view-skeleton [node]
    1.97    (let [sd
    1.98 @@ -154,33 +191,17 @@
    1.99          bones)))
   1.100      debug-node)
   1.101  
   1.102 -(defn skel [node]
   1.103 -  (doto
   1.104 -      (.getSkeleton
   1.105 -       (.getControl node SkeletonControl))
   1.106 -    ;; this is necessary to force the skeleton to have accurate world
   1.107 -    ;; transforms before it is rendered to the screen. 
   1.108 -    (.resetAndUpdate)))
   1.109 -
   1.110 -  
   1.111 -                         
   1.112 -
   1.113 -
   1.114 -(view
   1.115 - (init-debug-skel-node
   1.116 -  (fn [b] (.getWorldBindPosition b))
   1.117 -  (Node. "skel-debug") (skel (worm))))
   1.118 -  
   1.119 -
   1.120 -
   1.121 -
   1.122 +(import jme3test.bullet.PhysicsTestHelper)
   1.123  
   1.124  (defn test-ragdoll []
   1.125    
   1.126    (let [the-worm
   1.127          (body
   1.128 -         (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")
   1.129 +         ;;(.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")
   1.130           ;;(worm-blender)
   1.131 +         (worm)
   1.132 +         ;;(oto)
   1.133 +         ;;(sinbad)
   1.134          )
   1.135      ]
   1.136  
   1.137 @@ -192,6 +213,11 @@
   1.138        {"mouse-left" (fire-cannon-ball)}
   1.139        (fn [world]
   1.140          (light-up-everything world)
   1.141 +        (PhysicsTestHelper/createPhysicsTestWorld
   1.142 +         (.getRootNode world)
   1.143 +         (asset-manager)
   1.144 +         (.getPhysicsSpace
   1.145 +          (.getState (.getStateManager world) BulletAppState)))
   1.146          ;;(.setTimer world (NanoTimer.))
   1.147          ;;(org.lwjgl.input.Mouse/setGrabbed false)
   1.148          )
   1.149 @@ -203,60 +229,6 @@
   1.150      
   1.151  
   1.152  
   1.153 -
   1.154 -
   1.155 -
   1.156 -
   1.157 -
   1.158 -
   1.159 -
   1.160 -
   1.161 -
   1.162 -
   1.163 -
   1.164 -
   1.165 -
   1.166 -
   1.167 -
   1.168 -(defn test-worm-anim []
   1.169 -  
   1.170 -  (let [the-worm
   1.171 -;;        (oto)
   1.172 -        (worm-blender)
   1.173 -        anim-control (.getControl the-worm AnimControl)
   1.174 -        channel (doto (.createChannel anim-control)
   1.175 -;;                  (.setAnim "Walk")
   1.176 -                  (.setAnim "moveHead")
   1.177 -                  )
   1.178 -
   1.179 -        play-anim
   1.180 -        no-op
   1.181 -        ;; (fn [world pressed]
   1.182 -;;           (if (not pressed)
   1.183 -;;             (do 
   1.184 -;;               (println-repl "space")
   1.185 -;; ;;              (.setAnim channel "moveHead")
   1.186 -;;               (.setAnim channel "Walk" (float 0.5))
   1.187 -;;                         )))
   1.188 -
   1.189 -        ]
   1.190 -
   1.191 -    (.start 
   1.192 -     (world
   1.193 -      (doto (Node.)
   1.194 -        (.attachChild the-worm))
   1.195 -      {"key-space" play-anim
   1.196 -       "mouse-left" (fire-cannon-ball)}
   1.197 -      (fn [world]
   1.198 -        (light-up-everything world)
   1.199 -        ;;(.setTimer world (NanoTimer.))
   1.200 -        (org.lwjgl.input.Mouse/setGrabbed false)
   1.201 -        )
   1.202 -      no-op
   1.203 -      )
   1.204 -  
   1.205 -     
   1.206 -     )))
   1.207      
   1.208  
   1.209