threeagent icon indicating copy to clipboard operation
threeagent copied to clipboard

Adding fog to a scene

Open chr15m opened this issue 3 years ago • 1 comments

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?

chr15m avatar Jul 31 '22 16:07 chr15m

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.

timothypratley avatar Dec 01 '22 00:12 timothypratley