X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fassimp.scm;h=dad56342e5eff3afa8a23cbd42048090b615325c;hb=fe037abb54b99784fa30c9f8ffa1c594482b97bf;hp=5c8ccd2b99df311616aa3d2eb292d1be4e818ad2;hpb=3232da94d35e82b13b04e703fe68c5f1f3232838;p=guile-assimp.git diff --git a/src/assimp.scm b/src/assimp.scm index 5c8ccd2..dad5634 100644 --- a/src/assimp.scm +++ b/src/assimp.scm @@ -20,11 +20,19 @@ #:use-module (assimp low-level cimport) #:use-module (assimp low-level color) #: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 (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 @@ -55,7 +63,7 @@ (define-conversion-type parse-aiNode -> ai-node (name (sized-string (field 'mName))) - (transformation (field 'mTransformation)) + (transformation (wrap (parse-aiMatrix4x4 (field 'mTransformation) #:reverse #t) wrap-ai-matrix4x4)) (parent (wrap (field 'mParent) wrap-ai-node)) (children (wrap (array (field 'mNumChildren) (field 'mChildren)) wrap-ai-node)) (meshes (array (field 'mNumMeshes) (field 'mMeshes)))) @@ -133,6 +141,42 @@ 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 @@ -166,6 +210,69 @@ ai-vector3d-z) +;;; Matrixes + +(define-conversion-type parse-aiMatrix3x3 -> ai-matrix3x3 + (a1 (field 'a1)) + (a2 (field 'a2)) + (a3 (field 'a3)) + (b1 (field 'b1)) + (b2 (field 'b2)) + (b3 (field 'b3)) + (c1 (field 'c1)) + (c2 (field 'c2)) + (c3 (field 'c3))) + +(export ai-matrix3x3? + ai-matrix3x3-contents + ai-matrix3x3-a1 + ai-matrix3x3-a2 + ai-matrix3x3-a3 + ai-matrix3x3-b1 + ai-matrix3x3-b2 + ai-matrix3x3-b3 + ai-matrix3x3-c1 + ai-matrix3x3-c2 + ai-matrix3x3-c3) + +(define-conversion-type parse-aiMatrix4x4 -> ai-matrix4x4 + (a1 (field 'a1)) + (a2 (field 'a2)) + (a3 (field 'a3)) + (a4 (field 'a4)) + (b1 (field 'b1)) + (b2 (field 'b2)) + (b3 (field 'b3)) + (b4 (field 'b4)) + (c1 (field 'c1)) + (c2 (field 'c2)) + (c3 (field 'c3)) + (c4 (field 'c4)) + (d1 (field 'd1)) + (d2 (field 'd2)) + (d3 (field 'd3)) + (d4 (field 'd4))) + +(export ai-matrix4x4? + ai-matrix4x4-contents + ai-matrix4x4-a1 + ai-matrix4x4-a2 + ai-matrix4x4-a3 + ai-matrix4x4-a4 + ai-matrix4x4-b1 + ai-matrix4x4-b2 + ai-matrix4x4-b3 + ai-matrix4x4-b4 + ai-matrix4x4-c1 + ai-matrix4x4-c2 + ai-matrix4x4-c3 + ai-matrix4x4-c4 + ai-matrix4x4-d1 + ai-matrix4x4-d2 + ai-matrix4x4-d3 + ai-matrix4x4-d4) + + ;;; Colors (define-conversion-type parse-aiColor4D -> ai-color4d @@ -189,7 +296,7 @@ (weights (wrap (array (field 'mNumWeights) (field 'mWeights) #:element-size 8 #:element-proc get-element-address) wrap-ai-vertex-weight)) - (offset-matrix (field 'mOffsetMatrix))) + (offset-matrix (wrap (parse-aiMatrix4x4 (field 'mOffsetMatrix) #:reverse #t) wrap-ai-matrix4x4))) (export ai-bone? ai-bone-contents @@ -217,8 +324,40 @@ (aiImportFile (string->pointer filename) flags))) +(define-public (ai-transform-vec-by-matrix4 vec mat) + (let ((cvec (parse-aiVector3D (map cdr (ai-vector3d-contents vec)) #:reverse #t)) + (cmat (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents mat)) #:reverse #t))) + (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 (make-c-struct aiMatrix4x4-type m1)) - (cm2 (make-c-struct aiMatrix4x4-type 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) - (parse-c-struct cm1 aiMatrix4x4-type))) + (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)))