view 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 source
1 #+title: The BODY!!!
2 #+author: Robert McIntyre
3 #+email: rlm@mit.edu
4 #+description: Simulating a body (movement, touch, propioception) in jMonkeyEngine3.
5 #+SETUPFILE: ../../aurellem/org/setup.org
6 #+INCLUDE: ../../aurellem/org/level-0.org
8 * Body
10 #+srcname: body-main
11 #+begin_src clojure
12 (ns cortex.body
13 (use (cortex world util import)))
15 (use 'clojure.contrib.def)
16 (cortex.import/mega-import-jme3)
17 (rlm.rlm-commands/help)
19 ;;(.loadModel
20 ;; (doto (asset-manager)
21 ;; (.registerLoader BlenderModelLoader (into-array String ["blend"])))
22 ;; "Models/person/person.blend")
24 (defn view-model [^String model]
25 (view
26 (.loadModel
27 (doto (asset-manager)
28 (.registerLoader BlenderModelLoader (into-array String ["blend"])))
29 model)))
31 (defn load-blender-scene [^String model]
32 (.loadModel
33 (doto (asset-manager)
34 (.registerLoader BlenderLoader (into-array String ["blend"])))
35 model))
37 (defn load-blender-model
38 [^String model]
39 (.loadModel
40 (doto (asset-manager)
41 (.registerLoader BlenderModelLoader (into-array String ["blend"])))
42 model))
44 (defn worm
45 []
46 (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml"))
48 (defn oto
49 []
50 (.loadModel (asset-manager) "Models/Oto/Oto.mesh.xml"))
52 (defn sinbad
53 []
54 (.loadModel (asset-manager) "Models/Sinbad/Sinbad.mesh.xml"))
56 (defn worm-blender
57 []
58 (first (seq (.getChildren (load-blender-model
59 "Models/anim2/worm3.blend")))))
62 (defprotocol Textual
63 (text [something]
64 "Display a detailed textual analysis of the given object."))
66 (extend-type com.jme3.scene.Node
67 Textual
68 (text [node]
69 (println "Total Vertexes: " (.getVertexCount node))
70 (println "Total Triangles: " (.getTriangleCount node))
71 (println "Controls :")
72 (dorun (map #(text (.getControl node %)) (range (.getNumControls node))))
73 (println "Has " (.getQuantity node) " Children:")
74 (doall (map text (.getChildren node)))))
76 (extend-type com.jme3.animation.AnimControl
77 Textual
78 (text [control]
79 (let [animations (.getAnimationNames control)]
80 (println "Animation Control with " (count animations) " animations:")
81 (dorun (map println animations)))))
83 (extend-type com.jme3.animation.SkeletonControl
84 Textual
85 (text [control]
86 (println "Skeleton Control with the following skeleton:")
87 (println (.getSkeleton control))))
89 (extend-type com.jme3.scene.Geometry
90 Textual
91 (text [control]
92 (println "...geo...")))
97 (defn body
98 "given a node with a skeleton, will produce a body sutiable for AI
99 control with movement and proprioception."
100 [node]
101 (let [skeleton-control (.getControl node SkeletonControl)
102 krc (KinematicRagdollControl. (float 0.5))]
103 (dorun
104 (map #(.addBoneName krc %)
105 ["mid1" "mid2" "mid3" "tail" "head"]))
106 (.addControl node krc)
107 (.setRagdollMode krc))
108 node
109 )
111 (defn view-skeleton [node]
112 (let [sd
113 (doto
114 (SkeletonDebugger. "aurellem-skel-debug" (skel node))
115 (.setMaterial
116 (doto (Material. (asset-manager)
117 "Common/MatDefs/Misc/Unshaded.j3md")
118 (-> (.getAdditionalRenderState) (.setDepthTest
119 false)))))]
121 (.attachChild debug-node sd)))
124 (defn init-debug-skel-node
125 [f debug-node skeleton]
126 (let [bones
127 (map #(.getBone skeleton %)
128 (range (.getBoneCount skeleton)))]
129 (dorun (map #(.setUserControl % true) bones))
130 (dorun (map (fn [b]
131 (println (.getName b)
132 " -- " (f b)))
133 bones))
135 (dorun
136 (map #(.attachChild
137 debug-node
138 (sphere 0.1
139 :position (f %)
140 :rotation (.getWorldBindRotation %)
141 :physical? false))
142 bones)))
143 debug-node)
145 (defn skel [node]
146 (.getSkeleton (.getControl node SkeletonControl)))
151 (view
152 (init-debug-skel-node
153 (fn [b] (.getWorldBindPosition b))
154 (Node. "skel-debug") (skel (worm))))
160 (defn test-ragdoll []
162 (let [the-worm
163 (body
164 (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")
165 ;;(worm-blender)
166 )
167 ]
170 (.start
171 (world
172 (doto (Node.)
173 (.attachChild the-worm))
174 {"mouse-left" (fire-cannon-ball)}
175 (fn [world]
176 (light-up-everything world)
177 ;;(.setTimer world (NanoTimer.))
178 ;;(org.lwjgl.input.Mouse/setGrabbed false)
179 )
180 no-op
181 )
184 )))
203 (defn test-worm-anim []
205 (let [the-worm
206 ;; (oto)
207 (worm-blender)
208 anim-control (.getControl the-worm AnimControl)
209 channel (doto (.createChannel anim-control)
210 ;; (.setAnim "Walk")
211 (.setAnim "moveHead")
212 )
214 play-anim
215 no-op
216 ;; (fn [world pressed]
217 ;; (if (not pressed)
218 ;; (do
219 ;; (println-repl "space")
220 ;; ;; (.setAnim channel "moveHead")
221 ;; (.setAnim channel "Walk" (float 0.5))
222 ;; )))
224 ]
226 (.start
227 (world
228 (doto (Node.)
229 (.attachChild the-worm))
230 {"key-space" play-anim
231 "mouse-left" (fire-cannon-ball)}
232 (fn [world]
233 (light-up-everything world)
234 ;;(.setTimer world (NanoTimer.))
235 (org.lwjgl.input.Mouse/setGrabbed false)
236 )
237 no-op
238 )
241 )))
249 #+end_src
258 * COMMENT generate Source.
259 #+begin_src clojure :tangle ../src/cortex/body.clj
260 <<body-main>>
261 #+end_src