diff options
Diffstat (limited to 'sly/mesh.scm')
-rw-r--r-- | sly/mesh.scm | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/sly/mesh.scm b/sly/mesh.scm index 1d7d89c..65154a7 100644 --- a/sly/mesh.scm +++ b/sly/mesh.scm @@ -34,7 +34,7 @@ #:use-module (sly color) #:use-module (sly shader) #:use-module (sly texture) - #:use-module (sly vector) + #:use-module (sly math vector) #:use-module (sly signal) #:export (make-mesh mesh? @@ -78,27 +78,30 @@ (attribute-size elem))))) (setter (if index? u32vector-set! f32vector-set!))) (vector-for-each - (cond - ((number? elem) - (lambda (i k) - (setter bv i k))) - ((or (vector2? elem) - (vector3? elem) - (vector4? elem)) - (let ((dimensions (vector-length elem))) - (lambda (i v) - (let ((offset (* i dimensions))) - (vector-for-each - (lambda (j n) - (setter bv (+ offset j) n)) - v))))) - ((color? elem) - (lambda (i c) - (let ((offset (* i 4))) - (setter bv offset (color-r c)) - (setter bv (1+ offset) (color-g c)) - (setter bv (+ offset 2) (color-b c)) - (setter bv (+ offset 3) (color-a c)))))) + (match-lambda* + ((i (? number? k)) + (setter bv i k)) + ((i (? vector2? v)) + (let ((offset (* i 2))) + (setter bv offset (vx v)) + (setter bv (1+ offset) (vy v)))) + ((i (? vector3? v)) + (let ((offset (* i 3))) + (setter bv offset (vx v)) + (setter bv (1+ offset) (vy v)) + (setter bv (+ offset 2) (vz v)))) + ((i (? vector4? v)) + (let ((offset (* i 4))) + (setter bv offset (vx v)) + (setter bv (1+ offset) (vy v)) + (setter bv (+ offset 2) (vz v)) + (setter bv (+ offset 3) (vw v)))) + ((i (color? c)) + (let ((offset (* i 4))) + (setter bv offset (color-r c)) + (setter bv (1+ offset) (color-g c)) + (setter bv (+ offset 2) (color-b c)) + (setter bv (+ offset 3) (color-a c))))) vertices) bv)) |