Mercurial > cortex
diff org/body.org @ 50:b1b90c4ab0bf
trying to resolve problem with skeleton debugging
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 14 Nov 2011 18:46:34 -0700 |
parents | 96a41b384100 |
children | 2a6ede6d8ad8 |
line wrap: on
line diff
1.1 --- a/org/body.org Sat Nov 12 16:52:38 2011 -0700 1.2 +++ b/org/body.org Mon Nov 14 18:46:34 2011 -0700 1.3 @@ -41,32 +41,185 @@ 1.4 (.registerLoader BlenderModelLoader (into-array String ["blend"]))) 1.5 model)) 1.6 1.7 - 1.8 (defn worm 1.9 [] 1.10 - (.loadModel (asset-manager) "Models/anim/worm.mesh.xml")) 1.11 + (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")) 1.12 1.13 - 1.14 -(defn worm 1.15 +(defn oto 1.16 [] 1.17 (.loadModel (asset-manager) "Models/Oto/Oto.mesh.xml")) 1.18 1.19 +(defn sinbad 1.20 + [] 1.21 + (.loadModel (asset-manager) "Models/Sinbad/Sinbad.mesh.xml")) 1.22 + 1.23 +(defn worm-blender 1.24 + [] 1.25 + (first (seq (.getChildren (load-blender-model 1.26 + "Models/anim2/worm3.blend"))))) 1.27 + 1.28 + 1.29 +(defprotocol Textual 1.30 + (text [something] 1.31 + "Display a detailed textual analysis of the given object.")) 1.32 + 1.33 +(extend-type com.jme3.scene.Node 1.34 + Textual 1.35 + (text [node] 1.36 + (println "Total Vertexes: " (.getVertexCount node)) 1.37 + (println "Total Triangles: " (.getTriangleCount node)) 1.38 + (println "Controls :") 1.39 + (dorun (map #(text (.getControl node %)) (range (.getNumControls node)))) 1.40 + (println "Has " (.getQuantity node) " Children:") 1.41 + (doall (map text (.getChildren node))))) 1.42 + 1.43 +(extend-type com.jme3.animation.AnimControl 1.44 + Textual 1.45 + (text [control] 1.46 + (let [animations (.getAnimationNames control)] 1.47 + (println "Animation Control with " (count animations) " animations:") 1.48 + (dorun (map println animations))))) 1.49 + 1.50 +(extend-type com.jme3.animation.SkeletonControl 1.51 + Textual 1.52 + (text [control] 1.53 + (println "Skeleton Control with the following skeleton:") 1.54 + (println (.getSkeleton control)))) 1.55 + 1.56 +(extend-type com.jme3.scene.Geometry 1.57 + Textual 1.58 + (text [control] 1.59 + (println "...geo..."))) 1.60 + 1.61 + 1.62 + 1.63 + 1.64 +(defn body 1.65 + "given a node with a skeleton, will produce a body sutiable for AI 1.66 + control with movement and proprioception." 1.67 + [node] 1.68 + (let [skeleton-control (.getControl node SkeletonControl) 1.69 + krc (KinematicRagdollControl. (float 0.5))] 1.70 + (dorun 1.71 + (map #(.addBoneName krc %) 1.72 + ["mid1" "mid2" "mid3" "tail" "head"])) 1.73 + (.addControl node krc) 1.74 + (.setRagdollMode krc)) 1.75 + node 1.76 + ) 1.77 + 1.78 +(defn view-skeleton [node] 1.79 + (let [sd 1.80 + (doto 1.81 + (SkeletonDebugger. "aurellem-skel-debug" (skel node)) 1.82 + (.setMaterial 1.83 + (doto (Material. (asset-manager) 1.84 + "Common/MatDefs/Misc/Unshaded.j3md") 1.85 + (-> (.getAdditionalRenderState) (.setDepthTest 1.86 + false)))))] 1.87 + 1.88 + (.attachChild debug-node sd))) 1.89 + 1.90 + 1.91 +(defn init-debug-skel-node 1.92 + [f debug-node skeleton] 1.93 + (let [bones 1.94 + (map #(.getBone skeleton %) 1.95 + (range (.getBoneCount skeleton)))] 1.96 + (dorun (map #(.setUserControl % true) bones)) 1.97 + (dorun (map (fn [b] 1.98 + (println (.getName b) 1.99 + " -- " (f b))) 1.100 + bones)) 1.101 + 1.102 + (dorun 1.103 + (map #(.attachChild 1.104 + debug-node 1.105 + (sphere 0.1 1.106 + :position (f %) 1.107 + :rotation (.getWorldBindRotation %) 1.108 + :physical? false)) 1.109 + bones))) 1.110 + debug-node) 1.111 + 1.112 +(defn skel [node] 1.113 + (.getSkeleton (.getControl node SkeletonControl))) 1.114 + 1.115 + 1.116 + 1.117 + 1.118 +(view 1.119 + (init-debug-skel-node 1.120 + (fn [b] (.getWorldBindPosition b)) 1.121 + (Node. "skel-debug") (skel (worm)))) 1.122 + 1.123 + 1.124 + 1.125 + 1.126 + 1.127 +(defn test-ragdoll [] 1.128 + 1.129 + (let [the-worm 1.130 + (body 1.131 + (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml") 1.132 + ;;(worm-blender) 1.133 + ) 1.134 + ] 1.135 + 1.136 + 1.137 + (.start 1.138 + (world 1.139 + (doto (Node.) 1.140 + (.attachChild the-worm)) 1.141 + {"mouse-left" (fire-cannon-ball)} 1.142 + (fn [world] 1.143 + (light-up-everything world) 1.144 + ;;(.setTimer world (NanoTimer.)) 1.145 + ;;(org.lwjgl.input.Mouse/setGrabbed false) 1.146 + ) 1.147 + no-op 1.148 + ) 1.149 + 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 1.169 1.170 (defn test-worm-anim [] 1.171 1.172 - (let [the-worm (worm) 1.173 - anim-control (.getControl (worm) AnimControl) 1.174 + (let [the-worm 1.175 +;; (oto) 1.176 + (worm-blender) 1.177 + anim-control (.getControl the-worm AnimControl) 1.178 channel (doto (.createChannel anim-control) 1.179 - (.addAllBones) 1.180 - (.setLoopMode LoopMode/Loop)) 1.181 +;; (.setAnim "Walk") 1.182 + (.setAnim "moveHead") 1.183 + ) 1.184 1.185 play-anim 1.186 - (fn [world pressed] 1.187 - (if (not pressed) 1.188 - (do 1.189 - (println-repl "space is pressed") 1.190 - (.setAnim channel "Walk")))) 1.191 + no-op 1.192 + ;; (fn [world pressed] 1.193 +;; (if (not pressed) 1.194 +;; (do 1.195 +;; (println-repl "space") 1.196 +;; ;; (.setAnim channel "moveHead") 1.197 +;; (.setAnim channel "Walk" (float 0.5)) 1.198 +;; ))) 1.199 1.200 ] 1.201 1.202 @@ -74,15 +227,22 @@ 1.203 (world 1.204 (doto (Node.) 1.205 (.attachChild the-worm)) 1.206 - {"key-space" play-anim} 1.207 - light-up-everything 1.208 + {"key-space" play-anim 1.209 + "mouse-left" (fire-cannon-ball)} 1.210 + (fn [world] 1.211 + (light-up-everything world) 1.212 + ;;(.setTimer world (NanoTimer.)) 1.213 + (org.lwjgl.input.Mouse/setGrabbed false) 1.214 + ) 1.215 no-op 1.216 ) 1.217 1.218 1.219 ))) 1.220 1.221 - 1.222 + 1.223 + 1.224 + 1.225 1.226 1.227