Mercurial > cortex
view org/body.org @ 53:bb24106cbd6a
many problems solved by tightening up the vertex groups in the blender model
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 15 Nov 2011 00:24:46 -0700 |
parents | 00d0e1639d4b |
children | 7bc3b22c507b |
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 (.add (.getLocalPosition b) Vector3f/UNIT_X)190 Quaternion/IDENTITY191 (Vector3f. 1 1 1))193 )197 (println-repl "hi! <3"))))200 (defn test-ragdoll []202 (let [the-worm204 ;;(.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml")205 (doto (show-skeleton (worm-blender))206 (.setLocalTranslation (Vector3f. 0 10 0))207 ;;(worm)208 ;;(oto)209 ;;(sinbad)210 )211 ]214 (.start215 (world216 (doto (Node.)217 (.attachChild the-worm))218 {"key-return" (fire-cannon-ball)219 "key-space" (partial test-zzz the-worm)220 }221 (fn [world]222 (light-up-everything world)223 (PhysicsTestHelper/createPhysicsTestWorld224 (.getRootNode world)225 (asset-manager)226 (.getPhysicsSpace227 (.getState (.getStateManager world) BulletAppState)))228 (set-gravity world Vector3f/ZERO)229 ;;(.setTimer world (NanoTimer.))230 ;;(org.lwjgl.input.Mouse/setGrabbed false)231 )232 no-op233 )236 )))247 #+end_src256 * COMMENT generate Source.257 #+begin_src clojure :tangle ../src/cortex/body.clj258 <<body-main>>259 #+end_src