comparison org/test-creature.org @ 90:6d7c17c847a3

saving progress
author Robert McIntyre <rlm@mit.edu>
date Sun, 08 Jan 2012 06:11:58 -0700
parents cd5151b5e7c3
children 2bcc7636cfea
comparison
equal deleted inserted replaced
89:cd5151b5e7c3 90:6d7c17c847a3
262 262
263 (def hand "Models/creature1/one.blend") 263 (def hand "Models/creature1/one.blend")
264 264
265 (def worm "Models/creature1/try-again.blend") 265 (def worm "Models/creature1/try-again.blend")
266 266
267 (def touch "Models/creature1/touch.blend")
268
269 (defn worm-model [] (load-blender-model worm))
270
267 (defn x-ray [#^ColorRGBA color] 271 (defn x-ray [#^ColorRGBA color]
268 (doto (Material. (asset-manager) 272 (doto (Material. (asset-manager)
269 "Common/MatDefs/Misc/Unshaded.j3md") 273 "Common/MatDefs/Misc/Unshaded.j3md")
270 (.setColor "Color" color) 274 (.setColor "Color" color)
271 (-> (.getAdditionalRenderState) 275 (-> (.getAdditionalRenderState)
283 (box 10 2 10 :position (Vector3f. 0 -9 0) 287 (box 10 2 10 :position (Vector3f. 0 -9 0)
284 :color ColorRGBA/Gray :mass 0) 288 :color ColorRGBA/Gray :mass 0)
285 x-axis y-axis z-axis 289 x-axis y-axis z-axis
286 ]) 290 ])
287 standard-debug-controls 291 standard-debug-controls
288 (comp light-up-everything enable-debug 292 (fn [world]
289 (fn [world] 293 (light-up-everything world)
290 (.setTimer world (NanoTimer.)) 294 (enable-debug world)
291 ;;(set-gravity world (Vector3f. 0 0 0)) 295 ;;(com.aurellem.capture.Capture/captureVideo
292 (speed-up world) 296 ;; world (file-str "/home/r/proj/ai-videos/hand"))
293 world 297 (.setTimer world (NanoTimer.))
294 )) 298 ;;(set-gravity world (Vector3f. 0 0 0))
295 no-op))) 299 (speed-up world)
300 )
301 no-op
302 ;;(let [timer (atom 0)]
303 ;; (fn [_ _]
304 ;; (swap! timer inc)
305 ;; (if (= (rem @timer 60) 0)
306 ;; (println-repl (float (/ @timer 60))))))
307 )))
308
309
310 (def colorful (.getChild (worm-model) "worm-21"))
311
312 (def im-data
313 (let [sink (byte-array 3145727)
314 data (.getData (.getImage texture) 0)]
315 (.rewind data)
316 (.get data sink)
317 (vec (seq sink))))
318
319
320 (import jme3tools.converters.ImageToAwt)
321
322 (import ij.ImagePlus)
323
324
325
326 (defn triangle-indices
327 "Get the triangle vertex indices of a given triangle from a given
328 mesh."
329 [#^Mesh mesh triangle-index]
330 (let [indices (int-array 3)]
331 (.getTriangle mesh triangle-index indices)
332 (vec indices)))
333
334 (defn uv-coord
335 "Get the uv-coordinates of the vertex named by vertex-index"
336 [#^Mesh mesh vertex-index]
337 (let [UV-buffer
338 (.getData
339 (.getBuffer
340 mesh
341 VertexBuffer$Type/TexCoord))]
342 [(.get UV-buffer (* vertex-index 2))
343 (.get UV-buffer (+ 1 (* vertex-index 2)))]))
344
345 (defn touch-receptor-image [#^Geometry obj]
346
347
348
349 ;; yay there's a converter!
350
351 (defn uv-image []
352 (let
353 [colorful (.getChild (worm-model) "worm-21")
354 mat (.getMaterial colorful)
355 texture
356 (.getTextureValue
357 (.getTextureParam
358 mat
359 MaterialHelper/TEXTURE_TYPE_DIFFUSE))
360 im (.getImage texture)]
361 (ImagePlus.
362 "UV-map"
363 (ImageToAwt/convert im false false 0))))
364
365 ;; for each triangle in the mesh,
366 ;; get the normal to the triangle,
367 ;; look at the UV touch map, restricted to that triangle,
368 ;; get the positions of those touch sensors in geometry-relative
369 ;; coordinates.
370
371
372
373
374
375
376
377
378
379 (defrecord LulzLoader [])
380 (defprotocol Lulzable (load-lulz [this]))
381 (extend-type LulzLoader
382 Lulzable
383 (load-lulz [this] (println "the lulz have arrived!")))
384
385 (defn
386
387
296 388
297 (defn world-setup [joint] 389 (defn world-setup [joint]
298 (let [ 390 (let [joint-position (Vector3f. 0 0 0)
299
300 joint-position (Vector3f. 0 0 0)
301 joint-rotation 391 joint-rotation
302 (.toRotationMatrix 392 (.toRotationMatrix
303 (.mult 393 (.mult
304 (doto (Quaternion.) 394 (doto (Quaternion.)
305 (.fromAngleAxis 395 (.fromAngleAxis