Mercurial > cortex
view org/body.org @ 51:2a6ede6d8ad8
problem was that the skeleton was not 'ready'
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 14 Nov 2011 19:44:30 -0700 |
parents | b1b90c4ab0bf |
children | 00d0e1639d4b |
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")))))61 (defprotocol Textual62 (text [something]63 "Display a detailed textual analysis of the given object."))65 (extend-type com.jme3.scene.Node66 Textual67 (text [node]68 (println "Total Vertexes: " (.getVertexCount node))69 (println "Total Triangles: " (.getTriangleCount node))70 (println "Controls :")71 (dorun (map #(text (.getControl node %)) (range (.getNumControls node))))72 (println "Has " (.getQuantity node) " Children:")73 (doall (map text (.getChildren node)))))75 (extend-type com.jme3.animation.AnimControl76 Textual77 (text [control]78 (let [animations (.getAnimationNames control)]79 (println "Animation Control with " (count animations) " animations:")80 (dorun (map println animations)))))82 (extend-type com.jme3.animation.SkeletonControl83 Textual84 (text [control]85 (println "Skeleton Control with the following skeleton:")86 (println (.getSkeleton control))))88 (extend-type com.jme3.scene.Geometry89 Textual90 (text [control]91 (println "...geo...")))96 (defn body97 "given a node with a skeleton, will produce a body sutiable for AI98 control with movement and proprioception."99 [node]100 (let [skeleton-control (.getControl node SkeletonControl)101 krc (KinematicRagdollControl. (float 0.5))]102 (dorun103 (map #(.addBoneName krc %)104 ["mid1" "mid2" "mid3" "tail" "head"]))105 (.addControl node krc)106 (.setRagdollMode krc))107 node108 )110 (defn111 green-x-ray []112 (doto (Material. (asset-manager)113 "Common/MatDefs/Misc/Unshaded.j3md")114 (.setColor "Color" ColorRGBA/Green)115 (-> (.getAdditionalRenderState) (.setDepthTest116 false))))118 (defn view-skeleton [node]119 (let [sd121 (doto122 (SkeletonDebugger. "aurellem-skel-debug"123 (skel node))124 (.setMaterial (green-x-ray)))]125 (view (doto (Node. "view node")126 (.attachChild sd)131 ;;(.attachChild node)132 ))))135 (defn init-debug-skel-node136 [f debug-node skeleton]137 (let [bones138 (map #(.getBone skeleton %)139 (range (.getBoneCount skeleton)))]140 (dorun (map #(.setUserControl % true) bones))141 (dorun (map (fn [b]142 (println (.getName b)143 " -- " (f b)))144 bones))146 (dorun147 (map #(.attachChild148 debug-node149 (doto150 (sphere 0.1151 :position (f %)152 :physical? false)153 (.setMaterial (green-x-ray))))154 bones)))155 debug-node)157 (defn skel [node]158 (doto159 (.getSkeleton160 (.getControl node SkeletonControl))161 ;; this is necessary to force the skeleton to have accurate world162 ;; transforms before it is rendered to the screen.163 (.resetAndUpdate)))169 (view170 (init-debug-skel-node171 (fn [b] (.getWorldBindPosition b))172 (Node. "skel-debug") (skel (worm))))178 (defn test-ragdoll []180 (let [the-worm181 (body182 (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")183 ;;(worm-blender)184 )185 ]188 (.start189 (world190 (doto (Node.)191 (.attachChild the-worm))192 {"mouse-left" (fire-cannon-ball)}193 (fn [world]194 (light-up-everything world)195 ;;(.setTimer world (NanoTimer.))196 ;;(org.lwjgl.input.Mouse/setGrabbed false)197 )198 no-op199 )202 )))221 (defn test-worm-anim []223 (let [the-worm224 ;; (oto)225 (worm-blender)226 anim-control (.getControl the-worm AnimControl)227 channel (doto (.createChannel anim-control)228 ;; (.setAnim "Walk")229 (.setAnim "moveHead")230 )232 play-anim233 no-op234 ;; (fn [world pressed]235 ;; (if (not pressed)236 ;; (do237 ;; (println-repl "space")238 ;; ;; (.setAnim channel "moveHead")239 ;; (.setAnim channel "Walk" (float 0.5))240 ;; )))242 ]244 (.start245 (world246 (doto (Node.)247 (.attachChild the-worm))248 {"key-space" play-anim249 "mouse-left" (fire-cannon-ball)}250 (fn [world]251 (light-up-everything world)252 ;;(.setTimer world (NanoTimer.))253 (org.lwjgl.input.Mouse/setGrabbed false)254 )255 no-op256 )259 )))267 #+end_src276 * COMMENT generate Source.277 #+begin_src clojure :tangle ../src/cortex/body.clj278 <<body-main>>279 #+end_src