generated from Quatrefoil-GL/quatrefoil-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
282 lines (281 loc) · 13.1 KB
/
compact.cirru
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.4)
:modules $ [] |touch-control/ |pointed-prompt/ |quatrefoil/ |quaternion/
:entries $ {}
:files $ {}
|app.comp.container $ %{} :FileEntry
:defs $ {}
|comp-container $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-container (store)
let
states $ :states store
cursor $ :cursor states
state $ either (:data states)
{} $ :tab :portal
tab $ :tab state
scaled 0.02
scene ({})
group
{}
:scale $ [] scaled scaled scaled
:position $ [] 0 1.2 -0.5
comp-multiply $ >> states :multiply
ambient-light $ {} (:color 0x666666)
; point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 20 40 50
; point-light $ {} (:color 0xffffff) (:intensity 2) (:distance 200)
:position $ [] 0 60 0
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.container $ :require
quatrefoil.alias :refer $ group box sphere point-light ambient-light perspective-camera scene text
quatrefoil.core :refer $ defcomp >>
app.comp.multiply :refer $ comp-multiply
|app.comp.multiply $ %{} :FileEntry
:defs $ {}
|comp-fade-rotate $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-fade-rotate () (; "\"TODO not in use")
group ({}) & $ identity
let
inverted-p $ invert multiplier
p0 $ q+ ([] 8 5 0 0)
v-scale ([] 0 0 6 0) 1
p1 $ &q* multiplier p0
p2 $ &q* p1 inverted-p
points $ [] p0 p1 p2
[]
group ({}) & $ -> points
map-indexed $ fn (idx p)
comp-point p $ = 0 idx
line $ {} (:points points)
:position $ [] 0 0 0
:material $ {} (:kind :line-dashed) (:color 0xaaaaff) (:opacity 1) (:transparent false)
|comp-labels $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-labels (a-position b-position)
group ({})
text $ {} (:text "\"b") (:size 2) (:height 0.1) (:position b-position)
:material $ {} (:kind :mesh-lambert) (:color 0xffcccc) (:opacity 0.9) (:transparent true)
text $ {} (:text "\"a") (:size 2) (:height 0.1) (:position a-position)
:material $ {} (:kind :mesh-lambert) (:color 0xffcccc) (:opacity 0.9) (:transparent true)
text $ {} (:text "\"z") (:size 2) (:height 0.1)
:position $ [] 0 0 20
:material $ {} (:kind :mesh-lambert) (:color 0x664488) (:opacity 0.9) (:transparent true)
text $ {} (:text "\"y") (:size 2) (:height 0.1)
:position $ [] 0 20 0
:material $ {} (:kind :mesh-lambert) (:color 0x664488) (:opacity 0.9) (:transparent true)
text $ {} (:text "\"x") (:size 2) (:height 0.1)
:position $ [] 20 0 0
:material $ {} (:kind :mesh-lambert) (:color 0x664488) (:opacity 0.9) (:transparent true)
|comp-multiply $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-multiply (states)
let
cursor $ :cursor states
state $ or (:data states)
{} (:w-ratio 0.4) (:z-base 0) (:z-inc 0) (:z-inc-size 1) (:rotate-inc 1) (:a-w 0) (:rotate-inc-size 1) (:show-labels? true)
w-ratio $ :w-ratio state
z-base $ :z-base state
z-inc $ :z-inc state
multiplier $ let
x 0
y 0
w w-ratio
rest-space $ - 1 (pow x 2) (pow y 2) (pow w 2)
z_ $ if (>= rest-space 0) (sqrt rest-space) 0
wo-log $ [] x y z_ w
calc-points $ fn (p0 next)
apply-args
[]
, p0 $ js/Math.ceil (:rotate-inc-size state)
fn (acc p n)
if (<= n 0) acc $ recur (conj acc p) (&q* next p) (dec n)
group ({}) element-axis
group ({}) & $ ->
range $ js/Math.ceil (:z-inc-size state)
mapcat $ fn (idx)
let
points $ calc-points
q+
[] 8 5 z-base $ :a-w state
v-scale ([] 0 0 z-inc 0) idx
, multiplier
[]
group ({}) & $ -> points
map-indexed $ fn (idx p)
comp-point p $ = 0 idx
line $ {} (:points points)
:position $ [] 0 0 0
:material $ {} (:kind :line-dashed) (:color 0xaaaaff) (:opacity 1) (:transparent false)
comp-point (v-scale multiplier 10) true
if (:show-labels? state)
comp-labels
[] 8 5 z-base $ :a-w state
v-scale multiplier 10
comp-value
{} (:speed 0.04) (:show-text? true) (:label "\"w-ratio")
:value $ :w-ratio state
:position $ [] 4 2 12
:bound $ [] 0 1
:color 0xffff55
fn (v1 d!)
d! cursor $ assoc state :w-ratio v1
comp-value
{} (:speed 1) (:show-text? true) (:label "\"z-base")
:value $ :z-base state
:position $ [] 12 12 1
:bound $ [] -20 60
:color 0xffff55
fn (v1 d!)
d! cursor $ assoc state :z-base v1
comp-value
{} (:speed 2) (:show-text? true) (:label "\"a-w")
:value $ :a-w state
:position $ [] 12 22 1
:bound $ [] 0 20
:color 0x77ffcc
fn (v1 d!)
d! cursor $ assoc state :a-w v1
comp-value
{} (:speed 1) (:show-text? true) (:label "\"z-inc")
:value $ :z-inc state
:position $ [] 13 14 4
:bound $ [] 0.4 20
:color 0xffff55
fn (v1 d!)
d! cursor $ assoc state :z-inc v1
comp-value
{} (:speed 1) (:show-text? true) (:label "\"z-inc-size")
:value $ :z-inc-size state
:position $ [] 18 15 1
:bound $ [] 1 6
:color 0xff55ff
fn (v1 d!)
d! cursor $ assoc state :z-inc-size v1
comp-value
{} (:speed 2) (:show-text? true) (:label "\"rotate-inc-size")
:value $ :rotate-inc-size state
:position $ [] -4 4 -20
:bound $ [] 1 20
:color 0xff55ff
fn (v1 d!)
d! cursor $ assoc state :rotate-inc-size v1
comp-switch
{} (:label "\"labels?") (:color 0x8855ff)
:value $ :show-labels? state
:position $ [] 30 0 0
fn (v d!)
d! cursor $ assoc state :show-labels? v
point-light $ {} (:color 0xffffff) (:intensity 1.4) (:distance 200)
:position $ [] 20 40 50
|comp-point $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-point (position first?)
group ({})
sphere $ {} (:radius 0.5) (:position position)
:material $ {} (:kind :mesh-standard) (:opacity 0.6) (:transparent true)
:color $ if first? 0xffaa88 0xcc88cc
tube $ {} (:points-fn w-hint-fn)
:factor $ last position
:radius 0.1
:tubularSegments 400
:radialSegments 20
:position position
:material $ {} (:kind :mesh-standard) (:color 0xdd0088) (:opacity 0.6) (:transparent false)
|element-axis $ %{} :CodeEntry (:doc |)
:code $ quote
def element-axis $ group ({})
line $ {}
:points $ [] ([] -20 0 0) zero-point ([] 20 0 0) zero-point ([] 0 20 0) zero-point ([] 0 -20 0)
:material cover-line
line $ {}
:points $ [][] (0 0 20) (0 0 -20)
:material $ assoc cover-line :color 0xffff99
|w-hint-fn $ %{} :CodeEntry (:doc |)
:code $ quote
defn w-hint-fn (ratio factor)
[] 0 (* ratio factor) 0
|zero-point $ %{} :CodeEntry (:doc |)
:code $ quote
def zero-point $ [] 0 0 0
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.multiply $ :require
quatrefoil.alias :refer $ group box sphere text line tube point-light
quatrefoil.core :refer $ defcomp
quaternion.core :refer $ q* &q* v-scale q+ invert
quatrefoil.comp.control :refer $ comp-pin-point comp-switch comp-value
quatrefoil.app.materials :refer $ cover-line
|app.main $ %{} :FileEntry
:defs $ {}
|*store $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *store $ {}
:states $ {}
:cursor $ []
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op op-data)
if (list? op)
recur :states $ [] op op-data
let
store $ updater @*store op op-data
; js/console.log |Dispatch: op op-data store
reset! *store store
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! () (load-console-formatter!) (inject-tree-methods)
set-perspective-camera! $ {} (:fov 40) (:near 0.1) (:far 100)
:position $ [] 0 0 8
:aspect $ / js/window.innerWidth js/window.innerHeight
let
canvas-el $ js/document.querySelector |canvas
init-renderer! canvas-el $ {} (:background 0x110022)
render-app!
add-watch *store :changes $ fn (store prev) (render-app!)
set! js/window.onkeydown handle-key-event
when mobile? (render-control!) (handle-control-events)
init-controls!
println "|App started!"
|mobile? $ %{} :CodeEntry (:doc |)
:code $ quote
def mobile? $ .!mobile (new mobile-detect js/window.navigator.userAgent)
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () $ if (some? build-errors) (hud! "\"error" build-errors)
do (hud! "\"ok~" nil) (clear-cache!)
when mobile? (clear-control-loop!) (handle-control-events)
remove-watch *store :changes
add-watch *store :changes $ fn (store prev) (render-app!)
render-app!
set! js/window.onkeydown handle-key-event
println "|Code updated."
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! () (; println "|Render app:")
render-canvas! (comp-container @*store) dispatch!
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.main $ :require
"\"@quamolit/quatrefoil-utils" :refer $ inject-tree-methods
quatrefoil.core :refer $ render-canvas! *global-tree init-controls! clear-cache! init-renderer! handle-key-event handle-control-events
app.comp.container :refer $ comp-container
app.updater :refer $ [] updater
"\"three" :as THREE
touch-control.core :refer $ render-control! control-states start-control-loop! clear-control-loop!
"\"mobile-detect" :default mobile-detect
"\"bottom-tip" :default hud!
quatrefoil.dsl.object3d-dom :refer $ set-perspective-camera!
"\"./calcit.build-errors" :default build-errors
|app.updater $ %{} :FileEntry
:defs $ {}
|updater $ %{} :CodeEntry (:doc |)
:code $ quote
defn updater (store op op-data)
case-default op store $ :states (update-states store op-data)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.updater $ :require
quatrefoil.cursor :refer $ update-states