summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-05-05 18:49:31 -0400
committerDavid Thompson <dthompson2@worcester.edu>2021-05-05 18:49:31 -0400
commita2b8006c27d6ad8d7af701b94e869ab39c3a7ad4 (patch)
tree9b905b1379f6d702426e6ac2b85eb4b769247ec5
parenta5b23f4a19c3f31c398a28b502f2dde3aeabe1b0 (diff)
graphics: model: Add crude support for base64 glTF buffer data.
-rw-r--r--chickadee/graphics/model.scm19
1 files changed, 12 insertions, 7 deletions
diff --git a/chickadee/graphics/model.scm b/chickadee/graphics/model.scm
index 92be430..3024673 100644
--- a/chickadee/graphics/model.scm
+++ b/chickadee/graphics/model.scm
@@ -23,6 +23,7 @@
(define-module (chickadee graphics model)
#:use-module (chickadee array-list)
+ #:use-module (chickadee base64)
#:use-module (chickadee json)
#:use-module (chickadee math matrix)
#:use-module (chickadee math vector)
@@ -641,7 +642,7 @@
value))
(define (object-ref/optional obj key)
(let ((value (assoc-ref obj key)))
- (unless (or (not value) (pair? value))
+ (unless (or (not value) (pair? value) (null? value))
(error "expected object for optional key" key value))
value))
(define (array-ref obj key)
@@ -728,8 +729,8 @@
(if (absolute-file-name? other-file)
other-file
(string-append gltf-root "/" other-file)))))
+ (define base64-prefix "data:application/octet-stream;base64,")
(define (parse-buffer obj)
- ;; TODO: support base64 encoded buffer data as uri
;; TODO: support glb-stored buffers:
;; https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-stored-buffer
(let* ((uri (string-ref/optional obj "uri"))
@@ -737,11 +738,15 @@
(name (or (string-ref/optional obj "name") "anonymous"))
(extensions (object-ref/optional obj "extensions"))
(extras (assoc-ref obj "extras"))
- (data (if uri
- (call-with-input-file (scope-file uri)
- (lambda (port)
- (get-bytevector-n port length)))
- (make-bytevector length))))
+ (data (cond
+ ((string-prefix? base64-prefix uri)
+ (base64-decode (substring uri (string-length base64-prefix))))
+ (uri
+ (call-with-input-file (scope-file uri)
+ (lambda (port)
+ (get-bytevector-n port length))))
+ (else
+ (make-bytevector length)))))
data))
(define (parse-buffer-view obj buffers)
(let ((name (string-ref/optional obj "name"))