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