summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2019-10-28 17:18:09 -0400
committerDavid Thompson <dthompson2@worcester.edu>2019-10-28 17:20:52 -0400
commitc128c2e53e054c9eb18c7e17acbb895660e5ee36 (patch)
treea1e63cce34ddca2c4414bf2b7599141f58bf837e
parent1a76ff6b213d9975921dc3ff707da549917cba3e (diff)
render: model: Load ambient maps in .mtl files.
-rw-r--r--chickadee/render/model.scm17
1 files changed, 16 insertions, 1 deletions
diff --git a/chickadee/render/model.scm b/chickadee/render/model.scm
index ec2246b..7771127 100644
--- a/chickadee/render/model.scm
+++ b/chickadee/render/model.scm
@@ -225,6 +225,9 @@
(make-phong-material
#:name name
#:ambient (assq-ref opts 'ambient)
+ #:ambient-map (assq-ref opts 'ambient-map)
+ #:use-ambient-map
+ (assq-ref opts 'use-ambient-map?)
#:diffuse (assq-ref opts 'diffuse)
#:diffuse-map (assq-ref opts 'diffuse-map)
#:use-diffuse-map
@@ -278,7 +281,17 @@
;; Force specular exponent to be a float.
(let ((new-shininess (* (string->number n) 1.0)))
(loop (cons (cons 'shininess new-shininess) opts))))
- (("map_Kd" . args)
+ (("map_Ka" . args) ; ambient map
+ (let* ((ambient-opts (parse-map-args args))
+ (file (scope-file (assq-ref ambient-opts
+ 'file-name)))
+ (texture (load-image file
+ #:min-filter 'linear
+ #:mag-filter 'linear)))
+ (loop (cons* (cons 'ambient-map texture)
+ (cons 'use-ambient-map? #t)
+ opts))))
+ (("map_Kd" . args) ; diffuse map
(let* ((diffuse-opts (parse-map-args args))
(file (scope-file (assq-ref diffuse-opts
'file-name)))
@@ -313,6 +326,8 @@
(maybe-add-material)
(loop `((name . ,new-name)
(ambient . ,(vec3 0.0 0.0 0.0))
+ (ambient-map . ,null-texture)
+ (use-ambient-map? . #f)
(diffuse . ,(vec3 0.0 0.0 0.0))
(diffuse-map . ,null-texture)
(use-diffuse-map? . #f)