comparison org/body.org @ 57:37a3256e1ed3

problems resolved
author Robert McIntyre <rlm@mit.edu>
date Wed, 16 Nov 2011 02:42:50 -0700
parents 8b571c137f81
children 25142dad240a
comparison
equal deleted inserted replaced
56:8b571c137f81 57:37a3256e1ed3
289 (defn position [index] 289 (defn position [index]
290 (.get 290 (.get
291 (.getFloatBuffer worm-mesh VertexBuffer$Type/Position) 291 (.getFloatBuffer worm-mesh VertexBuffer$Type/Position)
292 index)) 292 index))
293 293
294 (defn vec-pos [index] 294 (defn bones [index]
295 (.get
296 (.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex))
297 index))
298
299 (defn bone-weights [index]
300 (.get
301 (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight)
302 index))
303
304
305
306 (defn vertex-bones [vertex]
307 (vec (map (comp int bones) (range (* vertex 4) (+ (* vertex 4) 4)))))
308
309 (defn vertex-weights [vertex]
310 (vec (map (comp float bone-weights) (range (* vertex 4) (+ (* vertex 4) 4)))))
311
312 (defn vertex-position [index]
295 (let [offset (* index 3)] 313 (let [offset (* index 3)]
296 (Vector3f. (position offset) 314 (Vector3f. (position offset)
297 (position (inc offset)) 315 (position (inc offset))
298 (position (inc(inc offset)))))) 316 (position (inc(inc offset))))))
299 317
300 (defn bones [index] 318 (def vertex-info (juxt vertex-position vertex-bones vertex-weights))
301 (.get
302 (.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex))
303 index))
304 319
305 (defn bone-control-color [index] 320 (defn bone-control-color [index]
306 (get {[1 0 0 0] ColorRGBA/Red 321 (get {[1 0 0 0] ColorRGBA/Red
307 [1 2 0 0] ColorRGBA/Magenta 322 [1 2 0 0] ColorRGBA/Magenta
308 [2 0 0 0] ColorRGBA/Blue} 323 [2 0 0 0] ColorRGBA/Blue}
309 (vec (map (comp int bones) (range (* index 4) (+ (* index 4) 4)))) 324 (vertex-bones index)
310 ColorRGBA/White)) 325 ColorRGBA/White))
311
312 (defn bone-weights [index]
313 (.get
314 (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight)
315 index))
316 326
317 (defn influence-color [index bone-num] 327 (defn influence-color [index bone-num]
318 (get 328 (get
319 {(float 0) ColorRGBA/Blue 329 {(float 0) ColorRGBA/Blue
320 (float 0.5) ColorRGBA/Green 330 (float 0.5) ColorRGBA/Green
321 (float 1) ColorRGBA/Red} 331 (float 1) ColorRGBA/Red}
322 (bone-weights (+ (* 4 index) bone-num)))) 332 ;; find the weight of the desired bone
333 ((zipmap (vertex-bones index)(vertex-weights index))
334 bone-num)
335 ColorRGBA/Blue))
336
337
338
339
340 (def worm-vertices (set (map vertex-info (range 60))))
341
323 342
324 (defn test-info [] 343 (defn test-info []
325 (let [points (Node.)] 344 (let [points (Node.)]
326 (dorun 345 (dorun
327 (map #(.attachChild points %) 346 (map #(.attachChild points %)
328 (map #(sphere 0.01 347 (map #(sphere 0.01
329 :position (vec-pos %) 348 :position (vertex-position %)
330 :color (influence-color % 0) 349 :color (influence-color % 1)
331 :physical? false) 350 :physical? false)
332 (range 12)))) 351 (range 60))))
333 (view points))) 352 (view points)))
334 353
335 354
336 355
337 356