# HG changeset patch # User Robert McIntyre # Date 1322540926 25200 # Node ID 2b9d81017cb780435a5a8077242af1952e37862b # Parent 7b44348af538c585e9f7737ddc75f3e55fc8dbea moved utility functions out of body and into util diff -r 7b44348af538 -r 2b9d81017cb7 org/body.org --- a/org/body.org Mon Nov 28 21:22:35 2011 -0700 +++ b/org/body.org Mon Nov 28 21:28:46 2011 -0700 @@ -31,44 +31,6 @@ ;; transforms before it is rendered to the screen. (.resetAndUpdate))) -(defprotocol Textual - (text [something] - "Display a detailed textual analysis of the given object.")) - -(extend-type com.jme3.scene.Node - Textual - (text [node] - (println "Total Vertexes: " (.getVertexCount node)) - (println "Total Triangles: " (.getTriangleCount node)) - (println "Controls :") - (dorun (map #(text (.getControl node %)) (range (.getNumControls node)))) - (println "Has " (.getQuantity node) " Children:") - (doall (map text (.getChildren node))))) - -(extend-type com.jme3.animation.AnimControl - Textual - (text [control] - (let [animations (.getAnimationNames control)] - (println "Animation Control with " (count animations) " animation(s):") - (dorun (map println animations))))) - -(extend-type com.jme3.animation.SkeletonControl - Textual - (text [control] - (println "Skeleton Control with the following skeleton:") - (println (.getSkeleton control)))) - -(extend-type com.jme3.bullet.control.KinematicRagdollControl - Textual - (text [control] - (println "Ragdoll Control"))) - - -(extend-type com.jme3.scene.Geometry - Textual - (text [control] - (println "...geo..."))) - (defn green-x-ray [] (doto (Material. (asset-manager) @@ -93,14 +55,6 @@ :color (ColorRGBA/randomColor)))] (map nth-segment (range num-segments)))) -(defn nodify - "take a sequence of things that can be attached to a node and return - a node with all of them attached" - ([name children] - (let [node (Node. name)] - (dorun (map #(.attachChild node %) children)) - node)) - ([children] (nodify "" children))) (defn connect-at-midpoint [segmentA segmentB] @@ -153,14 +107,6 @@ ;; torque applied to their joints. There's not a single straight line ;; of force in the human body at all! (a straight line of force would ;; correspond to some sort of jet or rocket propulseion) - -(defn node-seq - "Take a node and return a seq of all its children - recursively. There will be no nodes left in the resulting - structure" - [#^Node node] - (tree-seq #(isa? (class %) Node) #(.getChildren %) node)) - (defn torque-controls [control] (let [torques diff -r 7b44348af538 -r 2b9d81017cb7 org/util.org --- a/org/util.org Mon Nov 28 21:22:35 2011 -0700 +++ b/org/util.org Mon Nov 28 21:28:46 2011 -0700 @@ -274,6 +274,24 @@ (make-shape (assoc options :shape (Sphere. 32 32 (float r)))))) ([] (sphere 0.5))) + +(defn node-seq + "Take a node and return a seq of all its children + recursively. There will be no nodes left in the resulting + structure" + [#^Node node] + (tree-seq #(isa? (class %) Node) #(.getChildren %) node)) + +(defn nodify + "Take a sequence of things that can be attached to a node and return + a node with all of them attached" + ([name children] + (let [node (Node. name)] + (dorun (map #(.attachChild node %) children)) + node)) + ([children] (nodify "" children))) + + #+end_src @@ -372,6 +390,50 @@ (set-gravity world Vector3f/ZERO) (light-up-everything world)) no-op)))) + +(extend-type com.jme3.math.ColorRGBA + Viewable + (view + [color] + (view (doto (Node.) + (.attachChild (box 1 1 1 :color color)))))) + +(defprotocol Textual + (text [something] + "Display a detailed textual analysis of the given object.")) + +(extend-type com.jme3.scene.Node + Textual + (text [node] + (println "Total Vertexes: " (.getVertexCount node)) + (println "Total Triangles: " (.getTriangleCount node)) + (println "Controls :") + (dorun (map #(text (.getControl node %)) (range (.getNumControls node)))) + (println "Has " (.getQuantity node) " Children:") + (doall (map text (.getChildren node))))) + +(extend-type com.jme3.animation.AnimControl + Textual + (text [control] + (let [animations (.getAnimationNames control)] + (println "Animation Control with " (count animations) " animation(s):") + (dorun (map println animations))))) + +(extend-type com.jme3.animation.SkeletonControl + Textual + (text [control] + (println "Skeleton Control with the following skeleton:") + (println (.getSkeleton control)))) + +(extend-type com.jme3.bullet.control.KinematicRagdollControl + Textual + (text [control] + (println "Ragdoll Control"))) + +(extend-type com.jme3.scene.Geometry + Textual + (text [control] + (println "...geo..."))) #+end_src Here I make the =Viewable= protocol and extend it to JME's types. Now