-
-
Save rm-hull/7060012 to your computer and use it in GitHub Desktop.
Simple demonstration of using THREE.js with ClojureScript [from a fork of https://gist.github.com/spacemanaki/1157978], now working with thanks to @seabre
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns three.demo | |
(:require [THREE :as THREE])) | |
(def camera | |
(THREE/PerspectiveCamera. | |
75 | |
(/ 800 600) | |
1 | |
10000)) | |
(set! (.-z (.-position camera)) 1000) | |
(def scene (THREE/Scene.)) | |
(def geometry (THREE/CubeGeometry. 400 400 400)) | |
(def obj (js/Object.)) | |
(set! (.-color obj) 0xff0000) | |
(set! (.-wireframe obj) true) | |
(def material (THREE/MeshBasicMaterial. obj)) | |
(def mesh (THREE/Mesh. geometry material)) | |
(def renderer (THREE/CanvasRenderer.)) | |
(.add scene mesh) | |
(.setSize renderer 800 600) | |
(.appendChild | |
(.getElementById | |
js/document | |
"main-arena") | |
(.-domElement renderer)) | |
(set! (.-dynamic (.-geometry mesh)) true) | |
(defn render [] | |
(set! (.-x (.-rotation mesh)) (+ (.-x (.-rotation mesh)) 0.01)) | |
(set! (.-y (.-rotation mesh)) (+ (.-y (.-rotation mesh)) 0.02)) | |
(set! (.-verticesNeedUpdating (.-geometry mesh)) true) | |
(set! (.-normalsNeedUpdating (.-geometry mesh)) true) | |
(.render renderer scene camera)) | |
(defn animate [] | |
(.requestAnimationFrame js/window animate) | |
(render)) | |
(animate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few things.
On
THREE.Camera.
should beTHREE.PerspectiveCamera.
And anywhere you see
window/innerWidth
andwindow/innerHeight
should be(.-innerWidth js/window)
and(.-innerHeight js/window)
.Also, if you're not actually compiling in Three.js with cljsbuild, you should add
(def THREE js/THREE)
after your namespace declaration, but make sure you're actually loading Three.js before your compiled ClojureScript on your webpage.My working fork is here: https://gist.github.com/seabre/9030268