Mercurial > cortex
view org/body.org @ 50:b1b90c4ab0bf
trying to resolve problem with skeleton debugging
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 14 Nov 2011 18:46:34 -0700 |
parents | 96a41b384100 |
children | 2a6ede6d8ad8 |
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 * 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")))))62 (defprotocol Textual63 (text [something]64 "Display a detailed textual analysis of the given object."))66 (extend-type com.jme3.scene.Node67 Textual68 (text [node]69 (println "Total Vertexes: " (.getVertexCount node))70 (println "Total Triangles: " (.getTriangleCount node))71 (println "Controls :")72 (dorun (map #(text (.getControl node %)) (range (.getNumControls node))))73 (println "Has " (.getQuantity node) " Children:")74 (doall (map text (.getChildren node)))))76 (extend-type com.jme3.animation.AnimControl77 Textual78 (text [control]79 (let [animations (.getAnimationNames control)]80 (println "Animation Control with " (count animations) " animations:")81 (dorun (map println animations)))))83 (extend-type com.jme3.animation.SkeletonControl84 Textual85 (text [control]86 (println "Skeleton Control with the following skeleton:")87 (println (.getSkeleton control))))89 (extend-type com.jme3.scene.Geometry90 Textual91 (text [control]92 (println "...geo...")))97 (defn body98 "given a node with a skeleton, will produce a body sutiable for AI99 control with movement and proprioception."100 [node]101 (let [skeleton-control (.getControl node SkeletonControl)102 krc (KinematicRagdollControl. (float 0.5))]103 (dorun104 (map #(.addBoneName krc %)105 ["mid1" "mid2" "mid3" "tail" "head"]))106 (.addControl node krc)107 (.setRagdollMode krc))108 node109 )111 (defn view-skeleton [node]112 (let [sd113 (doto114 (SkeletonDebugger. "aurellem-skel-debug" (skel node))115 (.setMaterial116 (doto (Material. (asset-manager)117 "Common/MatDefs/Misc/Unshaded.j3md")118 (-> (.getAdditionalRenderState) (.setDepthTest119 false)))))]121 (.attachChild debug-node sd)))124 (defn init-debug-skel-node125 [f debug-node skeleton]126 (let [bones127 (map #(.getBone skeleton %)128 (range (.getBoneCount skeleton)))]129 (dorun (map #(.setUserControl % true) bones))130 (dorun (map (fn [b]131 (println (.getName b)132 " -- " (f b)))133 bones))135 (dorun136 (map #(.attachChild137 debug-node138 (sphere 0.1139 :position (f %)140 :rotation (.getWorldBindRotation %)141 :physical? false))142 bones)))143 debug-node)145 (defn skel [node]146 (.getSkeleton (.getControl node SkeletonControl)))151 (view152 (init-debug-skel-node153 (fn [b] (.getWorldBindPosition b))154 (Node. "skel-debug") (skel (worm))))160 (defn test-ragdoll []162 (let [the-worm163 (body164 (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")165 ;;(worm-blender)166 )167 ]170 (.start171 (world172 (doto (Node.)173 (.attachChild the-worm))174 {"mouse-left" (fire-cannon-ball)}175 (fn [world]176 (light-up-everything world)177 ;;(.setTimer world (NanoTimer.))178 ;;(org.lwjgl.input.Mouse/setGrabbed false)179 )180 no-op181 )184 )))203 (defn test-worm-anim []205 (let [the-worm206 ;; (oto)207 (worm-blender)208 anim-control (.getControl the-worm AnimControl)209 channel (doto (.createChannel anim-control)210 ;; (.setAnim "Walk")211 (.setAnim "moveHead")212 )214 play-anim215 no-op216 ;; (fn [world pressed]217 ;; (if (not pressed)218 ;; (do219 ;; (println-repl "space")220 ;; ;; (.setAnim channel "moveHead")221 ;; (.setAnim channel "Walk" (float 0.5))222 ;; )))224 ]226 (.start227 (world228 (doto (Node.)229 (.attachChild the-worm))230 {"key-space" play-anim231 "mouse-left" (fire-cannon-ball)}232 (fn [world]233 (light-up-everything world)234 ;;(.setTimer world (NanoTimer.))235 (org.lwjgl.input.Mouse/setGrabbed false)236 )237 no-op238 )241 )))249 #+end_src258 * COMMENT generate Source.259 #+begin_src clojure :tangle ../src/cortex/body.clj260 <<body-main>>261 #+end_src