comparison 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
comparison
equal deleted inserted replaced
49:96a41b384100 50:b1b90c4ab0bf
39 (.loadModel 39 (.loadModel
40 (doto (asset-manager) 40 (doto (asset-manager)
41 (.registerLoader BlenderModelLoader (into-array String ["blend"]))) 41 (.registerLoader BlenderModelLoader (into-array String ["blend"])))
42 model)) 42 model))
43 43
44
45 (defn worm 44 (defn worm
46 [] 45 []
47 (.loadModel (asset-manager) "Models/anim/worm.mesh.xml")) 46 (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml"))
48 47
49 48 (defn oto
50 (defn worm
51 [] 49 []
52 (.loadModel (asset-manager) "Models/Oto/Oto.mesh.xml")) 50 (.loadModel (asset-manager) "Models/Oto/Oto.mesh.xml"))
53 51
54 52 (defn sinbad
55 53 []
56 (defn test-worm-anim [] 54 (.loadModel (asset-manager) "Models/Sinbad/Sinbad.mesh.xml"))
57 55
58 (let [the-worm (worm) 56 (defn worm-blender
59 anim-control (.getControl (worm) AnimControl) 57 []
60 channel (doto (.createChannel anim-control) 58 (first (seq (.getChildren (load-blender-model
61 (.addAllBones) 59 "Models/anim2/worm3.blend")))))
62 (.setLoopMode LoopMode/Loop)) 60
63 61
64 play-anim 62 (defprotocol Textual
65 (fn [world pressed] 63 (text [something]
66 (if (not pressed) 64 "Display a detailed textual analysis of the given object."))
67 (do 65
68 (println-repl "space is pressed") 66 (extend-type com.jme3.scene.Node
69 (.setAnim channel "Walk")))) 67 Textual
70 68 (text [node]
71 ] 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)))))
75
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)))))
82
83 (extend-type com.jme3.animation.SkeletonControl
84 Textual
85 (text [control]
86 (println "Skeleton Control with the following skeleton:")
87 (println (.getSkeleton control))))
88
89 (extend-type com.jme3.scene.Geometry
90 Textual
91 (text [control]
92 (println "...geo...")))
93
94
95
96
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 )
110
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)))))]
120
121 (.attachChild debug-node sd)))
122
123
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))
134
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)
144
145 (defn skel [node]
146 (.getSkeleton (.getControl node SkeletonControl)))
147
148
149
150
151 (view
152 (init-debug-skel-node
153 (fn [b] (.getWorldBindPosition b))
154 (Node. "skel-debug") (skel (worm))))
155
156
157
158
159
160 (defn test-ragdoll []
161
162 (let [the-worm
163 (body
164 (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")
165 ;;(worm-blender)
166 )
167 ]
168
72 169
73 (.start 170 (.start
74 (world 171 (world
75 (doto (Node.) 172 (doto (Node.)
76 (.attachChild the-worm)) 173 (.attachChild the-worm))
77 {"key-space" play-anim} 174 {"mouse-left" (fire-cannon-ball)}
78 light-up-everything 175 (fn [world]
176 (light-up-everything world)
177 ;;(.setTimer world (NanoTimer.))
178 ;;(org.lwjgl.input.Mouse/setGrabbed false)
179 )
79 no-op 180 no-op
80 ) 181 )
81 182
82 183
83 ))) 184 )))
84 185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203 (defn test-worm-anim []
204
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 )
213
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 ;; )))
223
224 ]
225
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 )
239
240
241 )))
85 242
243
244
245
86 246
87 247
88 248
89 #+end_src 249 #+end_src
90 250