]> git.jsancho.org Git - guile-assimp.git/commitdiff
A lot of functionality added
authorJavier Sancho <jsf@jsancho.org>
Fri, 25 Jul 2014 12:52:51 +0000 (14:52 +0200)
committerJavier Sancho <jsf@jsancho.org>
Fri, 25 Jul 2014 12:52:51 +0000 (14:52 +0200)
* src/assimp.scm: New foreign functions mapped:
  ai-get-material-color
  ai-get-material-float-array
  ai-get-material-integer-array
  ai-multiply-matrix3
  ai-identity-matrix3
  ai-identity-matrix4
  ai-transpose-matrix3
  ai-transpose-matrix4

* src/low-level.scm: New tools for C library support:
  define-assimp-function
  define-enumeration
  define-bitfield

* src/low-level/cimport.scm: New foreign functions defined:
  aiMultiplyMatrix3
  aiMultiplyMatrix4
  aiIdentityMatrix3
  aiIdentityMatrix4
  aiTransposeMatrix3
  aiTransposeMatrix4

* src/low-level/material.scm:
  Parsers: parse-aiMaterial, parse-aiMaterialProperty
  Enumerations: ai-material-key
  Functions: aiGetMaterialColor, aiGetMaterialFloatArray, aiGetMaterialIntegerArray

* src/low-level/postprocess.scm: Flags used when importing assets.

src/assimp.scm
src/low-level.scm
src/low-level/cimport.scm
src/low-level/material.scm
src/low-level/postprocess.scm [new file with mode: 0644]

index 917a6853732dece010142646e1294684b19cca5f..dad56342e5eff3afa8a23cbd42048090b615325c 100644 (file)
   #:use-module (assimp low-level material)
   #:use-module (assimp low-level matrix)
   #:use-module (assimp low-level mesh)
   #:use-module (assimp low-level material)
   #:use-module (assimp low-level matrix)
   #:use-module (assimp low-level mesh)
+  #:use-module (assimp low-level postprocess)
   #:use-module (assimp low-level scene)
   #:use-module (assimp low-level types)
   #:use-module (assimp low-level vector)
   #:use-module (assimp low-level scene)
   #:use-module (assimp low-level types)
   #:use-module (assimp low-level vector)
-  #:use-module (system foreign))
+  #:use-module (system foreign)
+  #:re-export (ai-material-key
+              ai-process-steps
+              ai-process-convert-to-left-handed
+              ai-process-preset-target-realtime-fast
+              ai-process-preset-target-realtime-quality
+              ai-process-preset-target-realtime-max-quality))
 
 
 ;;; Scenes
 
 
 ;;; Scenes
        ai-material-num-allocated)
 
 
        ai-material-num-allocated)
 
 
+(define-public (ai-get-material-color mat color-type)
+  (let ((pmat (unwrap-ai-material mat))
+       (pkey (string->pointer (car color-type)))
+       (type (cadr color-type))
+       (index (caddr color-type))
+       (pout (parse-aiColor4D (make-list 4 0) #:reverse #t)))
+    (let ((res (aiGetMaterialColor pmat pkey type index pout)))
+      (if (< res 0)
+         res
+         (wrap-ai-color4d pout)))))
+
+(define-public (ai-get-material-float-array mat color-type max)
+  (let ((pmat (unwrap-ai-material mat))
+       (pkey (string->pointer (car color-type)))
+       (type (cadr color-type))
+       (index (caddr color-type))
+       (pout (make-c-struct (make-list max float) '(0)))
+       (pmax (make-c-struct (list unsigned-int) (list max))))
+    (let ((res (aiGetMaterialFloatArray pmat pkey type index pout pmax)))
+      (if (< res 0)
+         res
+         (parse-c-struct pout (make-list max float))))))
+
+(define-public (ai-get-material-integer-array mat color-type max)
+  (let ((pmat (unwrap-ai-material mat))
+       (pkey (string->pointer (car color-type)))
+       (type (cadr color-type))
+       (index (caddr color-type))
+       (pout (make-c-struct (make-list max int) '(0)))
+       (pmax (make-c-struct (list unsigned-int) (list max))))
+    (let ((res (aiGetMaterialIntegerArray pmat pkey type index pout pmax)))
+      (if (< res 0)
+         res
+         (parse-c-struct pout (make-list max int))))))
+
+
 ;;; Faces
 
 (define-conversion-type parse-aiFace -> ai-face
 ;;; Faces
 
 (define-conversion-type parse-aiFace -> ai-face
     (aiTransformVecByMatrix4 cvec cmat)
     (wrap-ai-vector3d cvec)))
 
     (aiTransformVecByMatrix4 cvec cmat)
     (wrap-ai-vector3d cvec)))
 
+(define-public (ai-multiply-matrix3 m1 m2)
+  (let ((cm1 (parse-aiMatrix3x3 (map cdr (ai-matrix3x3-contents m1)) #:reverse #t))
+       (cm2 (parse-aiMatrix3x3 (map cdr (ai-matrix3x3-contents m2)) #:reverse #t)))
+    (aiMultiplyMatrix3 cm1 cm2)
+    (wrap-ai-matrix3x3 cm1)))
+
 (define-public (ai-multiply-matrix4 m1 m2)
   (let ((cm1 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m1)) #:reverse #t))
        (cm2 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m2)) #:reverse #t)))
     (aiMultiplyMatrix4 cm1 cm2)
     (wrap-ai-matrix4x4 cm1)))
 (define-public (ai-multiply-matrix4 m1 m2)
   (let ((cm1 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m1)) #:reverse #t))
        (cm2 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m2)) #:reverse #t)))
     (aiMultiplyMatrix4 cm1 cm2)
     (wrap-ai-matrix4x4 cm1)))
+
+(define-public (ai-identity-matrix3)
+  (let ((cmat (parse-aiMatrix3x3 (make-list 9 0) #:reverse #t)))
+    (aiIdentityMatrix3 cmat)
+    (wrap-ai-matrix3x3 cmat)))
+
+(define-public (ai-identity-matrix4)
+  (let ((cmat (parse-aiMatrix4x4 (make-list 16 0) #:reverse #t)))
+    (aiIdentityMatrix4 cmat)
+    (wrap-ai-matrix4x4 cmat)))
+
+(define-public (ai-transpose-matrix3 mat)
+  (let ((cmat (parse-aiMatrix3x3 (map cdr (ai-matrix3x3-contents mat)) #:reverse #t)))
+    (aiTransposeMatrix3 cmat)
+    (wrap-ai-matrix3x3 cmat)))
+
+(define-public (ai-transpose-matrix4 mat)
+  (let ((cmat (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents mat)) #:reverse #t)))
+    (aiTransposeMatrix4 cmat)
+    (wrap-ai-matrix4x4 cmat)))
index fd7af9ddea932881e7decdd718c69107d0bde48a..148b26d9b102e5e41b5824c9d095f3785921e54b 100644 (file)
@@ -21,6 +21,8 @@
   #:use-module (system foreign))
 
 
   #:use-module (system foreign))
 
 
+;;; Generic Functions
+
 (define (mk-string . args)
   (string-concatenate
    (map (lambda (a)
 (define (mk-string . args)
   (string-concatenate
    (map (lambda (a)
                                 (dynamic-func name-string foreign-lib)
                                 (list arg-type ...))))))))
 
                                 (dynamic-func name-string foreign-lib)
                                 (list arg-type ...))))))))
 
-(export-syntax define-foreign-function)
+
+(define libassimp (dynamic-link "libassimp"))
+
+(define-syntax define-assimp-function
+  (syntax-rules (->)
+    ((_ (name arg-type ...) -> return-type)
+     (define-foreign-function ((libassimp name) arg-type ...) -> return-type))))
+
+
+(export-syntax define-foreign-function
+              define-assimp-function)
+
+
+;;; Enumerators and bitfields (copìed from figl code, thanks to Andy Wingo
+
+(define-syntax-rule (define-enumeration enumerator (name value) ...)
+  (define-syntax enumerator
+    (lambda (x)
+      (syntax-case x ()
+        ((_)
+         #''(name ...))
+        ((_ enum) (number? (syntax->datum #'enum))
+         #'enum)
+        ((_ enum)
+         #'(or (assq-ref `((name . ,(syntax->datum value)) ...)
+                        (syntax->datum #'enum))
+              (syntax-violation 'enumerator "invalid enumerated value"
+                                #'enum)))))))
+
+(define-syntax-rule (define-bitfield bitfield (name value) ...)
+  (define-syntax bitfield
+    (lambda (x)
+      (syntax-case x () 
+        ((_)
+         #''(name ...))
+        ((_ bit (... ...))
+         #`(logior
+            #,@(map
+                (lambda (bit)
+                  (let ((datum (syntax->datum bit)))
+                    (if (number? datum)
+                        datum
+                        (or (assq-ref '((name . value) ...) datum)
+                            (syntax-violation 'bitfield "invalid bitfield value"
+                                              bit)))))
+                #'(bit (... ...)))))))))
+
+(export-syntax define-enumeration
+              define-bitfield)
index b0d71e7e252e4c7fe896df4aeb8206416f131c04..023dc7a44f42456c97e1d1cf5fa795b8365bc0bd 100644 (file)
   #:use-module (system foreign)
   #:export (aiImportFile
            aiTransformVecByMatrix4
   #:use-module (system foreign)
   #:export (aiImportFile
            aiTransformVecByMatrix4
-           aiMultiplyMatrix4))
-
-(define libassimp (dynamic-link "libassimp"))
-
-(define-syntax define-assimp-function
-  (syntax-rules (->)
-    ((_ (name arg-type ...) -> return-type)
-     (define-foreign-function ((libassimp name) arg-type ...) -> return-type))))
+           aiMultiplyMatrix3
+           aiMultiplyMatrix4
+           aiIdentityMatrix3
+           aiIdentityMatrix4
+           aiTransposeMatrix3
+           aiTransposeMatrix4))
 
 (define-assimp-function (aiImportFile '* unsigned-int) -> '*)
 (define-assimp-function (aiTransformVecByMatrix4 '* '*) -> void)
 
 (define-assimp-function (aiImportFile '* unsigned-int) -> '*)
 (define-assimp-function (aiTransformVecByMatrix4 '* '*) -> void)
+(define-assimp-function (aiMultiplyMatrix3 '* '*) -> void)
 (define-assimp-function (aiMultiplyMatrix4 '* '*) -> void)
 (define-assimp-function (aiMultiplyMatrix4 '* '*) -> void)
+(define-assimp-function (aiIdentityMatrix3 '*) -> void)
+(define-assimp-function (aiIdentityMatrix4 '*) -> void)
+(define-assimp-function (aiTransposeMatrix3 '*) -> void)
+(define-assimp-function (aiTransposeMatrix4 '*) -> void)
index a67a762980f63cc187e951c1b3461fe4ebbf5dfe..2b3ade15d05ee94a0c5c5f4e110239ef1dfdd376 100644 (file)
 
 (define-module (assimp low-level material)
   #:use-module (assimp low-level)
 
 (define-module (assimp low-level material)
   #:use-module (assimp low-level)
-  #:use-module (system foreign))
+  #:use-module (assimp low-level types)
+  #:use-module (system foreign)
+  #:export (parse-aiMaterial
+           parse-aiMaterialProperty
+           ai-material-key
+           aiGetMaterialColor
+           aiGetMaterialFloatArray
+           aiGetMaterialIntegerArray))
 
 
 
 
+(define-struct-parser parse-aiMaterialProperty
+  (mKey aiString-type)
+  (mSemantic unsigned-int)
+  (mIndex unsigned-int)
+  (mDataLength unsigned-int)
+  (mType unsigned-int)
+  (mData '*))
+
 (define-struct-parser parse-aiMaterial
   (mProperties '*)
   (mNumProperties unsigned-int)
   (mNumAllocated unsigned-int))
 
 (define-struct-parser parse-aiMaterial
   (mProperties '*)
   (mNumProperties unsigned-int)
   (mNumAllocated unsigned-int))
 
-(export parse-aiMaterial)
+
+(define-enumeration
+  ai-material-key
+  (name '("?mat.name" 0 0))
+  (twosided '("$mat.twosided" 0 0))
+  (shading-model '("$mat.shadingm" 0 0))
+  (enable-wireframe '("$mat.wireframe" 0 0))
+  (blend-func '("$mat.blend" 0 0))
+  (opacity '("$mat.opacity" 0 0))
+  (bumpscaling '("$mat.bumpscaling" 0 0))
+  (shininess '("$mat.shininess" 0 0))
+  (reflectivity '("$mat.reflectivity" 0 0))
+  (shininess-strength '("$mat.shinpercent" 0 0))
+  (refracti '("$mat.refracti" 0 0))
+  (color-diffuse '("$clr.diffuse" 0 0))
+  (color-ambient '("$clr.ambient" 0 0))
+  (color-specular '("$clr.specular" 0 0))
+  (color-emissive '("$clr.emissive" 0 0))
+  (color-transparent '("$clr.transparent" 0 0))
+  (color-reflective '("$clr.reflective" 0 0))
+  (global-background-image '("?bg.global" 0 0)))
+
+
+(define-assimp-function (aiGetMaterialColor '* '* unsigned-int unsigned-int '*) -> int)
+(define-assimp-function (aiGetMaterialFloatArray '* '* unsigned-int unsigned-int '* '*) -> int)
+(define-assimp-function (aiGetMaterialIntegerArray '* '* unsigned-int unsigned-int '* '*) -> int)
diff --git a/src/low-level/postprocess.scm b/src/low-level/postprocess.scm
new file mode 100644 (file)
index 0000000..20ca550
--- /dev/null
@@ -0,0 +1,92 @@
+;;; guile-assimp, foreign interface to libassimp
+;;; Copyright (C) 2014 by Javier Sancho Fernandez <jsf at jsancho dot org>
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+(define-module (assimp low-level postprocess)
+  #:use-module (assimp low-level)
+  #:export (ai-process-steps
+           ai-process-convert-to-left-handed
+           ai-process-preset-target-realtime-fast
+           ai-process-preset-target-realtime-quality
+           ai-process-preset-target-realtime-max-quality))
+
+
+(define-bitfield
+  ai-process-steps
+  (calc-tangent-space #x1)
+  (join-identical-vertices #x2)
+  (make-left-handed #x4)
+  (triangulate #x8)
+  (remove-component #x10)
+  (gen-normals #x20)
+  (gen-smooth-normals #x40)
+  (split-large-meshes #x80)
+  (pretransform-vertices #x100)
+  (limit-bone-weights #x200)
+  (validate-data-structure #x400)
+  (improve-cache-locality #x800)
+  (remove-redundant-materials #x1000)
+  (fix-infacing-normals #x2000)
+  (sort-by-ptype #x8000)
+  (find-degenerates #x10000)
+  (find-invalid-data #x20000)
+  (gen-UV-coords #x40000)
+  (transform-UV-coords #x80000)
+  (find-instances #x100000)
+  (optimize-meshes #x200000)
+  (optimize-graph #x400000)
+  (flip-UVs #x800000)
+  (flip-winding-order #x1000000)
+  (split-by-bone-count #x2000000)
+  (debone #x4000000))
+
+(define ai-process-convert-to-left-handed
+  (ai-process-steps
+   make-left-handed
+   flip-UVs
+   flip-winding-order))
+
+(define ai-process-preset-target-realtime-fast
+  (ai-process-steps
+   calc-tangent-space
+   gen-normals
+   join-identical-vertices
+   triangulate
+   gen-UV-coords
+   sort-by-ptype))
+
+(define ai-process-preset-target-realtime-quality
+  (ai-process-steps
+   calc-tangent-space
+   gen-smooth-normals
+   join-identical-vertices
+   improve-cache-locality
+   limit-bone-weights
+   remove-redundant-materials
+   split-large-meshes
+   triangulate
+   gen-UV-coords
+   sort-by-ptype
+   find-degenerates
+   find-invalid-data))
+
+(define ai-process-preset-target-realtime-max-quality
+  (+ ai-process-preset-target-realtime-quality
+     (ai-process-steps
+      find-instances
+      validate-data-structure
+      optimize-meshes
+      debone)))