2009-09-28 08:57:29 +00:00
|
|
|
;; p l a n t e y e s [ copyright (c) 2009 foam vzw : gpl v3 ]
|
|
|
|
|
2009-08-25 08:55:32 +00:00
|
|
|
#lang scheme/base
|
2009-09-28 08:57:29 +00:00
|
|
|
(require scheme/class
|
|
|
|
fluxus-016/fluxus
|
2009-10-21 18:07:30 +00:00
|
|
|
"sound.ss"
|
|
|
|
"list-utils.ss")
|
2009-09-28 08:57:29 +00:00
|
|
|
|
2009-08-25 08:55:32 +00:00
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
(define (clamp v l u)
|
|
|
|
(if (< v l) l
|
|
|
|
(if (> v u) u v)))
|
|
|
|
|
|
|
|
(define (property->ornament property pos width dir col)
|
|
|
|
(make-object (cond
|
|
|
|
((eq? property 'inflatoe) inflatoe-ornament-view%)
|
2009-10-21 18:07:30 +00:00
|
|
|
|
|
|
|
;((eq? property 'horn) horn-ornament-view%)
|
|
|
|
;((eq? property 'leaf) leaf-ornament-view%)
|
|
|
|
;((eq? property 'flower) flower-ornament-view%)
|
|
|
|
;((eq? property 'fork) fork-ornament-view%)
|
|
|
|
|
|
|
|
; horn
|
|
|
|
((eq? property 'horn) (choose (list horn-ornament-view%
|
|
|
|
fork-ornament-view%
|
|
|
|
flower-ornament-view%)))
|
|
|
|
|
|
|
|
; fork
|
|
|
|
((eq? property 'flower) (choose (list tot-flower-ornament-view%
|
|
|
|
tot-bud-ornament-view%)))
|
|
|
|
|
|
|
|
; flower
|
|
|
|
((eq? property 'fork) (choose (list tot-hanger-ornament-view%
|
|
|
|
tot-mushroom-ornament-view%)))
|
|
|
|
|
|
|
|
; leaf
|
|
|
|
((eq? property 'leaf) (choose (list tot-leaf-ornament-view%
|
|
|
|
tot-leaf2-ornament-view%)))
|
|
|
|
|
|
|
|
|
2009-08-25 08:55:32 +00:00
|
|
|
(else (error "can't find ornament for property " property)))
|
|
|
|
pos width dir col))
|
|
|
|
|
|
|
|
(define ornament-view%
|
|
|
|
(class object%
|
|
|
|
(init-field
|
|
|
|
(pos (vector 0 0 0))
|
|
|
|
(sc 1)
|
|
|
|
(dir (vector 0 0 1))
|
|
|
|
(col (vector 1 1 1))
|
|
|
|
(time 0)
|
|
|
|
(ev-time 0)
|
|
|
|
(ev-dur 8)
|
|
|
|
(ev-col (vector 0 0 1))
|
2009-10-14 18:00:45 +00:00
|
|
|
(light 0)
|
|
|
|
(shrink-t 0))
|
2009-08-25 08:55:32 +00:00
|
|
|
|
|
|
|
(field
|
|
|
|
(const-scale 4)
|
|
|
|
(rot (vector 0 0 0))
|
|
|
|
(excitation-changed #f)
|
2009-10-21 18:07:30 +00:00
|
|
|
(root (let ((p (with-state (build-root)))) (with-primitive p (hide 1)) p))
|
2009-08-25 08:55:32 +00:00
|
|
|
(particles (if (want-particles?)
|
|
|
|
(let ((p (with-state
|
|
|
|
(parent root)
|
|
|
|
(translate (vector 0 0 1))
|
|
|
|
(hint-depth-sort)
|
|
|
|
(hint-unlit)
|
2009-10-14 18:00:45 +00:00
|
|
|
(hint-frustum-cull)
|
2009-08-25 08:55:32 +00:00
|
|
|
(blend-mode 'src-alpha 'one)
|
|
|
|
(texture (load-texture "textures/particle.png"))
|
|
|
|
(build-particles 30))))
|
|
|
|
(with-primitive p
|
|
|
|
(pdata-add "vel" "v")
|
|
|
|
(pdata-map!
|
|
|
|
(lambda (vel)
|
|
|
|
(vmul (srndvec) 0.01))
|
|
|
|
"vel")
|
|
|
|
(pdata-map!
|
|
|
|
(lambda (s)
|
|
|
|
(vmul (vector 1 1 1) (* 0.25 (rndf))))
|
|
|
|
"s")
|
|
|
|
(pdata-map!
|
|
|
|
(lambda (c)
|
|
|
|
(vadd ev-col (vmul (rndvec) (* 0.2 (rndf)))))
|
|
|
|
"c"))
|
|
|
|
p)
|
|
|
|
0)))
|
|
|
|
|
|
|
|
(define/public (destroy-ornament)
|
|
|
|
(destroy root))
|
|
|
|
|
|
|
|
(define/pubment (want-particles?)
|
2009-10-21 18:07:30 +00:00
|
|
|
#f
|
|
|
|
#;(inner #f want-particles?))
|
2009-08-25 08:55:32 +00:00
|
|
|
|
|
|
|
(define/pubment (centred?)
|
|
|
|
(inner #f centred?))
|
|
|
|
|
2009-10-21 18:07:30 +00:00
|
|
|
(define/pubment (fixed?)
|
|
|
|
(inner #f fixed?))
|
|
|
|
|
2009-08-25 08:55:32 +00:00
|
|
|
(define/pubment (want-morph?)
|
|
|
|
(inner #f want-morph?))
|
|
|
|
|
|
|
|
(define/pubment (build-root)
|
|
|
|
(inner (build-root) build-root))
|
|
|
|
|
|
|
|
(define/public (set-excitations! a b)
|
|
|
|
(set! excitation-changed #t)
|
|
|
|
(set! light a)
|
|
|
|
(set! ev-dur (if (zero? a) 9999 (/ 1 a)))
|
|
|
|
(set! ev-col (vmix (vector 0 0 1) (vector 1 0 0) b))
|
|
|
|
(set! ev-time (* ev-dur 4 (rndf))))
|
2009-10-14 18:00:45 +00:00
|
|
|
|
|
|
|
(define/pubment (start-shrinking)
|
|
|
|
(set! shrink-t 10))
|
2009-08-25 08:55:32 +00:00
|
|
|
|
|
|
|
(define/pubment (update t d)
|
|
|
|
#;(inner (build-root) update)
|
|
|
|
|
|
|
|
(when (< time 1)
|
|
|
|
(with-primitive root
|
2009-10-21 18:07:30 +00:00
|
|
|
(hide 0)
|
2009-08-25 08:55:32 +00:00
|
|
|
(identity)
|
|
|
|
(translate pos)
|
2009-10-21 18:07:30 +00:00
|
|
|
(cond ((fixed?)
|
|
|
|
(concat (maim (vcross dir (vector 0 1 0)) (vector 0 1 0)))
|
|
|
|
(rotate (vector 0 90 -90)))
|
|
|
|
(else
|
|
|
|
(concat (maim dir (vector 0 1 0)))
|
|
|
|
(rotate rot)))
|
2009-08-25 08:55:32 +00:00
|
|
|
(scale (* const-scale sc 0.2 time))
|
|
|
|
(when (not (centred?))
|
2009-10-14 18:00:45 +00:00
|
|
|
(translate (vector 0 0 0.8)))
|
|
|
|
(recalc-bb))
|
2009-08-25 08:55:32 +00:00
|
|
|
(set! time (+ time (* 0.05 d))))
|
|
|
|
|
2009-10-14 18:00:45 +00:00
|
|
|
(when (> shrink-t 0)
|
|
|
|
(with-primitive root
|
|
|
|
(identity)
|
|
|
|
(translate pos)
|
|
|
|
(concat (maim dir (vector 0 1 0)))
|
2009-10-21 18:07:30 +00:00
|
|
|
(if (fixed?)
|
|
|
|
(concat (maim (vtransform (vector 0 1 0) (get-transform)) (vector 0 1 0)))
|
|
|
|
(rotate rot))
|
2009-10-14 18:00:45 +00:00
|
|
|
(scale (* const-scale sc 0.2 (/ shrink-t 10)))
|
|
|
|
(when (not (centred?))
|
|
|
|
(translate (vector 0 0 0.8)))
|
|
|
|
(set! shrink-t (- shrink-t d))))
|
|
|
|
|
2009-08-25 08:55:32 +00:00
|
|
|
(when (and (want-morph?) excitation-changed)
|
|
|
|
(printf "morphing~n")
|
|
|
|
(with-primitive root
|
|
|
|
(pdata-map!
|
|
|
|
(lambda (p p1 p2)
|
|
|
|
(vmix p1 p2 (clamp light 0 1)))
|
|
|
|
"p" "p1" "p2")))
|
|
|
|
|
|
|
|
(when (want-particles?)
|
|
|
|
(with-primitive particles
|
|
|
|
(pdata-op "+" "p" "vel")
|
|
|
|
(pdata-op "*" "c" 0.995))
|
|
|
|
|
|
|
|
(when (< ev-time 0)
|
|
|
|
(play-sound "snd/wateringcan.wav" pos (+ 0.1 (rndf)) 0.3)
|
|
|
|
|
|
|
|
; todo inherit and call event happen or somesuch
|
|
|
|
(when (want-particles?)
|
|
|
|
(with-primitive particles
|
|
|
|
(pdata-index-map!
|
|
|
|
(lambda (i p)
|
|
|
|
(cond ((zero? (random 2)) p)
|
|
|
|
(else
|
|
|
|
(pdata-set! "c" i (vector (+ 0.5 (* 0.5 (rndf))) (+ 0.5 (* 0.5 (rndf))) 1))
|
|
|
|
(vector 0 0 0))))
|
|
|
|
"p")))
|
|
|
|
(set! ev-time ev-dur))
|
|
|
|
(set! ev-time (- ev-time d)))
|
|
|
|
|
|
|
|
(set! excitation-changed #f))
|
|
|
|
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define leaf-ornament-view%
|
|
|
|
(class ornament-view%
|
2009-10-21 18:07:30 +00:00
|
|
|
(inherit-field col rot pos)
|
2009-08-25 08:55:32 +00:00
|
|
|
(define/augment (centred?) #t)
|
|
|
|
(define/augment (build-root)
|
2009-08-25 13:44:43 +00:00
|
|
|
(colour col)
|
2009-08-25 08:55:32 +00:00
|
|
|
(texture (load-texture "textures/leaf.png"))
|
2009-10-21 18:07:30 +00:00
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
2009-08-25 08:55:32 +00:00
|
|
|
(set! rot (vector 0 0 0))
|
2009-10-21 18:07:30 +00:00
|
|
|
(let ((p (load-primitive "meshes/leaf.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
|
|
|
|
2009-08-25 08:55:32 +00:00
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define horn-ornament-view%
|
|
|
|
(class ornament-view%
|
2009-10-21 18:07:30 +00:00
|
|
|
(inherit-field rot col pos)
|
2009-08-25 08:55:32 +00:00
|
|
|
(define/augment (want-particles?) #t)
|
|
|
|
(define/augment (build-root)
|
2009-08-25 13:44:43 +00:00
|
|
|
(texture (load-texture "textures/wiggle.png"))
|
2009-08-25 08:55:32 +00:00
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
|
|
|
(colour col)
|
|
|
|
(set! rot (vector (* (rndf) 360) 0 0))
|
2009-10-21 18:07:30 +00:00
|
|
|
(let ((p (load-primitive "meshes/horn.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
2009-08-25 08:55:32 +00:00
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define inflatoe-ornament-view%
|
|
|
|
(class ornament-view%
|
2009-10-21 18:07:30 +00:00
|
|
|
(inherit-field rot col pos)
|
2009-08-25 08:55:32 +00:00
|
|
|
(define/augment (want-morph?) #t)
|
|
|
|
(define/augment (build-root)
|
2009-10-21 18:07:30 +00:00
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
2009-08-25 08:55:32 +00:00
|
|
|
(texture (load-texture "textures/wiggle.png"))
|
|
|
|
(colour col)
|
|
|
|
(set! rot (vector (* (rndf) 360) 0 0))
|
|
|
|
(let ((p (load-primitive "meshes/inflatoe-full.obj")))
|
|
|
|
(let ((dp (load-primitive "meshes/inflatoe-empty.obj")))
|
|
|
|
(with-primitive p
|
2009-10-21 18:07:30 +00:00
|
|
|
(shader-set! (list "Origin" pos))
|
2009-08-25 08:55:32 +00:00
|
|
|
(pdata-copy "p" "p1")
|
|
|
|
(pdata-add "p2" "v")
|
|
|
|
(pdata-index-map!
|
|
|
|
(lambda (i p2)
|
|
|
|
(with-primitive dp
|
|
|
|
(pdata-ref "p" i)))
|
|
|
|
"p2"))
|
|
|
|
(destroy dp))
|
|
|
|
p))
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define fork-ornament-view%
|
|
|
|
(class ornament-view%
|
2009-10-21 18:07:30 +00:00
|
|
|
(inherit-field rot col pos)
|
2009-08-25 08:55:32 +00:00
|
|
|
(define/augment (build-root)
|
2009-10-21 18:07:30 +00:00
|
|
|
;(texture (load-texture "textures/wiggle.png"))
|
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
2009-08-25 08:55:32 +00:00
|
|
|
(colour col)
|
|
|
|
(set! rot (vector (* (rndf) 360) 0 0))
|
2009-10-21 18:07:30 +00:00
|
|
|
(let ((p (load-primitive "meshes/fork.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
2009-08-25 08:55:32 +00:00
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define flower-ornament-view%
|
|
|
|
(class ornament-view%
|
2009-10-21 18:07:30 +00:00
|
|
|
(inherit-field rot col pos)
|
2009-08-25 08:55:32 +00:00
|
|
|
(define/augment (build-root)
|
2009-08-25 13:44:43 +00:00
|
|
|
(texture (load-texture "textures/wiggle.png"))
|
2009-10-21 18:07:30 +00:00
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
|
|
|
(colour (hsv->rgb (vector 0.9 0.5 (+ 0.5 (* 0.5 (rndf))))))
|
|
|
|
(set! rot (vector (* (rndf) 360) 0 0))
|
|
|
|
(let ((p (load-primitive "meshes/flower.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define tot-flower-ornament-view%
|
|
|
|
(class ornament-view%
|
|
|
|
(inherit-field rot col pos)
|
|
|
|
(define/augment (build-root)
|
|
|
|
;(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
|
|
|
(colour (hsv->rgb (vector 0.7 0.5 (+ 0.5 (* 0.5 (rndf))))))
|
|
|
|
(set! rot (vector (* (rndf) 360) 0 0))
|
|
|
|
(let ((p (load-primitive "meshes/tot-flower.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define tot-bud-ornament-view%
|
|
|
|
(class ornament-view%
|
|
|
|
(inherit-field rot col pos)
|
|
|
|
(define/augment (build-root)
|
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
|
|
|
(colour (hsv->rgb (vector 0.7 0.5 (+ 0.5 (* 0.5 (rndf))))))
|
|
|
|
(set! rot (vector (* (rndf) 360) 0 0))
|
|
|
|
(let ((p (load-primitive "meshes/tot-bud.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define tot-mushroom-ornament-view%
|
|
|
|
(class ornament-view%
|
|
|
|
(inherit-field rot col pos)
|
|
|
|
(define/augment (build-root)
|
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
|
|
|
(colour col)
|
|
|
|
(set! rot (vector (* (rndf) 360) 0 0))
|
|
|
|
(let ((p (load-primitive "meshes/tot-mushroom.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define tot-leaf2-ornament-view%
|
|
|
|
(class ornament-view%
|
|
|
|
(inherit-field rot col pos)
|
|
|
|
(define/augment (build-root)
|
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
2009-08-25 08:55:32 +00:00
|
|
|
(colour col)
|
|
|
|
(set! rot (vector (* (rndf) 360) 0 0))
|
2009-10-21 18:07:30 +00:00
|
|
|
(let ((p (load-primitive "meshes/tot-leaf2.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
2009-08-25 08:55:32 +00:00
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2009-10-21 18:07:30 +00:00
|
|
|
(define tot-hanger-ornament-view%
|
|
|
|
(class ornament-view%
|
|
|
|
(inherit-field rot col pos)
|
|
|
|
(define/augment (fixed?) #t)
|
|
|
|
(define/augment (build-root)
|
|
|
|
;(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
|
|
|
(colour col)
|
|
|
|
;(set! rot (vector (* (rndf) 360) 0 0))
|
|
|
|
(let ((p (load-primitive "meshes/tot-hanger.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
(define tot-leaf-ornament-view%
|
|
|
|
(class ornament-view%
|
|
|
|
(inherit-field col rot pos)
|
|
|
|
(define/augment (centred?) #t)
|
|
|
|
(define/augment (build-root)
|
|
|
|
(colour col)
|
|
|
|
(texture (load-texture "textures/leaf.png"))
|
|
|
|
(shader "shaders/toon.vert.glsl" "shaders/toon.frag.glsl")
|
|
|
|
(set! rot (vector 0 0 0))
|
|
|
|
(let ((p (load-primitive "meshes/tot-leaf.obj")))
|
|
|
|
(with-primitive p
|
|
|
|
(shader-set! (list "Origin" pos))) p))
|
|
|
|
|
|
|
|
(super-new)))
|