# HG changeset patch # User Robert McIntyre # Date 1325079876 25200 # Node ID fb810a2c50c28c680a17b83101d95e255491b47a # Parent 257a86328adb1ef5e9963f8da6c606d692d1ac05 trying to get the hand to work diff -r 257a86328adb -r fb810a2c50c2 assets/Models/creature1/one.blend Binary file assets/Models/creature1/one.blend has changed diff -r 257a86328adb -r fb810a2c50c2 assets/Models/creature1/try-again.blend Binary file assets/Models/creature1/try-again.blend has changed diff -r 257a86328adb -r fb810a2c50c2 org/body.org --- a/org/body.org Wed Dec 28 00:00:23 2011 -0700 +++ b/org/body.org Wed Dec 28 06:44:36 2011 -0700 @@ -730,8 +730,6 @@ (.setTimer world (NanoTimer.))) (fn [_ _] (dorun (motor-map [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0])))))) - - #+end_src diff -r 257a86328adb -r fb810a2c50c2 org/test-creature.org --- a/org/test-creature.org Wed Dec 28 00:00:23 2011 -0700 +++ b/org/test-creature.org Wed Dec 28 06:44:36 2011 -0700 @@ -61,13 +61,132 @@ (.registerLoader BlenderModelLoader (into-array String ["blend"]))) model)) +(defn meta-data [blender-node key] + (if-let [data (.getUserData blender-node "properties")] + (.findValue data key) + nil)) -(defn apply-skeleton - "Given an imported blender model, apply the armature using the - following pattern: if two bones are connected and have the same - names as two shapes, connect the shapes with a joint constraint." - [armature-name creature] +(defn hand2 [] + (load-blender-model "Models/creature1/try-again.blend")) + +(defn hand [] + (load-blender-model "Models/creature1/one.blend")) + + +(def hand-names + #{ + "middle-1" + "middle-2" + "middle-3" + "palm" + "pinky-1" + "pinky-2" + "pinky-3" + "pointer-1" + "pointer-2" + "pointer-3" + "ring-1" + "ring-2" + "ring-3" + "thumb-1" + "thumb-2"}) + +(defn hand-pieces [] + (filter + (comp hand-names #(apply str (drop-last (.getName %)))) (node-seq (hand)))) + +(defn hand-joints [] + (map #(.getWorldTranslation %) + (filter #(re-matches #"joint\.\d\d\d" (.getName %)) + (node-seq (hand))))) + +(defn worm-pieces [] + (filter + (comp #{"worm-2" "worm-1"} + #(apply str (drop-last (.getName %)))) + (node-seq (hand2)))) + +(defn worm-joints [] + [Vector3f/ZERO]) + + + +(defn find-joint + [#^Node parts #^Vector3f joint-position] + (loop [radius (float 0.01)] + (let [results (CollisionResults.)] + (.collideWith + parts + (BoundingBox. joint-position radius radius radius) + results) + (let [targets + (distinct + (map #(.getGeometry %) results))] + (if (>= (count targets) 2) + (take 2 targets) + (recur (float (* radius 2)))))))) + + + +(defn connect-at-point + [obj-a obj-b point] + (let [center-a (.getWorldTranslation obj-a) + center-b (.getWorldTranslation obj-b) + pivot-a (.subtract point center-a) + pivot-b (.subtract point center-b) + ;; A side-effect of creating a joint registers + ;; it with both physics objects which in turn + ;; will register the joint with the physics system + ;; when the simulation is started. + joint (Point2PointJoint. + (.getControl obj-a RigidBodyControl) + (.getControl obj-b RigidBodyControl) + pivot-a + pivot-b)] + obj-a)) + + +(defn physical-hand [#^Node pieces joints] + ;; Make each piece a physical entity in the simulation. + (dorun + (map + (fn [geom] + (let [physics-control + (RigidBodyControl. + (HullCollisionShape. + (.getMesh geom)) + ;; TODO: fix this. + (float 1.0))] + (.addControl geom physics-control))) + (filter #(isa? (class %) Geometry ) + (node-seq pieces)))) + (dorun + (map + (fn [joint-position] + (let [[geom-a geom-b] (find-joint pieces joint-position)] + (connect-at-point geom-a geom-b joint-position))) + joints)) + pieces) + + +(defn the-hand! [] (physical-hand (hand) (hand-joints))) + + +(defn test-hand [] + (world + (nodify [(the-hand!) + (box 10 0.1 10 :position (Vector3f. 0 -10 0) + :color ColorRGBA/Gray + :mass 0)]) + standard-debug-controls + enable-debug + no-op)) + + + + + #+end_src diff -r 257a86328adb -r fb810a2c50c2 org/util.org --- a/org/util.org Wed Dec 28 00:00:23 2011 -0700 +++ b/org/util.org Wed Dec 28 06:44:36 2011 -0700 @@ -274,6 +274,16 @@ :shape (Sphere. 32 32 (float r)))))) ([] (sphere 0.5))) +(defn green-x-ray + "A usefull material for debuging -- it can be seen no matter what + object occuldes it." + [] + (doto (Material. (asset-manager) + "Common/MatDefs/Misc/Unshaded.j3md") + (.setColor "Color" ColorRGBA/Green) + (-> (.getAdditionalRenderState) + (.setDepthTest false)))) + (defn node-seq "Take a node and return a seq of all its children recursively. There will be no nodes left in the resulting