#: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 scene)
#:use-module (assimp low-level types)
(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))))
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
(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
flags)))
(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)))
#:use-module (system foreign))
+(define (mk-string . args)
+ (string-concatenate
+ (map (lambda (a)
+ (if (string? a)
+ a
+ (symbol->string (syntax->datum a))))
+ args)))
+
+(define (lambda-mk-symbol x)
+ (lambda args
+ (datum->syntax x
+ (string->symbol
+ (apply mk-string args)))))
+
+
;;; Parsers Definition
(define-syntax define-struct-parser
((_ name (field type) ...)
(with-syntax (((field-name ...) (map car #'((field type) ...)))
((field-type ...) (map cadr #'((field type) ...))))
- #'(define (name pointer)
- (map cons
- '(field-name ...)
- (parse-c-struct pointer (list field-type ...)))))))))
+ #'(define* (name pointer-or-data #:key (reverse #f))
+ (cond (reverse
+ (make-c-struct
+ (list field-type ...)
+ pointer-or-data))
+ (else
+ (map cons
+ '(field-name ...)
+ (parse-c-struct pointer-or-data (list field-type ...)))))))))))
(export-syntax define-struct-parser)
(define-syntax define-conversion-type
(lambda (x)
- (define (mk-string . args)
- (string-concatenate
- (map (lambda (a)
- (if (string? a)
- a
- (symbol->string (syntax->datum a))))
- args)))
- (define (mk-symbol . args)
- (datum->syntax x
- (string->symbol
- (apply mk-string args))))
+ (define mk-symbol (lambda-mk-symbol x))
(syntax-case x (->)
((_ parser -> name (field-name field-proc) ...)
(with-syntax ((type? (mk-symbol #'name "?"))
--- /dev/null
+;;; 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 matrix)
+ #:use-module (assimp low-level)
+ #:use-module (system foreign))
+
+
+(define-struct-parser parse-aiMatrix3x3
+ (a1 float)
+ (a2 float)
+ (a3 float)
+ (b1 float)
+ (b2 float)
+ (b3 float)
+ (c1 float)
+ (c2 float)
+ (c3 float))
+
+(define-struct-parser parse-aiMatrix4x4
+ (a1 float)
+ (a2 float)
+ (a3 float)
+ (a4 float)
+ (b1 float)
+ (b2 float)
+ (b3 float)
+ (b4 float)
+ (c1 float)
+ (c2 float)
+ (c3 float)
+ (c4 float)
+ (d1 float)
+ (d2 float)
+ (d3 float)
+ (d4 float))
+
+(export parse-aiMatrix3x3
+ parse-aiMatrix4x4)