Mercurial > cortex
comparison org/body.org @ 56:8b571c137f81
bone influence appears to be wrong! Investigating...
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 15 Nov 2011 23:18:37 -0700 |
parents | 8b95180f5c69 |
children | 37a3256e1ed3 |
comparison
equal
deleted
inserted
replaced
55:8b95180f5c69 | 56:8b571c137f81 |
---|---|
54 (.loadModel (asset-manager) "Models/Sinbad/Sinbad.mesh.xml")) | 54 (.loadModel (asset-manager) "Models/Sinbad/Sinbad.mesh.xml")) |
55 | 55 |
56 (defn worm-blender | 56 (defn worm-blender |
57 [] | 57 [] |
58 (first (seq (.getChildren (load-blender-model | 58 (first (seq (.getChildren (load-blender-model |
59 "Models/anim2/worm3.blend"))))) | 59 "Models/anim2/simple-worm.blend"))))) |
60 | 60 |
61 (defn skel [node] | 61 (defn skel [node] |
62 (doto | 62 (doto |
63 (.getSkeleton | 63 (.getSkeleton |
64 (.getControl node SkeletonControl)) | 64 (.getControl node SkeletonControl)) |
176 (map | 176 (map |
177 #(.setUserControl (.getBone skeleton %) true) | 177 #(.setUserControl (.getBone skeleton %) true) |
178 (range (.getBoneCount skeleton)))) | 178 (range (.getBoneCount skeleton)))) |
179 | 179 |
180 | 180 |
181 (let [b (.getBone skeleton 6)] | 181 (let [b (.getBone skeleton 2)] |
182 (println-repl "moving " (.getName b)) | 182 (println-repl "moving " (.getName b)) |
183 (println-repl (.getLocalPosition b)) | 183 (println-repl (.getLocalPosition b)) |
184 (.setUserTransforms b | 184 (.setUserTransforms b |
185 Vector3f/UNIT_X | 185 Vector3f/UNIT_X |
186 Quaternion/IDENTITY | 186 Quaternion/IDENTITY |
231 ) | 231 ) |
232 | 232 |
233 | 233 |
234 ))) | 234 ))) |
235 | 235 |
236 | |
237 | |
238 | |
239 (defn joint-control | 236 (defn joint-control |
240 [joint] | 237 [joint] |
241 (let [physics-space (ref nil) | 238 (let [physics-space (ref nil)] |
242 enabled? (ref true)] | |
243 (reify PhysicsControl | 239 (reify PhysicsControl |
244 (setPhysicsSpace [this space] | 240 (setPhysicsSpace [this space] |
245 (dosync | 241 (dosync |
246 (ref-set physics-space space)) | 242 (ref-set physics-space space)) |
247 (.addJoint space joint)) | 243 (.addJoint space joint)) |
248 (update [this tpf]) | 244 (update [this tpf]) |
249 (setSpatial [this spatial]) | 245 (setSpatial [this spatial]) |
250 (render [this rm vp]) | 246 (render [this rm vp]) |
251 (getPhysicsSpace [this] (deref physics-space)) | 247 (getPhysicsSpace [this] (deref physics-space)) |
252 (isEnabled [this] (deref enabled?)) | 248 (isEnabled [this] true) |
253 (setEnabled [this state] | 249 (setEnabled [this state])))) |
254 (dosync (ref-set enabled? state)))))) | |
255 | 250 |
256 (defn add-joint | 251 (defn add-joint |
257 "Add a joint to a particular object. When the object is added to the | 252 "Add a joint to a particular object. When the object is added to the |
258 PhysicsSpace of a simulation, the joint will also be added" | 253 PhysicsSpace of a simulation, the joint will also be added" |
259 [object joint] | 254 [object joint] |
271 Vector3f/ZERO (Vector3f. 3 3 3))] | 266 Vector3f/ZERO (Vector3f. 3 3 3))] |
272 (add-joint sphere1 joint) | 267 (add-joint sphere1 joint) |
273 (doto (Node. "hinge-world") | 268 (doto (Node. "hinge-world") |
274 (.attachChild sphere1) | 269 (.attachChild sphere1) |
275 (.attachChild sphere2)))) | 270 (.attachChild sphere2)))) |
276 | 271 |
277 | 272 (defn test-joint [] |
278 (defn test-joint | 273 (view (hinge-world))) |
279 [] | |
280 (.start | |
281 (world | |
282 (doto (Node.) | |
283 (.attachChild | |
284 | 274 |
275 | |
276 | |
277 | |
278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
279 ;;; here is the ragdoll stuff | |
280 | |
281 (def worm-mesh (.getMesh (.getChild (worm-blender) 0))) | |
282 (def mesh worm-mesh) | |
283 | |
284 (.getFloatBuffer mesh VertexBuffer$Type/Position) | |
285 (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) | |
286 (.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) | |
287 | |
288 | |
289 (defn position [index] | |
290 (.get | |
291 (.getFloatBuffer worm-mesh VertexBuffer$Type/Position) | |
292 index)) | |
293 | |
294 (defn vec-pos [index] | |
295 (let [offset (* index 3)] | |
296 (Vector3f. (position offset) | |
297 (position (inc offset)) | |
298 (position (inc(inc offset)))))) | |
299 | |
300 (defn bones [index] | |
301 (.get | |
302 (.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) | |
303 index)) | |
304 | |
305 (defn bone-control-color [index] | |
306 (get {[1 0 0 0] ColorRGBA/Red | |
307 [1 2 0 0] ColorRGBA/Magenta | |
308 [2 0 0 0] ColorRGBA/Blue} | |
309 (vec (map (comp int bones) (range (* index 4) (+ (* index 4) 4)))) | |
310 ColorRGBA/White)) | |
311 | |
312 (defn bone-weights [index] | |
313 (.get | |
314 (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) | |
315 index)) | |
316 | |
317 (defn influence-color [index bone-num] | |
318 (get | |
319 {(float 0) ColorRGBA/Blue | |
320 (float 0.5) ColorRGBA/Green | |
321 (float 1) ColorRGBA/Red} | |
322 (bone-weights (+ (* 4 index) bone-num)))) | |
323 | |
324 (defn test-info [] | |
325 (let [points (Node.)] | |
326 (dorun | |
327 (map #(.attachChild points %) | |
328 (map #(sphere 0.01 | |
329 :position (vec-pos %) | |
330 :color (influence-color % 0) | |
331 :physical? false) | |
332 (range 12)))) | |
333 (view points))) | |
334 | |
335 | |
336 | |
337 | |
338 | |
339 | |
340 | |
341 | |
342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
343 | |
344 | |
345 | |
346 | |
347 | |
285 | 348 |
286 | 349 |
287 | 350 |
288 #+end_src | 351 #+end_src |
289 | 352 |