changeset 47:ee55966ce7f6

enhanced cortex.utils to do proper lighting when viewing objects
author Robert McIntyre <rlm@mit.edu>
date Fri, 11 Nov 2011 00:52:47 -0700
parents 286a00500ee5
children acd040680005
files .hgignore assets/Models/uv/uv3.blend assets/Models/uv/uv3.blend1 assets/Models/uv/uv3.blend2 org/body.org org/util.org
diffstat 6 files changed, 41 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/.hgignore	Thu Nov 10 23:24:02 2011 -0700
     1.2 +++ b/.hgignore	Fri Nov 11 00:52:47 2011 -0700
     1.3 @@ -3,4 +3,8 @@
     1.4  src*
     1.5  html*
     1.6  tmp*
     1.7 -capture-video.html
     1.8 \ No newline at end of file
     1.9 +capture-video.html
    1.10 +
    1.11 +
    1.12 +syntax: regexp
    1.13 +^.*blend\d$
    1.14 \ No newline at end of file
     2.1 Binary file assets/Models/uv/uv3.blend has changed
     3.1 Binary file assets/Models/uv/uv3.blend1 has changed
     4.1 Binary file assets/Models/uv/uv3.blend2 has changed
     5.1 --- a/org/body.org	Thu Nov 10 23:24:02 2011 -0700
     5.2 +++ b/org/body.org	Fri Nov 11 00:52:47 2011 -0700
     5.3 @@ -27,7 +27,6 @@
     5.4      (doto (asset-manager)
     5.5        (.registerLoader BlenderModelLoader (into-array String ["blend"])))
     5.6      model)))
     5.7 -
     5.8  #+end_src
     5.9  
    5.10  
     6.1 --- a/org/util.org	Thu Nov 10 23:24:02 2011 -0700
     6.2 +++ b/org/util.org	Fri Nov 11 00:52:47 2011 -0700
     6.3 @@ -92,6 +92,7 @@
     6.4    (:import com.jme3.scene.shape.Box)
     6.5    (:import com.jme3.scene.Node)
     6.6    (:import com.jme3.scene.shape.Sphere)
     6.7 +  (:import com.jme3.light.AmbientLight)
     6.8    (:import com.jme3.light.DirectionalLight)
     6.9    (:import com.jme3.math.ColorRGBA)
    6.10    (:import com.jme3.bullet.BulletAppState)
    6.11 @@ -185,6 +186,9 @@
    6.12  
    6.13  #+end_src
    6.14  
    6.15 +#+results: util
    6.16 +: #'cortex.util/apply-map
    6.17 +
    6.18  
    6.19  *** Creating Basic Shapes
    6.20  
    6.21 @@ -284,6 +288,37 @@
    6.22    (view [geo]
    6.23  	(view (doto (Node.)(.attachChild geo)))))
    6.24  
    6.25 +(defn basic-light-setup
    6.26 +  "returns a sequence of lights appropiate for fully lighting a scene"
    6.27 +  []
    6.28 +  (conj
    6.29 +   (doall
    6.30 +    (map
    6.31 +     (fn [direction]
    6.32 +       (doto (DirectionalLight.)
    6.33 +         (.setDirection direction)
    6.34 +         (.setColor ColorRGBA/White)))
    6.35 +     [;; six faces of a cube
    6.36 +      Vector3f/UNIT_X
    6.37 +      Vector3f/UNIT_Y
    6.38 +      Vector3f/UNIT_Z
    6.39 +      (.mult Vector3f/UNIT_X (float -1))
    6.40 +      (.mult Vector3f/UNIT_Y (float -1))
    6.41 +      (.mult Vector3f/UNIT_Z (float -1))]))
    6.42 +   (doto (AmbientLight.)
    6.43 +     (.setColor ColorRGBA/White))))
    6.44 +
    6.45 +(defn light-up-everything
    6.46 +  "Add lights to a world appropiate for quickly seeing everything
    6.47 +  in the scene.  Adds six DirectionalLights facing in orthogonal
    6.48 +  directions, and one AmbientLight to provide overall lighting
    6.49 +  coverage."
    6.50 +  [world]
    6.51 +  (dorun
    6.52 +   (map
    6.53 +    #(.addLight (.getRootNode world) %)
    6.54 +    (basic-light-setup))))
    6.55 +    
    6.56  (extend-type com.jme3.scene.Node
    6.57    Viewable
    6.58    (view 
    6.59 @@ -295,13 +330,7 @@
    6.60        (fn [world]
    6.61          (enable-debug world)
    6.62          (set-gravity world Vector3f/ZERO)
    6.63 -        (let [sun 
    6.64 -              (doto (DirectionalLight.)
    6.65 -                (.setDirection
    6.66 -                 (.normalizeLocal (Vector3f. 1 0 -2)))
    6.67 -                (.setColor ColorRGBA/White))]
    6.68 -          ;; lights are required to view some objects.
    6.69 -          (.addLight (.getRootNode world) sun)))
    6.70 +        (light-up-everything world))
    6.71        no-op))))
    6.72  #+end_src
    6.73