Mercurial > cortex
view org/body.org @ 52:00d0e1639d4b
simplified world, got buggy physics ragdoll working
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 14 Nov 2011 21:30:23 -0700 |
parents | 2a6ede6d8ad8 |
children | bb24106cbd6a |
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 (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. (float 0.5))]116 (dorun117 (map #(.addBoneName krc %)118 ["mid1" "mid2" "mid3" "tail" "head"]119 ;; ["Ulna.L"120 ;; "Ulna.R"121 ;; "Chest"122 ;; "Foot.L"123 ;; "Foot.R"124 ;; "Hand.R"125 ;; "Hand.L"126 ;; "Neck"127 ;; "Root"128 ;; "Stomach"129 ;; "Waist"130 ;; "Humerus.L"131 ;; "Humerus.R"132 ;; "Thigh.L"133 ;; "Thigh.R"134 ;; "Calf.L"135 ;; "Calf.R"136 ;; "Clavicle.L"137 ;; "Clavicle.R"]138 ))142 (.addControl node krc)143 (.setRagdollMode krc)144 )145 node146 )148 (defn green-x-ray []149 (doto (Material. (asset-manager)150 "Common/MatDefs/Misc/Unshaded.j3md")151 (.setColor "Color" ColorRGBA/Green)152 (-> (.getAdditionalRenderState)153 (.setDepthTest false))))155 (defn view-skeleton [node]156 (let [sd158 (doto159 (SkeletonDebugger. "aurellem-skel-debug"160 (skel node))161 (.setMaterial (green-x-ray)))]162 (view (doto (Node. "view node")163 (.attachChild sd)168 ;;(.attachChild node)169 ))))172 (defn init-debug-skel-node173 [f debug-node skeleton]174 (let [bones175 (map #(.getBone skeleton %)176 (range (.getBoneCount skeleton)))]177 (dorun (map #(.setUserControl % true) bones))178 (dorun (map (fn [b]179 (println (.getName b)180 " -- " (f b)))181 bones))183 (dorun184 (map #(.attachChild185 debug-node186 (doto187 (sphere 0.1188 :position (f %)189 :physical? false)190 (.setMaterial (green-x-ray))))191 bones)))192 debug-node)194 (import jme3test.bullet.PhysicsTestHelper)196 (defn test-ragdoll []198 (let [the-worm199 (body200 ;;(.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")201 ;;(worm-blender)202 (worm)203 ;;(oto)204 ;;(sinbad)205 )206 ]209 (.start210 (world211 (doto (Node.)212 (.attachChild the-worm))213 {"mouse-left" (fire-cannon-ball)}214 (fn [world]215 (light-up-everything world)216 (PhysicsTestHelper/createPhysicsTestWorld217 (.getRootNode world)218 (asset-manager)219 (.getPhysicsSpace220 (.getState (.getStateManager world) BulletAppState)))221 ;;(.setTimer world (NanoTimer.))222 ;;(org.lwjgl.input.Mouse/setGrabbed false)223 )224 no-op225 )228 )))239 #+end_src248 * COMMENT generate Source.249 #+begin_src clojure :tangle ../src/cortex/body.clj250 <<body-main>>251 #+end_src