comparison org/body.org @ 53:bb24106cbd6a

many problems solved by tightening up the vertex groups in the blender model
author Robert McIntyre <rlm@mit.edu>
date Tue, 15 Nov 2011 00:24:46 -0700
parents 00d0e1639d4b
children 7bc3b22c507b
comparison
equal deleted inserted replaced
52:00d0e1639d4b 53:bb24106cbd6a
3 #+email: rlm@mit.edu 3 #+email: rlm@mit.edu
4 #+description: Simulating a body (movement, touch, propioception) in jMonkeyEngine3. 4 #+description: Simulating a body (movement, touch, propioception) in jMonkeyEngine3.
5 #+SETUPFILE: ../../aurellem/org/setup.org 5 #+SETUPFILE: ../../aurellem/org/setup.org
6 #+INCLUDE: ../../aurellem/org/level-0.org 6 #+INCLUDE: ../../aurellem/org/level-0.org
7 7
8 * Body 8 * COMMENT Body
9 9
10 #+srcname: body-main 10 #+srcname: body-main
11 #+begin_src clojure 11 #+begin_src clojure
12 (ns cortex.body 12 (ns cortex.body
13 (use (cortex world util import))) 13 (use (cortex world util import)))
110 (defn body 110 (defn body
111 "given a node with a SkeletonControl, will produce a body sutiable 111 "given a node with a SkeletonControl, will produce a body sutiable
112 for AI control with movement and proprioception." 112 for AI control with movement and proprioception."
113 [node] 113 [node]
114 (let [skeleton-control (.getControl node SkeletonControl) 114 (let [skeleton-control (.getControl node SkeletonControl)
115 krc (KinematicRagdollControl. (float 0.5))] 115 krc (KinematicRagdollControl.)]
116 (comment
116 (dorun 117 (dorun
117 (map #(.addBoneName krc %) 118 (map #(.addBoneName krc %)
118 ["mid1" "mid2" "mid3" "tail" "head"] 119 ["mid2" "tail" "head" "mid1" "mid3" "mid4" "Dummy-Root" ""]
119 ;; ["Ulna.L" 120 ;;"mid2" "mid3" "tail" "head"]
120 ;; "Ulna.R" 121 )))
121 ;; "Chest"
122 ;; "Foot.L"
123 ;; "Foot.R"
124 ;; "Hand.R"
125 ;; "Hand.L"
126 ;; "Neck"
127 ;; "Root"
128 ;; "Stomach"
129 ;; "Waist"
130 ;; "Humerus.L"
131 ;; "Humerus.R"
132 ;; "Thigh.L"
133 ;; "Thigh.R"
134 ;; "Calf.L"
135 ;; "Calf.R"
136 ;; "Clavicle.L"
137 ;; "Clavicle.R"]
138 ))
139 122
140 123
141 124
142 (.addControl node krc) 125 (.addControl node krc)
143 (.setRagdollMode krc) 126 (.setRagdollMode krc)
150 "Common/MatDefs/Misc/Unshaded.j3md") 133 "Common/MatDefs/Misc/Unshaded.j3md")
151 (.setColor "Color" ColorRGBA/Green) 134 (.setColor "Color" ColorRGBA/Green)
152 (-> (.getAdditionalRenderState) 135 (-> (.getAdditionalRenderState)
153 (.setDepthTest false)))) 136 (.setDepthTest false))))
154 137
155 (defn view-skeleton [node] 138 (defn show-skeleton [node]
156 (let [sd 139 (let [sd
157 140
158 (doto 141 (doto
159 (SkeletonDebugger. "aurellem-skel-debug" 142 (SkeletonDebugger. "aurellem-skel-debug"
160 (skel node)) 143 (skel node))
161 (.setMaterial (green-x-ray)))] 144 (.setMaterial (green-x-ray)))]
162 (view (doto (Node. "view node") 145 (.attachChild node sd)
163 (.attachChild sd) 146 node))
164 147
165
166
167
168 ;;(.attachChild node)
169 ))))
170 148
171 149
172 (defn init-debug-skel-node 150 (defn init-debug-skel-node
173 [f debug-node skeleton] 151 [f debug-node skeleton]
174 (let [bones 152 (let [bones
191 bones))) 169 bones)))
192 debug-node) 170 debug-node)
193 171
194 (import jme3test.bullet.PhysicsTestHelper) 172 (import jme3test.bullet.PhysicsTestHelper)
195 173
174
175 (defn test-zzz [the-worm world value]
176 (if (not value)
177 (let [skeleton (skel the-worm)]
178 (println-repl "enabling bones")
179 (dorun
180 (map
181 #(.setUserControl (.getBone skeleton %) true)
182 (range (.getBoneCount skeleton))))
183
184
185 (let [b (.getBone skeleton 6)]
186 (println-repl "moving " (.getName b))
187 (println-repl (.getLocalPosition b))
188 (.setUserTransforms b
189 (.add (.getLocalPosition b) Vector3f/UNIT_X)
190 Quaternion/IDENTITY
191 (Vector3f. 1 1 1))
192
193 )
194
195
196
197 (println-repl "hi! <3"))))
198
199
196 (defn test-ragdoll [] 200 (defn test-ragdoll []
197 201
198 (let [the-worm 202 (let [the-worm
199 (body 203
200 ;;(.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml") 204 ;;(.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")
201 ;;(worm-blender) 205 (doto (show-skeleton (worm-blender))
202 (worm) 206 (.setLocalTranslation (Vector3f. 0 10 0))
207 ;;(worm)
203 ;;(oto) 208 ;;(oto)
204 ;;(sinbad) 209 ;;(sinbad)
205 ) 210 )
206 ] 211 ]
207 212
208 213
209 (.start 214 (.start
210 (world 215 (world
211 (doto (Node.) 216 (doto (Node.)
212 (.attachChild the-worm)) 217 (.attachChild the-worm))
213 {"mouse-left" (fire-cannon-ball)} 218 {"key-return" (fire-cannon-ball)
219 "key-space" (partial test-zzz the-worm)
220 }
214 (fn [world] 221 (fn [world]
215 (light-up-everything world) 222 (light-up-everything world)
216 (PhysicsTestHelper/createPhysicsTestWorld 223 (PhysicsTestHelper/createPhysicsTestWorld
217 (.getRootNode world) 224 (.getRootNode world)
218 (asset-manager) 225 (asset-manager)
219 (.getPhysicsSpace 226 (.getPhysicsSpace
220 (.getState (.getStateManager world) BulletAppState))) 227 (.getState (.getStateManager world) BulletAppState)))
228 (set-gravity world Vector3f/ZERO)
221 ;;(.setTimer world (NanoTimer.)) 229 ;;(.setTimer world (NanoTimer.))
222 ;;(org.lwjgl.input.Mouse/setGrabbed false) 230 ;;(org.lwjgl.input.Mouse/setGrabbed false)
223 ) 231 )
224 no-op 232 no-op
225 ) 233 )