DougHamil / threeagent

ClojureScript library for building Three.js apps in a reagent-like fashion
MIT License
134 stars 10 forks source link

Adding fog to a scene #57

Open chr15m opened 2 years ago

chr15m commented 2 years ago

What is the recommended way to add fog to a scene? Can I pass the values to the renderer or is it something I should use interop to add after setting up?

timothypratley commented 1 year ago

This worked for me:

(ns my.ns (:require ["three" :as three]))
(defn canvas [world*]
  (reagent/with-let [render (fn [] [root @world*])]
    [:canvas {:width  400
              :height 300
              :style {:border "solid 1px lightgrey"}
              :ref    (fn [el]
                        (when el
                          (doto (ta/render render el)
                            (-> :threejs-scene (.-background) (set! (three/Color. 0xffffff)))
                            (-> :threejs-scene (.-fog) (set! (three/FogExp2. 0xffffff 0.5))))))}]))

^^ This is inter-oping with the underlying scene directly; it would be nice if scene attributes could be set by data instead like [:scene {:fog ... :background {:color 0xffffff}] but I don't think that's a feature yet.