changeset 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
files assets/Models/anim2/Cube.material org/body.org org/skin.org org/world.org
diffstat 4 files changed, 100 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/assets/Models/anim2/Cube.material	Mon Nov 14 21:30:23 2011 -0700
     1.3 @@ -0,0 +1,32 @@
     1.4 +
     1.5 +// blender material: Material
     1.6 +material Material 
     1.7 +{
     1.8 +    receive_shadows on
     1.9 +    technique b2ogre_1321319923.771223
    1.10 +    {
    1.11 +        pass b2ogre_1321319923.77125
    1.12 +        {
    1.13 +            ambient 0.800000011920929 0.800000011920929 0.800000011920929 1.0
    1.14 +            diffuse 0.6400000190734865 0.6400000190734865 0.6400000190734865 1.0
    1.15 +            specular 0.5 0.5 0.5 1.0 12.5
    1.16 +            emissive 0.0 0.0 0.0 1.0
    1.17 +            alpha_to_coverage off
    1.18 +            colour_write on
    1.19 +            cull_hardware clockwise
    1.20 +            depth_check on
    1.21 +            depth_func less_equal
    1.22 +            depth_write on
    1.23 +            illumination_stage 
    1.24 +            light_clip_planes off
    1.25 +            light_scissor off
    1.26 +            lighting on
    1.27 +            normalise_normals off
    1.28 +            polygon_mode solid
    1.29 +            scene_blend one zero
    1.30 +            scene_blend_op add
    1.31 +            shading gouraud
    1.32 +            transparent_sorting on
    1.33 +        }
    1.34 +    }
    1.35 +}
     2.1 --- a/org/body.org	Mon Nov 14 19:44:30 2011 -0700
     2.2 +++ b/org/body.org	Mon Nov 14 21:30:23 2011 -0700
     2.3 @@ -58,6 +58,14 @@
     2.4    (first (seq (.getChildren (load-blender-model
     2.5                               "Models/anim2/worm3.blend")))))
     2.6  
     2.7 +(defn skel [node]
     2.8 +  (doto
     2.9 +      (.getSkeleton
    2.10 +       (.getControl node SkeletonControl))
    2.11 +    ;; this is necessary to force the skeleton to have accurate world
    2.12 +    ;; transforms before it is rendered to the screen. 
    2.13 +    (.resetAndUpdate)))
    2.14 +
    2.15  (defprotocol Textual
    2.16    (text [something]
    2.17      "Display a detailed textual analysis of the given object."))
    2.18 @@ -76,7 +84,7 @@
    2.19    Textual
    2.20    (text [control]
    2.21      (let [animations (.getAnimationNames control)]
    2.22 -      (println "Animation Control with " (count animations) " animations:")
    2.23 +      (println "Animation Control with " (count animations) " animation(s):")
    2.24        (dorun (map println animations)))))
    2.25  
    2.26  (extend-type com.jme3.animation.SkeletonControl
    2.27 @@ -85,6 +93,12 @@
    2.28      (println "Skeleton Control with the following skeleton:")
    2.29      (println (.getSkeleton control))))
    2.30  
    2.31 +(extend-type com.jme3.bullet.control.KinematicRagdollControl
    2.32 +  Textual
    2.33 +  (text [control]
    2.34 +    (println "Ragdoll Control")))
    2.35 +                 
    2.36 +
    2.37  (extend-type com.jme3.scene.Geometry
    2.38    Textual
    2.39    (text [control]
    2.40 @@ -94,26 +108,49 @@
    2.41  
    2.42  
    2.43  (defn body
    2.44 -  "given a node with a skeleton, will produce a body sutiable for AI
    2.45 -  control with movement and proprioception."
    2.46 +  "given a node with a SkeletonControl, will produce a body sutiable
    2.47 +  for AI control with movement and proprioception."
    2.48    [node]
    2.49    (let [skeleton-control (.getControl node SkeletonControl)
    2.50          krc (KinematicRagdollControl. (float 0.5))]
    2.51      (dorun
    2.52       (map #(.addBoneName krc %)
    2.53 -          ["mid1" "mid2" "mid3" "tail" "head"]))
    2.54 +          ["mid1" "mid2" "mid3" "tail" "head"]
    2.55 +        ;; ["Ulna.L"
    2.56 +        ;;  "Ulna.R"
    2.57 +        ;;  "Chest"
    2.58 +        ;;  "Foot.L"
    2.59 +        ;;  "Foot.R"
    2.60 +        ;;  "Hand.R"
    2.61 +        ;;  "Hand.L"
    2.62 +        ;;  "Neck"
    2.63 +        ;;  "Root"
    2.64 +        ;;  "Stomach"
    2.65 +        ;;  "Waist"
    2.66 +        ;;  "Humerus.L"
    2.67 +        ;;  "Humerus.R"
    2.68 +        ;;  "Thigh.L"
    2.69 +        ;;  "Thigh.R"
    2.70 +        ;;  "Calf.L"
    2.71 +        ;;  "Calf.R"
    2.72 +        ;;  "Clavicle.L"
    2.73 +        ;;  "Clavicle.R"]
    2.74 +        ))
    2.75 +
    2.76 +
    2.77 +    
    2.78      (.addControl node krc)
    2.79 -    (.setRagdollMode krc))
    2.80 +    (.setRagdollMode krc)
    2.81 +    )
    2.82    node
    2.83    )
    2.84  
    2.85 -(defn
    2.86 -  green-x-ray []
    2.87 +(defn green-x-ray []
    2.88    (doto (Material. (asset-manager)
    2.89                     "Common/MatDefs/Misc/Unshaded.j3md")
    2.90      (.setColor "Color" ColorRGBA/Green)
    2.91 -    (-> (.getAdditionalRenderState) (.setDepthTest
    2.92 -                                     false))))
    2.93 +    (-> (.getAdditionalRenderState)
    2.94 +        (.setDepthTest false))))
    2.95  
    2.96  (defn view-skeleton [node]
    2.97    (let [sd
    2.98 @@ -154,33 +191,17 @@
    2.99          bones)))
   2.100      debug-node)
   2.101  
   2.102 -(defn skel [node]
   2.103 -  (doto
   2.104 -      (.getSkeleton
   2.105 -       (.getControl node SkeletonControl))
   2.106 -    ;; this is necessary to force the skeleton to have accurate world
   2.107 -    ;; transforms before it is rendered to the screen. 
   2.108 -    (.resetAndUpdate)))
   2.109 -
   2.110 -  
   2.111 -                         
   2.112 -
   2.113 -
   2.114 -(view
   2.115 - (init-debug-skel-node
   2.116 -  (fn [b] (.getWorldBindPosition b))
   2.117 -  (Node. "skel-debug") (skel (worm))))
   2.118 -  
   2.119 -
   2.120 -
   2.121 -
   2.122 +(import jme3test.bullet.PhysicsTestHelper)
   2.123  
   2.124  (defn test-ragdoll []
   2.125    
   2.126    (let [the-worm
   2.127          (body
   2.128 -         (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")
   2.129 +         ;;(.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")
   2.130           ;;(worm-blender)
   2.131 +         (worm)
   2.132 +         ;;(oto)
   2.133 +         ;;(sinbad)
   2.134          )
   2.135      ]
   2.136  
   2.137 @@ -192,6 +213,11 @@
   2.138        {"mouse-left" (fire-cannon-ball)}
   2.139        (fn [world]
   2.140          (light-up-everything world)
   2.141 +        (PhysicsTestHelper/createPhysicsTestWorld
   2.142 +         (.getRootNode world)
   2.143 +         (asset-manager)
   2.144 +         (.getPhysicsSpace
   2.145 +          (.getState (.getStateManager world) BulletAppState)))
   2.146          ;;(.setTimer world (NanoTimer.))
   2.147          ;;(org.lwjgl.input.Mouse/setGrabbed false)
   2.148          )
   2.149 @@ -203,60 +229,6 @@
   2.150      
   2.151  
   2.152  
   2.153 -
   2.154 -
   2.155 -
   2.156 -
   2.157 -
   2.158 -
   2.159 -
   2.160 -
   2.161 -
   2.162 -
   2.163 -
   2.164 -
   2.165 -
   2.166 -
   2.167 -
   2.168 -(defn test-worm-anim []
   2.169 -  
   2.170 -  (let [the-worm
   2.171 -;;        (oto)
   2.172 -        (worm-blender)
   2.173 -        anim-control (.getControl the-worm AnimControl)
   2.174 -        channel (doto (.createChannel anim-control)
   2.175 -;;                  (.setAnim "Walk")
   2.176 -                  (.setAnim "moveHead")
   2.177 -                  )
   2.178 -
   2.179 -        play-anim
   2.180 -        no-op
   2.181 -        ;; (fn [world pressed]
   2.182 -;;           (if (not pressed)
   2.183 -;;             (do 
   2.184 -;;               (println-repl "space")
   2.185 -;; ;;              (.setAnim channel "moveHead")
   2.186 -;;               (.setAnim channel "Walk" (float 0.5))
   2.187 -;;                         )))
   2.188 -
   2.189 -        ]
   2.190 -
   2.191 -    (.start 
   2.192 -     (world
   2.193 -      (doto (Node.)
   2.194 -        (.attachChild the-worm))
   2.195 -      {"key-space" play-anim
   2.196 -       "mouse-left" (fire-cannon-ball)}
   2.197 -      (fn [world]
   2.198 -        (light-up-everything world)
   2.199 -        ;;(.setTimer world (NanoTimer.))
   2.200 -        (org.lwjgl.input.Mouse/setGrabbed false)
   2.201 -        )
   2.202 -      no-op
   2.203 -      )
   2.204 -  
   2.205 -     
   2.206 -     )))
   2.207      
   2.208  
   2.209  
     3.1 --- a/org/skin.org	Mon Nov 14 19:44:30 2011 -0700
     3.2 +++ b/org/skin.org	Mon Nov 14 21:30:23 2011 -0700
     3.3 @@ -112,7 +112,7 @@
     3.4  
     3.5  (cortex.import/mega-import-jme3)
     3.6    
     3.7 -(use 'hello.brick-wall)
     3.8 +
     3.9  
    3.10  (defn ray-origin-debug
    3.11    [ray color]
     4.1 --- a/org/world.org	Mon Nov 14 19:44:30 2011 -0700
     4.2 +++ b/org/world.org	Mon Nov 14 21:30:23 2011 -0700
     4.3 @@ -293,14 +293,18 @@
     4.4                            (Vector3f. 0 -9.81 0))
     4.5               ;; go through every object and add it to the physics
     4.6               ;; manager if relevant.
     4.7 -             (traverse (fn [geom]
     4.8 -                         (dorun
     4.9 -                          (for [n (range (.getNumControls geom))]
    4.10 -                            (do
    4.11 -                              (.add (.getPhysicsSpace physics-manager)
    4.12 -                                    (.getControl geom n))))))
    4.13 -                       (.getRootNode this))
    4.14 +             ;;(traverse (fn [geom]
    4.15 +             ;;            (dorun
    4.16 +             ;;             (for [n (range (.getNumControls geom))]
    4.17 +             ;;               (do
    4.18 +             ;;                 (cortex.util/println-repl
    4.19 +             ;;                  "adding " (.getControl geom n))
    4.20 +             ;;                 (.add (.getPhysicsSpace physics-manager)
    4.21 +             ;;                       (.getControl geom n))))))
    4.22 +             ;;          (.getRootNode this))
    4.23               ;; call the supplied setup-fn
    4.24 +             ;; simpler !
    4.25 +             (.addAll (.getPhysicsSpace physics-manager) root-node)
    4.26               (if setup-fn
    4.27                 (setup-fn this))))
    4.28            (simpleUpdate