1 ;;; guile-assimp, foreign interface to libassimp
2 ;;; Copyright (C) 2014 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 (define-module (assimp assimp)
19 #:use-module (assimp low-level)
20 #:use-module (assimp low-level cimport)
21 #:use-module (assimp low-level color)
22 #:use-module (assimp low-level material)
23 #:use-module (assimp low-level matrix)
24 #:use-module (assimp low-level mesh)
25 #:use-module (assimp low-level scene)
26 #:use-module (assimp low-level types)
27 #:use-module (assimp low-level vector)
28 #:use-module (system foreign))
33 (define-conversion-type parse-aiScene -> ai-scene
34 (flags (field 'mFlags))
35 (root-node (wrap (field 'mRootNode) wrap-ai-node))
36 (meshes (wrap (array (field 'mNumMeshes) (field 'mMeshes)) wrap-ai-mesh))
37 (materials (wrap (array (field 'mNumMaterials) (field 'mMaterials)) wrap-ai-material))
38 (animations (array (field 'mNumAnimations) (field 'mAnimations)))
39 (textures (array (field 'mNumTextures) (field 'mTextures)))
40 (lights (array (field 'mNumLights) (field 'mLights)))
41 (cameras (array (field 'mNumCameras) (field 'mCameras))))
57 (define-conversion-type parse-aiNode -> ai-node
58 (name (sized-string (field 'mName)))
59 (transformation (wrap (parse-aiMatrix4x4 (field 'mTransformation) #:reverse #t) wrap-ai-matrix4x4))
60 (parent (wrap (field 'mParent) wrap-ai-node))
61 (children (wrap (array (field 'mNumChildren) (field 'mChildren)) wrap-ai-node))
62 (meshes (array (field 'mNumMeshes) (field 'mMeshes))))
67 ai-node-transformation
75 (define-conversion-type parse-aiMesh -> ai-mesh
76 (name (sized-string (field 'mName)))
77 (primitive-types (field 'mPrimitiveTypes))
79 (array (field 'mNumVertices) (field 'mVertices) #:element-proc get-element-address)
82 (array (field 'mNumFaces) (field 'mFaces) #:element-size 8 #:element-proc get-element-address)
85 (array (field 'mNumVertices) (field 'mNormals) #:element-size 12 #:element-proc get-element-address)
88 (array (field 'mNumVertices) (field 'mTangents) #:element-size 12 #:element-proc get-element-address)
91 (array (field 'mNumVertices) (field 'mBitangents) #:element-size 12 #:element-proc get-element-address)
96 (array (field 'mNumVertices) c #:element-size 16 #:element-proc get-element-address)
102 (array (field 'mNumVertices) tc #:element-size 12 #:element-proc get-element-address)
104 (field 'mTextureCoords)))
105 (num-uv-components (field 'mNumUVComponents))
106 (bones (wrap (array (field 'mNumBones) (field 'mBones)) wrap-ai-bone))
107 (material-index (field 'mMaterialIndex)))
112 ai-mesh-primitive-types
119 ai-mesh-texture-coords
120 ai-mesh-num-uv-components
122 ai-mesh-material-index)
127 (define-conversion-type parse-aiMaterial -> ai-material
128 (properties (array (field 'mNumProperties) (field 'mProperties)))
129 (num-allocated (field 'mNumAllocated)))
133 ai-material-properties
134 ai-material-num-allocated)
139 (define-conversion-type parse-aiFace -> ai-face
140 (indices (array (field 'mNumIndices) (field 'mIndices))))
149 (define-conversion-type parse-aiVector2D -> ai-vector2d
158 (define-conversion-type parse-aiVector3D -> ai-vector3d
172 (define-conversion-type parse-aiMatrix3x3 -> ai-matrix3x3
183 (export ai-matrix3x3?
184 ai-matrix3x3-contents
195 (define-conversion-type parse-aiMatrix4x4 -> ai-matrix4x4
213 (export ai-matrix4x4?
214 ai-matrix4x4-contents
235 (define-conversion-type parse-aiColor4D -> ai-color4d
251 (define-conversion-type parse-aiBone -> ai-bone
252 (name (sized-string (field 'mName)))
254 (array (field 'mNumWeights) (field 'mWeights) #:element-size 8 #:element-proc get-element-address)
255 wrap-ai-vertex-weight))
256 (offset-matrix (wrap (parse-aiMatrix4x4 (field 'mOffsetMatrix) #:reverse #t) wrap-ai-matrix4x4)))
262 ai-bone-offset-matrix)
267 (define-conversion-type parse-aiVertexWeight -> ai-vertex-weight
268 (vertex-id (field 'mVertexId))
269 (weight (field 'mWeight)))
271 (export ai-vertex-weight?
272 ai-vertex-weight-contents
273 ai-vertex-weight-vertex-id
274 ai-vertex-weight-weight)
279 (define-public (ai-import-file filename flags)
281 (aiImportFile (string->pointer filename)
284 (define-public (ai-transform-vec-by-matrix4 vec mat)
285 (let ((cvec (parse-aiVector3D (map cdr (ai-vector3d-contents vec)) #:reverse #t))
286 (cmat (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents mat)) #:reverse #t)))
287 (aiTransformVecByMatrix4 cvec cmat)
288 (wrap-ai-vector3d cvec)))
290 (define-public (ai-multiply-matrix4 m1 m2)
291 (let ((cm1 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m1)) #:reverse #t))
292 (cm2 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m2)) #:reverse #t)))
293 (aiMultiplyMatrix4 cm1 cm2)
294 (wrap-ai-matrix4x4 cm1)))