Mercurial > cortex
changeset 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 |
files | assets/Models/anim2/simple-worm.blend org/body.org |
diffstat | 2 files changed, 80 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
1.1 Binary file assets/Models/anim2/simple-worm.blend has changed
2.1 --- a/org/body.org Tue Nov 15 17:48:10 2011 -0700 2.2 +++ b/org/body.org Tue Nov 15 23:18:37 2011 -0700 2.3 @@ -56,7 +56,7 @@ 2.4 (defn worm-blender 2.5 [] 2.6 (first (seq (.getChildren (load-blender-model 2.7 - "Models/anim2/worm3.blend"))))) 2.8 + "Models/anim2/simple-worm.blend"))))) 2.9 2.10 (defn skel [node] 2.11 (doto 2.12 @@ -178,7 +178,7 @@ 2.13 (range (.getBoneCount skeleton)))) 2.14 2.15 2.16 - (let [b (.getBone skeleton 6)] 2.17 + (let [b (.getBone skeleton 2)] 2.18 (println-repl "moving " (.getName b)) 2.19 (println-repl (.getLocalPosition b)) 2.20 (.setUserTransforms b 2.21 @@ -233,13 +233,9 @@ 2.22 2.23 ))) 2.24 2.25 - 2.26 - 2.27 - 2.28 (defn joint-control 2.29 [joint] 2.30 - (let [physics-space (ref nil) 2.31 - enabled? (ref true)] 2.32 + (let [physics-space (ref nil)] 2.33 (reify PhysicsControl 2.34 (setPhysicsSpace [this space] 2.35 (dosync 2.36 @@ -249,9 +245,8 @@ 2.37 (setSpatial [this spatial]) 2.38 (render [this rm vp]) 2.39 (getPhysicsSpace [this] (deref physics-space)) 2.40 - (isEnabled [this] (deref enabled?)) 2.41 - (setEnabled [this state] 2.42 - (dosync (ref-set enabled? state)))))) 2.43 + (isEnabled [this] true) 2.44 + (setEnabled [this state])))) 2.45 2.46 (defn add-joint 2.47 "Add a joint to a particular object. When the object is added to the 2.48 @@ -273,18 +268,86 @@ 2.49 (doto (Node. "hinge-world") 2.50 (.attachChild sphere1) 2.51 (.attachChild sphere2)))) 2.52 - 2.53 2.54 -(defn test-joint 2.55 - [] 2.56 - (.start 2.57 - (world 2.58 - (doto (Node.) 2.59 - (.attachChild 2.60 +(defn test-joint [] 2.61 + (view (hinge-world))) 2.62 2.63 2.64 2.65 2.66 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2.67 +;;; here is the ragdoll stuff 2.68 + 2.69 +(def worm-mesh (.getMesh (.getChild (worm-blender) 0))) 2.70 +(def mesh worm-mesh) 2.71 + 2.72 +(.getFloatBuffer mesh VertexBuffer$Type/Position) 2.73 +(.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) 2.74 +(.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) 2.75 + 2.76 + 2.77 +(defn position [index] 2.78 + (.get 2.79 + (.getFloatBuffer worm-mesh VertexBuffer$Type/Position) 2.80 + index)) 2.81 + 2.82 +(defn vec-pos [index] 2.83 + (let [offset (* index 3)] 2.84 + (Vector3f. (position offset) 2.85 + (position (inc offset)) 2.86 + (position (inc(inc offset)))))) 2.87 + 2.88 +(defn bones [index] 2.89 + (.get 2.90 + (.getData (.getBuffer mesh VertexBuffer$Type/BoneIndex)) 2.91 + index)) 2.92 + 2.93 +(defn bone-control-color [index] 2.94 + (get {[1 0 0 0] ColorRGBA/Red 2.95 + [1 2 0 0] ColorRGBA/Magenta 2.96 + [2 0 0 0] ColorRGBA/Blue} 2.97 + (vec (map (comp int bones) (range (* index 4) (+ (* index 4) 4)))) 2.98 + ColorRGBA/White)) 2.99 + 2.100 +(defn bone-weights [index] 2.101 + (.get 2.102 + (.getFloatBuffer mesh VertexBuffer$Type/BoneWeight) 2.103 + index)) 2.104 + 2.105 +(defn influence-color [index bone-num] 2.106 + (get 2.107 + {(float 0) ColorRGBA/Blue 2.108 + (float 0.5) ColorRGBA/Green 2.109 + (float 1) ColorRGBA/Red} 2.110 + (bone-weights (+ (* 4 index) bone-num)))) 2.111 + 2.112 +(defn test-info [] 2.113 + (let [points (Node.)] 2.114 + (dorun 2.115 + (map #(.attachChild points %) 2.116 + (map #(sphere 0.01 2.117 + :position (vec-pos %) 2.118 + :color (influence-color % 0) 2.119 + :physical? false) 2.120 + (range 12)))) 2.121 + (view points))) 2.122 + 2.123 + 2.124 + 2.125 + 2.126 + 2.127 + 2.128 + 2.129 + 2.130 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2.131 + 2.132 + 2.133 + 2.134 + 2.135 + 2.136 + 2.137 + 2.138 + 2.139 #+end_src 2.140 2.141