diff options
Diffstat (limited to 'sly/shape.scm')
-rw-r--r-- | sly/shape.scm | 159 |
1 files changed, 81 insertions, 78 deletions
diff --git a/sly/shape.scm b/sly/shape.scm index 8283875..b71f59c 100644 --- a/sly/shape.scm +++ b/sly/shape.scm @@ -24,6 +24,7 @@ (define-module (sly shape) #:use-module (sly math) #:use-module (sly mesh) + #:use-module (sly scene) #:use-module (sly shader) #:use-module (sly texture) #:use-module (sly math vector) @@ -32,88 +33,90 @@ (define* (make-cube size #:optional #:key (texture #f) (shader (load-default-shader))) (let ((half-size (half size))) - (make-mesh - #:shader shader + (make-scene-node #:texture texture - #:indices #( - ;; Front - 0 3 2 0 2 1 - ;; Back - 4 6 7 4 5 6 - ;; Top - 8 11 10 8 10 9 - ;; Bottom - 12 14 15 12 13 14 - ;; Left - 16 19 18 16 18 17 - ;; Right - 20 22 23 20 21 22) - #:data `(("position" ,(vector + #:children + (make-mesh + #:shader shader + #:indices #( + ;; Front + 0 3 2 0 2 1 + ;; Back + 4 6 7 4 5 6 + ;; Top + 8 11 10 8 10 9 + ;; Bottom + 12 14 15 12 13 14 + ;; Left + 16 19 18 16 18 17 + ;; Right + 20 22 23 20 21 22) + #:data `(("position" ,(vector + ;; Front + (vector3 (- half-size) (- half-size) (- half-size)) + (vector3 half-size (- half-size) (- half-size)) + (vector3 half-size half-size (- half-size)) + (vector3 (- half-size) half-size (- half-size)) + ;; Back + (vector3 (- half-size) (- half-size) half-size) + (vector3 half-size (- half-size) half-size) + (vector3 half-size half-size half-size) + (vector3 (- half-size) half-size half-size) + ;; Top + (vector3 (- half-size) half-size (- half-size)) + (vector3 half-size half-size (- half-size)) + (vector3 half-size half-size half-size) + (vector3 (- half-size) half-size half-size) + ;; Bottom + (vector3 (- half-size) (- half-size) (- half-size)) + (vector3 half-size (- half-size) (- half-size)) + (vector3 half-size (- half-size) half-size) + (vector3 (- half-size) (- half-size) half-size) + ;; Left + (vector3 (- half-size) (- half-size) (- half-size)) + (vector3 (- half-size) half-size (- half-size)) + (vector3 (- half-size) half-size half-size) + (vector3 (- half-size) (- half-size) half-size) + ;; Right + (vector3 half-size (- half-size) (- half-size)) + (vector3 half-size half-size (- half-size)) + (vector3 half-size half-size half-size) + (vector3 half-size (- half-size) half-size))) + ,@(if texture + (let ((s1 (texture-s1 texture)) + (t1 (texture-t1 texture)) + (s2 (texture-s2 texture)) + (t2 (texture-t2 texture))) + `(("tex" + ,(vector ;; Front - (vector3 (- half-size) (- half-size) (- half-size)) - (vector3 half-size (- half-size) (- half-size)) - (vector3 half-size half-size (- half-size)) - (vector3 (- half-size) half-size (- half-size)) + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) ;; Back - (vector3 (- half-size) (- half-size) half-size) - (vector3 half-size (- half-size) half-size) - (vector3 half-size half-size half-size) - (vector3 (- half-size) half-size half-size) + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) ;; Top - (vector3 (- half-size) half-size (- half-size)) - (vector3 half-size half-size (- half-size)) - (vector3 half-size half-size half-size) - (vector3 (- half-size) half-size half-size) + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) ;; Bottom - (vector3 (- half-size) (- half-size) (- half-size)) - (vector3 half-size (- half-size) (- half-size)) - (vector3 half-size (- half-size) half-size) - (vector3 (- half-size) (- half-size) half-size) + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) ;; Left - (vector3 (- half-size) (- half-size) (- half-size)) - (vector3 (- half-size) half-size (- half-size)) - (vector3 (- half-size) half-size half-size) - (vector3 (- half-size) (- half-size) half-size) + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2) ;; Right - (vector3 half-size (- half-size) (- half-size)) - (vector3 half-size half-size (- half-size)) - (vector3 half-size half-size half-size) - (vector3 half-size (- half-size) half-size))) - ,@(if texture - (let ((s1 (texture-s1 texture)) - (t1 (texture-t1 texture)) - (s2 (texture-s2 texture)) - (t2 (texture-t2 texture))) - `(("tex" - ,(vector - ;; Front - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Back - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Top - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Bottom - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Left - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2) - ;; Right - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2))))) - '()))))) + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2))))) + '())))))) |