-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.clj
146 lines (119 loc) · 3.93 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
(ns teacups.core
(:use arcadia.core
arcadia.linear
arcadia.hydrate)
(:require [arcadia.updater :as updr])
(:import [UnityEngine Transform GameObject Component PhysicMaterial Rigidbody MeshCollider BoxCollider MeshRenderer Color]))
;; (import '[UnityEngine
;; Color
;; PhysicMaterial
;; Transform
;; Rigidbody
;; Time]
;; '[UnityEditor
;; Selection])
;; hi there
(defmacro set-with! [obj [sym & props] & body]
`(let [obj# ~obj
~sym (.. obj# ~@props)]
(set! (.. obj# ~@props) (do ~@body))))
(def ^:dynamic *you*
;;(object-named "NormalController")
(object-named "OVRPlayerController")
)
(defn- kill! [x]
(let [s (dehydrate x)]
(destroy x)
s))
(def cylinder-spec
(let [s (kill! (create-primitive :cylinder))]
(-> s
(dissoc :capsule-collider)
(assoc :mesh-collider [{:shared-mesh (:shared-mesh (first (:mesh-filter s)))}]))))
(defn transform ^Transform [x]
(get-component x Transform))
(defn game-object ^GameObject [x]
(condcast-> x x
GameObject x
Component (.gameObject x)))
(defn shader-material ^Material [^String name]
(Material. (Shader/Find name)))
(def white
(shader-material "Standard"))
(def black
(doto (shader-material "Standard")
(set-with! [_ color]
(Color. 0 0 0))))
(defn tea-cupit [subcirc-n, diameter]
(for [i (range subcirc-n)
:let [height 1
lp (point-pivot
(v3 0.5 (+ height 1) 0)
(v3 0)
(aa (* i (/ 360 subcirc-n))
0 1 0))]]
(->
(deep-merge-mv cylinder-spec
{:name (str "subcirc" i)
:transform [{:local-position lp
:local-scale [diameter height diameter]}]})
(assoc :mesh-renderer [{:shared-material (if (odd? i)
white
black)}]))))
(defscn teacups
(let [base-diameter 10
base-scale (v3 base-diameter 0.1 base-diameter)
base-position (v3
0
(+ 0.5 (/ (.y base-scale) 2))
20)
subcirc-n 3
subcircs (last
(take 1
(iterate
(fn [kids]
(for [subc (tea-cupit subcirc-n 0.59)]
(-> subc
(assoc :children kids)
(dissoc :mesh-collider)
(update-in [:transform 0 :local-position]
#(v3+ % (v3 0 0 0))))))
(for [subc (tea-cupit subcirc-n 0.59)]
(assoc subc :children
(vec (let [n 3]
(tea-cupit n (/ n (+ 1 (* 2 n)))))))))))]
(hydrate
(deep-merge-mv (dissoc cylinder-spec :mesh-collider)
{:name "teacups"
:transform [{:local-scale base-scale
:local-position base-position}]
:children (vec subcircs)}))))
(defn position-you! [v]
(set!
(.position (transform *you*))
v))
(defn teacup-driver []
(doto (transform teacups)
(set-with! [r localRotation]
(qq* r (aa 0.2 0 1 0))))
(let [circs-1 (map game-object (transform teacups))]
(doseq [circ circs-1]
(let [t (transform circ)]
(doto t
(set-with! [r localRotation]
(qq* r (aa -1.5 0 1 0)))))
(doseq [trns (transform circ)]
(set-with! trns [r localRotation]
(qq* r (aa 1 0 1 0))))))
(let [your-teacup (game-object (first (first (transform teacups))))]
(position-you!
(v3+
(.position (transform your-teacup))
(v3 0 2 0)))
;; (set-with! (transform *you*) [r localRotation]
;; (qq* ))
)
)
(when-not *compile-files*
(updr/put! :teacup-driver #'teacup-driver))
(updr/toggle! :teacup-driver)