Mercurial > cortex
view org/body.org @ 54:7bc3b22c507b
translation behaves as expected, but the debug mesh does seems to be reversed from the actual bone layout
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 15 Nov 2011 00:53:06 -0700 |
parents | bb24106cbd6a |
children | 8b95180f5c69 |
line wrap: on
line source
1 #+title: The BODY!!!2 #+author: Robert McIntyre3 #+email: rlm@mit.edu4 #+description: Simulating a body (movement, touch, propioception) in jMonkeyEngine3.5 #+SETUPFILE: ../../aurellem/org/setup.org6 #+INCLUDE: ../../aurellem/org/level-0.org8 * COMMENT Body10 #+srcname: body-main11 #+begin_src clojure12 (ns cortex.body13 (use (cortex world util import)))15 (use 'clojure.contrib.def)16 (cortex.import/mega-import-jme3)17 (rlm.rlm-commands/help)19 ;;(.loadModel20 ;; (doto (asset-manager)21 ;; (.registerLoader BlenderModelLoader (into-array String ["blend"])))22 ;; "Models/person/person.blend")24 (defn view-model [^String model]25 (view26 (.loadModel27 (doto (asset-manager)28 (.registerLoader BlenderModelLoader (into-array String ["blend"])))29 model)))31 (defn load-blender-scene [^String model]32 (.loadModel33 (doto (asset-manager)34 (.registerLoader BlenderLoader (into-array String ["blend"])))35 model))37 (defn load-blender-model38 [^String model]39 (.loadModel40 (doto (asset-manager)41 (.registerLoader BlenderModelLoader (into-array String ["blend"])))42 model))44 (defn worm45 []46 (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml"))48 (defn oto49 []50 (.loadModel (asset-manager) "Models/Oto/Oto.mesh.xml"))52 (defn sinbad53 []54 (.loadModel (asset-manager) "Models/Sinbad/Sinbad.mesh.xml"))56 (defn worm-blender57 []58 (first (seq (.getChildren (load-blender-model59 "Models/anim2/worm3.blend")))))61 (defn skel [node]62 (doto63 (.getSkeleton64 (.getControl node SkeletonControl))65 ;; this is necessary to force the skeleton to have accurate world66 ;; transforms before it is rendered to the screen.67 (.resetAndUpdate)))69 (defprotocol Textual70 (text [something]71 "Display a detailed textual analysis of the given object."))73 (extend-type com.jme3.scene.Node74 Textual75 (text [node]76 (println "Total Vertexes: " (.getVertexCount node))77 (println "Total Triangles: " (.getTriangleCount node))78 (println "Controls :")79 (dorun (map #(text (.getControl node %)) (range (.getNumControls node))))80 (println "Has " (.getQuantity node) " Children:")81 (doall (map text (.getChildren node)))))83 (extend-type com.jme3.animation.AnimControl84 Textual85 (text [control]86 (let [animations (.getAnimationNames control)]87 (println "Animation Control with " (count animations) " animation(s):")88 (dorun (map println animations)))))90 (extend-type com.jme3.animation.SkeletonControl91 Textual92 (text [control]93 (println "Skeleton Control with the following skeleton:")94 (println (.getSkeleton control))))96 (extend-type com.jme3.bullet.control.KinematicRagdollControl97 Textual98 (text [control]99 (println "Ragdoll Control")))102 (extend-type com.jme3.scene.Geometry103 Textual104 (text [control]105 (println "...geo...")))110 (defn body111 "given a node with a SkeletonControl, will produce a body sutiable112 for AI control with movement and proprioception."113 [node]114 (let [skeleton-control (.getControl node SkeletonControl)115 krc (KinematicRagdollControl.)]116 (comment117 (dorun118 (map #(.addBoneName krc %)119 ["mid2" "tail" "head" "mid1" "mid3" "mid4" "Dummy-Root" ""]120 ;;"mid2" "mid3" "tail" "head"]121 )))125 (.addControl node krc)126 (.setRagdollMode krc)127 )128 node129 )131 (defn green-x-ray []132 (doto (Material. (asset-manager)133 "Common/MatDefs/Misc/Unshaded.j3md")134 (.setColor "Color" ColorRGBA/Green)135 (-> (.getAdditionalRenderState)136 (.setDepthTest false))))138 (defn show-skeleton [node]139 (let [sd141 (doto142 (SkeletonDebugger. "aurellem-skel-debug"143 (skel node))144 (.setMaterial (green-x-ray)))]145 (.attachChild node sd)146 node))150 (defn init-debug-skel-node151 [f debug-node skeleton]152 (let [bones153 (map #(.getBone skeleton %)154 (range (.getBoneCount skeleton)))]155 (dorun (map #(.setUserControl % true) bones))156 (dorun (map (fn [b]157 (println (.getName b)158 " -- " (f b)))159 bones))161 (dorun162 (map #(.attachChild163 debug-node164 (doto165 (sphere 0.1166 :position (f %)167 :physical? false)168 (.setMaterial (green-x-ray))))169 bones)))170 debug-node)172 (import jme3test.bullet.PhysicsTestHelper)175 (defn test-zzz [the-worm world value]176 (if (not value)177 (let [skeleton (skel the-worm)]178 (println-repl "enabling bones")179 (dorun180 (map181 #(.setUserControl (.getBone skeleton %) true)182 (range (.getBoneCount skeleton))))185 (let [b (.getBone skeleton 6)]186 (println-repl "moving " (.getName b))187 (println-repl (.getLocalPosition b))188 (.setUserTransforms b189 Vector3f/UNIT_X190 Quaternion/IDENTITY191 ;;(doto (Quaternion.)192 ;; (.fromAngles (/ Math/PI 2)193 ;; 0194 ;; 0196 (Vector3f. 1 1 1))198 )202 (println-repl "hi! <3"))))205 (defn test-ragdoll []207 (let [the-worm209 ;;(.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")210 (doto (show-skeleton (worm-blender))211 (.setLocalTranslation (Vector3f. 0 10 0))212 ;;(worm)213 ;;(oto)214 ;;(sinbad)215 )216 ]219 (.start220 (world221 (doto (Node.)222 (.attachChild the-worm))223 {"key-return" (fire-cannon-ball)224 "key-space" (partial test-zzz the-worm)225 }226 (fn [world]227 (light-up-everything world)228 (PhysicsTestHelper/createPhysicsTestWorld229 (.getRootNode world)230 (asset-manager)231 (.getPhysicsSpace232 (.getState (.getStateManager world) BulletAppState)))233 (set-gravity world Vector3f/ZERO)234 ;;(.setTimer world (NanoTimer.))235 ;;(org.lwjgl.input.Mouse/setGrabbed false)236 )237 no-op238 )241 )))252 #+end_src261 * COMMENT generate Source.262 #+begin_src clojure :tangle ../src/cortex/body.clj263 <<body-main>>264 #+end_src