diff org/util.org @ 62:2b9d81017cb7

moved utility functions out of body and into util
author Robert McIntyre <rlm@mit.edu>
date Mon, 28 Nov 2011 21:28:46 -0700
parents e5e627f50a3a
children 1381a6ebd08b
line wrap: on
line diff
     1.1 --- a/org/util.org	Mon Nov 28 21:22:35 2011 -0700
     1.2 +++ b/org/util.org	Mon Nov 28 21:28:46 2011 -0700
     1.3 @@ -274,6 +274,24 @@
     1.4         (make-shape (assoc options
     1.5  		     :shape (Sphere. 32 32 (float r)))))) 
     1.6    ([] (sphere 0.5)))
     1.7 +
     1.8 +(defn node-seq
     1.9 +  "Take a node and return a seq of all its children
    1.10 +   recursively. There will be no nodes left in the resulting
    1.11 +   structure"
    1.12 +  [#^Node node]
    1.13 +  (tree-seq #(isa? (class %) Node) #(.getChildren %) node))
    1.14 +
    1.15 +(defn nodify
    1.16 +  "Take a sequence of things that can be attached to a node and return
    1.17 +  a node with all of them attached"
    1.18 +  ([name children]
    1.19 +     (let [node (Node. name)]
    1.20 +       (dorun (map #(.attachChild node %) children))
    1.21 +       node))
    1.22 +  ([children] (nodify "" children)))
    1.23 +
    1.24 +
    1.25  #+end_src
    1.26  
    1.27  
    1.28 @@ -372,6 +390,50 @@
    1.29          (set-gravity world Vector3f/ZERO)
    1.30          (light-up-everything world))
    1.31        no-op))))
    1.32 +
    1.33 +(extend-type com.jme3.math.ColorRGBA
    1.34 +  Viewable
    1.35 +  (view
    1.36 +    [color]
    1.37 +    (view (doto (Node.)
    1.38 +            (.attachChild (box 1 1 1 :color color))))))
    1.39 +
    1.40 +(defprotocol Textual
    1.41 +  (text [something]
    1.42 +    "Display a detailed textual analysis of the given object."))
    1.43 +
    1.44 +(extend-type com.jme3.scene.Node
    1.45 +  Textual
    1.46 +  (text [node]
    1.47 +    (println "Total Vertexes: " (.getVertexCount node))
    1.48 +    (println "Total Triangles: " (.getTriangleCount node))
    1.49 +    (println "Controls :")
    1.50 +    (dorun (map #(text (.getControl node %)) (range (.getNumControls node))))
    1.51 +    (println "Has " (.getQuantity node) " Children:")
    1.52 +    (doall (map text (.getChildren node)))))
    1.53 +
    1.54 +(extend-type com.jme3.animation.AnimControl
    1.55 +  Textual
    1.56 +  (text [control]
    1.57 +    (let [animations (.getAnimationNames control)]
    1.58 +      (println "Animation Control with " (count animations) " animation(s):")
    1.59 +      (dorun (map println animations)))))
    1.60 +
    1.61 +(extend-type com.jme3.animation.SkeletonControl
    1.62 +  Textual
    1.63 +  (text [control]
    1.64 +    (println "Skeleton Control with the following skeleton:")
    1.65 +    (println (.getSkeleton control))))
    1.66 +
    1.67 +(extend-type com.jme3.bullet.control.KinematicRagdollControl
    1.68 +  Textual
    1.69 +  (text [control]
    1.70 +    (println "Ragdoll Control")))
    1.71 +                 
    1.72 +(extend-type com.jme3.scene.Geometry
    1.73 +  Textual
    1.74 +  (text [control]
    1.75 +    (println "...geo...")))
    1.76  #+end_src
    1.77  
    1.78  Here I make the =Viewable= protocol and extend it to JME's types.  Now