rlm@281
|
1 #+title:
|
rlm@73
|
2 #+author: Robert McIntyre
|
rlm@73
|
3 #+email: rlm@mit.edu
|
rlm@73
|
4 #+description:
|
rlm@73
|
5 #+keywords: simulation, jMonkeyEngine3, clojure
|
rlm@73
|
6 #+SETUPFILE: ../../aurellem/org/setup.org
|
rlm@73
|
7 #+INCLUDE: ../../aurellem/org/level-0.org
|
rlm@73
|
8
|
rlm@281
|
9 * Intro
|
rlm@129
|
10
|
rlm@281
|
11 This is the ultimate test which features all of the senses that I've
|
rlm@281
|
12 made so far. The blender file for the creature serves as an example of
|
rlm@281
|
13 a fully equipped creature in terms of senses. You can find it [[../assets/Models/test-creature/hand.blend][here]].
|
rlm@73
|
14
|
rlm@192
|
15 #+name: integration
|
rlm@73
|
16 #+begin_src clojure
|
rlm@192
|
17 (ns cortex.integration
|
rlm@73
|
18 "let's play!"
|
rlm@192
|
19 {:author "Robert McIntyre"}
|
rlm@281
|
20 (:use (cortex world util body sense
|
rlm@281
|
21 hearing touch vision proprioception movement))
|
rlm@192
|
22 (:import (com.jme3.math ColorRGBA Vector3f))
|
rlm@281
|
23 (:import java.io.File)
|
rlm@192
|
24 (:import com.jme3.audio.AudioNode)
|
rlm@192
|
25 (:import com.aurellem.capture.RatchetTimer))
|
rlm@73
|
26
|
rlm@281
|
27 (dorun (cortex.import/mega-import-jme3))
|
rlm@281
|
28 (rlm.rlm-commands/help)
|
rlm@74
|
29
|
rlm@281
|
30 (def hand "Models/test-creature/hand.blend")
|
rlm@78
|
31
|
rlm@281
|
32 (def output-base (File. "/home/r/proj/cortex/render/hand"))
|
rlm@189
|
33
|
rlm@297
|
34
|
rlm@297
|
35 ;; Let the hand fall palm-up
|
rlm@297
|
36
|
rlm@297
|
37 ;; it curls its phalanges, starting with the pinky.
|
rlm@297
|
38
|
rlm@297
|
39 ;; it lets these fall back down?
|
rlm@297
|
40
|
rlm@297
|
41 ;; block falls down onto the hand, accompanied by a sound. The block
|
rlm@297
|
42 ;; can be seen by the hand's eye.
|
rlm@297
|
43
|
rlm@297
|
44 ;; hand FORCEFULLY catapults the block so that it hits the camera.
|
rlm@297
|
45
|
rlm@297
|
46
|
rlm@296
|
47 (defn motor-control-program
|
rlm@296
|
48 "Create a function which will execute the motor script"
|
rlm@296
|
49 [muscle-positions
|
rlm@296
|
50 script]
|
rlm@296
|
51 (let [current-frame (atom -1)
|
rlm@296
|
52 keyed-script (group-by first script)
|
rlm@296
|
53 current-forces (atom {}) ]
|
rlm@296
|
54 (fn [effectors]
|
rlm@296
|
55 (let [indexed-effectors (vec effectors)]
|
rlm@296
|
56 (dorun
|
rlm@296
|
57 (for [[_ part force] (keyed-script (swap! current-frame inc))]
|
rlm@296
|
58 (swap! current-forces (fn [m] (assoc m part force)))))
|
rlm@296
|
59 (doall (map (fn [effector power]
|
rlm@296
|
60 (effector (int power)))
|
rlm@296
|
61 effectors
|
rlm@296
|
62 (map #(@current-forces % 0) muscle-positions)))))))
|
rlm@296
|
63
|
rlm@296
|
64 (def muscle-positions
|
rlm@296
|
65 [:pointer-2-e
|
rlm@296
|
66 :pointer-2-f
|
rlm@296
|
67 :thumb-1
|
rlm@296
|
68 :thumb-1
|
rlm@296
|
69 :pointer-1-e
|
rlm@296
|
70 :pointer-1-f
|
rlm@296
|
71 :thumb-2-e
|
rlm@296
|
72 :thumb-2-f
|
rlm@296
|
73 :middle-1-e
|
rlm@296
|
74 :middle-1-f
|
rlm@296
|
75 :pointer-3-f
|
rlm@296
|
76 :pointer-3-e
|
rlm@296
|
77 :middle-2-e
|
rlm@296
|
78 :middle-2-f
|
rlm@296
|
79 :middle-3-f
|
rlm@296
|
80 :middle-3-e
|
rlm@296
|
81 :pinky-2-e
|
rlm@296
|
82 :pinky-2-f
|
rlm@296
|
83 :pinky-3-f
|
rlm@296
|
84 :pinky-3-e
|
rlm@296
|
85 :ring-3-e
|
rlm@296
|
86 :ring-3-f
|
rlm@296
|
87 :ring-2-f
|
rlm@296
|
88 :ring-2-e
|
rlm@296
|
89 :ring-1-e
|
rlm@296
|
90 :ring-1-f
|
rlm@296
|
91 :thumb-1-e
|
rlm@296
|
92 :thumb-1-f
|
rlm@296
|
93 :pinky-1-f
|
rlm@296
|
94 :pinky-1-e])
|
rlm@296
|
95
|
rlm@296
|
96 (def full 9001)
|
rlm@296
|
97 ;; the systax here is [keyframe body-part force]
|
rlm@296
|
98 (def wiggle-each-finger-tip
|
rlm@298
|
99 [[300 :pinky-3-f 50]
|
rlm@298
|
100 [320 :pinky-2-f 80]
|
rlm@298
|
101 [340 :pinky-1-f 100]
|
rlm@297
|
102
|
rlm@298
|
103 [310 :ring-3-f 100]
|
rlm@298
|
104 [330 :ring-2-f 120]
|
rlm@298
|
105 [350 :ring-1-f 140]
|
rlm@296
|
106
|
rlm@298
|
107 [330 :middle-3-f 120]
|
rlm@298
|
108 [340 :middle-2-f 120]
|
rlm@298
|
109 [360 :middle-1-f 30]
|
rlm@296
|
110
|
rlm@298
|
111 [350 :pointer-3-f 120]
|
rlm@298
|
112 [360 :pointer-2-f 120]
|
rlm@298
|
113 [380 :pointer-1-f 30]
|
rlm@296
|
114
|
rlm@298
|
115 [800 :pinky-3-f 0]
|
rlm@298
|
116 [800 :pinky-2-f 0]
|
rlm@298
|
117 [800 :pinky-1-f 0]
|
rlm@296
|
118
|
rlm@298
|
119 [800 :ring-3-f 0]
|
rlm@298
|
120 [800 :ring-2-f 0]
|
rlm@298
|
121 [800 :ring-1-f 0]
|
rlm@296
|
122
|
rlm@298
|
123 [800 :middle-3-f 0]
|
rlm@298
|
124 [800 :middle-2-f 0]
|
rlm@298
|
125 [800 :middle-1-f 0]
|
rlm@296
|
126
|
rlm@298
|
127 [800 :pointer-3-f 0]
|
rlm@298
|
128 [800 :pointer-2-f 0]
|
rlm@298
|
129 [800 :pointer-1-f 0]
|
rlm@297
|
130
|
rlm@297
|
131
|
rlm@298
|
132 [800 :pinky-3-e 50]
|
rlm@298
|
133 [800 :pinky-2-e 80]
|
rlm@298
|
134 [800 :pinky-1-e 100]
|
rlm@297
|
135
|
rlm@298
|
136 [800 :ring-3-e 100]
|
rlm@298
|
137 [800 :ring-2-e 120]
|
rlm@298
|
138 [800 :ring-1-e 140]
|
rlm@298
|
139
|
rlm@298
|
140 [800 :middle-3-e 120]
|
rlm@298
|
141 [800 :middle-2-e 120]
|
rlm@298
|
142 [800 :middle-1-e 30]
|
rlm@298
|
143
|
rlm@298
|
144 [800 :pointer-3-e 120]
|
rlm@298
|
145 [800 :pointer-2-e 120]
|
rlm@298
|
146 [800 :pointer-1-e 30]
|
rlm@298
|
147
|
rlm@298
|
148 [870 :pinky-3-e 0]
|
rlm@298
|
149 [870 :pinky-2-e 0]
|
rlm@298
|
150 [870 :pinky-1-e 0]
|
rlm@298
|
151
|
rlm@298
|
152 [870 :ring-3-e 0]
|
rlm@298
|
153 [870 :ring-2-e 0]
|
rlm@298
|
154 [870 :ring-1-e 0]
|
rlm@298
|
155
|
rlm@298
|
156 [870 :middle-3-e 0]
|
rlm@298
|
157 [870 :middle-2-e 0]
|
rlm@298
|
158 [870 :middle-1-e 0]
|
rlm@298
|
159
|
rlm@298
|
160 [870 :pointer-3-e 0]
|
rlm@298
|
161 [870 :pointer-2-e 0]
|
rlm@298
|
162 [870 :pointer-1-e 0]
|
rlm@298
|
163
|
rlm@298
|
164 [1500 :pointer-1-f full]
|
rlm@298
|
165 [1500 :pointer-2-f full]
|
rlm@298
|
166 [1500 :pointer-3-f full]
|
rlm@298
|
167
|
rlm@298
|
168 [1500 :middle-1-f full]
|
rlm@298
|
169 [1500 :middle-2-f full]
|
rlm@298
|
170 [1500 :middle-3-f full]
|
rlm@298
|
171
|
rlm@298
|
172 [1510 :pointer-1-f 0]
|
rlm@298
|
173 [1510 :pointer-2-f 0]
|
rlm@298
|
174 [1510 :pointer-3-f 0]
|
rlm@298
|
175
|
rlm@298
|
176 [1510 :middle-1-f 0]
|
rlm@298
|
177 [1510 :middle-2-f 0]
|
rlm@298
|
178 [1510 :middle-3-f 0]
|
rlm@297
|
179 ])
|
rlm@297
|
180
|
rlm@298
|
181 (defn gen-summon-ball [debug?]
|
rlm@298
|
182 (let [wait (atom 1100)]
|
rlm@297
|
183 (fn [world]
|
rlm@297
|
184 (if (= 0 (swap! wait dec))
|
rlm@297
|
185 (let [brick
|
rlm@297
|
186 (box 0.8 0.8 0.8 :mass 0.05
|
rlm@298
|
187 :position (Vector3f. -0.5 0 0.5)
|
rlm@298
|
188 :color (ColorRGBA/Red))
|
rlm@298
|
189 bell (AudioNode. (asset-manager)
|
rlm@298
|
190 "Sounds/pure.wav" false)]
|
rlm@298
|
191 (.play bell)
|
rlm@298
|
192 (if debug?
|
rlm@298
|
193 (.addControl
|
rlm@298
|
194 brick
|
rlm@298
|
195 (proxy [AbstractControl] []
|
rlm@298
|
196 (controlUpdate [tpf]
|
rlm@298
|
197 (println-repl (.getWorldTranslation brick)))
|
rlm@298
|
198 (controlRender [_ _]))))
|
rlm@297
|
199 (add-element world brick))))))
|
rlm@297
|
200
|
rlm@296
|
201
|
rlm@295
|
202 (def control-list
|
rlm@295
|
203 [
|
rlm@295
|
204 0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@296
|
205 0 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
206 0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)>
|
rlm@295
|
207 0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)>
|
rlm@295
|
208 0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
209 0 ;;pointer-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
210 0 ;;thumb-2.0011 #<Vector3f (-0.71705645, -0.44753736, -0.5343599)>
|
rlm@295
|
211 0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)>
|
rlm@295
|
212 0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
213 0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@298
|
214 0 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
215 0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
216 0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
217 0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
218 0 ;;middle-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
219 0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
220 0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
221 0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@296
|
222 0 ;;pinky-31 #<Vector3f (-1, 0.0, 0.0)>
|
rlm@296
|
223 0 ;;pinky-31 #<Vector3f (1.0, 0.0, 0.0)>
|
rlm@295
|
224 0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
225 0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
226 0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
227 0 ;;ring-21 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
228 0 ;;ring-11 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
229 0 ;;ring-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
230 0 ;;thumb-11 #<Vector3f (-0.43154645, 0.7302033, 0.5296894)>
|
rlm@295
|
231 0 ;;thumb-11 #<Vector3f (-0.8032993, -0.2722854, -0.5296895)>
|
rlm@295
|
232 0 ;;pinky-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
233 0 ;;pinky-11 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
234 ])
|
rlm@295
|
235
|
rlm@298
|
236 (import com.aurellem.capture.Capture)
|
rlm@298
|
237
|
rlm@281
|
238 (defn test-everything!
|
rlm@281
|
239 ([] (test-everything! false))
|
rlm@281
|
240 ([record?]
|
rlm@281
|
241 (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
|
rlm@281
|
242
|
rlm@298
|
243 base (File. "/home/r/proj/cortex/render/hand")
|
rlm@298
|
244
|
rlm@298
|
245
|
rlm@281
|
246 creature (doto (load-blender-model hand)
|
rlm@281
|
247 (body!))
|
rlm@297
|
248
|
rlm@298
|
249 summon-ball (gen-summon-ball false)
|
rlm@192
|
250 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
rlm@298
|
251 touch (touch! creature)
|
rlm@298
|
252 touch-display (view-touch)
|
rlm@189
|
253
|
rlm@298
|
254 vision (vision! creature)
|
rlm@298
|
255 vision-display (view-vision)
|
rlm@189
|
256
|
rlm@298
|
257 hearing (hearing! creature)
|
rlm@298
|
258 hearing-display (view-hearing)
|
rlm@189
|
259
|
rlm@173
|
260 prop (proprioception! creature)
|
rlm@190
|
261 prop-display (view-proprioception)
|
rlm@148
|
262
|
rlm@296
|
263 control-script (motor-control-program
|
rlm@296
|
264 muscle-positions wiggle-each-finger-tip)
|
rlm@191
|
265 muscles (movement! creature)
|
rlm@281
|
266 muscle-display (view-movement)
|
rlm@281
|
267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
rlm@189
|
268
|
rlm@281
|
269 fix-display (gen-fix-display)]
|
rlm@285
|
270 (world
|
rlm@285
|
271 (nodify [creature
|
rlm@285
|
272 (box 10 2 10 :position (Vector3f. 0 -9 0)
|
rlm@285
|
273 :color ColorRGBA/Gray :mass 0)
|
rlm@285
|
274 me])
|
rlm@298
|
275 standard-debug-controls
|
rlm@298
|
276
|
rlm@285
|
277 (fn [world]
|
rlm@285
|
278 (.setTimer world (RatchetTimer. 60))
|
rlm@297
|
279 (position-camera
|
rlm@298
|
280 world (Vector3f. -0.13217318, 5.816415, -5.3089414)
|
rlm@298
|
281 (Quaternion. 0.55685693, 0.0042774677, -0.0028673497, 0.83059245))
|
rlm@298
|
282
|
rlm@285
|
283 (light-up-everything world)
|
rlm@285
|
284 (enable-debug world)
|
rlm@285
|
285 (add-camera! world
|
rlm@285
|
286 (add-eye! creature
|
rlm@285
|
287 (.getChild
|
rlm@285
|
288 (.getChild creature "eyes") "eye"))
|
rlm@285
|
289 (comp (view-image) BufferedImage!))
|
rlm@298
|
290
|
rlm@298
|
291 (if record?
|
rlm@298
|
292 (Capture/captureVideo
|
rlm@298
|
293 world (File. base "main")))
|
rlm@298
|
294 (if record?
|
rlm@298
|
295 (Capture/captureAudio
|
rlm@298
|
296 world (File. base "main.wav"))))
|
rlm@285
|
297 (fn [world tpf]
|
rlm@298
|
298 (prop-display
|
rlm@298
|
299 (prop)
|
rlm@298
|
300 (if record? (File. base "proprio")))
|
rlm@298
|
301 (touch-display
|
rlm@298
|
302 (map #(% (.getRootNode world)) touch)
|
rlm@298
|
303 (if record? (File. base "touch")))
|
rlm@298
|
304 (vision-display
|
rlm@298
|
305 (map #(% world) vision)
|
rlm@298
|
306 (if record? (File. base "vision")))
|
rlm@298
|
307 (hearing-display
|
rlm@298
|
308 (map #(% world) hearing)
|
rlm@298
|
309 (if record? (File. base "hearing")))
|
rlm@298
|
310 (muscle-display
|
rlm@298
|
311 (control-script muscles)
|
rlm@298
|
312 (if record? (File. base "muscle")))
|
rlm@298
|
313
|
rlm@297
|
314 (summon-ball world)
|
rlm@298
|
315
|
rlm@285
|
316 (.setLocalTranslation me (.getLocation (.getCamera world)))
|
rlm@285
|
317 (fix-display world))))))
|
rlm@298
|
318
|
rlm@298
|
319
|
rlm@298
|
320 (comment
|
rlm@298
|
321 ;; list of touch targets
|
rlm@298
|
322 0 middle-11
|
rlm@298
|
323 1 middle-21
|
rlm@298
|
324 2 middle-31
|
rlm@298
|
325 3 pinky-11
|
rlm@298
|
326 4 pinky-21
|
rlm@298
|
327 5 pinky-31
|
rlm@298
|
328 6 pointer-11
|
rlm@298
|
329 7 pointer-21
|
rlm@298
|
330 8 pointer-31
|
rlm@298
|
331 9 ring-11
|
rlm@298
|
332 10 ring-21
|
rlm@298
|
333 11 ring-31
|
rlm@298
|
334 12 thumb-11
|
rlm@298
|
335 13 thumb-2.0011
|
rlm@298
|
336
|
rlm@298
|
337
|
rlm@298
|
338 ;; list of vision targets
|
rlm@298
|
339 0 :all
|
rlm@298
|
340 1 :green
|
rlm@298
|
341 2 :blue
|
rlm@298
|
342 3 :red
|
rlm@298
|
343
|
rlm@298
|
344 ;; list of proprio targets
|
rlm@298
|
345 0 middle-11 -> middle-21
|
rlm@298
|
346 1 middle-21 -> middle-31
|
rlm@298
|
347 2 thumb-11 -> thumb-2.0011
|
rlm@298
|
348 3 pointer-11 -> pointer-21
|
rlm@298
|
349 4 pointer-21 -> pointer-31
|
rlm@298
|
350 5 ring-21 -> ring-31
|
rlm@298
|
351 6 ring-11 -> ring-21
|
rlm@298
|
352 7 pinky-21 -> pinky-31
|
rlm@298
|
353 8 pinky-11 -> pinky-21
|
rlm@298
|
354 9 middle-11 -> palm1
|
rlm@298
|
355 10 pinky-11 -> palm1
|
rlm@298
|
356 11 palm1 -> pointer-11
|
rlm@298
|
357 12 palm1 -> ring-11
|
rlm@298
|
358 13 palm1 -> thumb-11
|
rlm@298
|
359
|
rlm@298
|
360
|
rlm@298
|
361 ;; list of muscle targets
|
rlm@298
|
362 0 :pointer-2-e
|
rlm@298
|
363 1 :pointer-2-f
|
rlm@298
|
364 2 :thumb-1
|
rlm@298
|
365 3 :thumb-1
|
rlm@298
|
366 4 :pointer-1-e
|
rlm@298
|
367 5 :pointer-1-f
|
rlm@298
|
368 6 :thumb-2-e
|
rlm@298
|
369 7 :thumb-2-f
|
rlm@298
|
370 8 :middle-1-e
|
rlm@298
|
371 9 :middle-1-f
|
rlm@298
|
372 10 :pointer-3-f
|
rlm@298
|
373 11 :pointer-3-e
|
rlm@298
|
374 12 :middle-2-e
|
rlm@298
|
375 13 :middle-2-f
|
rlm@298
|
376 14 :middle-3-f
|
rlm@298
|
377 15 :middle-3-e
|
rlm@298
|
378 16 :pinky-2-e
|
rlm@298
|
379 17 :pinky-2-f
|
rlm@298
|
380 18 :pinky-3-f
|
rlm@298
|
381 19 :pinky-3-e
|
rlm@298
|
382 20 :ring-3-e
|
rlm@298
|
383 21 :ring-3-f
|
rlm@298
|
384 22 :ring-2-f
|
rlm@298
|
385 23 :ring-2-e
|
rlm@298
|
386 24 :ring-1-e
|
rlm@298
|
387 25 :ring-1-f
|
rlm@298
|
388 26 :thumb-1-e
|
rlm@298
|
389 27 :thumb-1-f
|
rlm@298
|
390 28 :pinky-1-f
|
rlm@298
|
391 29 :pinky-1-e
|
rlm@298
|
392 )
|
rlm@298
|
393
|
rlm@298
|
394 (def base (File. "/home/r/proj/cortex/render/hand"))
|
rlm@298
|
395
|
rlm@298
|
396 (defn prepare-muscle [muscle]
|
rlm@298
|
397 ["(" muscle "-rotate" "90" "-scale" "15x60!" ")"])
|
rlm@298
|
398
|
rlm@298
|
399 (defn prepare-touch [touch]
|
rlm@298
|
400 ["(" touch "-rotate" "180" ")"])
|
rlm@298
|
401
|
rlm@298
|
402 (defn generate-top-finger [tip-flexor tip-extensor tip
|
rlm@298
|
403 joint-2-3
|
rlm@298
|
404 mid-flexor mid-extensor mid
|
rlm@298
|
405 joint-1-2]
|
rlm@298
|
406 ["("
|
rlm@298
|
407 "-size" "113x357" "xc:transparent"
|
rlm@298
|
408 (prepare-muscle tip-flexor) "-geometry" "+0+7" "-composite"
|
rlm@298
|
409 (prepare-muscle tip-extensor) "-geometry" "+98+7" "-composite"
|
rlm@298
|
410 (prepare-touch tip) "-geometry" "+18+0" "-composite"
|
rlm@298
|
411
|
rlm@298
|
412 joint-2-3 "-geometry" "+32+79" "-composite"
|
rlm@298
|
413
|
rlm@298
|
414 (prepare-muscle mid-flexor) "-geometry" "+19+131" "-composite"
|
rlm@298
|
415 (prepare-muscle mid-extensor) "-geometry" "+80+131" "-composite"
|
rlm@298
|
416 (prepare-touch mid) "-geometry" "+39+133" "-composite"
|
rlm@298
|
417
|
rlm@298
|
418 joint-1-2 "-geometry" "+32+193" "-composite"
|
rlm@298
|
419 ")"])
|
rlm@298
|
420
|
rlm@299
|
421 (defn file-names [#^File dir]
|
rlm@299
|
422 (map #(.getCanonicalPath %) (next (sort (file-seq dir)))))
|
rlm@299
|
423
|
rlm@299
|
424 (defn file-groups [& paths]
|
rlm@299
|
425 (apply (partial map list )
|
rlm@299
|
426 (map (comp file-names #(File. base %))
|
rlm@299
|
427 paths)))
|
rlm@299
|
428
|
rlm@299
|
429
|
rlm@299
|
430 (defn pinky []
|
rlm@299
|
431 (file-groups
|
rlm@299
|
432 "muscle/18"
|
rlm@299
|
433 "muscle/19"
|
rlm@299
|
434 "touch/5"
|
rlm@299
|
435 "proprio/7"
|
rlm@299
|
436
|
rlm@299
|
437 "muscle/17"
|
rlm@299
|
438 "muscle/16"
|
rlm@299
|
439 "touch/4"
|
rlm@299
|
440 "proprio/8"
|
rlm@299
|
441
|
rlm@299
|
442 "muscle/28"
|
rlm@299
|
443 "muscle/29"
|
rlm@299
|
444 "touch/3"
|
rlm@299
|
445 "proprio/10"))
|
rlm@299
|
446
|
rlm@299
|
447 (defn ring []
|
rlm@299
|
448 (file-groups
|
rlm@299
|
449 "muscle/21"
|
rlm@299
|
450 "muscle/20"
|
rlm@299
|
451 "touch/11"
|
rlm@299
|
452 "proprio/5"
|
rlm@299
|
453
|
rlm@299
|
454 "muscle/22"
|
rlm@299
|
455 "muscle/23"
|
rlm@299
|
456 "touch/10"
|
rlm@299
|
457 "proprio/6"
|
rlm@299
|
458
|
rlm@299
|
459 "muscle/25"
|
rlm@299
|
460 "muscle/24"
|
rlm@299
|
461 "touch/9"
|
rlm@299
|
462 "proprio/12"))
|
rlm@299
|
463
|
rlm@299
|
464 (defn middle []
|
rlm@299
|
465 (file-groups
|
rlm@299
|
466 "muscle/14"
|
rlm@299
|
467 "muscle/15"
|
rlm@299
|
468 "touch/2"
|
rlm@299
|
469 "proprio/1"
|
rlm@299
|
470
|
rlm@299
|
471 "muscle/12"
|
rlm@299
|
472 "muscle/13"
|
rlm@299
|
473 "touch/1"
|
rlm@299
|
474 "proprio/0"
|
rlm@299
|
475
|
rlm@299
|
476 "muscle/8"
|
rlm@299
|
477 "muscle/9"
|
rlm@299
|
478 "touch/0"
|
rlm@299
|
479 "proprio/9"))
|
rlm@299
|
480
|
rlm@299
|
481 (defn pointer []
|
rlm@299
|
482 (file-groups
|
rlm@299
|
483 "muscle/10"
|
rlm@299
|
484 "muscle/11"
|
rlm@299
|
485 "touch/8"
|
rlm@299
|
486 "proprio/4"
|
rlm@299
|
487
|
rlm@299
|
488 "muscle/1"
|
rlm@299
|
489 "muscle/0"
|
rlm@299
|
490 "touch/7"
|
rlm@299
|
491 "proprio/3"
|
rlm@299
|
492
|
rlm@299
|
493 "muscle/5"
|
rlm@299
|
494 "muscle/4"
|
rlm@299
|
495 "touch/6"
|
rlm@299
|
496 "proprio/11"))
|
rlm@299
|
497
|
rlm@299
|
498 (defn thumb []
|
rlm@299
|
499 (file-groups
|
rlm@299
|
500 "muscle/7"
|
rlm@299
|
501 "muscle/6"
|
rlm@299
|
502 "touch/13"
|
rlm@299
|
503 "proprio/2"
|
rlm@299
|
504
|
rlm@299
|
505 "muscle/27"
|
rlm@299
|
506 "muscle/26"
|
rlm@299
|
507 "muscle/3"
|
rlm@299
|
508 "muscle/2"
|
rlm@299
|
509 "touch/12"
|
rlm@299
|
510 "proprio/13"))
|
rlm@299
|
511
|
rlm@298
|
512 (defn generate-finger
|
rlm@298
|
513 [tip-flexor tip-extensor tip
|
rlm@298
|
514 joint-2-3
|
rlm@298
|
515 mid-flexor mid-extensor mid
|
rlm@298
|
516 joint-1-2
|
rlm@298
|
517 base-flexor base-extensor base
|
rlm@298
|
518 joint-palm-1]
|
rlm@298
|
519 ["("
|
rlm@298
|
520 "-size" "113x357" "xc:transparent"
|
rlm@298
|
521 (generate-top-finger
|
rlm@298
|
522 tip-flexor tip-extensor tip
|
rlm@298
|
523 joint-2-3
|
rlm@298
|
524 mid-flexor mid-extensor mid
|
rlm@298
|
525 joint-1-2) "-geometry" "+0+0" "-composite"
|
rlm@298
|
526 (prepare-muscle base-flexor) "-geometry" "+19+245" "-composite"
|
rlm@298
|
527 (prepare-muscle base-extensor) "-geometry" "+80+245" "-composite"
|
rlm@298
|
528 (prepare-touch base) "-geometry" "+39+247" "-composite"
|
rlm@298
|
529 joint-palm-1 "-geometry" "+32+307" "-composite"
|
rlm@298
|
530 ")"])
|
rlm@298
|
531
|
rlm@298
|
532 (defn generate-thumb
|
rlm@298
|
533 [tip-flexor tip-extensor tip
|
rlm@298
|
534 joint-1-2
|
rlm@298
|
535 mid-flexor mid-extensor mid-flexor-2 mid-extensor-2 mid
|
rlm@298
|
536 joint-palm-1]
|
rlm@298
|
537 ["("
|
rlm@298
|
538 "-size" "113x357" "xc:transparent"
|
rlm@298
|
539 (generate-top-finger
|
rlm@298
|
540 tip-flexor tip-extensor tip
|
rlm@298
|
541 joint-1-2
|
rlm@298
|
542 mid-flexor mid-extensor mid
|
rlm@298
|
543 joint-palm-1) "-geometry" "+0+0" "-composite"
|
rlm@298
|
544 (prepare-muscle mid-flexor-2) "-geometry" "+2+131" "-composite"
|
rlm@298
|
545 (prepare-muscle mid-extensor-2) "-geometry" "+100+131" "-composite"
|
rlm@298
|
546 ")"])
|
rlm@298
|
547
|
rlm@298
|
548 (defn generate-hand
|
rlm@298
|
549 [pinky-pieces
|
rlm@298
|
550 ring-pieces
|
rlm@298
|
551 middle-pieces
|
rlm@298
|
552 pointer-pieces
|
rlm@298
|
553 thumb-pieces]
|
rlm@298
|
554 ["("
|
rlm@298
|
555 "-size" "688x769" "xc:transparent"
|
rlm@298
|
556 (apply generate-finger pinky-pieces)
|
rlm@298
|
557 "-geometry" "+0+195" "-composite"
|
rlm@298
|
558 (apply generate-finger ring-pieces)
|
rlm@298
|
559 "-geometry" "+111+100" "-composite"
|
rlm@298
|
560 (apply generate-finger middle-pieces)
|
rlm@298
|
561 "-geometry" "+228+0" "-composite"
|
rlm@298
|
562 "(" (apply generate-thumb thumb-pieces) "-background" "#00000000"
|
rlm@298
|
563 "-rotate" "45" ")"
|
rlm@298
|
564 "-geometry" "+300+420" "-composite"
|
rlm@298
|
565 (apply generate-finger pointer-pieces)
|
rlm@298
|
566 "-geometry" "+350+96" "-composite"
|
rlm@298
|
567 ")"])
|
rlm@298
|
568
|
rlm@298
|
569 (defn generate-vision
|
rlm@298
|
570 [all green blue red]
|
rlm@298
|
571 ["("
|
rlm@298
|
572 "-size" "204x192" "xc:transparent"
|
rlm@298
|
573 all "-geometry" "+0+0" "-composite"
|
rlm@298
|
574 green "-geometry" "+113+0" "-composite"
|
rlm@298
|
575 blue "-geometry" "+0+105" "-composite"
|
rlm@298
|
576 red "-geometry" "+113+105" "-composite"
|
rlm@298
|
577 ")"])
|
rlm@298
|
578
|
rlm@298
|
579 (def test-muscle (File. base "muscle/0/0000000.png"))
|
rlm@298
|
580 (def test-proprio (File. base "proprio/0/0000000.png"))
|
rlm@298
|
581 (def test-tip (File. base "touch/2/0000000.png"))
|
rlm@298
|
582 (def test-mid (File. base "touch/0/0000000.png"))
|
rlm@298
|
583 (def test-vision (File. base "vision/0/0000000.png"))
|
rlm@298
|
584 (def test-hearing (File. base "hearing/0/0000000.png"))
|
rlm@298
|
585 (def test-main (File. base "main/0000000.png"))
|
rlm@298
|
586
|
rlm@298
|
587 (def test-target (File. base "output.png"))
|
rlm@298
|
588
|
rlm@298
|
589 (def background (File. base "background.png"))
|
rlm@298
|
590
|
rlm@298
|
591 (use 'clojure.contrib.shell-out)
|
rlm@299
|
592
|
rlm@299
|
593 (defn vision []
|
rlm@299
|
594 (file-groups
|
rlm@299
|
595 "vision/0"
|
rlm@299
|
596 "vision/1"
|
rlm@299
|
597 "vision/2"
|
rlm@299
|
598 "vision/3"))
|
rlm@299
|
599
|
rlm@299
|
600 (defn hearing []
|
rlm@299
|
601 (file-names (File. base "hearing/0")))
|
rlm@299
|
602
|
rlm@299
|
603 (defn main []
|
rlm@299
|
604 (file-names (File. base "main")))
|
rlm@299
|
605
|
rlm@299
|
606 (defn targets []
|
rlm@299
|
607 (map
|
rlm@299
|
608 (comp #(.getCanonicalPath %)
|
rlm@299
|
609 #(File. (str base "/out/" (format "%07d.png" %))))
|
rlm@299
|
610 (range 0 (count (main)))))
|
rlm@299
|
611
|
rlm@299
|
612
|
rlm@299
|
613 (defn final-image [main [all red green blue] hearing
|
rlm@299
|
614 pinky ring middle pointer thumb target]
|
rlm@299
|
615 (println target)
|
rlm@299
|
616 (apply
|
rlm@298
|
617 sh
|
rlm@298
|
618 (flatten
|
rlm@298
|
619 ["convert"
|
rlm@298
|
620 (.getCanonicalPath background)
|
rlm@299
|
621
|
rlm@299
|
622 (generate-hand pinky ring middle pointer thumb)
|
rlm@298
|
623 "-geometry" "+809+22" "-composite"
|
rlm@298
|
624
|
rlm@299
|
625 (generate-vision all red green blue)
|
rlm@298
|
626 "-geometry" "+974+599" "-composite"
|
rlm@298
|
627
|
rlm@298
|
628 hearing
|
rlm@298
|
629 "-geometry" "+784+819" "-composite"
|
rlm@298
|
630
|
rlm@298
|
631 main
|
rlm@298
|
632 "-geometry" "+78+202" "-composite"
|
rlm@298
|
633
|
rlm@299
|
634 target])))
|
rlm@298
|
635
|
rlm@299
|
636 (defn convert-files []
|
rlm@299
|
637 (dorun
|
rlm@299
|
638 (pmap final-image
|
rlm@299
|
639 (main)
|
rlm@299
|
640 (vision)
|
rlm@299
|
641 (hearing)
|
rlm@299
|
642 (pinky)
|
rlm@299
|
643 (ring)
|
rlm@299
|
644 (middle)
|
rlm@299
|
645 (pointer)
|
rlm@299
|
646 (thumb)
|
rlm@299
|
647 (targets))))
|
rlm@299
|
648 #+end_src
|
rlm@298
|
649
|
rlm@298
|
650
|
rlm@299
|
651 #+begin_src sh
|
rlm@299
|
652 cd /home/r/proj/cortex/render/hand
|
rlm@298
|
653
|
rlm@299
|
654 ffmpeg -r 60 -i out/%07d.png -i main.wav -b:a 128k \
|
rlm@299
|
655 -b:v 9000k -c:a libvorbis -c:v libtheora hand.ogg
|
rlm@87
|
656 #+end_src
|
rlm@83
|
657
|
rlm@282
|
658 #+results: integration
|
rlm@299
|
659 : #'cortex.integration/convert-files
|
rlm@282
|
660
|
rlm@78
|
661 * COMMENT purgatory
|
rlm@78
|
662 #+begin_src clojure
|
rlm@77
|
663 (defn bullet-trans* []
|
rlm@77
|
664 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
|
rlm@77
|
665 :position (Vector3f. 5 0 0)
|
rlm@77
|
666 :mass 90)
|
rlm@77
|
667 obj-b (sphere 0.5 :color ColorRGBA/Blue
|
rlm@77
|
668 :position (Vector3f. -5 0 0)
|
rlm@77
|
669 :mass 0)
|
rlm@77
|
670 control-a (.getControl obj-a RigidBodyControl)
|
rlm@77
|
671 control-b (.getControl obj-b RigidBodyControl)
|
rlm@77
|
672 move-up? (atom nil)
|
rlm@77
|
673 move-down? (atom nil)
|
rlm@77
|
674 move-left? (atom nil)
|
rlm@77
|
675 move-right? (atom nil)
|
rlm@77
|
676 roll-left? (atom nil)
|
rlm@77
|
677 roll-right? (atom nil)
|
rlm@77
|
678 force 100
|
rlm@77
|
679 swivel
|
rlm@77
|
680 (.toRotationMatrix
|
rlm@77
|
681 (doto (Quaternion.)
|
rlm@77
|
682 (.fromAngleAxis (/ Math/PI 2)
|
rlm@77
|
683 Vector3f/UNIT_X)))
|
rlm@77
|
684 x-move
|
rlm@77
|
685 (doto (Matrix3f.)
|
rlm@77
|
686 (.fromStartEndVectors Vector3f/UNIT_X
|
rlm@77
|
687 (.normalize (Vector3f. 1 1 0))))
|
rlm@77
|
688
|
rlm@77
|
689 timer (atom 0)]
|
rlm@77
|
690 (doto
|
rlm@77
|
691 (ConeJoint.
|
rlm@77
|
692 control-a control-b
|
rlm@77
|
693 (Vector3f. -8 0 0)
|
rlm@77
|
694 (Vector3f. 2 0 0)
|
rlm@77
|
695 ;;swivel swivel
|
rlm@77
|
696 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
|
rlm@77
|
697 x-move Matrix3f/IDENTITY
|
rlm@77
|
698 )
|
rlm@77
|
699 (.setCollisionBetweenLinkedBodys false)
|
rlm@77
|
700 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
|
rlm@77
|
701 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
|
rlm@77
|
702 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
|
rlm@77
|
703 (world (nodify
|
rlm@77
|
704 [obj-a obj-b])
|
rlm@77
|
705 (merge standard-debug-controls
|
rlm@77
|
706 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
|
rlm@77
|
707 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
|
rlm@77
|
708 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
|
rlm@77
|
709 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
|
rlm@77
|
710 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
|
rlm@77
|
711 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
|
rlm@77
|
712
|
rlm@77
|
713 (fn [world]
|
rlm@77
|
714 (enable-debug world)
|
rlm@77
|
715 (set-gravity world Vector3f/ZERO)
|
rlm@77
|
716 )
|
rlm@77
|
717
|
rlm@77
|
718 (fn [world _]
|
rlm@77
|
719
|
rlm@77
|
720 (if @move-up?
|
rlm@77
|
721 (.applyForce control-a
|
rlm@77
|
722 (Vector3f. force 0 0)
|
rlm@77
|
723 (Vector3f. 0 0 0)))
|
rlm@77
|
724 (if @move-down?
|
rlm@77
|
725 (.applyForce control-a
|
rlm@77
|
726 (Vector3f. (- force) 0 0)
|
rlm@77
|
727 (Vector3f. 0 0 0)))
|
rlm@77
|
728 (if @move-left?
|
rlm@77
|
729 (.applyForce control-a
|
rlm@77
|
730 (Vector3f. 0 force 0)
|
rlm@77
|
731 (Vector3f. 0 0 0)))
|
rlm@77
|
732 (if @move-right?
|
rlm@77
|
733 (.applyForce control-a
|
rlm@77
|
734 (Vector3f. 0 (- force) 0)
|
rlm@77
|
735 (Vector3f. 0 0 0)))
|
rlm@77
|
736
|
rlm@77
|
737 (if @roll-left?
|
rlm@77
|
738 (.applyForce control-a
|
rlm@77
|
739 (Vector3f. 0 0 force)
|
rlm@77
|
740 (Vector3f. 0 0 0)))
|
rlm@77
|
741 (if @roll-right?
|
rlm@77
|
742 (.applyForce control-a
|
rlm@77
|
743 (Vector3f. 0 0 (- force))
|
rlm@77
|
744 (Vector3f. 0 0 0)))
|
rlm@77
|
745
|
rlm@77
|
746 (if (zero? (rem (swap! timer inc) 100))
|
rlm@77
|
747 (.attachChild
|
rlm@77
|
748 (.getRootNode world)
|
rlm@77
|
749 (sphere 0.05 :color ColorRGBA/Yellow
|
rlm@77
|
750 :physical? false :position
|
rlm@77
|
751 (.getWorldTranslation obj-a)))))
|
rlm@77
|
752 )
|
rlm@77
|
753 ))
|
rlm@77
|
754
|
rlm@106
|
755 (defn test-joint [joint]
|
rlm@106
|
756 (let [[origin top bottom floor] (world-setup joint)
|
rlm@106
|
757 control (.getControl top RigidBodyControl)
|
rlm@106
|
758 move-up? (atom false)
|
rlm@106
|
759 move-down? (atom false)
|
rlm@106
|
760 move-left? (atom false)
|
rlm@106
|
761 move-right? (atom false)
|
rlm@106
|
762 roll-left? (atom false)
|
rlm@106
|
763 roll-right? (atom false)
|
rlm@106
|
764 timer (atom 0)]
|
rlm@106
|
765
|
rlm@106
|
766 (world
|
rlm@106
|
767 (nodify [top bottom floor origin])
|
rlm@106
|
768 (merge standard-debug-controls
|
rlm@106
|
769 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
|
rlm@106
|
770 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
|
rlm@106
|
771 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
|
rlm@106
|
772 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
|
rlm@106
|
773 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
|
rlm@106
|
774 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
|
rlm@106
|
775
|
rlm@106
|
776 (fn [world]
|
rlm@106
|
777 (light-up-everything world)
|
rlm@106
|
778 (enable-debug world)
|
rlm@106
|
779 (set-gravity world (Vector3f. 0 0 0))
|
rlm@106
|
780 )
|
rlm@106
|
781
|
rlm@106
|
782 (fn [world _]
|
rlm@106
|
783 (if (zero? (rem (swap! timer inc) 100))
|
rlm@106
|
784 (do
|
rlm@106
|
785 ;; (println-repl @timer)
|
rlm@106
|
786 (.attachChild (.getRootNode world)
|
rlm@106
|
787 (sphere 0.05 :color ColorRGBA/Yellow
|
rlm@106
|
788 :position (.getWorldTranslation top)
|
rlm@106
|
789 :physical? false))
|
rlm@106
|
790 (.attachChild (.getRootNode world)
|
rlm@106
|
791 (sphere 0.05 :color ColorRGBA/LightGray
|
rlm@106
|
792 :position (.getWorldTranslation bottom)
|
rlm@106
|
793 :physical? false))))
|
rlm@106
|
794
|
rlm@106
|
795 (if @move-up?
|
rlm@106
|
796 (.applyTorque control
|
rlm@106
|
797 (.mult (.getPhysicsRotation control)
|
rlm@106
|
798 (Vector3f. 0 0 10))))
|
rlm@106
|
799 (if @move-down?
|
rlm@106
|
800 (.applyTorque control
|
rlm@106
|
801 (.mult (.getPhysicsRotation control)
|
rlm@106
|
802 (Vector3f. 0 0 -10))))
|
rlm@106
|
803 (if @move-left?
|
rlm@106
|
804 (.applyTorque control
|
rlm@106
|
805 (.mult (.getPhysicsRotation control)
|
rlm@106
|
806 (Vector3f. 0 10 0))))
|
rlm@106
|
807 (if @move-right?
|
rlm@106
|
808 (.applyTorque control
|
rlm@106
|
809 (.mult (.getPhysicsRotation control)
|
rlm@106
|
810 (Vector3f. 0 -10 0))))
|
rlm@106
|
811 (if @roll-left?
|
rlm@106
|
812 (.applyTorque control
|
rlm@106
|
813 (.mult (.getPhysicsRotation control)
|
rlm@106
|
814 (Vector3f. -1 0 0))))
|
rlm@106
|
815 (if @roll-right?
|
rlm@106
|
816 (.applyTorque control
|
rlm@106
|
817 (.mult (.getPhysicsRotation control)
|
rlm@106
|
818 (Vector3f. 1 0 0))))))))
|
rlm@99
|
819 #+end_src
|
rlm@192
|
820
|
rlm@99
|
821
|
rlm@99
|
822 * COMMENT generate source
|
rlm@192
|
823 #+begin_src clojure :tangle ../src/cortex/integration.clj
|
rlm@192
|
824 <<integration>>
|
rlm@99
|
825 #+end_src
|
rlm@99
|
826
|
rlm@99
|
827
|
rlm@94
|
828
|
rlm@94
|
829
|