Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
Last active October 18, 2022 01:53
Show Gist options
  • Save chase-lambert/9f4055ce8efcb7a1ae406cf1a8b5031d to your computer and use it in GitHub Desktop.
Save chase-lambert/9f4055ce8efcb7a1ae406cf1a8b5031d to your computer and use it in GitHub Desktop.
three.js -> cljs demo
(ns three.core
(:require ["three" :as three]))
(defn make-animation-fn [renderer mesh scene camera]
(fn animation [time]
(set! (.. mesh -rotation -x) (/ time 2000))
(set! (.. mesh -rotation -y) (/ time 2000))
(.render renderer scene camera)))
(defn cube []
(let [camera (three/PerspectiveCamera. 70 (/ (.-innerWidth js/window) (.-innerHeight js/window)) 0.01 10)
scene (three/Scene.)
geometry (three/BoxGeometry. 0.2 0.2 0.2)
material (three/MeshNormalMaterial.)
mesh (three/Mesh. geometry material)
renderer (three/WebGLRenderer. #js {:antialias true})]
(set! (.. camera -position -z) 1)
(.add scene mesh)
(.setSize renderer (.-innerWidth js/window) (.-innerHeight js/window))
(.setAnimationLoop renderer (make-animation-fn renderer mesh scene camera))
(.appendChild (.-body js/document) (.-domElement renderer))))
(defn ^:dev/after-load render-cube []
(cube))
(defn ^:export main []
(render-cube))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment